wip: begin dynamic library loading dev
This commit is contained in:
@@ -3,7 +3,6 @@ project(fz-lang
|
|||||||
LANGUAGES C)
|
LANGUAGES C)
|
||||||
|
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
set(BUILD_SHARED_LIBS OFF)
|
|
||||||
add_compile_options(-Wall -Wextra -Werror=implicit-function-declaration)
|
add_compile_options(-Wall -Wextra -Werror=implicit-function-declaration)
|
||||||
|
|
||||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ typedef enum
|
|||||||
FZL_TYPE_NULL,
|
FZL_TYPE_NULL,
|
||||||
FZL_TYPE_OBJECT,
|
FZL_TYPE_OBJECT,
|
||||||
|
|
||||||
|
FZL_TYPE_EXTERN_FN,
|
||||||
|
|
||||||
FZL_TYPE_STRING,
|
FZL_TYPE_STRING,
|
||||||
FZL_TYPE_CHAR,
|
FZL_TYPE_CHAR,
|
||||||
FZL_TYPE_BOOL,
|
FZL_TYPE_BOOL,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <vm/fzl_vm_env.h>
|
#include <vm/fzl_vm_env.h>
|
||||||
|
#include <vm/fzl_vm_extern.h>
|
||||||
#include <vm/fzl_vm_object.h>
|
#include <vm/fzl_vm_object.h>
|
||||||
|
|
||||||
// VM descriptor
|
// VM descriptor
|
||||||
@@ -14,6 +15,9 @@ typedef struct
|
|||||||
fzl_const_t *consts;
|
fzl_const_t *consts;
|
||||||
size_t consts_count;
|
size_t consts_count;
|
||||||
|
|
||||||
|
fzl_vm_extern_t *externs;
|
||||||
|
size_t externs_count;
|
||||||
|
|
||||||
uint64_t *ops;
|
uint64_t *ops;
|
||||||
size_t ops_count;
|
size_t ops_count;
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -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;
|
||||||
|
|
||||||
@@ -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
@@ -28,14 +28,16 @@ fzl_vm_t *fzl_mkvm(const char *filepath)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
vm->consts = NULL;
|
vm->consts = NULL;
|
||||||
vm->consts_count = 0;
|
vm->consts_count = 0;
|
||||||
vm->ops = NULL;
|
vm->ops = NULL;
|
||||||
vm->ops_count = 0;
|
vm->ops_count = 0;
|
||||||
vm->ip = 0;
|
vm->externs = NULL;
|
||||||
vm->dtop = 0;
|
vm->externs_count = 0;
|
||||||
vm->ctop = 0;
|
vm->ip = 0;
|
||||||
vm->etop = 0;
|
vm->dtop = 0;
|
||||||
|
vm->ctop = 0;
|
||||||
|
vm->etop = 0;
|
||||||
|
|
||||||
memset(vm->dstack, 0, sizeof(vm->dstack));
|
memset(vm->dstack, 0, sizeof(vm->dstack));
|
||||||
memset(vm->cstack, 0, sizeof(vm->cstack));
|
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;
|
size_t consts_count, ops_count;
|
||||||
fread(&consts_count, sizeof(size_t), 1, fd);
|
fread(&consts_count, sizeof(size_t), 1, fd);
|
||||||
fread(&ops_count, sizeof(size_t), 1, fd);
|
fread(&ops_count, sizeof(size_t), 1, fd);
|
||||||
|
// TODO: read externs count
|
||||||
|
|
||||||
if (ops_count < 1)
|
if (ops_count < 1)
|
||||||
{
|
{
|
||||||
@@ -116,6 +119,8 @@ fzl_vm_t *fzl_mkvm(const char *filepath)
|
|||||||
fread(&op, sizeof(uint64_t), 1, fd);
|
fread(&op, sizeof(uint64_t), 1, fd);
|
||||||
vm->ops[i] = op;
|
vm->ops[i] = op;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: read externs
|
||||||
fclose(fd);
|
fclose(fd);
|
||||||
|
|
||||||
return vm;
|
return vm;
|
||||||
|
|||||||
Reference in New Issue
Block a user