This commit is contained in:
2026-05-02 08:25:31 -05:00
parent a1dbc40961
commit 728fc9d571

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) {