From 3d26296d06c4122c14408eb4e418903c1faec687 Mon Sep 17 00:00:00 2001 From: Liz3 Date: Thu, 14 Nov 2024 00:51:02 +0100 Subject: [PATCH 01/13] feat: call dictu from native code This uses a stack loaded piece of code to interrupt the current vm execution in order to invoke a function called by native code. It creates a new callframe for that and then makes sure the vm loop breaks after that frame was reached again, this way the result is returned tp the caller. It then resets the vm state and continues normally. --- src/vm/datatypes/strings.c | 8 ++++++++ src/vm/vm.c | 32 +++++++++++++++++++++++++++++++- src/vm/vm.h | 2 ++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/vm/datatypes/strings.c b/src/vm/datatypes/strings.c index d4244068..0f983fcf 100644 --- a/src/vm/datatypes/strings.c +++ b/src/vm/datatypes/strings.c @@ -884,6 +884,13 @@ static Value isValidUtf8(DictuVM *vm, int argCount, Value *args) { return BOOL_VAL(string->character_len != -1); } +static Value testThing(DictuVM *vm, int argCount, Value *args) { + int argC = argCount-1; + Value func = args[1]; + Value* func_args = args +2; + return executeDirect(vm, func, argC, func_args); +} + void declareStringMethods(DictuVM *vm) { // Note(Liz3): We need functions from the c stdlib for iswalpha, iswlower, // iswupper(the utf8.c library functions do not work) @@ -916,4 +923,5 @@ void declareStringMethods(DictuVM *vm) { defineNative(vm, &vm->stringMethods, "collapseSpaces", collapseSpacesString); defineNative(vm, &vm->stringMethods, "wrap", wrapString); + defineNative(vm, &vm->stringMethods, "testThing", testThing); } diff --git a/src/vm/vm.c b/src/vm/vm.c index 3caef3d8..5ab16200 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -27,6 +27,7 @@ #include "datatypes/enums.h" #include "natives.h" #include "../optionals/optionals.h" +#include "value.h" static void resetStack(DictuVM *vm) { vm->stackTop = vm->stack; @@ -866,7 +867,9 @@ static void copyAnnotations(DictuVM *vm, ObjDict *superAnnotations, ObjDict *kla } } -static DictuInterpretResult run(DictuVM *vm) { + + +static DictuInterpretResult runWithBreakFrame(DictuVM *vm, int breakFrame) { CallFrame *frame = &vm->frames[vm->frameCount - 1]; register uint8_t* ip = frame->ip; @@ -877,6 +880,7 @@ static DictuInterpretResult run(DictuVM *vm) { #define READ_CONSTANT() \ (frame->closure->function->chunk.constants.values[READ_BYTE()]) + #define READ_STRING() AS_STRING(READ_CONSTANT()) #define UNSUPPORTED_OPERAND_TYPE_ERROR(op) \ @@ -2253,6 +2257,7 @@ static DictuInterpretResult run(DictuVM *vm) { } CASE_CODE(RETURN): { + Value result = pop(vm); // Close any upvalues still in scope. @@ -2270,6 +2275,10 @@ static DictuInterpretResult run(DictuVM *vm) { frame = &vm->frames[vm->frameCount - 1]; ip = frame->ip; + if (breakFrame != -1 && vm->frameCount == breakFrame) { + return INTERPRET_OK; + } + DISPATCH(); } @@ -2435,6 +2444,9 @@ static DictuInterpretResult run(DictuVM *vm) { return INTERPRET_RUNTIME_ERROR; } +static DictuInterpretResult run(DictuVM *vm) { + return runWithBreakFrame(vm, -1); +} DictuInterpretResult dictuInterpret(DictuVM *vm, char *moduleName, char *source) { ObjString *name = copyString(vm, moduleName, strlen(moduleName)); @@ -2457,3 +2469,21 @@ DictuInterpretResult dictuInterpret(DictuVM *vm, char *moduleName, char *source) return result; } +Value executeDirect(DictuVM* vm, Value function, int argCount, Value* args) { + if(!IS_FUNCTION(function) && !IS_CLOSURE(function)) + return NIL_VAL; + int currentFrameCount = vm->frameCount; + Value* currentStack = vm->stackTop; + CallFrame *frame = &vm->frames[vm->frameCount++]; + uint8_t code[4] = {OP_CALL, argCount, 0, OP_RETURN}; + frame->ip = code; + push(vm, function); + for(int i = argCount -1; i >= 0; i--) { + push(vm, args[i]); + } + runWithBreakFrame(vm, currentFrameCount+1); + Value v = pop(vm); + vm->stackTop = currentStack; + vm->frameCount--; + return v; +} \ No newline at end of file diff --git a/src/vm/vm.h b/src/vm/vm.h index 9bc63e2f..0468873b 100644 --- a/src/vm/vm.h +++ b/src/vm/vm.h @@ -69,4 +69,6 @@ bool isFalsey(Value value); ObjClosure *compileModuleToClosure(DictuVM *vm, char *name, char *source); +Value executeDirect(DictuVM* vm, Value function, int argCount, Value* args); + #endif From 70d10835b04e5cb909e4ae17e4d7badca1842289 Mon Sep 17 00:00:00 2001 From: Liz3 Date: Thu, 14 Nov 2024 01:51:59 +0100 Subject: [PATCH 02/13] fix: rename and add entry for ffi --- src/include/dictu_ffi_include.h | 11 +++++++++-- src/optionals/ffi/ffi.c | 3 ++- src/optionals/ffi/ffi.h | 2 +- src/vm/datatypes/strings.c | 2 +- src/vm/vm.c | 2 +- src/vm/vm.h | 2 +- 6 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/include/dictu_ffi_include.h b/src/include/dictu_ffi_include.h index abefa144..7763834b 100644 --- a/src/include/dictu_ffi_include.h +++ b/src/include/dictu_ffi_include.h @@ -11,7 +11,7 @@ extern "C" { // This is used ti determine if we can safely load the function pointers without // UB. -#define FFI_MOD_API_VERSION 2 +#define FFI_MOD_API_VERSION 3 #define UNUSED(__x__) (void)__x__ @@ -343,7 +343,7 @@ struct _vm { }; #define DICTU_MAJOR_VERSION "0" -#define DICTU_MINOR_VERSION "29" +#define DICTU_MINOR_VERSION "30" #define DICTU_PATCH_VERSION "0" #define DICTU_STRING_VERSION \ @@ -364,6 +364,7 @@ struct sObjString { int length; char *chars; uint32_t hash; + int character_len; }; struct sObjList { @@ -550,6 +551,9 @@ typedef void defineNative_t(DictuVM *vm, Table *table, const char *name, typedef void defineNativeProperty_t(DictuVM *vm, Table *table, const char *name, Value value); + +typedef Value callFunction_t(DictuVM* vm, Value function, int argCount, Value* args); + reallocate_t * reallocate = NULL; copyString_t *copyString = NULL; @@ -616,6 +620,8 @@ defineNative_t *defineNative = NULL; defineNativeProperty_t *defineNativeProperty = NULL; +callFunction_t *callFunction = NULL; + // This needs to be implemented by the user and register all functions int dictu_ffi_init(DictuVM *vm, Table *method_table); @@ -665,6 +671,7 @@ int dictu_internal_ffi_init(void **function_ptrs, DictuVM *vm, defineNative = (defineNative_t *)function_ptrs[count++]; defineNativeProperty = (defineNativeProperty_t *)function_ptrs[count++]; reallocate = (reallocate_t *)function_ptrs[count++]; + callFunction = (callFunction_t *)function_ptrs[count++]; int initResult = dictu_ffi_init(vm, methodTable); if (initResult > 0) return 3 + initResult; diff --git a/src/optionals/ffi/ffi.c b/src/optionals/ffi/ffi.c index 90adec19..d9d00113 100644 --- a/src/optionals/ffi/ffi.c +++ b/src/optionals/ffi/ffi.c @@ -53,7 +53,8 @@ void *ffi_function_pointers[] = {©String, &compareStringGreater, &defineNative, &defineNativeProperty, - &reallocate}; + &reallocate, + &callFunction}; void freeFFI(DictuVM *vm, ObjAbstract *abstract) { FFIInstance *instance = (FFIInstance *)abstract->data; diff --git a/src/optionals/ffi/ffi.h b/src/optionals/ffi/ffi.h index 245ebcb6..7b1de964 100644 --- a/src/optionals/ffi/ffi.h +++ b/src/optionals/ffi/ffi.h @@ -19,7 +19,7 @@ // This is used to determine if we can safely load the function pointers without UB, // if this is greater then the version from the mod we error in the internal mod load function. -#define DICTU_FFI_API_VERSION 2 +#define DICTU_FFI_API_VERSION 3 Value createFFIModule(DictuVM *vm); diff --git a/src/vm/datatypes/strings.c b/src/vm/datatypes/strings.c index 0f983fcf..3d724594 100644 --- a/src/vm/datatypes/strings.c +++ b/src/vm/datatypes/strings.c @@ -888,7 +888,7 @@ static Value testThing(DictuVM *vm, int argCount, Value *args) { int argC = argCount-1; Value func = args[1]; Value* func_args = args +2; - return executeDirect(vm, func, argC, func_args); + return callFunction(vm, func, argC, func_args); } void declareStringMethods(DictuVM *vm) { diff --git a/src/vm/vm.c b/src/vm/vm.c index 5ab16200..59919d5e 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -2469,7 +2469,7 @@ DictuInterpretResult dictuInterpret(DictuVM *vm, char *moduleName, char *source) return result; } -Value executeDirect(DictuVM* vm, Value function, int argCount, Value* args) { +Value callFunction(DictuVM* vm, Value function, int argCount, Value* args) { if(!IS_FUNCTION(function) && !IS_CLOSURE(function)) return NIL_VAL; int currentFrameCount = vm->frameCount; diff --git a/src/vm/vm.h b/src/vm/vm.h index 0468873b..74e7cb36 100644 --- a/src/vm/vm.h +++ b/src/vm/vm.h @@ -69,6 +69,6 @@ bool isFalsey(Value value); ObjClosure *compileModuleToClosure(DictuVM *vm, char *name, char *source); -Value executeDirect(DictuVM* vm, Value function, int argCount, Value* args); +Value callFunction(DictuVM* vm, Value function, int argCount, Value* args); #endif From 5415b63b7c5f71952752fed0f7c92f57256ff930 Mon Sep 17 00:00:00 2001 From: Liz3 Date: Thu, 14 Nov 2024 02:35:19 +0100 Subject: [PATCH 03/13] fix: address comments --- src/vm/vm.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/vm/vm.c b/src/vm/vm.c index 59919d5e..9b93c371 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -2470,10 +2470,19 @@ DictuInterpretResult dictuInterpret(DictuVM *vm, char *moduleName, char *source) return result; } Value callFunction(DictuVM* vm, Value function, int argCount, Value* args) { - if(!IS_FUNCTION(function) && !IS_CLOSURE(function)) - return NIL_VAL; + + if(!IS_FUNCTION(function) && !IS_CLOSURE(function)){ + runtimeError(vm, "Value passed to callFunction is not callable"); + return EMPTY_VAL; + } int currentFrameCount = vm->frameCount; Value* currentStack = vm->stackTop; + if (vm->frameCount == vm->frameCapacity) { + int oldCapacity = vm->frameCapacity; + vm->frameCapacity = GROW_CAPACITY(vm->frameCapacity); + vm->frames = GROW_ARRAY(vm, vm->frames, CallFrame, + oldCapacity, vm->frameCapacity); + } CallFrame *frame = &vm->frames[vm->frameCount++]; uint8_t code[4] = {OP_CALL, argCount, 0, OP_RETURN}; frame->ip = code; @@ -2481,7 +2490,10 @@ Value callFunction(DictuVM* vm, Value function, int argCount, Value* args) { for(int i = argCount -1; i >= 0; i--) { push(vm, args[i]); } - runWithBreakFrame(vm, currentFrameCount+1); + DictuInterpretResult result = runWithBreakFrame(vm, currentFrameCount+1); + if(result != INTERPRET_OK) { + exit(70); + } Value v = pop(vm); vm->stackTop = currentStack; vm->frameCount--; From 9d7354074e25cee6a378644c054dea5883ee0b58 Mon Sep 17 00:00:00 2001 From: Liz3 Date: Thu, 14 Nov 2024 02:40:09 +0100 Subject: [PATCH 04/13] add native handler --- src/vm/vm.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/vm/vm.c b/src/vm/vm.c index 9b93c371..2383e925 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -2472,6 +2472,10 @@ DictuInterpretResult dictuInterpret(DictuVM *vm, char *moduleName, char *source) Value callFunction(DictuVM* vm, Value function, int argCount, Value* args) { if(!IS_FUNCTION(function) && !IS_CLOSURE(function)){ + if(IS_NATIVE(function)) { + NativeFn native = AS_NATIVE(function); + return native(vm, argCount, args); + } runtimeError(vm, "Value passed to callFunction is not callable"); return EMPTY_VAL; } From 285e4d0a73d970cc36265bd166657274cee0109b Mon Sep 17 00:00:00 2001 From: Liz3 Date: Thu, 14 Nov 2024 02:54:59 +0100 Subject: [PATCH 05/13] this is not reversed --- src/vm/vm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm/vm.c b/src/vm/vm.c index 2383e925..9685a599 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -2491,7 +2491,7 @@ Value callFunction(DictuVM* vm, Value function, int argCount, Value* args) { uint8_t code[4] = {OP_CALL, argCount, 0, OP_RETURN}; frame->ip = code; push(vm, function); - for(int i = argCount -1; i >= 0; i--) { + for(int i = 0; i < argCount; i++) { push(vm, args[i]); } DictuInterpretResult result = runWithBreakFrame(vm, currentFrameCount+1); From 7f3c8399a3af4500f99d1d713966768340cdf939 Mon Sep 17 00:00:00 2001 From: Liz3 Date: Thu, 14 Nov 2024 05:13:30 +0100 Subject: [PATCH 06/13] add tests for callback based ffi entries --- .github/workflows/main.yml | 12 +++++ .../clangd/index/lib.c.E0B4FF22A3F07B5C.idx | Bin 0 -> 1438 bytes examples/ffi-example/src/lib.c | 8 ++++ tests/ffi/ffi.du | 43 ++++++++++++++++-- tests/ffi/libs/test-lib.dll | Bin 10240 -> 0 bytes tests/ffi/libs/test-lib.so | Bin 16352 -> 0 bytes tests/ffi/libs/test-lib_64.dylib | Bin 18240 -> 0 bytes tests/ffi/libs/test-lib_arm.dylib | Bin 18512 -> 0 bytes 8 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 examples/ffi-example/.cache/clangd/index/lib.c.E0B4FF22A3F07B5C.idx delete mode 100644 tests/ffi/libs/test-lib.dll delete mode 100755 tests/ffi/libs/test-lib.so delete mode 100755 tests/ffi/libs/test-lib_64.dylib delete mode 100755 tests/ffi/libs/test-lib_arm.dylib diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9bdf2d00..f2231647 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -30,6 +30,10 @@ jobs: - uses: actions/checkout@v3 - name: Make dictu and run tests (No HTTP) run: | + cd examples/ffi-example + cmake -DCMAKE_BUILD_TYPE=Debug -B ./build + cmake --build ./build + cd ../.. cmake -DCMAKE_BUILD_TYPE=Debug -DDISABLE_HTTP=1 -B ./build cmake --build ./build ./dictu tests/runTests.du ci | tee /dev/stderr | grep -q 'Total bytes lost: 0' @@ -54,6 +58,10 @@ jobs: - uses: actions/checkout@v3 - name: Make dictu and run tests (No HTTP) run: | + cd examples/ffi-example + cmake -DCMAKE_BUILD_TYPE=Debug -B ./build + cmake --build ./build + cd ../.. cmake -DCMAKE_BUILD_TYPE=Debug -DDISABLE_HTTP=1 -B ./build cmake --build ./build ./dictu tests/runTests.du ci | tee /dev/stderr | grep -q 'Total bytes lost: 0' @@ -76,6 +84,10 @@ jobs: - uses: actions/checkout@v3 - name: Make dictu and run tests (No HTTP) run: | + cd examples\ffi-example + cmake -DCMAKE_BUILD_TYPE=Debug -B .\build + cmake --build ./build --config Debug + cd ..\.. cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_SYSTEM_VERSION="10.0.18362.0" -DCICD=1 -DDISABLE_HTTP=1 -B build cmake --build build Debug\dictu.exe tests/runTests.du ci diff --git a/examples/ffi-example/.cache/clangd/index/lib.c.E0B4FF22A3F07B5C.idx b/examples/ffi-example/.cache/clangd/index/lib.c.E0B4FF22A3F07B5C.idx new file mode 100644 index 0000000000000000000000000000000000000000..8bc6e94e5c22fd968242909c57f98fe2308eab5b GIT binary patch literal 1438 zcmWIYbaR`=%D~{9;#rZKT9U}Zz`!63#Kk2=nGTE$46~US7%Jw>o#^k)Y$$N_`Qj%R zoTF#)t`?7cu`=|d3P*L_@sQG_x|0pSM3mS)Ozx%t@8cf83!u1obO&L zq-eM1z^XHI0)2j*z6o9JWBvvz8#$18)zj|qitbvI`+EOnS(y7p9q-IVM7vv2Qy zYkNU7JGb3u^>^=Wh2J<`KfIZ7?8DYq^GvI*?S3&mA#&Qh@+M8?k|`V^3~S9-vtD3Z z!TRdL?H4RTEAPy4egCWAT+2G2!=JPl*qx|MPMUXk=2aUl-SeiZm-g8U7q~n;RkP?o zQtaCgZnf{1uTHW3*sr*GL+(^{w!kVOorfMFr`}v(nbNX<;svEnIoXvxDtyvUorR(% zTS*B{F_m-K$TaiEsgj!15Q!64s+7Dh{;pIlTV5z5l24Hyhgw2?==Jhjn9tKec1~D!+E(tIJlmUa<(8*_}@3Ul?zP@?;~{hnOMZQxw(a4Zf6mb z=8)!xDS|l}XcEZ1FpGG^#7xATV2WTgBNy1!FhyH$|5fR28P`$j5@> z%eE4V+&p4T3{0#r8-P3mCQ}%XMT~`?MGVH{5#wUuVuiU7$TQ)xgz->a&m+diz=sGX zF+NK^J6NExhzaluh{1R~VuCD!oG>1$uN#-2JDGlIqX{r**!bBbV9sC>W9Mgw^I%$m zK?8~in6G)nBrGKYV4gi=m~I!+Ho=P-7-CFfd@x~POfZQf@g$fe;JiXj*EzQuG<{is zAtK5o1G60HYe_Bzn6H8Ul;cx{IRO~J!lF_z!|#RaUwM8rD1nIw?0SU5K(2@JdRIOW zm%9741gHoU`!Hc1aO}f)-4VL8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A@i@XY!#T)w_n+`M3QSKh#TWfeC=i;6af*Vs3D>hHAI}E z21lydrV~bHu^aq|5o=0PlrobTrOf1Pl=8IMLz2RliN7&!pfYW5pfWKUxWZvm=!P|i zCR0R-nHa>-8?77nCUY( z&2>Iid@6*ge^+USYsF88(3W~WqH;8rx$V=<$-bxeZeQ`pq09HL{^_w(m47+*)+0L_ zatpgQYo`vKJl&ocez&uz|L($tC)BO&^QQNo+5hBIe|Y_yEzhn#{-5jzp5Obu9k<*+ z-FM&P(fTz*cJadTb4%a*zTdxV`ufotxcpisb>#<7uKoS?;hG=+y6RL#^;=60g8j}9 PYYr^i`O3sy(*XYfmQ|Rj From 9b16ab0c0503ad288bde4a3d7a80e34d15057e97 Mon Sep 17 00:00:00 2001 From: Liz3 Date: Thu, 14 Nov 2024 05:14:38 +0100 Subject: [PATCH 07/13] fix: remove dummy function --- src/vm/datatypes/strings.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/vm/datatypes/strings.c b/src/vm/datatypes/strings.c index 3d724594..622f57be 100644 --- a/src/vm/datatypes/strings.c +++ b/src/vm/datatypes/strings.c @@ -884,12 +884,6 @@ static Value isValidUtf8(DictuVM *vm, int argCount, Value *args) { return BOOL_VAL(string->character_len != -1); } -static Value testThing(DictuVM *vm, int argCount, Value *args) { - int argC = argCount-1; - Value func = args[1]; - Value* func_args = args +2; - return callFunction(vm, func, argC, func_args); -} void declareStringMethods(DictuVM *vm) { // Note(Liz3): We need functions from the c stdlib for iswalpha, iswlower, @@ -923,5 +917,4 @@ void declareStringMethods(DictuVM *vm) { defineNative(vm, &vm->stringMethods, "collapseSpaces", collapseSpacesString); defineNative(vm, &vm->stringMethods, "wrap", wrapString); - defineNative(vm, &vm->stringMethods, "testThing", testThing); } From b07a8236625530e7658fdf9ffc481b3369612998 Mon Sep 17 00:00:00 2001 From: Liz3 Date: Thu, 14 Nov 2024 05:17:32 +0100 Subject: [PATCH 08/13] remove clangd file --- .gitignore | 1 + .../clangd/index/lib.c.E0B4FF22A3F07B5C.idx | Bin 1438 -> 0 bytes 2 files changed, 1 insertion(+) delete mode 100644 examples/ffi-example/.cache/clangd/index/lib.c.E0B4FF22A3F07B5C.idx diff --git a/.gitignore b/.gitignore index 67cd9090..9c22668e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ \.idea/ +.cache build/ \.DS_Store dictu diff --git a/examples/ffi-example/.cache/clangd/index/lib.c.E0B4FF22A3F07B5C.idx b/examples/ffi-example/.cache/clangd/index/lib.c.E0B4FF22A3F07B5C.idx deleted file mode 100644 index 8bc6e94e5c22fd968242909c57f98fe2308eab5b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1438 zcmWIYbaR`=%D~{9;#rZKT9U}Zz`!63#Kk2=nGTE$46~US7%Jw>o#^k)Y$$N_`Qj%R zoTF#)t`?7cu`=|d3P*L_@sQG_x|0pSM3mS)Ozx%t@8cf83!u1obO&L zq-eM1z^XHI0)2j*z6o9JWBvvz8#$18)zj|qitbvI`+EOnS(y7p9q-IVM7vv2Qy zYkNU7JGb3u^>^=Wh2J<`KfIZ7?8DYq^GvI*?S3&mA#&Qh@+M8?k|`V^3~S9-vtD3Z z!TRdL?H4RTEAPy4egCWAT+2G2!=JPl*qx|MPMUXk=2aUl-SeiZm-g8U7q~n;RkP?o zQtaCgZnf{1uTHW3*sr*GL+(^{w!kVOorfMFr`}v(nbNX<;svEnIoXvxDtyvUorR(% zTS*B{F_m-K$TaiEsgj!15Q!64s+7Dh{;pIlTV5z5l24Hyhgw2?==Jhjn9tKec1~D!+E(tIJlmUa<(8*_}@3Ul?zP@?;~{hnOMZQxw(a4Zf6mb z=8)!xDS|l}XcEZ1FpGG^#7xATV2WTgBNy1!FhyH$|5fR28P`$j5@> z%eE4V+&p4T3{0#r8-P3mCQ}%XMT~`?MGVH{5#wUuVuiU7$TQ)xgz->a&m+diz=sGX zF+NK^J6NExhzaluh{1R~VuCD!oG>1$uN#-2JDGlIqX{r**!bBbV9sC>W9Mgw^I%$m zK?8~in6G)nBrGKYV4gi=m~I!+Ho=P-7-CFfd@x~POfZQf@g$fe;JiXj*EzQuG<{is zAtK5o1G60HYe_Bzn6H8Ul;cx{IRO~J!lF_z!|#RaUwM8rD1nIw?0SU5K(2@JdRIOW zm%9741gHoU`!Hc1aO}f)-4VL8kJ&722F9Qew~#o@x)1UEm*;)>-T@Tm;N}1(bqLTq zsx7tb*}F+>EMm-(%t|na19=9_mIxkl#G*zXY6PK1Nk`fI+bZ)KrUUJiWRetv`L!zT zkP!Y&sF!us^K!?G2yUwk0KDq1u3!oy9 z3t_@M;6wxC{fJErcfYsiHzNz!=P*wdrRF4ploS^w7mEXFMlqIUf4y=N7qT&mGk^r3 aAUQWBhY!f+;o)Op<=|%L Date: Fri, 15 Nov 2024 00:55:41 +0100 Subject: [PATCH 09/13] fix: add error handling for sythentic call frame --- src/vm/vm.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/vm/vm.c b/src/vm/vm.c index 9685a599..782f1f42 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -59,21 +59,25 @@ void runtimeError(DictuVM *vm, const char *format, ...) { for (int i = vm->frameCount - 1; i >= 0; i--) { CallFrame *frame = &vm->frames[i]; - ObjFunction *function = frame->closure->function; + if(frame->closure == NULL) { + // synthetic frame created by callFunction + log_error("Function {reset}"); + } else { + ObjFunction *function = frame->closure->function; - // -1 because the IP is sitting on the next instruction to be - // executed. - size_t instruction = frame->ip - function->chunk.code - 1; + // -1 because the IP is sitting on the next instruction to be + // executed. + size_t instruction = frame->ip - function->chunk.code - 1; - if (function->name == NULL) { - log_error("File '%s', {bold}line %d{reset}", function->module->name->chars, function->chunk.lines[instruction]); - i = -1; - } else { - log_error("Function '%s' in '%s', {bold}line %d{reset}", function->name->chars, function->module->name->chars, function->chunk.lines[instruction]); - } + if (function->name == NULL) { + log_error("File '%s', {bold}line %d{reset}", function->module->name->chars, function->chunk.lines[instruction]); + i = -1; + } else { + log_error("Function '%s' in '%s', {bold}line %d{reset}", function->name->chars, function->module->name->chars, function->chunk.lines[instruction]); + } + } log_pad(""); - va_list args; va_start(args, format); vfprintf(stderr, format, args); @@ -2490,6 +2494,7 @@ Value callFunction(DictuVM* vm, Value function, int argCount, Value* args) { CallFrame *frame = &vm->frames[vm->frameCount++]; uint8_t code[4] = {OP_CALL, argCount, 0, OP_RETURN}; frame->ip = code; + frame->closure = NULL; push(vm, function); for(int i = 0; i < argCount; i++) { push(vm, args[i]); From a6f331a450fbfad8f0e15614dae7a9aed8ecb612 Mon Sep 17 00:00:00 2001 From: Liz3 Date: Fri, 15 Nov 2024 02:05:10 +0100 Subject: [PATCH 10/13] fix: continue on synthetic frame --- src/vm/vm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm/vm.c b/src/vm/vm.c index 782f1f42..0a3eb2ca 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -61,7 +61,7 @@ void runtimeError(DictuVM *vm, const char *format, ...) { if(frame->closure == NULL) { // synthetic frame created by callFunction - log_error("Function {reset}"); + continue; } else { ObjFunction *function = frame->closure->function; From 69e10a4a7ec662326813c02a703fb05cdf99010a Mon Sep 17 00:00:00 2001 From: Liz3 Date: Fri, 15 Nov 2024 02:22:26 +0100 Subject: [PATCH 11/13] fix: remove unneeded changes --- src/vm/datatypes/strings.c | 1 - src/vm/vm.c | 28 ++++++++++++---------------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/vm/datatypes/strings.c b/src/vm/datatypes/strings.c index 622f57be..d4244068 100644 --- a/src/vm/datatypes/strings.c +++ b/src/vm/datatypes/strings.c @@ -884,7 +884,6 @@ static Value isValidUtf8(DictuVM *vm, int argCount, Value *args) { return BOOL_VAL(string->character_len != -1); } - void declareStringMethods(DictuVM *vm) { // Note(Liz3): We need functions from the c stdlib for iswalpha, iswlower, // iswupper(the utf8.c library functions do not work) diff --git a/src/vm/vm.c b/src/vm/vm.c index 0a3eb2ca..2e57dc4d 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -62,21 +62,20 @@ void runtimeError(DictuVM *vm, const char *format, ...) { if(frame->closure == NULL) { // synthetic frame created by callFunction continue; - } else { - ObjFunction *function = frame->closure->function; + } + ObjFunction *function = frame->closure->function; - // -1 because the IP is sitting on the next instruction to be - // executed. - size_t instruction = frame->ip - function->chunk.code - 1; - - if (function->name == NULL) { - log_error("File '%s', {bold}line %d{reset}", function->module->name->chars, function->chunk.lines[instruction]); - i = -1; - } else { - log_error("Function '%s' in '%s', {bold}line %d{reset}", function->name->chars, function->module->name->chars, function->chunk.lines[instruction]); - } + // -1 because the IP is sitting on the next instruction to be + // executed. + size_t instruction = frame->ip - function->chunk.code - 1; + if (function->name == NULL) { + log_error("File '%s', {bold}line %d{reset}", function->module->name->chars, function->chunk.lines[instruction]); + i = -1; + } else { + log_error("Function '%s' in '%s', {bold}line %d{reset}", function->name->chars, function->module->name->chars, function->chunk.lines[instruction]); } + log_pad(""); va_list args; va_start(args, format); @@ -884,7 +883,6 @@ static DictuInterpretResult runWithBreakFrame(DictuVM *vm, int breakFrame) { #define READ_CONSTANT() \ (frame->closure->function->chunk.constants.values[READ_BYTE()]) - #define READ_STRING() AS_STRING(READ_CONSTANT()) #define UNSUPPORTED_OPERAND_TYPE_ERROR(op) \ @@ -2261,7 +2259,6 @@ static DictuInterpretResult runWithBreakFrame(DictuVM *vm, int breakFrame) { } CASE_CODE(RETURN): { - Value result = pop(vm); // Close any upvalues still in scope. @@ -2474,7 +2471,6 @@ DictuInterpretResult dictuInterpret(DictuVM *vm, char *moduleName, char *source) return result; } Value callFunction(DictuVM* vm, Value function, int argCount, Value* args) { - if(!IS_FUNCTION(function) && !IS_CLOSURE(function)){ if(IS_NATIVE(function)) { NativeFn native = AS_NATIVE(function); @@ -2507,4 +2503,4 @@ Value callFunction(DictuVM* vm, Value function, int argCount, Value* args) { vm->stackTop = currentStack; vm->frameCount--; return v; -} \ No newline at end of file +} From 4391dd47a9472b439afb3e8b73d0c8ae2e751814 Mon Sep 17 00:00:00 2001 From: Liz3 Date: Fri, 15 Nov 2024 02:24:31 +0100 Subject: [PATCH 12/13] fix: remove useless change --- src/vm/vm.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/vm/vm.c b/src/vm/vm.c index 2e57dc4d..d11ae39c 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -77,6 +77,7 @@ void runtimeError(DictuVM *vm, const char *format, ...) { } log_pad(""); + va_list args; va_start(args, format); vfprintf(stderr, format, args); From 1a6764ac4631f9e0307ac4cba10efb4543da138c Mon Sep 17 00:00:00 2001 From: Liz3 Date: Fri, 15 Nov 2024 21:16:32 +0100 Subject: [PATCH 13/13] use unit tests: setUp --- tests/ffi/ffi.du | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/ffi/ffi.du b/tests/ffi/ffi.du index de8b4799..a59de0db 100644 --- a/tests/ffi/ffi.du +++ b/tests/ffi/ffi.du @@ -39,7 +39,7 @@ import Path; class TestFFIModule < UnitTest { var mod = nil; - doSetup() { + setUp() { if(this.mod != nil) return; const parts = ["examples", "ffi-example", "build"]; @@ -54,7 +54,6 @@ class TestFFIModule < UnitTest { this.mod = FFI.load(path); } testFFIModule() { - this.doSetup(); const mod = this.mod; this.assertEquals(mod.test, "Dictu!"); for(var i = 0; i < 40; i+=2) { @@ -63,7 +62,6 @@ class TestFFIModule < UnitTest { this.assertEquals(mod.dictuFFITestStr(), "Hello From Dictu FFI module!"); } testFFIModuleCallback() { - this.doSetup(); const mod = this.mod; var count = 0; const list = [];