aboutsummaryrefslogtreecommitdiff
path: root/tests/programs/misc.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 /tests/programs/misc.zc
a
Diffstat (limited to 'tests/programs/misc.zc')
-rw-r--r--tests/programs/misc.zc27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/programs/misc.zc b/tests/programs/misc.zc
new file mode 100644
index 0000000..530322a
--- /dev/null
+++ b/tests/programs/misc.zc
@@ -0,0 +1,27 @@
+// ct { ... } runs a block while compiling and leaves its result as a constant
+immediate fn ct() {
+ let q, v;
+ next();
+ q = grab();
+ v = eval(q);
+ free(d*q);
+ lit(v);
+ return 0;
+}
+// teach the asm syntax that p means out, like the old repl demo
+immediate fn teach() { next(); mnem[12] = 'p'; return 0; }
+teach
+
+fn countdown() {
+ asm { 5 :top 0 $ '0' + p 1 - 0 $ done z top j :done _ 10 p }
+ return 0;
+}
+fn main() {
+ put_n(ct { let i = 0, s = 0; while (i < 10) { s += i; i++; } return s; }); put_c(10);
+ countdown();
+ put_s(lazy()); put_c(10);
+ return 0;
+}
+// the analyzer is off from here on
+unchecked;
+fn lazy() { let p = new(3); p[0] = 'o'; p[1] = 'k'; return p; }