Skip to content

Commit

Permalink
fix: rename and add entry for ffi
Browse files Browse the repository at this point in the history
  • Loading branch information
liz3 committed Nov 14, 2024
1 parent 3d26296 commit 70d1083
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 7 deletions.
11 changes: 9 additions & 2 deletions src/include/dictu_ffi_include.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__

Expand Down Expand Up @@ -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 \
Expand All @@ -364,6 +364,7 @@ struct sObjString {
int length;
char *chars;
uint32_t hash;
int character_len;
};

struct sObjList {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/optionals/ffi/ffi.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ void *ffi_function_pointers[] = {&copyString,
&compareStringGreater,
&defineNative,
&defineNativeProperty,
&reallocate};
&reallocate,
&callFunction};

void freeFFI(DictuVM *vm, ObjAbstract *abstract) {
FFIInstance *instance = (FFIInstance *)abstract->data;
Expand Down
2 changes: 1 addition & 1 deletion src/optionals/ffi/ffi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/vm/datatypes/strings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/vm/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/vm/vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 70d1083

Please sign in to comment.