.
This commit is contained in:
49
src/bytecode/bytecode.hh
Normal file
49
src/bytecode/bytecode.hh
Normal file
@@ -0,0 +1,49 @@
|
||||
#ifndef TYCHE_BYTECODE_HH
|
||||
#define TYCHE_BYTECODE_HH
|
||||
|
||||
#include "bytearray.hh"
|
||||
|
||||
namespace tyche {
|
||||
|
||||
class Bytecode {
|
||||
public:
|
||||
// reading
|
||||
|
||||
Bytecode(std::vector<uint8_t> data);
|
||||
|
||||
[[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;
|
||||
|
||||
struct FunctionDef { uint16_t n_params, locals; };
|
||||
[[nodiscard]] FunctionDef get_function_def(uint32_t function_id) const;
|
||||
|
||||
[[nodiscard]] uint8_t get_code_byte(uint32_t function_id, uint32_t idx) const;
|
||||
[[nodiscard]] int32_t get_code_int(uint32_t function_id, uint32_t idx) const;
|
||||
[[nodiscard]] float get_code_float(uint32_t function_id, uint32_t idx) const;
|
||||
|
||||
// writing
|
||||
|
||||
Bytecode();
|
||||
|
||||
uint32_t add_constant(int32_t value);
|
||||
uint32_t add_constant(float value);
|
||||
uint32_t add_constant(std::string const& str);
|
||||
|
||||
uint32_t add_function(uint16_t n_params, uint16_t locals);
|
||||
|
||||
uint32_t add_code(uint8_t operation);
|
||||
uint32_t add_code(uint8_t operation, int32_t operand_);
|
||||
|
||||
// TODO - debugging info
|
||||
|
||||
private:
|
||||
ByteArray byte_array_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //TYCHE_BYTECODE_HH
|
||||
Reference in New Issue
Block a user