about summary refs log tree commit diff
path: root/boot/tests/lower/if_else_chain.cskt
diff options
context:
space:
mode:
Diffstat (limited to 'boot/tests/lower/if_else_chain.cskt')
-rw-r--r--boot/tests/lower/if_else_chain.cskt38
1 files changed, 38 insertions, 0 deletions
diff --git a/boot/tests/lower/if_else_chain.cskt b/boot/tests/lower/if_else_chain.cskt
new file mode 100644
index 0000000..a8bf358
--- /dev/null
+++ b/boot/tests/lower/if_else_chain.cskt
@@ -0,0 +1,38 @@
+a three-branch if/else-if/else chain lowers to a single flat
+conditional.
+
+<<<
+
+classify = fun (n int) int {
+    if n < 0 {
+        return -1
+    } else if n == 0 {
+        return 0
+    } else {
+        return 1
+    }
+}
+
+>>>
+
+(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 classify (returns (ref int)) (param n (ref int)) (block
+			(conditional (when (expr (binary < (expr (name n)) (expr 0)))) (block
+				(return (expr (unary - (expr 1))))
+			) (when (expr (binary == (expr (name n)) (expr 0)))) (block
+				(return (expr 0))
+			) (else) (block
+				(return (expr 1))
+			))
+		)))
+	(emission_order 0 1 2 3 4 5 6 7))