diff --git a/CMakeLists.txt b/CMakeLists.txt index c46da83..61237e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,6 @@ project(fz-lang LANGUAGES C) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -set(BUILD_SHARED_LIBS OFF) add_compile_options(-Wall -Wextra -Werror=implicit-function-declaration) if (CMAKE_BUILD_TYPE STREQUAL "Debug") diff --git a/include/common/fzl_types.h b/include/common/fzl_types.h index 346cb96..65069ce 100644 --- a/include/common/fzl_types.h +++ b/include/common/fzl_types.h @@ -6,6 +6,8 @@ typedef enum FZL_TYPE_NULL, FZL_TYPE_OBJECT, + FZL_TYPE_EXTERN_FN, + FZL_TYPE_STRING, FZL_TYPE_CHAR, FZL_TYPE_BOOL, diff --git a/include/vm/fzl_vm.h b/include/vm/fzl_vm.h index 92fedd7..33e2f58 100644 --- a/include/vm/fzl_vm.h +++ b/include/vm/fzl_vm.h @@ -6,6 +6,7 @@ #include #include #include +#include #include // VM descriptor @@ -14,6 +15,9 @@ typedef struct fzl_const_t *consts; size_t consts_count; + fzl_vm_extern_t *externs; + size_t externs_count; + uint64_t *ops; size_t ops_count; diff --git a/include/vm/fzl_vm_extern.h b/include/vm/fzl_vm_extern.h new file mode 100644 index 0000000..19f3f80 --- /dev/null +++ b/include/vm/fzl_vm_extern.h @@ -0,0 +1,14 @@ +#ifndef FZL_VM_EXTERN_H +#define FZL_VM_EXTERN_H + +#include + +// Loaded extern function definition +typedef struct +{ + void *func_ptr; + ffi_cif cif; + ffi_type **arg_types; +} fzl_vm_extern_t; + +#endif // FZL_VM_EXTERN_H diff --git a/src/stdlib/bindings/conv.fzs b/src/stdlib/bindings/conv.fzs new file mode 100644 index 0000000..2f247c2 --- /dev/null +++ b/src/stdlib/bindings/conv.fzs @@ -0,0 +1,6 @@ +/// Converts integer [value] to string +extern fn itos(int value) str; + +/// Converts string [value] to integer +extern fn stoi(str value) int; + diff --git a/src/stdlib/bindings/math.fzs b/src/stdlib/bindings/math.fzs new file mode 100644 index 0000000..c8aa524 --- /dev/null +++ b/src/stdlib/bindings/math.fzs @@ -0,0 +1,6 @@ +/// Get the minimum of specified values +extern fn min([]int ...values) int; + +/// Get the maximum of specified values +extern fn max([]int ...values) int; + diff --git a/src/vm/fzl_vm.c b/src/vm/fzl_vm.c index c3e4552..c2e062a 100644 --- a/src/vm/fzl_vm.c +++ b/src/vm/fzl_vm.c @@ -28,14 +28,16 @@ fzl_vm_t *fzl_mkvm(const char *filepath) return NULL; } - vm->consts = NULL; - vm->consts_count = 0; - vm->ops = NULL; - vm->ops_count = 0; - vm->ip = 0; - vm->dtop = 0; - vm->ctop = 0; - vm->etop = 0; + vm->consts = NULL; + vm->consts_count = 0; + vm->ops = NULL; + vm->ops_count = 0; + vm->externs = NULL; + vm->externs_count = 0; + vm->ip = 0; + vm->dtop = 0; + vm->ctop = 0; + vm->etop = 0; memset(vm->dstack, 0, sizeof(vm->dstack)); memset(vm->cstack, 0, sizeof(vm->cstack)); @@ -63,6 +65,7 @@ fzl_vm_t *fzl_mkvm(const char *filepath) size_t consts_count, ops_count; fread(&consts_count, sizeof(size_t), 1, fd); fread(&ops_count, sizeof(size_t), 1, fd); + // TODO: read externs count if (ops_count < 1) { @@ -116,6 +119,8 @@ fzl_vm_t *fzl_mkvm(const char *filepath) fread(&op, sizeof(uint64_t), 1, fd); vm->ops[i] = op; } + + // TODO: read externs fclose(fd); return vm;