aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/run.zc
blob: 60193a788daf62d74e957db985c8cb0ff1c85e4b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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;
}