aboutsummaryrefslogtreecommitdiff
path: root/examples/repl.zc
blob: 235063ff800a0322f491e5e65086a49f5d6036cd (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
// a repl on the resident compiler: each backtick-separated chunk of input is
// compiled as a function body and run. definitions (fn ...) can be loaded too:
// a chunk that starts with "fn" goes through load instead of eval.
let buf[4000];
fn readchunk() {
	let n = 0, c;
	while (!eof()) {
		c = get_c();
		if (c == 96) break;
		if (n < 3999) { buf[n] = c; n++; }
	}
	buf[n] = 0;
	return n;
}
fn main() {
	let q, i;
	while (!eof()) {
		readchunk();
		q = tokens(buf);
		if (q[0] && q[1] == T_ID && q[2] == intern("fn")) load(q);
		else eval(q);
		free(d*q);
	}
	return 0;
}