diff options
| author | 2026-10-12 08:46:23 +0330 | |
|---|---|---|
| committer | 2026-10-12 08:46:23 +0330 | |
| commit | ecc350ca5c2eb50be8309c5f14f8bf0d87db9a02 (patch) | |
| tree | 70e0af76a1b13affff7c6cc8aac7b3e6ef960478 /examples/repl.zc | |
a
Diffstat (limited to 'examples/repl.zc')
| -rw-r--r-- | examples/repl.zc | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/examples/repl.zc b/examples/repl.zc new file mode 100644 index 0000000..235063f --- /dev/null +++ b/examples/repl.zc @@ -0,0 +1,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; +} |
