aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/run.zc
diff options
context:
space:
mode:
authorGravatar Moon Flower <moonflower@elhenney.local> 2026-10-12 08:46:23 +0330
committerGravatar Moon Flower <moonflower@elhenney.local> 2026-10-12 08:46:23 +0330
commitecc350ca5c2eb50be8309c5f14f8bf0d87db9a02 (patch)
tree70e0af76a1b13affff7c6cc8aac7b3e6ef960478 /src/runtime/run.zc
a
Diffstat (limited to 'src/runtime/run.zc')
-rw-r--r--src/runtime/run.zc27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/runtime/run.zc b/src/runtime/run.zc
new file mode 100644
index 0000000..60193a7
--- /dev/null
+++ b/src/runtime/run.zc
@@ -0,0 +1,27 @@
+// 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).
+//
+// 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).
+int main();
+
+// 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);
+ return 0;
+}
+
+// the first code a run-only image executes: it sets up the heap, runs main and halts.
+int start() {
+ heap_init();
+ main();
+ halt();
+ return 0;
+}