diff options
Diffstat (limited to 'src/runtime/run.zc')
| -rw-r--r-- | src/runtime/run.zc | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/src/runtime/run.zc b/src/runtime/run.zc index 60193a7..a8f82e2 100644 --- a/src/runtime/run.zc +++ b/src/runtime/run.zc @@ -1,27 +1,50 @@ +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, and compile with zc0 (the program has to stay in -// the stage-0 subset: no types, no quote, no parse words). +// 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). +namespace; int 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() { - markrange(0, CODE_END); - markrange(GORG, GORG[6]); - gc_frames(); - markrange(dsp(), data_top); + 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: it sets up the heap, runs main and halts. +// the first code a run-only image executes: initialize the runtime, run main and halt. int start() { - heap_init(); + install_enhancements(); + rt.heap_init(); main(); - halt(); + rt.halt(); return 0; } |
