From ecc350ca5c2eb50be8309c5f14f8bf0d87db9a02 Mon Sep 17 00:00:00 2001 From: Moon Flower Date: Mon, 12 Oct 2026 08:46:23 +0330 Subject: a --- docs/history/13-gap-fixes/code/examples/repl.zc | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 docs/history/13-gap-fixes/code/examples/repl.zc (limited to 'docs/history/13-gap-fixes/code/examples/repl.zc') diff --git a/docs/history/13-gap-fixes/code/examples/repl.zc b/docs/history/13-gap-fixes/code/examples/repl.zc new file mode 100644 index 0000000..b7b81b8 --- /dev/null +++ b/docs/history/13-gap-fixes/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; +} -- cgit v1.2.3