diff options
Diffstat (limited to 'examples/repl.zc')
| -rw-r--r-- | examples/repl.zc | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/examples/repl.zc b/examples/repl.zc index 235063f..bff96c3 100644 --- a/examples/repl.zc +++ b/examples/repl.zc @@ -1,25 +1,28 @@ +namespace; +include rt, run; + // 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(); + while (!rt.eof()) { + c = rt.get_c(); if (c == 96) break; if (n < 3999) { buf[n] = c; n++; } } buf[n] = 0; return n; } -fn main() { +void main() { let q, i; - while (!eof()) { + while (!rt.eof()) { readchunk(); - q = tokens(buf); - if (q[0] && q[1] == T_ID && q[2] == intern("fn")) load(q); - else eval(q); - free(d*q); + q = run.tokens(buf); + if (q[0] && q[1] == run.T_ID && q[2] == run.intern("fn")) run.load(q); + else run.eval(q); + rt.free(q); } - return 0; + return; } |
