diff options
Diffstat (limited to 'docs/history/15-o3/code/examples/repl.zc')
| -rw-r--r-- | docs/history/15-o3/code/examples/repl.zc | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/docs/history/15-o3/code/examples/repl.zc b/docs/history/15-o3/code/examples/repl.zc new file mode 100644 index 0000000..b7b81b8 --- /dev/null +++ b/docs/history/15-o3/code/examples/repl.zc @@ -0,0 +1,27 @@ +// 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 = getc(); + 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; +} |
