From daceaa5492de55ee18fc18a52c16cfc1d6ef9d69 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sat, 20 Aug 2022 13:44:55 +0100 Subject: [PATCH] Found a weird bug, reporting it --- docs/TODO.txt | 11 +++++------ scripts/empty.toy | 9 +++++++++ source/interpreter.c | 4 ++-- test/jumps.toy | 1 - 4 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 scripts/empty.toy diff --git a/docs/TODO.txt b/docs/TODO.txt index 104f617..f403f00 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -3,17 +3,16 @@ DONE: var decl with a type, but no value DONE: type casting DONE: remove optimization option DONE: conditionals +DONE: if-then-else +DONE: chained if-then-else +DONE: optional block around a path if it's only one statement +DONE: while-then +DONE: for-then TODO: string concat with the + operator -TODO: empty string as falsy? TODO: increment & decrement operators TODO: a = b = c = 1; TODO: are compounds shallow or deep copies? -TODO: if-then-else -TODO: chained if-then-else -TODO: optional block around a path if it's only one statement -TODO: while-then -TODO: for-then TODO: break and continue statements TODO: functions, and all of their features TODO: Assertion-based test scripts diff --git a/scripts/empty.toy b/scripts/empty.toy new file mode 100644 index 0000000..3766a55 --- /dev/null +++ b/scripts/empty.toy @@ -0,0 +1,9 @@ + + +//BUG: this causes a strange error message +if (true) { + ; +} +else { + ; +} \ No newline at end of file diff --git a/source/interpreter.c b/source/interpreter.c index c06d612..f578e35 100644 --- a/source/interpreter.c +++ b/source/interpreter.c @@ -573,7 +573,7 @@ static bool execCompareLessEqual(Interpreter* interpreter, bool invert) { static bool execJump(Interpreter* interpreter) { int target = (int)readShort(interpreter->bytecode, &interpreter->count); - if (target >= interpreter->length) { + if (target + interpreter->codeStart > interpreter->length) { printf("Jump out of range\n"); return false; } @@ -587,7 +587,7 @@ static bool execJump(Interpreter* interpreter) { static bool execFalseJump(Interpreter* interpreter) { int target = (int)readShort(interpreter->bytecode, &interpreter->count); - if (target >= interpreter->length) { + if (target + interpreter->codeStart > interpreter->length) { printf("Jump out of range\n"); return false; } diff --git a/test/jumps.toy b/test/jumps.toy index c926910..1d6e89e 100644 --- a/test/jumps.toy +++ b/test/jumps.toy @@ -37,4 +37,3 @@ assert forCache == 19, "for-loop failed"; print "All good"; -