aboutsummaryrefslogtreecommitdiff
path: root/docs/history/15-o3/code/examples/repl.zc
diff options
context:
space:
mode:
authorGravatar Moon Flower <moonflower@elhenney.local> 2026-10-12 08:46:23 +0330
committerGravatar Moon Flower <moonflower@elhenney.local> 2026-10-12 08:46:23 +0330
commitecc350ca5c2eb50be8309c5f14f8bf0d87db9a02 (patch)
tree70e0af76a1b13affff7c6cc8aac7b3e6ef960478 /docs/history/15-o3/code/examples/repl.zc
a
Diffstat (limited to 'docs/history/15-o3/code/examples/repl.zc')
-rw-r--r--docs/history/15-o3/code/examples/repl.zc27
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;
+}