mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Added dist target, lowered recursion depth limit
This commit is contained in:
8
makefile
8
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 CFLAGS+=-std=c18 -pedantic -Werror
|
||||||
|
|
||||||
export TOY_OUTDIR = out
|
export TOY_OUTDIR = out
|
||||||
@@ -34,6 +30,10 @@ library-release: clean $(TOY_OUTDIR)
|
|||||||
static-release: clean $(TOY_OUTDIR)
|
static-release: clean $(TOY_OUTDIR)
|
||||||
$(MAKE) -j8 -C source static-release
|
$(MAKE) -j8 -C source static-release
|
||||||
|
|
||||||
|
#distribution
|
||||||
|
dist: export CFLAGS+=-O2 -mtune=native -march=native
|
||||||
|
dist: repl-release
|
||||||
|
|
||||||
#utils
|
#utils
|
||||||
test: clean $(TOY_OUTDIR)
|
test: clean $(TOY_OUTDIR)
|
||||||
$(MAKE) -C test
|
$(MAKE) -C test
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ fn fib(n : int) {
|
|||||||
return fib(n-1) + fib(n-2);
|
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);
|
var res = fib(i);
|
||||||
print string i + ": " + string res;
|
print string i + ": " + string res;
|
||||||
}
|
}
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
C 0.002s 1
|
|
||||||
JS 0.064s 32
|
|
||||||
Py3 0.070s 35
|
|
||||||
Toy 0.430s 215
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
//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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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);
|
|
||||||
}
|
|
||||||
@@ -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)
|
|
||||||
@@ -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);
|
|
||||||
}
|
|
||||||
@@ -1193,7 +1193,7 @@ static void readInterpreterSections(Toy_Interpreter* interpreter);
|
|||||||
//also supports identifier & arg1 to be other way around (looseFirstArgument)
|
//also supports identifier & arg1 to be other way around (looseFirstArgument)
|
||||||
static bool execFnCall(Toy_Interpreter* interpreter, bool looseFirstArgument) {
|
static bool execFnCall(Toy_Interpreter* interpreter, bool looseFirstArgument) {
|
||||||
//BUGFIX: depth check - don't drown!
|
//BUGFIX: depth check - don't drown!
|
||||||
if (interpreter->depth >= 1000 * 10) {
|
if (interpreter->depth >= 1000) {
|
||||||
interpreter->errorOutput("Infinite recursion detected - panicking\n");
|
interpreter->errorOutput("Infinite recursion detected - panicking\n");
|
||||||
interpreter->panic = true;
|
interpreter->panic = true;
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -372,8 +372,10 @@ int Toy_hashLiteral(Toy_Literal lit) {
|
|||||||
case TOY_LITERAL_INTEGER:
|
case TOY_LITERAL_INTEGER:
|
||||||
return hashUInt((unsigned int)TOY_AS_INTEGER(lit));
|
return hashUInt((unsigned int)TOY_AS_INTEGER(lit));
|
||||||
|
|
||||||
case TOY_LITERAL_FLOAT:
|
case TOY_LITERAL_FLOAT: {
|
||||||
return hashUInt(*(unsigned int*)(&TOY_AS_FLOAT(lit)));
|
unsigned int* ptr = (unsigned int*)(&TOY_AS_FLOAT(lit));
|
||||||
|
return hashUInt(*ptr);
|
||||||
|
}
|
||||||
|
|
||||||
case TOY_LITERAL_STRING:
|
case TOY_LITERAL_STRING:
|
||||||
return hashString(Toy_toCString(TOY_AS_STRING(lit)), Toy_lengthRefString(TOY_AS_STRING(lit)));
|
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);
|
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);
|
globalPrintCount += strlen(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user