mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Depth check
This commit is contained in:
@@ -33,18 +33,18 @@ DONE: Assertion-based test scripts
|
|||||||
DONE: Import/export keywords
|
DONE: Import/export keywords
|
||||||
DONE: A way to check the type of a variable (typeOf keyword)
|
DONE: A way to check the type of a variable (typeOf keyword)
|
||||||
DONE: slice and dot notation around the builtin _index and _dot functions
|
DONE: slice and dot notation around the builtin _index and _dot functions
|
||||||
|
DONE: maximum recursion/function depth
|
||||||
|
|
||||||
|
|
||||||
|
TODO: nested compound assignment
|
||||||
|
TODO: better sugar for _push and _pop
|
||||||
TODO: ternary operator
|
TODO: ternary operator
|
||||||
TODO: Nullish types?
|
TODO: Nullish types?
|
||||||
TODO: hooks on the external libraries, triggered on import
|
TODO: hooks on the external libraries, triggered on import
|
||||||
TODO: standard library
|
TODO: standard library
|
||||||
TODO: external script runner library
|
TODO: external script runner library
|
||||||
TODO: document how it all works - book?
|
TODO: document how it all works - book?
|
||||||
TODO: maximum recursion/function depth
|
|
||||||
TODO: better API
|
TODO: better API
|
||||||
TODO: better sugar for _push and _pop
|
|
||||||
TODO: nested compound assignment
|
|
||||||
TODO: packaging for release?
|
TODO: packaging for release?
|
||||||
|
|
||||||
NOPE: a = b = c = 1;
|
NOPE: a = b = c = 1;
|
||||||
|
|||||||
@@ -1,25 +1,10 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
fn loop(count) {
|
||||||
|
print count++;
|
||||||
|
|
||||||
fn makeCounter() {
|
loop(count);
|
||||||
var total: int = 0;
|
|
||||||
|
|
||||||
fn counter(): int {
|
|
||||||
return ++total;
|
|
||||||
}
|
|
||||||
|
|
||||||
return counter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var tally = makeCounter();
|
loop(0);
|
||||||
|
|
||||||
print tally(); //1
|
|
||||||
print tally(); //2
|
|
||||||
print tally(); //3
|
|
||||||
|
|
||||||
export tally;
|
|
||||||
|
|
||||||
//heck yeah!
|
|
||||||
import tally as tally2;
|
|
||||||
print tally2(); //4
|
|
||||||
@@ -991,6 +991,13 @@ static void execInterpreter(Interpreter*);
|
|||||||
static void readInterpreterSections(Interpreter* interpreter);
|
static void readInterpreterSections(Interpreter* interpreter);
|
||||||
|
|
||||||
static bool execFnCall(Interpreter* interpreter) {
|
static bool execFnCall(Interpreter* interpreter) {
|
||||||
|
//BUGFIX: depth check - don't drown!
|
||||||
|
if (interpreter->depth >= 1000) {
|
||||||
|
interpreter->errorOutput("Depth check failed\n");
|
||||||
|
interpreter->panic = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
LiteralArray arguments;
|
LiteralArray arguments;
|
||||||
initLiteralArray(&arguments);
|
initLiteralArray(&arguments);
|
||||||
|
|
||||||
@@ -1057,6 +1064,7 @@ static bool execFnCall(Interpreter* interpreter) {
|
|||||||
inner.length = func.as.function.length;
|
inner.length = func.as.function.length;
|
||||||
inner.count = 0;
|
inner.count = 0;
|
||||||
inner.codeStart = -1;
|
inner.codeStart = -1;
|
||||||
|
inner.depth = interpreter->depth + 1;
|
||||||
inner.panic = false;
|
inner.panic = false;
|
||||||
initLiteralArray(&inner.stack);
|
initLiteralArray(&inner.stack);
|
||||||
inner.exports = interpreter->exports;
|
inner.exports = interpreter->exports;
|
||||||
@@ -2368,6 +2376,7 @@ void runInterpreter(Interpreter* interpreter, unsigned char* bytecode, int lengt
|
|||||||
|
|
||||||
initLiteralArray(&interpreter->stack);
|
initLiteralArray(&interpreter->stack);
|
||||||
|
|
||||||
|
interpreter->depth = 0;
|
||||||
interpreter->panic = false;
|
interpreter->panic = false;
|
||||||
|
|
||||||
//prep the bytecode
|
//prep the bytecode
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ typedef struct Interpreter {
|
|||||||
PrintFn assertOutput;
|
PrintFn assertOutput;
|
||||||
PrintFn errorOutput;
|
PrintFn errorOutput;
|
||||||
|
|
||||||
|
int depth; //don't overflow
|
||||||
bool panic;
|
bool panic;
|
||||||
} Interpreter;
|
} Interpreter;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user