diff --git a/src/interpreter/interpreter.cpp b/src/interpreter/interpreter.cpp index d60030b69ba..42a83f73786 100644 --- a/src/interpreter/interpreter.cpp +++ b/src/interpreter/interpreter.cpp @@ -94,6 +94,9 @@ struct ExpressionInterpreter : OverriddenVisitor { if (curr->op == AddInt32) { push(lhs.add(rhs)); return {}; + } else if (curr->op == SubInt32) { + push(lhs.sub(rhs)); + return {}; } WASM_UNREACHABLE("TODO"); } diff --git a/test/gtest/interpreter.cpp b/test/gtest/interpreter.cpp index 1e6f6cdd139..399d46912e9 100644 --- a/test/gtest/interpreter.cpp +++ b/test/gtest/interpreter.cpp @@ -25,7 +25,7 @@ using namespace wasm; -TEST(InterpreterTest, Add) { +TEST(InterpreterTest, AddI32) { Module wasm; IRBuilder builder(wasm); @@ -41,3 +41,20 @@ TEST(InterpreterTest, Add) { EXPECT_EQ(results, expected); } + +TEST(InterpreterTest, SubI32) { + Module wasm; + IRBuilder builder(wasm); + + ASSERT_FALSE(builder.makeConst(Literal(uint32_t(1))).getErr()); + ASSERT_FALSE(builder.makeConst(Literal(uint32_t(2))).getErr()); + ASSERT_FALSE(builder.makeBinary(SubInt32).getErr()); + + auto expr = builder.build(); + ASSERT_FALSE(expr.getErr()); + + auto results = Interpreter{}.run(*expr); + std::vector expected{Literal(uint32_t(-1))}; + + EXPECT_EQ(results, expected); +}