mirror of
https://git.sr.ht/~crc_/retroforth
synced 2024-11-16 19:48:56 +01:00
nga-c: successfully import and run some external functions (retro.c)
FossilOrigin-Name: 4487fce6bf80eb3d2d7a9ecaf0ae6345d036f23b171ccae7114b4deaf4cbcd54
This commit is contained in:
parent
156522b431
commit
21eb0704c7
1 changed files with 10 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue