.
This commit is contained in:
@@ -59,15 +59,15 @@ FetchContent_MakeAvailable(googletest)
|
|||||||
#
|
#
|
||||||
|
|
||||||
add_library(lib${PROJECT_NAME} SHARED
|
add_library(lib${PROJECT_NAME} SHARED
|
||||||
src/bytecode/bytearray.hh
|
src/common/overloaded.hh
|
||||||
src/bytecode/bytearray.cc
|
src/common/bytearray.hh
|
||||||
|
src/common/bytearray.cc
|
||||||
src/bytecode/bytecode.cc
|
src/bytecode/bytecode.cc
|
||||||
src/bytecode/bytecode.hh
|
src/bytecode/bytecode.hh
|
||||||
src/bytecode/bytecodeprototype.hh
|
src/bytecode/bytecodeprototype.hh
|
||||||
src/common/overloaded.hh
|
src/bytecode/constant.hh
|
||||||
src/vm/code.cc
|
src/vm/code.cc
|
||||||
src/vm/code.hh
|
src/vm/code.hh
|
||||||
src/bytecode/constant.hh
|
|
||||||
src/vm/instruction.hh
|
src/vm/instruction.hh
|
||||||
src/vm/instruction.cc
|
src/vm/instruction.cc
|
||||||
src/vm/value.cc
|
src/vm/value.cc
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "bytecode.hh"
|
#include "bytecode.hh"
|
||||||
#include "../common/overloaded.hh"
|
#include "../common/overloaded.hh"
|
||||||
|
|
||||||
namespace tyche {
|
namespace tyche::bc {
|
||||||
|
|
||||||
Bytecode::Bytecode(ByteArray ba)
|
Bytecode::Bytecode(ByteArray ba)
|
||||||
: byte_array_(std::move(ba))
|
: byte_array_(std::move(ba))
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#ifndef TYCHE_BYTECODE_HH
|
#ifndef TYCHE_BYTECODE_HH
|
||||||
#define TYCHE_BYTECODE_HH
|
#define TYCHE_BYTECODE_HH
|
||||||
|
|
||||||
#include "bytearray.hh"
|
#include "../common/bytearray.hh"
|
||||||
#include "bytecodeprototype.hh"
|
#include "bytecodeprototype.hh"
|
||||||
|
|
||||||
namespace tyche {
|
namespace tyche::bc {
|
||||||
|
|
||||||
class Bytecode {
|
class Bytecode {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -6,9 +6,9 @@
|
|||||||
#include <variant>
|
#include <variant>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "constant.hh"
|
#include "constant.hh"
|
||||||
#include "bytearray.hh"
|
#include "../common/bytearray.hh"
|
||||||
|
|
||||||
namespace tyche {
|
namespace tyche::bc {
|
||||||
|
|
||||||
struct BytecodePrototype {
|
struct BytecodePrototype {
|
||||||
struct Function {
|
struct Function {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
|
||||||
namespace tyche {
|
namespace tyche::bc {
|
||||||
|
|
||||||
using ConstantValue = std::variant<float, std::string>;
|
using ConstantValue = std::variant<float, std::string>;
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,12 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
#include "bytearray.hh"
|
#include "../common/bytearray.hh"
|
||||||
#include "bytecodeprototype.hh"
|
#include "bytecodeprototype.hh"
|
||||||
#include "bytecode.hh"
|
#include "bytecode.hh"
|
||||||
|
|
||||||
using namespace tyche;
|
using namespace tyche;
|
||||||
|
using namespace tyche::bc;
|
||||||
|
|
||||||
TEST(ByteArray, ByteArray)
|
TEST(ByteArray, ByteArray)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
#include "../common/overloaded.hh"
|
#include "../common/overloaded.hh"
|
||||||
#include "instruction.hh"
|
#include "instruction.hh"
|
||||||
|
|
||||||
namespace tyche {
|
namespace tyche::vm {
|
||||||
|
|
||||||
FunctionId Code::import_bytecode(ByteArray incoming)
|
FunctionId Code::import_bytecode(ByteArray incoming)
|
||||||
{
|
{
|
||||||
Bytecode bc(std::move(incoming));
|
bc::Bytecode bc(std::move(incoming));
|
||||||
// TODO - adjust function calls, constants
|
// TODO - adjust function calls, constants
|
||||||
|
|
||||||
bytecode_ = std::move(bc);
|
bytecode_ = std::move(bc);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include "value.hh"
|
#include "value.hh"
|
||||||
#include "../bytecode/bytecode.hh"
|
#include "../bytecode/bytecode.hh"
|
||||||
|
|
||||||
namespace tyche {
|
namespace tyche::vm {
|
||||||
|
|
||||||
struct Operation
|
struct Operation
|
||||||
{
|
{
|
||||||
@@ -24,7 +24,7 @@ public:
|
|||||||
[[nodiscard]] Operation operation(Location const& location) const;
|
[[nodiscard]] Operation operation(Location const& location) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Bytecode bytecode_;
|
bc::Bytecode bytecode_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // tyche
|
} // tyche
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "vm_exceptions.hh"
|
#include "vm_exceptions.hh"
|
||||||
|
|
||||||
namespace tyche {
|
namespace tyche::vm {
|
||||||
|
|
||||||
Value binary_operation(Value const& a, Value const& b, BinaryOperationType op)
|
Value binary_operation(Value const& a, Value const& b, BinaryOperationType op)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#define TYCHE_EXPR_HH
|
#define TYCHE_EXPR_HH
|
||||||
#include "value.hh"
|
#include "value.hh"
|
||||||
|
|
||||||
namespace tyche {
|
namespace tyche::vm {
|
||||||
|
|
||||||
enum class BinaryOperationType { Sum };
|
enum class BinaryOperationType { Sum };
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "instruction.hh"
|
#include "instruction.hh"
|
||||||
|
|
||||||
namespace tyche {
|
namespace tyche::vm {
|
||||||
|
|
||||||
std::pair<std::string, size_t> debug_instruction(Instruction inst, int oper)
|
std::pair<std::string, size_t> debug_instruction(Instruction inst, int oper)
|
||||||
{
|
{
|
||||||
@@ -112,7 +112,7 @@ std::pair<std::string, size_t> debug_instruction(Instruction inst, int oper)
|
|||||||
return { out, 2 };
|
return { out, 2 };
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<std::string, size_t> debug_instruction(Bytecode const& bt, uint32_t function_id, uint32_t addr)
|
std::pair<std::string, size_t> debug_instruction(bc::Bytecode const& bt, uint32_t function_id, uint32_t addr)
|
||||||
{
|
{
|
||||||
auto inst = (Instruction) bt.get_code_byte(function_id, addr);
|
auto inst = (Instruction) bt.get_code_byte(function_id, addr);
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#include "../bytecode/bytecode.hh"
|
#include "../bytecode/bytecode.hh"
|
||||||
|
|
||||||
namespace tyche {
|
namespace tyche::vm {
|
||||||
|
|
||||||
enum class Instruction : uint8_t {
|
enum class Instruction : uint8_t {
|
||||||
|
|
||||||
@@ -96,7 +96,7 @@ enum class Instruction : uint8_t {
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::pair<std::string, size_t> debug_instruction(Instruction inst, int oper=0);
|
std::pair<std::string, size_t> debug_instruction(Instruction inst, int oper=0);
|
||||||
std::pair<std::string, size_t> debug_instruction(Bytecode const& bt, uint32_t function_id, uint32_t addr);
|
std::pair<std::string, size_t> debug_instruction(bc::Bytecode const& bt, uint32_t function_id, uint32_t addr);
|
||||||
|
|
||||||
enum class OperandType { NoOperand, Int8, Int16, Int32 };
|
enum class OperandType { NoOperand, Int8, Int16, Int32 };
|
||||||
OperandType instruction_operand_type(Instruction instruction);
|
OperandType instruction_operand_type(Instruction instruction);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
namespace tyche {
|
namespace tyche::vm {
|
||||||
|
|
||||||
struct Location
|
struct Location
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "vm_exceptions.hh"
|
#include "vm_exceptions.hh"
|
||||||
|
|
||||||
namespace tyche {
|
namespace tyche::vm {
|
||||||
|
|
||||||
Stack::Stack()
|
Stack::Stack()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
#include "value.hh"
|
#include "value.hh"
|
||||||
|
|
||||||
namespace tyche {
|
namespace tyche::vm {
|
||||||
|
|
||||||
class Stack {
|
class Stack {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
#include "../bytecode/bytecodeprototype.hh"
|
#include "../bytecode/bytecodeprototype.hh"
|
||||||
#include "../bytecode/bytearray.hh"
|
#include "../common/bytearray.hh"
|
||||||
#include "../bytecode/bytecode.hh"
|
#include "../bytecode/bytecode.hh"
|
||||||
#include "code.hh"
|
#include "code.hh"
|
||||||
#include "stack.hh"
|
#include "stack.hh"
|
||||||
#include "vm.hh"
|
#include "vm.hh"
|
||||||
|
|
||||||
using namespace tyche;
|
using namespace tyche;
|
||||||
|
using namespace tyche::bc;
|
||||||
|
using namespace tyche::vm;
|
||||||
|
|
||||||
TEST(Code, ImportSingleAndDebug)
|
TEST(Code, ImportSingleAndDebug)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "../common/overloaded.hh"
|
#include "../common/overloaded.hh"
|
||||||
|
|
||||||
namespace tyche {
|
namespace tyche::vm {
|
||||||
|
|
||||||
Type Value::type() const
|
Type Value::type() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
|
||||||
namespace tyche {
|
namespace tyche::vm {
|
||||||
|
|
||||||
using FunctionId = uint32_t;
|
using FunctionId = uint32_t;
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include "vm_exceptions.hh"
|
#include "vm_exceptions.hh"
|
||||||
#include "expr.hh"
|
#include "expr.hh"
|
||||||
|
|
||||||
namespace tyche {
|
namespace tyche::vm {
|
||||||
|
|
||||||
void VM::load_bytecode(ByteArray const& ba)
|
void VM::load_bytecode(ByteArray const& ba)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include "location.hh"
|
#include "location.hh"
|
||||||
#include "stack.hh"
|
#include "stack.hh"
|
||||||
|
|
||||||
namespace tyche {
|
namespace tyche::vm {
|
||||||
|
|
||||||
class VM {
|
class VM {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
#include "expr.hh"
|
#include "expr.hh"
|
||||||
|
|
||||||
namespace tyche {
|
namespace tyche::vm {
|
||||||
|
|
||||||
class VMRuntimeError : public std::runtime_error
|
class VMRuntimeError : public std::runtime_error
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user