VM basics #5
@@ -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
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
#include "constant.hh"
|
||||
#include "bytearray.hh"
|
||||
#include "../common/bytearray.hh"
|
||||
|
||||
namespace tyche {
|
||||
namespace tyche::bc {
|
||||
|
||||
struct BytecodePrototype {
|
||||
struct Function {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <string>
|
||||
#include <variant>
|
||||
|
||||
namespace tyche {
|
||||
namespace tyche::bc {
|
||||
|
||||
using ConstantValue = std::variant<float, std::string>;
|
||||
|
||||
|
||||
@@ -3,11 +3,12 @@
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
|
||||
#include "bytearray.hh"
|
||||
#include "../common/bytearray.hh"
|
||||
#include "bytecodeprototype.hh"
|
||||
#include "bytecode.hh"
|
||||
|
||||
using namespace tyche;
|
||||
using namespace tyche::bc;
|
||||
|
||||
TEST(ByteArray, ByteArray)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "vm_exceptions.hh"
|
||||
|
||||
namespace tyche {
|
||||
namespace tyche::vm {
|
||||
|
||||
Value binary_operation(Value const& a, Value const& b, BinaryOperationType op)
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define TYCHE_EXPR_HH
|
||||
#include "value.hh"
|
||||
|
||||
namespace tyche {
|
||||
namespace tyche::vm {
|
||||
|
||||
enum class BinaryOperationType { Sum };
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "instruction.hh"
|
||||
|
||||
namespace tyche {
|
||||
namespace tyche::vm {
|
||||
|
||||
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 };
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@@ -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<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 };
|
||||
OperandType instruction_operand_type(Instruction instruction);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace tyche {
|
||||
namespace tyche::vm {
|
||||
|
||||
struct Location
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "vm_exceptions.hh"
|
||||
|
||||
namespace tyche {
|
||||
namespace tyche::vm {
|
||||
|
||||
Stack::Stack()
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include "value.hh"
|
||||
|
||||
namespace tyche {
|
||||
namespace tyche::vm {
|
||||
|
||||
class Stack {
|
||||
public:
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "../common/overloaded.hh"
|
||||
|
||||
namespace tyche {
|
||||
namespace tyche::vm {
|
||||
|
||||
Type Value::type() const
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <string>
|
||||
#include <variant>
|
||||
|
||||
namespace tyche {
|
||||
namespace tyche::vm {
|
||||
|
||||
using FunctionId = uint32_t;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "vm_exceptions.hh"
|
||||
#include "expr.hh"
|
||||
|
||||
namespace tyche {
|
||||
namespace tyche::vm {
|
||||
|
||||
void VM::load_bytecode(ByteArray const& ba)
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "location.hh"
|
||||
#include "stack.hh"
|
||||
|
||||
namespace tyche {
|
||||
namespace tyche::vm {
|
||||
|
||||
class VM {
|
||||
public:
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include "expr.hh"
|
||||
|
||||
namespace tyche {
|
||||
namespace tyche::vm {
|
||||
|
||||
class VMRuntimeError : public std::runtime_error
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user