namespace run; include rt; // run-only image: the runtime, a collector root set, and start. there is no // resident compiler and none of its tables. put this between rt.zc and a // program that defines main. zc0 accepts the bootstrap subset; build.zc uses // the self-hosted compiler for typed programs and library receiver methods. // // cat build/run/rt.zc src/runtime/run.zc examples/hello.zc | ./zc0 >build/run/genome.h // the program's entry point, written by the program (see start). the prototype is untyped so // that main may be declared int, void or untyped, as in any other program: its value is ignored. namespace; fn main(); namespace run; include rt; // the collector's roots: the code and globals, the program's frames and the // operand stack. the collector marks from these before it frees anything. int gc_roots() { rt.markrange(0, rt.CODE_END); rt.markrange(rt.GORG, rt.GORG[6]); rt.gc_frames(); rt.markrange(rt.dsp(), rt.data_top); return 0; } // install enhancement descriptors from the image's symbol table before any // runtime arithmetic uses their opcodes. kind 6 is an enhancement record. int install_enhancements() { word p = rt.GORG[5], name; while (*p) { if (p[0] == 6 && rt.install(p[2] >> 8) < 0) { rt.put_s("run: cannot install image enhancement\n"); rt.syscall(rt.SYS_EXIT, 2, 0, 0); } name = p + 3; while (*name) name++; p = name + 1; } return 0; } // the first code a run-only image executes: initialize the runtime, run main and halt. int start() { install_enhancements(); rt.heap_init(); main(); rt.halt(); return 0; }