.
This commit is contained in:
@@ -8,15 +8,15 @@ namespace tyche {
|
||||
|
||||
class Bytecode {
|
||||
public:
|
||||
explicit Bytecode(std::vector<uint8_t> data) : byte_array_(std::move(data)) {}
|
||||
explicit Bytecode(std::vector<uint8_t> data);
|
||||
explicit Bytecode(BytecodePrototype const& bp);
|
||||
|
||||
[[nodiscard]] uint32_t n_constants() const;
|
||||
[[nodiscard]] uint32_t n_functions() const;
|
||||
|
||||
[[nodiscard]] int32_t get_constant_int(uint32_t addr) const;
|
||||
[[nodiscard]] float get_constant_float(uint32_t addr) const;
|
||||
[[nodiscard]] std::string get_constant_string(uint32_t addr) const;
|
||||
[[nodiscard]] int32_t get_constant_int(uint32_t idx) const;
|
||||
[[nodiscard]] float get_constant_float(uint32_t idx) const;
|
||||
[[nodiscard]] std::string get_constant_string(uint32_t idx) const;
|
||||
|
||||
struct FunctionDef { uint16_t n_params, locals; };
|
||||
[[nodiscard]] FunctionDef get_function_def(uint32_t function_id) const;
|
||||
@@ -30,11 +30,21 @@ public:
|
||||
[[nodiscard]] std::vector<uint8_t> const& data() const { return byte_array_.data(); }
|
||||
|
||||
private:
|
||||
ByteArray byte_array_;
|
||||
ByteArray byte_array_; // the actual data
|
||||
|
||||
static constexpr uint8_t VERSION = 1;
|
||||
static constexpr uint32_t MAGIC = 0x74b3c138;
|
||||
static constexpr uint32_t HEADER_SZ = 16,
|
||||
INDEX_SZ = 8 * 4;
|
||||
INDEX_SZ = 8 * 6;
|
||||
|
||||
// caching for faster reading of data
|
||||
struct Cache {
|
||||
uint32_t constants_addr;
|
||||
uint16_t n_constants;
|
||||
uint32_t functions_addr;
|
||||
uint32_t n_functions;
|
||||
};
|
||||
Cache cache_ {};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user