feat: introduce reference instruction
This commit is contained in:
@@ -40,6 +40,13 @@ enum class instruction_t : byte {
|
||||
*/
|
||||
Clone,
|
||||
|
||||
/**
|
||||
* @brief Pushes a new reference onto the stack.
|
||||
*
|
||||
* Pops the top thing from the stack and pushes its reference.
|
||||
*/
|
||||
Reference,
|
||||
|
||||
/**
|
||||
* @brief Adds two things together on the stack.
|
||||
*/
|
||||
|
||||
@@ -368,7 +368,7 @@ public:
|
||||
}
|
||||
|
||||
thing reference() const {
|
||||
thing res = { std::make_shared<type>({ m_type }), m_allocator };
|
||||
thing res = { std::make_shared<class type>(m_type), m_allocator };
|
||||
res.get<reference_t>() = m_data;
|
||||
return std::move(res);
|
||||
}
|
||||
|
||||
@@ -102,6 +102,10 @@ void executor::step() {
|
||||
case instruction_t::Clone: {
|
||||
push_thing(std::move(thing()->clone()));
|
||||
} break;
|
||||
case instruction_t::Reference: {
|
||||
auto thing = pop_thing();
|
||||
push_thing(std::move(thing->reference()));
|
||||
} break;
|
||||
case instruction_t::Add: {
|
||||
auto rhs = pop_thing();
|
||||
auto lhs = pop_thing();
|
||||
|
||||
+3
-2
@@ -8,10 +8,11 @@
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
static constexpr std::array<furvm::byte, 8> s_bytecode = {
|
||||
static constexpr std::array<furvm::byte, 9> s_bytecode = {
|
||||
furvm::byte(furvm::instruction_t::PushB2I),
|
||||
67,
|
||||
furvm::byte(furvm::instruction_t::Clone),
|
||||
furvm::byte(furvm::instruction_t::Duplicate),
|
||||
furvm::byte(furvm::instruction_t::Reference),
|
||||
furvm::byte(furvm::instruction_t::Add),
|
||||
furvm::byte(furvm::instruction_t::Call),
|
||||
1,
|
||||
|
||||
Reference in New Issue
Block a user