From 733df87c0850f416fd4bc23fb9bd1539e1d5ae41 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 7 Jun 2023 14:58:51 +1000 Subject: [PATCH] Added dist target, lowered recursion depth limit --- makefile | 8 ++++---- scripts/fib.toy | 2 +- scripts/test_sum/results.md | 4 ---- scripts/test_sum/test_sum.c | 22 ---------------------- scripts/test_sum/test_sum.js | 17 ----------------- scripts/test_sum/test_sum.py | 16 ---------------- scripts/test_sum/test_sum.toy | 17 ----------------- source/toy_interpreter.c | 2 +- source/toy_literal.c | 8 +++++--- 9 files changed, 11 insertions(+), 85 deletions(-) delete mode 100644 scripts/test_sum/results.md delete mode 100644 scripts/test_sum/test_sum.c delete mode 100644 scripts/test_sum/test_sum.js delete mode 100644 scripts/test_sum/test_sum.py delete mode 100644 scripts/test_sum/test_sum.toy diff --git a/makefile b/makefile index 8fb50fe..9a4db21 100644 --- a/makefile +++ b/makefile @@ -1,7 +1,3 @@ -# Optimisation Options -# export CFLAGS+=-O2 -mtune=native -march=native -# export CFLAGS+=-fsanitize=address,undefined - export CFLAGS+=-std=c18 -pedantic -Werror export TOY_OUTDIR = out @@ -34,6 +30,10 @@ library-release: clean $(TOY_OUTDIR) static-release: clean $(TOY_OUTDIR) $(MAKE) -j8 -C source static-release +#distribution +dist: export CFLAGS+=-O2 -mtune=native -march=native +dist: repl-release + #utils test: clean $(TOY_OUTDIR) $(MAKE) -C test diff --git a/scripts/fib.toy b/scripts/fib.toy index d2c85fe..43021bf 100644 --- a/scripts/fib.toy +++ b/scripts/fib.toy @@ -4,7 +4,7 @@ fn fib(n : int) { return fib(n-1) + fib(n-2); } -for (var i = 0; i < 20; i++) { +for (var i = 0; i <= 35; i++) { var res = fib(i); print string i + ": " + string res; } \ No newline at end of file diff --git a/scripts/test_sum/results.md b/scripts/test_sum/results.md deleted file mode 100644 index 88cc07b..0000000 --- a/scripts/test_sum/results.md +++ /dev/null @@ -1,4 +0,0 @@ -C 0.002s 1 -JS 0.064s 32 -Py3 0.070s 35 -Toy 0.430s 215 \ No newline at end of file diff --git a/scripts/test_sum/test_sum.c b/scripts/test_sum/test_sum.c deleted file mode 100644 index 1aad36c..0000000 --- a/scripts/test_sum/test_sum.c +++ /dev/null @@ -1,22 +0,0 @@ -#include - -//functions be local in C -int sum(int n) { - if (n < 2) { - return n; - } - - return n + sum(n - 1); -} - -//the test case (C) -void test_sum(int key, int val) { - const int result = sum(val); - printf("%d: %d\n", key, result); -} - -int main() { - for (int i = 0; i <= 10; i++) { - test_sum(i, i * 1000); - } -} \ No newline at end of file diff --git a/scripts/test_sum/test_sum.js b/scripts/test_sum/test_sum.js deleted file mode 100644 index 52c02cf..0000000 --- a/scripts/test_sum/test_sum.js +++ /dev/null @@ -1,17 +0,0 @@ -//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/test_sum.py b/scripts/test_sum/test_sum.py deleted file mode 100644 index 57e804a..0000000 --- a/scripts/test_sum/test_sum.py +++ /dev/null @@ -1,16 +0,0 @@ -import sys -sys.setrecursionlimit(11000) - -#the test case (python) -def test_sum(key: int, val: int): - def sum(n: int): - if n < 2: - return n - - return n + sum(n - 1) - - result: int = sum(val) - print(str(key) + ": " + str(result)) - -for i in range(0, 10): - test_sum(i, i * 1000) diff --git a/scripts/test_sum/test_sum.toy b/scripts/test_sum/test_sum.toy deleted file mode 100644 index 632c9e1..0000000 --- a/scripts/test_sum/test_sum.toy +++ /dev/null @@ -1,17 +0,0 @@ -//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 a48dd2b..caa1755 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 >= 1000 * 10) { + if (interpreter->depth >= 1000) { interpreter->errorOutput("Infinite recursion detected - panicking\n"); interpreter->panic = true; return false; diff --git a/source/toy_literal.c b/source/toy_literal.c index 9ceb3c9..3598338 100644 --- a/source/toy_literal.c +++ b/source/toy_literal.c @@ -372,8 +372,10 @@ int Toy_hashLiteral(Toy_Literal lit) { case TOY_LITERAL_INTEGER: return hashUInt((unsigned int)TOY_AS_INTEGER(lit)); - case TOY_LITERAL_FLOAT: - return hashUInt(*(unsigned int*)(&TOY_AS_FLOAT(lit))); + case TOY_LITERAL_FLOAT: { + unsigned int* ptr = (unsigned int*)(&TOY_AS_FLOAT(lit)); + return hashUInt(*ptr); + } case TOY_LITERAL_STRING: return hashString(Toy_toCString(TOY_AS_STRING(lit)), Toy_lengthRefString(TOY_AS_STRING(lit))); @@ -440,7 +442,7 @@ static void printToBuffer(const char* str) { globalPrintBuffer = TOY_GROW_ARRAY(char, globalPrintBuffer, oldCapacity, globalPrintCapacity); } - snprintf(globalPrintBuffer + globalPrintCount, strlen(str) + 1, "%s", str); + snprintf(globalPrintBuffer + globalPrintCount, strlen(str) + 1, "%s", str ? str : "\0"); globalPrintCount += strlen(str); }