diff --git a/compiler/gen_wasm/src/backend.rs b/compiler/gen_wasm/src/backend.rs index aba1aaa29d..b0bbf6a122 100644 --- a/compiler/gen_wasm/src/backend.rs +++ b/compiler/gen_wasm/src/backend.rs @@ -805,12 +805,19 @@ impl<'a> WasmBackend<'a> { // Zig's "fast calling convention" packs structs into CPU registers (stack machine slots) if possible. // If they're small enough they can go into an I32 or I64. If they're big, they're pointers (I32). for arg in arguments { - param_types.push(match self.storage.get(arg) { + match self.storage.get(arg) { StoredValue::StackMemory { size, .. } if *size > 4 && *size <= 8 => { - ValueType::I64 + param_types.push(ValueType::I64); } - stored => stored.value_type(), - }); + StoredValue::StackMemory { size, .. } if *size == 16 => { + // the exception to the rule: A Decimal is passed as two i64s + param_types.push(ValueType::I64); + param_types.push(ValueType::I64); + } + stored => { + param_types.push(stored.value_type()); + } + } } let signature_index = self.module.types.insert(Signature { diff --git a/compiler/gen_wasm/src/low_level.rs b/compiler/gen_wasm/src/low_level.rs index d94c6f8c7c..da096ec47b 100644 --- a/compiler/gen_wasm/src/low_level.rs +++ b/compiler/gen_wasm/src/low_level.rs @@ -63,12 +63,16 @@ pub fn decode_low_level<'a>( return NotImplemented; } - NumAdd => match ret_layout.value_type() { - I32 => code_builder.i32_add(), - I64 => code_builder.i64_add(), - F32 => code_builder.f32_add(), - F64 => code_builder.f64_add(), - }, + NumAdd => { + return BuiltinCall(bitcode::DEC_ADD_WITH_OVERFLOW); + + match ret_layout.value_type() { + I32 => code_builder.i32_add(), + I64 => code_builder.i64_add(), + F32 => code_builder.f32_add(), + F64 => code_builder.f64_add(), + } + } NumAddWrap => match ret_layout.value_type() { I32 => { code_builder.i32_add(); diff --git a/compiler/test_gen/src/gen_num.rs b/compiler/test_gen/src/gen_num.rs index 0adbf3e867..ecf899f1b4 100644 --- a/compiler/test_gen/src/gen_num.rs +++ b/compiler/test_gen/src/gen_num.rs @@ -609,7 +609,7 @@ fn gen_float_eq() { } #[test] -#[cfg(any(feature = "gen-llvm"))] +#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] fn gen_add_dec() { assert_evals_to!( indoc!(