From 6ccf0572469dfc8cd8fa7b8537b2ac6c265d2df6 Mon Sep 17 00:00:00 2001 From: Preston Pan Date: Tue, 9 Jan 2024 12:58:54 -0800 Subject: done FLI in theory --- builtins.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'builtins.c') diff --git a/builtins.c b/builtins.c index 288eec9..b8d3322 100644 --- a/builtins.c +++ b/builtins.c @@ -1,6 +1,7 @@ #include "builtins.h" #include "parser.h" #include +#include #include #include #include @@ -731,6 +732,31 @@ void ltequals(value_t *v) { value_free(v1); value_free(v2); } +void clib(value_t *v) { + value_t *v1 = array_pop(STACK); + void *handle = dlopen(v1->str_word->value, RTLD_LAZY); + if (!handle) { + array_append(STACK, v1); + eval_error(); + return; + } + dlerror(); + void (*af)(void); + void (*aobjs)(void); + char *error; + *(void **)(&af) = dlsym(handle, "add_funcs"); + *(void **)(&aobjs) = dlsym(handle, "add_objs"); + if ((error = dlerror()) != NULL) { + value_free(v1); + fprintf(stderr, "%s\n", error); + eval_error(); + return; + } else { + (*af)(); + (*aobjs)(); + value_free(v1); + } +} void gthan(value_t *v) { value_t *v2 = array_pop(STACK); @@ -1096,4 +1122,5 @@ void add_funcs() { add_func(FLIT, swap, "swap"); add_func(FLIT, isdef, "isdef"); add_func(FLIT, dsc, "dsc"); + add_func(FLIT, clib, "clib"); } -- cgit