Compare commits

..

2 Commits

Author SHA1 Message Date
Kayne Ruse 733df87c08 Added dist target, lowered recursion depth limit 2023-06-07 14:58:51 +10:00
Kayne Ruse bfd506f497 Forgot memory allocator for reffunctions 2023-06-07 02:02:35 +10:00
13 changed files with 28 additions and 88 deletions
+4 -4
View File
@@ -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
+1 -1
View File
@@ -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;
}
-4
View File
@@ -1,4 +0,0 @@
C 0.002s 1
JS 0.064s 32
Py3 0.070s 35
Toy 0.430s 215
-22
View File
@@ -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);
}
}
-17
View File
@@ -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);
}
-16
View File
@@ -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)
-17
View File
@@ -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);
}
+3 -1
View File
@@ -61,8 +61,10 @@ to the same string to save memory, and you can just create a new one of these va
rather than copying entirely for a speed boost. This module has it's own memory allocator system that is
plugged into the main memory allocator.
`Toy_RefFunction` acts similarly to `Toy_RefString`, but instead operates on function bytecode.
*/
#include "toy_scope.h"
#include "toy_refstring.h"
#include "toy_reffunction.h"
+1 -1
View File
@@ -6,7 +6,7 @@
#define TOY_VERSION_MAJOR 1
#define TOY_VERSION_MINOR 1
#define TOY_VERSION_PATCH 3
#define TOY_VERSION_PATCH 4
#define TOY_VERSION_BUILD __DATE__ " " __TIME__
//platform/compiler-specific instructions
+11 -1
View File
@@ -1,6 +1,16 @@
#pragma once
//NOTE: you need both font AND background for these to work
/* toy_console_colors.h - console utility
This file provides a number of macros that can set the color of text in a console
window. These are used for convenience only. They are supposed to be dropped into
a printf()'s first argument, like so:
printf(TOY_CC_NOTICE "Hello world" TOY_CC_RESET);
NOTE: you need both font AND background for these to work
*/
//platform/compiler-specific instructions
#if defined(__linux__) || defined(__MINGW32__) || defined(__GNUC__)
+1 -1
View File
@@ -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;
+5 -3
View File
@@ -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);
}
+2
View File
@@ -1,5 +1,6 @@
#include "toy_memory.h"
#include "toy_refstring.h"
#include "toy_reffunction.h"
#include "toy_console_colors.h"
@@ -49,4 +50,5 @@ void Toy_setMemoryAllocator(Toy_MemoryAllocatorFn fn) {
allocator = fn;
Toy_setRefStringAllocatorFn(fn);
Toy_setRefFunctionAllocatorFn(fn);
}