This commit is contained in:
Andre Wagner
2026-05-02 09:51:43 -05:00
parent 044dfd6a24
commit 4c7798f672
2 changed files with 10 additions and 4 deletions

View File

@@ -93,7 +93,7 @@ static int init_ = []() {
Value binary_operation(Value const& a, Value const& b, BinaryOperationType op) Value binary_operation(Value const& a, Value const& b, BinaryOperationType op)
{ {
return binary_ops[(size_t) op][(size_t) a.type()][(size_t) b.type()](a, b); return binary_ops[(size_t) op][(size_t) b.type()][(size_t) a.type()](a, b);
} }
} }

View File

@@ -154,19 +154,25 @@ TEST(VM, IntegerIntegerOperations)
TEST(VM, IntegerFloatOperations) TEST(VM, IntegerFloatOperations)
{ {
auto test_op = [](int32_t op1, float op2, std::string oper) -> VM { auto test_op = [](int op1, std::string const& op2, std::string oper) -> VM {
return VM().load_bytecode(as::Assembler(std::format(R"( return VM().load_bytecode(as::Assembler(std::format(R"(
.const .const
0: {} 0: {}
.func 0 .func 0
pushi {} pushi {}
pushc {} pushc 0
{} {}
ret ret
)", op2, op1, oper)).assemble()).call(0); )", op2, op1, oper)).assemble()).call(0);
}; };
ASSERT_FLOAT_EQ(test_op(2, 3.5f, "sum").to_float(-1), 5.5f); ASSERT_FLOAT_EQ(test_op(2, "3.5", "sum").to_float(-1), 5.5f);
ASSERT_FLOAT_EQ(test_op(2, "3.5", "sub").to_float(-1), -1.5f);
ASSERT_FLOAT_EQ(test_op(2, "3.5", "mul").to_float(-1), 7.f);
ASSERT_FLOAT_EQ(test_op(20, "3.5", "idiv").to_integer(-1), 6);
ASSERT_FLOAT_EQ(test_op(20, "3.5", "div").to_float(-1), 5.7142859);
ASSERT_FLOAT_EQ(test_op(3, "3.5", "eq").to_integer(-1), 0);
ASSERT_FLOAT_EQ(test_op(3, "3.0", "eq").to_integer(-1), 1);
/* /*
ASSERT_EQ(test_op(2, 3, "sub"), -1); ASSERT_EQ(test_op(2, 3, "sub"), -1);
ASSERT_EQ(test_op(2, 3, "mul"), 6); ASSERT_EQ(test_op(2, 3, "mul"), 6);