about summary refs log tree commit diff
path: root/boot/tests/lower/endless_loop.cskt
diff options
context:
space:
mode:
authorMel <mel@rnrd.eu>2026-05-28 00:29:53 +0200
committerMel <mel@rnrd.eu>2026-05-28 00:29:53 +0200
commit7db79f43b431b94d525308699a87a3daeff31d92 (patch)
tree7b6a6d10dc064c5ae54791dc1b65c8d42233b97a /boot/tests/lower/endless_loop.cskt
parentec2029cba68b1d25e1e1119d37318c1b0c581a83 (diff)
downloadcatskill-7db79f43b431b94d525308699a87a3daeff31d92.tar.zst
catskill-7db79f43b431b94d525308699a87a3daeff31d92.zip
Split endless and while loops into `loop` and `while`
Signed-off-by: Mel <mel@rnrd.eu>
Diffstat (limited to 'boot/tests/lower/endless_loop.cskt')
-rw-r--r--boot/tests/lower/endless_loop.cskt39
1 files changed, 39 insertions, 0 deletions
diff --git a/boot/tests/lower/endless_loop.cskt b/boot/tests/lower/endless_loop.cskt
new file mode 100644
index 0000000..692597a
--- /dev/null
+++ b/boot/tests/lower/endless_loop.cskt
@@ -0,0 +1,39 @@
+an endless `loop` block lowers to the single ir loop kind, with a
+synthetic `true` condition. exiting the loop requires an explicit
+`break` from inside the body.
+
+<<<
+
+main = fun () {
+    var count int = 0
+    loop {
+        count++
+        if count == 5 {
+            break
+        }
+    }
+}
+
+>>>
+
+(unit
+	(types
+		(type 0 int primitive)
+		(type 1 uint primitive)
+		(type 2 bool primitive)
+		(type 3 string primitive)
+		(type 4 float primitive)
+		(type 5 byte primitive)
+		(type 6 ascii primitive)
+		(type 7 void primitive))
+	(functions
+		(function 0 main main (returns (ref void)) (block
+			(declaration count (ref int) (initializer (expr 0)))
+			(loop (condition (expr true)) (block
+				(expression-stmt (expr (postfix-++ (expr (name count)))))
+				(conditional (when (expr (binary == (expr (name count)) (expr 5)))) (block
+					(break)
+				))
+			))
+		)))
+	(emission_order 0 1 2 3 4 5 6 7))