-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a8752d2
commit 386699f
Showing
14 changed files
with
246 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "spec/spec.h" | ||
|
||
TEST_CASE("NEW_FRAME COMPRESS returns to original frame") { | ||
bytecode::CodeBlob instructions = bytecode::CodeBlob{ | ||
bytecode::iTrue(), | ||
bytecode::iNewFrame(), | ||
bytecode::iCompress() | ||
}; | ||
|
||
REQUIRE(resultOf(instructions)->asBool() == true); | ||
} | ||
|
||
TEST_CASE("NEW_FRAME COMPRESS EXPAND uses new frame") { | ||
bytecode::CodeBlob instructions = bytecode::CodeBlob{ | ||
bytecode::iNewFrame(), | ||
bytecode::iTrue(), | ||
bytecode::iCompress(), | ||
bytecode::iExpand() | ||
}; | ||
|
||
REQUIRE(resultOf(instructions)->asBool() == true); | ||
} | ||
|
||
TEST_CASE("Dereference") { | ||
bytecode::CodeBlob instructions = bytecode::CodeBlob{ | ||
bytecode::iNewFrame(), | ||
bytecode::iTrue(), | ||
bytecode::iCompress(), | ||
bytecode::iExpand(), | ||
bytecode::iReturnLast() | ||
}; | ||
|
||
REQUIRE(resultOf(instructions)->asBool() == true); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// The Fn VM is a basic, hand-made virtual machine. | ||
// Using a handful of VM instructions, | ||
// this VM is capable of running any Fn program. | ||
|
||
#pragma once | ||
|
||
#include <vector> // std::vector | ||
#include <unordered_map> // std::unordered_map | ||
|
||
#define INITIAL_VALUE_MAP_CAPACITY 4 | ||
#define INITIAL_SYMBOL_TABLE_CAPACITY 16 | ||
|
||
namespace fn { | ||
namespace vm { | ||
typedef std::vector<vm::Value*> ValueMap; | ||
typedef std::unordered_map<bytecode::NameHash, vm::Value*> SymbolTable; | ||
|
||
class CallFrame { | ||
public: | ||
// Denotes the place the program counter will be set to | ||
// when RETURN_LAST is hit. | ||
bytecode::InstructionIndex returnCounter; | ||
|
||
// The values defined in the given frame. | ||
vm::ValueMap values; | ||
|
||
// The symbols defined in the given frame. | ||
vm::SymbolTable symbols; | ||
|
||
CallFrame(bytecode::InstructionIndex returnCounter) : CallFrame() { | ||
this->returnCounter = returnCounter; | ||
} | ||
|
||
CallFrame() { | ||
// The [] operator returns 0 if a value | ||
// is not found. To make sure that's not | ||
// confused with the first element, we push | ||
// a NULL value to the 0 position. | ||
this->values = vm::ValueMap(); | ||
this->values.reserve(INITIAL_VALUE_MAP_CAPACITY); | ||
this->values.push_back(NULL); | ||
|
||
this->symbols = vm::SymbolTable(); | ||
this->symbols.reserve(INITIAL_SYMBOL_TABLE_CAPACITY); | ||
} | ||
|
||
~CallFrame() { | ||
for(auto value : this->values) { | ||
if (value != NULL) { delete value; } | ||
} | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.