nga-c: successfully import and run some external functions (retro.c)

FossilOrigin-Name: 4487fce6bf80eb3d2d7a9ecaf0ae6345d036f23b171ccae7114b4deaf4cbcd54
This commit is contained in:
crc 2021-07-29 13:31:41 +00:00
parent 156522b431
commit 21eb0704c7

View file

@ -265,7 +265,10 @@ void query_multicore() {
/* External Functions ------------------------------------------------ */
#ifdef ENABLE_FFI
typedef void (*External)(void *, void *, void *);
void *handles[32];
External funcs[32000];
int nlibs, nffi;
void open_library() {
@ -278,14 +281,20 @@ void map_symbol() {
int h;
h = stack_pop();
char *s = string_extract(stack_pop());
dlsym(handles[h], s);
funcs[nffi] = dlsym(handles[h], s);
stack_push(nffi);
nffi++;
}
void invoke() {
funcs[stack_pop()](stack_push, stack_pop, memory);
}
void io_ffi() {
switch (stack_pop()) {
case 0: open_library(); break;
case 1: map_symbol(); break;
case 2: invoke(); break;
}
}