diff options
author | Preston Pan <preston@nullring.xyz> | 2024-01-09 12:58:54 -0800 |
---|---|---|
committer | Preston Pan <preston@nullring.xyz> | 2024-01-09 12:58:54 -0800 |
commit | 6ccf0572469dfc8cd8fa7b8537b2ac6c265d2df6 (patch) | |
tree | 058cb2c40c4450b4dec66ef4573d8a001208a4df | |
parent | 0cfcbe979277f6d3b096b85d7fb6f4c02c366c72 (diff) |
done FLI in theory
-rw-r--r-- | builtins.c | 27 | ||||
-rw-r--r-- | main.c | 5 |
2 files changed, 28 insertions, 4 deletions
@@ -1,6 +1,7 @@ #include "builtins.h" #include "parser.h" #include <ctype.h> +#include <dlfcn.h> #include <math.h> #include <stdio.h> #include <stdlib.h> @@ -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"); } @@ -47,10 +47,7 @@ int main(int argc, char **argv) { } ssize_t bytes_read = getdelim(&INBUF, &len, '\0', FP); - if (FP != NULL) { - fflush(FP); - fclose(FP); - } + fclose(FP); PARSER = init_parser(INBUF); STACK = init_array(10); |