about summary refs log tree commit diff
path: root/boot/tests
diff options
context:
space:
mode:
Diffstat (limited to 'boot/tests')
-rw-r--r--boot/tests/lower/endless_loop.cskt39
-rw-r--r--boot/tests/parse/loops.cskt9
2 files changed, 48 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))
diff --git a/boot/tests/parse/loops.cskt b/boot/tests/parse/loops.cskt
index 45b1040..8e5feba 100644
--- a/boot/tests/parse/loops.cskt
+++ b/boot/tests/parse/loops.cskt
@@ -16,6 +16,11 @@ while y < 10 {
   y++
 }
 
+loop {
+  print(0)
+  break
+}
+
 >>>
 
 (loop for-each (declaration i (type name uint) (initializer (expr (binary .. (expr 0) (expr 10))))) (block
@@ -28,4 +33,8 @@ while y < 10 {
 (loop while (condition (expr (binary < (expr (name y)) (expr 10)))) (block
 	(expr (call (expr (name print)) (arg (expr (name y)))))
 	(expr (increment/decrement ++ postfix (expr (name y))))
+))
+(loop endless (block
+	(expr (call (expr (name print)) (arg (expr 0))))
+	(break)
 ))
\ No newline at end of file