Expressions #7

Merged
andre merged 21 commits from vm2 into master 2026-05-02 15:07:12 -05:00
Showing only changes of commit 728fc9d571 - Show all commits

View File

@@ -1,7 +1,6 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "../bytecode/bytecodeprototype.hh" #include "../bytecode/bytecodeprototype.hh"
#include "../common/bytearray.hh"
#include "../bytecode/bytecode.hh" #include "../bytecode/bytecode.hh"
#include "../assembler/assembler.hh" #include "../assembler/assembler.hh"
#include "code.hh" #include "code.hh"
@@ -93,6 +92,24 @@ TEST(VM, BasicCode)
ASSERT_EQ(result, 5); ASSERT_EQ(result, 5);
} }
TEST(VM, StackOperations)
{
auto run = [](std::string oper) {
return VM().load_bytecode(as::Assembler(std::format(R"(
.const
0: 3.14
1: "Hello world"
.func 0
{}
ret
)", oper)).assemble()).call(0);
};
ASSERT_EQ(run("pushi 5000").to_integer(-1), 5000);
ASSERT_EQ(run("pushi -5000").to_integer(-1), -5000);
ASSERT_FLOAT_EQ(run("pushc 0").to_float(-1), 3.14f);
}
TEST(VM, IntegerIntegerOperations) TEST(VM, IntegerIntegerOperations)
{ {
auto test_op = [](int32_t op1, int32_t op2, std::string oper) { auto test_op = [](int32_t op1, int32_t op2, std::string oper) {