Expressions #7

Merged
andre merged 21 commits from vm2 into master 2026-05-02 15:07:12 -05:00
2 changed files with 10 additions and 4 deletions
Showing only changes of commit 4c7798f672 - Show all commits

View File

@@ -93,7 +93,7 @@ static int init_ = []() {
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)
{
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"(
.const
0: {}
.func 0
pushi {}
pushc {}
pushc 0
{}
ret
)", 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, "mul"), 6);