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 @@
|
|||||||
|
|
||||||
|
for (var i = 0; i < 40; i++) {
|
||||||
fn panic() {
|
print i;
|
||||||
assert false, "This should only be seen once";
|
print (string)i + " printed";
|
||||||
}
|
}
|
||||||
|
|
||||||
panic();
|
|
||||||
panic();
|
|
||||||
|
|||||||
@@ -441,6 +441,7 @@ void initInterpreter(Interpreter* interpreter) {
|
|||||||
interpreter->bytecode = NULL;
|
interpreter->bytecode = NULL;
|
||||||
interpreter->length = 0;
|
interpreter->length = 0;
|
||||||
interpreter->count = 0;
|
interpreter->count = 0;
|
||||||
|
interpreter->codeStart = -1;
|
||||||
|
|
||||||
initLiteralArray(&interpreter->stack);
|
initLiteralArray(&interpreter->stack);
|
||||||
|
|
||||||
@@ -1405,6 +1406,7 @@ static bool execFnCall(Interpreter* interpreter) {
|
|||||||
inner.bytecode = AS_FUNCTION(func).bytecode;
|
inner.bytecode = AS_FUNCTION(func).bytecode;
|
||||||
inner.length = func.as.function.length;
|
inner.length = func.as.function.length;
|
||||||
inner.count = 0;
|
inner.count = 0;
|
||||||
|
inner.codeStart = -1;
|
||||||
inner.panic = false;
|
inner.panic = false;
|
||||||
initLiteralArray(&inner.stack);
|
initLiteralArray(&inner.stack);
|
||||||
setInterpreterPrint(&inner, interpreter->printOutput);
|
setInterpreterPrint(&inner, interpreter->printOutput);
|
||||||
@@ -1614,7 +1616,9 @@ static bool execFnReturn(Interpreter* interpreter) {
|
|||||||
//the heart of toy
|
//the heart of toy
|
||||||
static void execInterpreter(Interpreter* interpreter) {
|
static void execInterpreter(Interpreter* interpreter) {
|
||||||
//set the starting point for the interpreter
|
//set the starting point for the interpreter
|
||||||
|
if (interpreter->codeStart == -1) {
|
||||||
interpreter->codeStart = interpreter->count;
|
interpreter->codeStart = interpreter->count;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned char opcode = readByte(interpreter->bytecode, &interpreter->count);
|
unsigned char opcode = readByte(interpreter->bytecode, &interpreter->count);
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ typedef struct Interpreter {
|
|||||||
unsigned char* bytecode;
|
unsigned char* bytecode;
|
||||||
int length;
|
int length;
|
||||||
int count;
|
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
|
LiteralArray literalCache; //read-only - built from the bytecode, refreshed each time new bytecode is provided
|
||||||
|
|
||||||
//operation
|
//operation
|
||||||
|
|||||||
Reference in New Issue
Block a user