Hello world
This is the smallest Mox program that prints something. Make sure you did the setup first.
The program
Save this as hello.mox:
import "std.mox";
#linkc fn main(): i32 {
println("hello {}!", .{ "world" });
return 0;
}
Line by line:
import "std.mox";loads the standard module. It hasprintlnand many other helpers.#linkcgives the function a plain C name. The C runtime callsmain, so it must have a C name.printlnprints a line. Each{}in the text is replaced with the next value from the list.{ ... }.
Build and run
Pass the file to the compiler:
mox ./hello.mox
The compiler makes hello.mox.obj, then calls clang to link it into hello.mox.exe. Run it:
./hello.mox.exe
It prints hello world!.
To choose the output name and turn on optimizations:
mox ./hello.mox -O3 -o=./hello
Comments
// one line comment
/* comment
on many lines */
Next: Compiler options.