fixed return bug
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 22 Feb 2021 00:00:23 +0000 (18:00 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 22 Feb 2021 00:00:23 +0000 (18:00 -0600)
bin/onyx
core/math.onyx
src/onyxwasm.c

index 59479302495ca59672677e3844d068955436e761..80399ea4c9b0cbea6072d3ba4a6b911bb1a3d653 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index 366b9fd1d14ecefcf71d9bf0d930b3b85b4c5afd..ad579b23fe4ab3b38958c9753744dbd4630aec87 100644 (file)
@@ -233,13 +233,13 @@ log :: (a: $T, base: $R) -> T {
 max :: proc { wasm.max_f32, wasm.max_f64, max_poly }
 max_poly :: (a: $T, b: T) -> T {
     if a >= b do return a;
-    return b;
+    else      do return b;
 }
 
 min :: proc { wasm.min_f32, wasm.min_f64, min_poly }
 min_poly :: (a: $T, b: T) -> T {
     if a <= b do return a;
-    return b;
+    else      do return b;
 }
 
 clamp :: (v: $T, lo: T, hi: T) -> T {
@@ -256,7 +256,7 @@ sqrt_poly :: proc (x: $T) -> T {
 abs :: proc { wasm.abs_f32, wasm.abs_f64, abs_poly }
 abs_poly :: (x: $T) -> T {
     if x >= 0 do return x;
-    return -x;
+    else      do return -x;
 }
 
 sign :: (x: $T) -> T {
index 7b533f837ee2a8d62a9dcb34418a2697e5ea9a38..726e4aeab1d11bcd00b6c02cbd2c0ae9c9a50f5c 100644 (file)
@@ -2608,6 +2608,21 @@ static void emit_function(OnyxWasmModule* mod, AstFunction* fd) {
         }
     }
 
+    {    
+        WasmFuncType* ft = mod->types[type_idx];
+        switch (ft->return_type) {
+            case WASM_TYPE_INT32:   bh_arr_push(wasm_func.code, ((WasmInstruction){ WI_I32_CONST, 0x00 })); break;
+            case WASM_TYPE_INT64:   bh_arr_push(wasm_func.code, ((WasmInstruction){ WI_I64_CONST, 0x00 })); break;
+            case WASM_TYPE_FLOAT32: bh_arr_push(wasm_func.code, ((WasmInstruction){ WI_F32_CONST, 0x00 })); break;
+            case WASM_TYPE_FLOAT64: bh_arr_push(wasm_func.code, ((WasmInstruction){ WI_F64_CONST, 0x00 })); break;
+            case WASM_TYPE_VAR128:  {
+                static u8 zero_v128[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+                bh_arr_push(wasm_func.code, ((WasmInstruction){ WI_V128_CONST, { .p = &zero_v128 } }));
+                break;
+            }
+        }
+    }
+
     bh_arr_push(wasm_func.code, ((WasmInstruction){ WI_BLOCK_END, 0x00 }));
 
     // HACK: This is gross