Swift プログラムの動かし方
// hello.swift
let message = "hello, world!"
print(message)
スクリプト(Immediate Mode)
swiftコマンドを利用して、swiftファイルを実行する。
$ swift hello.swift
hello, world!
$
インタプリタ(REPL Mode : Read Eval Print Loop)
swiftコマンドを実行し、逐次実行を行う。:quit, :q, ^D で終了。
$ swift 1> let message = "hello, world!" message: String = "hello, world!" 2> print(message) hello, world! 3> :quit $
コンパイラ(Batch Mode)
swiftcコマンドを利用して、実行可能なアプリを作成する。
$ swiftc hello.swift $ ./hello hello, world! $
実行イメージ:実際には以下の流れでコマンドが実行さるわけではありません。
- vi sample.c
- swiftc -emit-ir hello.swift -o hello.ll
- llvm-as hello.ll -o hello.bc
- llc hello.bc –o hello.s
- as hello.s -o hello.o
- ld hello.o -lobjc -lSystem -o hello