@@ -7,12 +7,9 @@ namespace tyche {
|
||||
|
||||
void ByteArray::set_byte(uint32_t addr, uint8_t byte)
|
||||
{
|
||||
try {
|
||||
data_.at(addr) = byte;
|
||||
} catch (std::out_of_range&) {
|
||||
if (data_.size() < (addr + 1))
|
||||
data_.resize(addr + 1, 0);
|
||||
data_.at(addr) = byte;
|
||||
}
|
||||
data_.at(addr) = byte;
|
||||
}
|
||||
|
||||
void ByteArray::set_int8(uint32_t addr, int8_t value)
|
||||
|
||||
@@ -25,7 +25,7 @@ Bytecode::Bytecode(ByteArray ba)
|
||||
uint32_t code_start = byte_array_.get_uint32(TOC_START + (3 * TOC_RECORD_SZ));
|
||||
for (uint32_t i = 0; i < cache_.n_functions; ++i) {
|
||||
cache_.function_addr.emplace_back(code_start + byte_array_.get_uint32(cache_.functions_idx_addr + (i * FUNCTION_RECORD_SZ)));
|
||||
cache_.function_sz.emplace_back(code_start + byte_array_.get_uint32(cache_.functions_idx_addr + (i * FUNCTION_RECORD_SZ) + 8));
|
||||
cache_.function_sz.emplace_back(byte_array_.get_uint32(cache_.functions_idx_addr + (i * FUNCTION_RECORD_SZ) + 8));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace tyche {
|
||||
|
||||
class Bytecode {
|
||||
public:
|
||||
Bytecode() = default;
|
||||
explicit Bytecode(ByteArray ba);
|
||||
|
||||
[[nodiscard]] uint32_t n_constants() const;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
#include "constant.hh"
|
||||
#include "bytearray.hh"
|
||||
|
||||
namespace tyche {
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
@@ -141,6 +140,8 @@ TEST(Bytecode, Parsing)
|
||||
|
||||
ASSERT_EQ(bc.n_constants(), 2);
|
||||
ASSERT_EQ(bc.n_functions(), 2);
|
||||
ASSERT_EQ(bc.get_function_sz(0), 2);
|
||||
ASSERT_EQ(bc.get_function_sz(1), 1);
|
||||
|
||||
ASSERT_FLOAT_EQ(std::get<float>(bc.get_constant(0)), 3.14f);
|
||||
ASSERT_EQ(std::get<std::string>(bc.get_constant(1)), "HELLO");
|
||||
|
||||
Reference in New Issue
Block a user