mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 23:04:08 +10:00
Fixed codeStart issue
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
|
||||
|
||||
fn panic() {
|
||||
assert false, "This should only be seen once";
|
||||
for (var i = 0; i < 40; i++) {
|
||||
print i;
|
||||
print (string)i + " printed";
|
||||
}
|
||||
|
||||
panic();
|
||||
panic();
|
||||
|
||||
@@ -441,6 +441,7 @@ void initInterpreter(Interpreter* interpreter) {
|
||||
interpreter->bytecode = NULL;
|
||||
interpreter->length = 0;
|
||||
interpreter->count = 0;
|
||||
interpreter->codeStart = -1;
|
||||
|
||||
initLiteralArray(&interpreter->stack);
|
||||
|
||||
@@ -1405,6 +1406,7 @@ static bool execFnCall(Interpreter* interpreter) {
|
||||
inner.bytecode = AS_FUNCTION(func).bytecode;
|
||||
inner.length = func.as.function.length;
|
||||
inner.count = 0;
|
||||
inner.codeStart = -1;
|
||||
inner.panic = false;
|
||||
initLiteralArray(&inner.stack);
|
||||
setInterpreterPrint(&inner, interpreter->printOutput);
|
||||
@@ -1614,7 +1616,9 @@ static bool execFnReturn(Interpreter* interpreter) {
|
||||
//the heart of toy
|
||||
static void execInterpreter(Interpreter* interpreter) {
|
||||
//set the starting point for the interpreter
|
||||
interpreter->codeStart = interpreter->count;
|
||||
if (interpreter->codeStart == -1) {
|
||||
interpreter->codeStart = interpreter->count;
|
||||
}
|
||||
|
||||
unsigned char opcode = readByte(interpreter->bytecode, &interpreter->count);
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ typedef struct Interpreter {
|
||||
unsigned char* bytecode;
|
||||
int length;
|
||||
int count;
|
||||
int codeStart; //for jumps
|
||||
int codeStart; //BUGFIX: for jumps, must be initialized to -1
|
||||
LiteralArray literalCache; //read-only - built from the bytecode, refreshed each time new bytecode is provided
|
||||
|
||||
//operation
|
||||
|
||||
Reference in New Issue
Block a user