diff --git a/CMakeLists.txt b/CMakeLists.txt index 17af31e..901ac73 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,15 +59,15 @@ FetchContent_MakeAvailable(googletest) # add_library(lib${PROJECT_NAME} SHARED - src/bytecode/bytearray.hh - src/bytecode/bytearray.cc + src/common/overloaded.hh + src/common/bytearray.hh + src/common/bytearray.cc src/bytecode/bytecode.cc src/bytecode/bytecode.hh src/bytecode/bytecodeprototype.hh - src/common/overloaded.hh + src/bytecode/constant.hh src/vm/code.cc src/vm/code.hh - src/bytecode/constant.hh src/vm/instruction.hh src/vm/instruction.cc src/vm/value.cc diff --git a/src/bytecode/bytecode.cc b/src/bytecode/bytecode.cc index 2f75371..1dd8d02 100644 --- a/src/bytecode/bytecode.cc +++ b/src/bytecode/bytecode.cc @@ -1,7 +1,7 @@ #include "bytecode.hh" #include "../common/overloaded.hh" -namespace tyche { +namespace tyche::bc { Bytecode::Bytecode(ByteArray ba) : byte_array_(std::move(ba)) diff --git a/src/bytecode/bytecode.hh b/src/bytecode/bytecode.hh index 9542f89..cc6ec04 100644 --- a/src/bytecode/bytecode.hh +++ b/src/bytecode/bytecode.hh @@ -1,10 +1,10 @@ #ifndef TYCHE_BYTECODE_HH #define TYCHE_BYTECODE_HH -#include "bytearray.hh" +#include "../common/bytearray.hh" #include "bytecodeprototype.hh" -namespace tyche { +namespace tyche::bc { class Bytecode { public: diff --git a/src/bytecode/bytecodeprototype.hh b/src/bytecode/bytecodeprototype.hh index 3f32ea9..df92c81 100644 --- a/src/bytecode/bytecodeprototype.hh +++ b/src/bytecode/bytecodeprototype.hh @@ -6,9 +6,9 @@ #include #include #include "constant.hh" -#include "bytearray.hh" +#include "../common/bytearray.hh" -namespace tyche { +namespace tyche::bc { struct BytecodePrototype { struct Function { diff --git a/src/bytecode/constant.hh b/src/bytecode/constant.hh index 5972d46..968c8e4 100644 --- a/src/bytecode/constant.hh +++ b/src/bytecode/constant.hh @@ -4,7 +4,7 @@ #include #include -namespace tyche { +namespace tyche::bc { using ConstantValue = std::variant; diff --git a/src/bytecode/tests.cc b/src/bytecode/tests.cc index fba1aa5..049332f 100644 --- a/src/bytecode/tests.cc +++ b/src/bytecode/tests.cc @@ -3,11 +3,12 @@ #include #include -#include "bytearray.hh" +#include "../common/bytearray.hh" #include "bytecodeprototype.hh" #include "bytecode.hh" using namespace tyche; +using namespace tyche::bc; TEST(ByteArray, ByteArray) { diff --git a/src/bytecode/bytearray.cc b/src/common/bytearray.cc similarity index 100% rename from src/bytecode/bytearray.cc rename to src/common/bytearray.cc diff --git a/src/bytecode/bytearray.hh b/src/common/bytearray.hh similarity index 100% rename from src/bytecode/bytearray.hh rename to src/common/bytearray.hh diff --git a/src/vm/code.cc b/src/vm/code.cc index 1f2cb81..d780fbc 100644 --- a/src/vm/code.cc +++ b/src/vm/code.cc @@ -2,11 +2,11 @@ #include "../common/overloaded.hh" #include "instruction.hh" -namespace tyche { +namespace tyche::vm { FunctionId Code::import_bytecode(ByteArray incoming) { - Bytecode bc(std::move(incoming)); + bc::Bytecode bc(std::move(incoming)); // TODO - adjust function calls, constants bytecode_ = std::move(bc); diff --git a/src/vm/code.hh b/src/vm/code.hh index 19084b6..1c4710b 100644 --- a/src/vm/code.hh +++ b/src/vm/code.hh @@ -6,7 +6,7 @@ #include "value.hh" #include "../bytecode/bytecode.hh" -namespace tyche { +namespace tyche::vm { struct Operation { @@ -24,7 +24,7 @@ public: [[nodiscard]] Operation operation(Location const& location) const; private: - Bytecode bytecode_; + bc::Bytecode bytecode_; }; } // tyche diff --git a/src/vm/expr.cc b/src/vm/expr.cc index 6475798..26878a7 100644 --- a/src/vm/expr.cc +++ b/src/vm/expr.cc @@ -2,7 +2,7 @@ #include "vm_exceptions.hh" -namespace tyche { +namespace tyche::vm { Value binary_operation(Value const& a, Value const& b, BinaryOperationType op) { diff --git a/src/vm/expr.hh b/src/vm/expr.hh index 1641534..539672e 100644 --- a/src/vm/expr.hh +++ b/src/vm/expr.hh @@ -2,7 +2,7 @@ #define TYCHE_EXPR_HH #include "value.hh" -namespace tyche { +namespace tyche::vm { enum class BinaryOperationType { Sum }; diff --git a/src/vm/instruction.cc b/src/vm/instruction.cc index d83a8c5..5508962 100644 --- a/src/vm/instruction.cc +++ b/src/vm/instruction.cc @@ -1,6 +1,6 @@ #include "instruction.hh" -namespace tyche { +namespace tyche::vm { std::pair debug_instruction(Instruction inst, int oper) { @@ -112,7 +112,7 @@ std::pair debug_instruction(Instruction inst, int oper) return { out, 2 }; } -std::pair debug_instruction(Bytecode const& bt, uint32_t function_id, uint32_t addr) +std::pair debug_instruction(bc::Bytecode const& bt, uint32_t function_id, uint32_t addr) { auto inst = (Instruction) bt.get_code_byte(function_id, addr); diff --git a/src/vm/instruction.hh b/src/vm/instruction.hh index 1bbc202..1710cdf 100644 --- a/src/vm/instruction.hh +++ b/src/vm/instruction.hh @@ -7,7 +7,7 @@ #include "../bytecode/bytecode.hh" -namespace tyche { +namespace tyche::vm { enum class Instruction : uint8_t { @@ -96,7 +96,7 @@ enum class Instruction : uint8_t { }; std::pair debug_instruction(Instruction inst, int oper=0); -std::pair debug_instruction(Bytecode const& bt, uint32_t function_id, uint32_t addr); +std::pair debug_instruction(bc::Bytecode const& bt, uint32_t function_id, uint32_t addr); enum class OperandType { NoOperand, Int8, Int16, Int32 }; OperandType instruction_operand_type(Instruction instruction); diff --git a/src/vm/location.hh b/src/vm/location.hh index 9e67c76..caff343 100644 --- a/src/vm/location.hh +++ b/src/vm/location.hh @@ -3,7 +3,7 @@ #include -namespace tyche { +namespace tyche::vm { struct Location { diff --git a/src/vm/stack.cc b/src/vm/stack.cc index 95908f2..801b9fa 100644 --- a/src/vm/stack.cc +++ b/src/vm/stack.cc @@ -2,7 +2,7 @@ #include "vm_exceptions.hh" -namespace tyche { +namespace tyche::vm { Stack::Stack() { diff --git a/src/vm/stack.hh b/src/vm/stack.hh index 775e902..96d04e9 100644 --- a/src/vm/stack.hh +++ b/src/vm/stack.hh @@ -6,7 +6,7 @@ #include "value.hh" -namespace tyche { +namespace tyche::vm { class Stack { public: diff --git a/src/vm/tests.cc b/src/vm/tests.cc index 47b29fe..0d75fdf 100644 --- a/src/vm/tests.cc +++ b/src/vm/tests.cc @@ -1,13 +1,15 @@ #include "gtest/gtest.h" #include "../bytecode/bytecodeprototype.hh" -#include "../bytecode/bytearray.hh" +#include "../common/bytearray.hh" #include "../bytecode/bytecode.hh" #include "code.hh" #include "stack.hh" #include "vm.hh" using namespace tyche; +using namespace tyche::bc; +using namespace tyche::vm; TEST(Code, ImportSingleAndDebug) { diff --git a/src/vm/value.cc b/src/vm/value.cc index 40d4f91..13f015e 100644 --- a/src/vm/value.cc +++ b/src/vm/value.cc @@ -2,7 +2,7 @@ #include "../common/overloaded.hh" -namespace tyche { +namespace tyche::vm { Type Value::type() const { diff --git a/src/vm/value.hh b/src/vm/value.hh index 7aed983..2592cd6 100644 --- a/src/vm/value.hh +++ b/src/vm/value.hh @@ -4,7 +4,7 @@ #include #include -namespace tyche { +namespace tyche::vm { using FunctionId = uint32_t; diff --git a/src/vm/vm.cc b/src/vm/vm.cc index 61d0971..502fad8 100644 --- a/src/vm/vm.cc +++ b/src/vm/vm.cc @@ -3,7 +3,7 @@ #include "vm_exceptions.hh" #include "expr.hh" -namespace tyche { +namespace tyche::vm { void VM::load_bytecode(ByteArray const& ba) { diff --git a/src/vm/vm.hh b/src/vm/vm.hh index 151dc65..d989268 100644 --- a/src/vm/vm.hh +++ b/src/vm/vm.hh @@ -5,7 +5,7 @@ #include "location.hh" #include "stack.hh" -namespace tyche { +namespace tyche::vm { class VM { public: diff --git a/src/vm/vm_exceptions.hh b/src/vm/vm_exceptions.hh index 49152dc..610f43b 100644 --- a/src/vm/vm_exceptions.hh +++ b/src/vm/vm_exceptions.hh @@ -6,7 +6,7 @@ #include "expr.hh" -namespace tyche { +namespace tyche::vm { class VMRuntimeError : public std::runtime_error {