wip: begin dynamic library loading dev

This commit is contained in:
samsonium
2026-10-28 15:20:58 +03:00
parent 70bf63e2ea
commit ea28c470d2
7 changed files with 45 additions and 9 deletions
-1
View File
@@ -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")
+2
View File
@@ -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,
+4
View File
@@ -6,6 +6,7 @@
#include <stddef.h>
#include <stdint.h>
#include <vm/fzl_vm_env.h>
#include <vm/fzl_vm_extern.h>
#include <vm/fzl_vm_object.h>
// 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;
+14
View File
@@ -0,0 +1,14 @@
#ifndef FZL_VM_EXTERN_H
#define FZL_VM_EXTERN_H
#include <ffi.h>
// 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
+6
View File
@@ -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;
+6
View File
@@ -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;
+13 -8
View File
@@ -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;