bytecode2 #2

Merged
andre merged 20 commits from bytecode2 into master 2026-04-28 19:50:48 -05:00
2 changed files with 44 additions and 0 deletions
Showing only changes of commit 7b39a40a32 - Show all commits

View File

@@ -27,6 +27,8 @@ public:
// TODO - debugging info // TODO - debugging info
[[nodiscard]] std::vector<uint8_t> const& data() const { return byte_array_.data(); }
private: private:
ByteArray byte_array_; ByteArray byte_array_;
static constexpr uint8_t VERSION = 1; static constexpr uint8_t VERSION = 1;

View File

@@ -1,9 +1,12 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "gmock/gmock.h"
#include <cstring> #include <cstring>
#include <functional> #include <functional>
#include "bytearray.hh" #include "bytearray.hh"
#include "bytecodeprototype.hh"
#include "bytecode.hh"
using namespace tyche; using namespace tyche;
@@ -38,6 +41,45 @@ TEST(ByteArray, ByteArray)
#undef TESTX #undef TESTX
} }
TEST(Bytecode, Constants)
{
BytecodePrototype bp;
bp.constants.emplace_back(42);
bp.constants.emplace_back("HELLO");
Bytecode bc(bp);
auto binary = bc.data();
ByteArray ba;
ba.append_int(42);
std::vector<uint8_t> expected = {
// header
0x38, 0xc1, 0xb3, 0x74, // magic
0x01, 0x00, 0x00, 0x00, // version
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// index
0x30, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
// constant indexes
0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
// constant values
0x54, 'H', 'e', 'l', 'l', 'o', 0x00
};
ASSERT_EQ(binary, expected);
}
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);