This commit is contained in:
2026-04-27 10:23:43 -05:00
parent 3f097b0ba8
commit 7bcf3b181b
4 changed files with 62 additions and 4 deletions

View File

@@ -61,6 +61,8 @@ FetchContent_MakeAvailable(googletest)
add_library(lib${PROJECT_NAME} STATIC add_library(lib${PROJECT_NAME} STATIC
src/bytecode/bytearray.hh src/bytecode/bytearray.hh
src/bytecode/bytearray.cc src/bytecode/bytearray.cc
src/bytecode/bytecode.cc
src/bytecode/bytecode.hh
) )
target_compile_options(lib${PROJECT_NAME} PRIVATE ${warnings}) target_compile_options(lib${PROJECT_NAME} PRIVATE ${warnings})

View File

@@ -4,9 +4,10 @@
- Auto-expand - Auto-expand
- Add/retrive byte/int/float/string - Add/retrive byte/int/float/string
- Should not be larger than the byte array itself - Should not be larger than the byte array itself
- [ ] Chunk - [ ] Bytecode
- Add/retrive all types of data - Add/retrive all types of data
- Keeps no memory except for caching - Keeps no memory except for caching
- [ ] Chunk loader - [ ] Bytecode debugging info
- [ ] Bytecode loader
- Combine multiple chunks - Combine multiple chunks
- Resolve function ids, constant ids, etc - Resolve function ids, constant ids, etc

6
src/bytecode/bytecode.cc Normal file
View File

@@ -0,0 +1,6 @@
#include "bytecode.hh"
namespace tyche {
}

49
src/bytecode/bytecode.hh Normal file
View 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