From: Brendan Hansen Date: Mon, 22 Feb 2021 00:00:23 +0000 (-0600) Subject: fixed return bug X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=c0c67d68fc8528015d55da569abb31d29b9767b8;p=onyx.git fixed return bug --- diff --git a/bin/onyx b/bin/onyx index 59479302..80399ea4 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/core/math.onyx b/core/math.onyx index 366b9fd1..ad579b23 100644 --- a/core/math.onyx +++ b/core/math.onyx @@ -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 { diff --git a/src/onyxwasm.c b/src/onyxwasm.c index 7b533f83..726e4aea 100644 --- a/src/onyxwasm.c +++ b/src/onyxwasm.c @@ -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