bugfix with if-expressions
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 6 Jul 2021 23:20:00 +0000 (18:20 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 6 Jul 2021 23:20:00 +0000 (18:20 -0500)
bin/onyx
src/onyxwasm.c
tests/if_expressions
tests/if_expressions.onyx

index c27bdd35b9dacfe02d1b45c98de4ace21751c8c4..b37e2794e5ad0a34958e90106686feab3e134304 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index 7393bd326ca23739170e8973fdd640893c440178..8f5fbe827bf11a0dd20f35a921da3b87314aa9df 100644 (file)
@@ -2257,6 +2257,7 @@ EMIT_FUNC(if_expression, AstIfExpression* if_expr) {
         if (!result_is_local) emit_store_instruction(mod, &code, if_expr->type, offset);
         else                  WIL(WI_LOCAL_SET, result_local);
 
+    offset = 0;
     WI(WI_ELSE);
         if (!result_is_local) emit_local_location(mod, &code, (AstLocal *) if_expr, &offset);
 
@@ -2267,6 +2268,7 @@ EMIT_FUNC(if_expression, AstIfExpression* if_expr) {
 
     emit_leave_structured_block(mod, &code);
 
+    offset = 0;
     if (!result_is_local) {
         emit_local_location(mod, &code, (AstLocal *) if_expr, &offset);
         emit_load_instruction(mod, &code, if_expr->type, offset);
index 462d77522d7b9758cabaf9aabd475d74a4f4e29b..28833affa2b6747cc1b505f73dfed03830917f7b 100644 (file)
@@ -1,3 +1,4 @@
 5678.0000
 True
 20
+V2 { x = 10.0000, y = 20.0000 }
index 3388df86e9a63f43960704214c2ad63be08f0702..050a26e172a2d3d2093447430aa9986a1665e8b2 100644 (file)
@@ -12,6 +12,8 @@ new_max :: (a: $T, b: T) -> T {
     return a if a > b else b;
 }
 
+V2 :: struct { x, y: f32; }
+
 main :: (args: [] cstr) {
 
     condition := 12 > 34;
@@ -22,4 +24,7 @@ main :: (args: [] cstr) {
     println("True" if x > 5000 else "False" if false else "REALLY FALSE");
 
     println(new_max(10, 20));
+
+    v: V2 = (.{ 10, 20 }) if true else .{ 30, 40 };
+    printf("{}\n", v);
 }
\ No newline at end of file