From bb81b8c474166e54762f7cb49127dc80393c2d54 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Tue, 6 Jun 2023 21:02:01 +1000 Subject: [PATCH] Changed recursion limit to 10,000 (was 200) --- scripts/example.toy | 4 ---- scripts/test_sum.js | 17 +++++++++++++++++ scripts/test_sum.toy | 17 +++++++++++++++++ source/toy_interpreter.c | 2 +- 4 files changed, 35 insertions(+), 5 deletions(-) delete mode 100644 scripts/example.toy create mode 100644 scripts/test_sum.js create mode 100644 scripts/test_sum.toy diff --git a/scripts/example.toy b/scripts/example.toy deleted file mode 100644 index 8937ede..0000000 --- a/scripts/example.toy +++ /dev/null @@ -1,4 +0,0 @@ -var s = "42"; -var t = "69"; - -print int (s + t) - 1; \ No newline at end of file diff --git a/scripts/test_sum.js b/scripts/test_sum.js new file mode 100644 index 0000000..52c02cf --- /dev/null +++ b/scripts/test_sum.js @@ -0,0 +1,17 @@ +//the test case (js) +function test_sum(key, val) { + function sum(n) { + if (n < 2) { + return n; + } + + return n + sum(n - 1); + } + + const result = sum(val); + console.log(`${key}: ${result}`); +} + +for (let i = 0; i <= 10; i++) { + test_sum(i, i * 1000); +} \ No newline at end of file diff --git a/scripts/test_sum.toy b/scripts/test_sum.toy new file mode 100644 index 0000000..632c9e1 --- /dev/null +++ b/scripts/test_sum.toy @@ -0,0 +1,17 @@ +//the test case (toy) +fn test_sum(key: int, val: int) { + fn sum(n: int) { + if (n < 2) { + return n; + } + + return n + sum(n - 1); + } + + var result: int const = sum(val); + print string key + ": " + string result; +} + +for (var i: int = 0; i <= 10; i++) { + test_sum(i, i * 1000); +} diff --git a/source/toy_interpreter.c b/source/toy_interpreter.c index f11f791..3668dcf 100644 --- a/source/toy_interpreter.c +++ b/source/toy_interpreter.c @@ -1193,7 +1193,7 @@ static void readInterpreterSections(Toy_Interpreter* interpreter); //also supports identifier & arg1 to be other way around (looseFirstArgument) static bool execFnCall(Toy_Interpreter* interpreter, bool looseFirstArgument) { //BUGFIX: depth check - don't drown! - if (interpreter->depth >= 200) { + if (interpreter->depth >= 1000 * 10) { interpreter->errorOutput("Infinite recursion detected - panicking\n"); interpreter->panic = true; return false;