small bugfixes
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 8 Aug 2020 03:38:51 +0000 (22:38 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 8 Aug 2020 03:38:51 +0000 (22:38 -0500)
onyx
progs/stack_based.onyx
src/onyxwasm.c

diff --git a/onyx b/onyx
index 22752e469c94f02caed9df161847bdd893e2cde4..376fff4dd8ac50d50e4bcaad5a5dda682cffcf92 100755 (executable)
Binary files a/onyx and b/onyx differ
index f2f4f4adfd146434603cad764eb77149f0c1f27e..e1b2b6eee75ead368d75127f9d35fb8e9c466926 100644 (file)
@@ -8,6 +8,8 @@ use package memory
 
 ret_val :: proc (x: i32, y: i32) -> i32 {
     big_arr : [128] i32;
+    big_arr[0] = 1234;
+    big_arr[1] = 1234;
     big_arr[127] = 1234;
     return big_arr[127] + x + y;
 }
@@ -22,7 +24,10 @@ sumN :: proc (x: [N] i32) -> i32 {
 
 summing :: proc (x: ^i32) -> i32 {
     s := 0;
-    for i: 0, N do s += x[i];
+    for i: 0, N {
+        tmp :: ^i;
+        s += x[i];
+    }
     return s;
 }
 
index 2d617a1ad118edb32f102791a06e18112c95fc5f..177d1f9d4f98a63c0b5ee98c7fe5085b7ba02cad 100644 (file)
@@ -976,7 +976,7 @@ COMPILE_FUNC(expression, AstTyped* expr) {
                     WI(WI_I32_ADD);
                 }
             }
-            
+
             break;
         }
 
@@ -1034,8 +1034,10 @@ COMPILE_FUNC(expression, AstTyped* expr) {
                 case Ast_Kind_Local: {
                     u64 offset = 0;
                     compile_local_location(mod, &code, (AstLocal *) aof->expr, &offset);
-                    WID(WI_I32_CONST, offset);
-                    WI(WI_I32_ADD);
+                    if (offset != 0) {
+                        WID(WI_I32_CONST, offset);
+                        WI(WI_I32_ADD);
+                    }
                     break;
                 }
 
@@ -1423,7 +1425,7 @@ static inline b32 should_compile_function(AstFunction* fd) {
 }
 
 static b32 local_is_wasm_local(AstLocal* local) {
-    if (local->flags & Ast_Flag_Address_Taken) return 1;
+    if (local->flags & Ast_Flag_Address_Taken) return 0;
     if (local->type->kind == Type_Kind_Basic) return 1;
     if (local->type->kind == Type_Kind_Pointer) return 1;
     return 0;