From 7bcf3b181bae9f27de64225d15b49098de508d80 Mon Sep 17 00:00:00 2001 From: Andre Wagner Date: Mon, 27 Apr 2026 10:23:43 -0500 Subject: [PATCH] . --- CMakeLists.txt | 6 +++-- TODO.md | 5 ++-- src/bytecode/bytecode.cc | 6 +++++ src/bytecode/bytecode.hh | 49 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 src/bytecode/bytecode.cc create mode 100644 src/bytecode/bytecode.hh diff --git a/CMakeLists.txt b/CMakeLists.txt index 2fac843..935c03d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,8 +59,10 @@ FetchContent_MakeAvailable(googletest) # add_library(lib${PROJECT_NAME} STATIC - src/bytecode/bytearray.hh - src/bytecode/bytearray.cc + src/bytecode/bytearray.hh + src/bytecode/bytearray.cc + src/bytecode/bytecode.cc + src/bytecode/bytecode.hh ) target_compile_options(lib${PROJECT_NAME} PRIVATE ${warnings}) diff --git a/TODO.md b/TODO.md index 70c6169..88c7594 100644 --- a/TODO.md +++ b/TODO.md @@ -4,9 +4,10 @@ - Auto-expand - Add/retrive byte/int/float/string - Should not be larger than the byte array itself -- [ ] Chunk +- [ ] Bytecode - Add/retrive all types of data - Keeps no memory except for caching -- [ ] Chunk loader +- [ ] Bytecode debugging info +- [ ] Bytecode loader - Combine multiple chunks - Resolve function ids, constant ids, etc \ No newline at end of file diff --git a/src/bytecode/bytecode.cc b/src/bytecode/bytecode.cc new file mode 100644 index 0000000..d9171fc --- /dev/null +++ b/src/bytecode/bytecode.cc @@ -0,0 +1,6 @@ +#include "bytecode.hh" + +namespace tyche { + + +} \ No newline at end of file diff --git a/src/bytecode/bytecode.hh b/src/bytecode/bytecode.hh new file mode 100644 index 0000000..1a0fa14 --- /dev/null +++ b/src/bytecode/bytecode.hh @@ -0,0 +1,49 @@ +#ifndef TYCHE_BYTECODE_HH +#define TYCHE_BYTECODE_HH + +#include "bytearray.hh" + +namespace tyche { + +class Bytecode { +public: + // reading + + Bytecode(std::vector 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