diff options
-rw-r--r-- | src/asm2wasm.h | 12 | ||||
-rw-r--r-- | test/unit.asm.js | 3 | ||||
-rw-r--r-- | test/unit.wast | 7 |
3 files changed, 13 insertions, 9 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h index 07e771108..5d88b8f38 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -346,6 +346,9 @@ private: assert(isInteger32(num)); return Literal((int32_t)num); } + if (ast[1] == PLUS && ast[2][0] == UNARY_PREFIX && ast[2][1] == MINUS && ast[2][2][0] == NUM) { + return Literal((double)-ast[2][2][1]->getNumber()); + } if (ast[1] == MINUS && ast[2][0] == UNARY_PREFIX && ast[2][1] == PLUS && ast[2][2][0] == NUM) { return Literal((double)-ast[2][2][1]->getNumber()); } @@ -785,12 +788,9 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) { return ret; } else if (what == UNARY_PREFIX) { if (ast[1] == PLUS) { - if (ast[2][0] == NUM) { - auto ret = allocator.alloc<Const>(); - ret->value.type = WasmType::f64; - ret->value.f64 = ast[2][1]->getNumber(); - ret->type = ret->value.type; - return ret; + Literal literal = checkLiteral(ast); + if (literal.type != none) { + return allocator.alloc<Const>()->set(literal); } auto ret = process(ast[2]); // we are a +() coercion if (ret->type == i32) { diff --git a/test/unit.asm.js b/test/unit.asm.js index 5695c3059..7575dfead 100644 --- a/test/unit.asm.js +++ b/test/unit.asm.js @@ -75,6 +75,9 @@ function () { Math_fround(5.0); Math_fround(0.0); } + function negZero() { + return +-0; + } function z() { } diff --git a/test/unit.wast b/test/unit.wast index 24692ba1c..1f1027556 100644 --- a/test/unit.wast +++ b/test/unit.wast @@ -8,9 +8,7 @@ (local $temp f64) (block (set_local $temp - (f64.convert_s/i32 - (i32.const -2147483648) - ) + (f64.const -2147483648) ) (set_local $temp (f64.const -2147483648) @@ -247,6 +245,9 @@ (f32.const 0) ) ) + (func $negZero (result f64) + (f64.const -0) + ) (func $z (nop) ) |