Hello, World!
Write the program
Section titled “Write the program”Create a file called hello.mw:
@import("std")
@export fn main(argc: i32, argv: rawptr) -> i32 { println("Hello from Marrow !");
print("Received arg count: "); println_i64(cast(i64) argc);
ret 0;};A few things worth noticing already (all covered in depth in the Language reference):
@import("std")pulls in the standard library’s umbrella module (std/std.mw), which in turn importsio.mw,mem.mw,string.mw,sys.mw,vec.mwandmap.mwfor you. This is what makesprintln,printandprintln_i64available.@exportmarksmainas an externally-visible symbol — required for the C linker to find your entry point.argc: i32, argv: rawptrmirrors the Cint argc, char** argvsignature, since Marrow programs are linked against the C runtime’s_start/mainmachinery.cast(i64) argcexplicitly converts thei32to ani64before it’s passed toprintln_i64.- Every statement ends in
;, including the closing}of the top-levelfndeclaration.
Compile it
Section titled “Compile it”marrow hello.mwThis single command runs the whole pipeline:
- Parses
hello.mwand resolves its@imports. - Generates QBE IL into
hello.ssa(the default output path — see CLI reference to override it). - Invokes
qbe hello.ssa -o hello.sto produce native assembly. - Since the program is not a library (no
@no_mainanywhere in the file), invokes your system C compiler to assemble and linkhello.sdirectly into an executable named after the input file with its extension stripped:hello.
On success you’ll see:
Compilation successful! Executable created at: helloRun it
Section titled “Run it”./hello arg1 arg2Hello from Marrow !Received arg count: 3(argc is 3 because the program’s own name counts as argv[0], per the usual C convention.)
Compiling a library instead of a binary
Section titled “Compiling a library instead of a binary”If your file is decorated with @no_main anywhere (this is how every file in std/ is written), marrow treats it as a library: it stops after producing an object file instead of linking an executable, and tells you how to link it yourself:
Library compiled (no 'main', see '@no_main'): hello.oLink it into a program with: cc your_program.o hello.o -o your_programSee Modules & decorators for the full explanation of @no_main, @export, @extern and @import.