-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathffi.c
42 lines (34 loc) · 830 Bytes
/
ffi.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdlib.h>
#include <stdio.h>
#include "./ffi.h"
void init_callable(callable *c) {
c->args = (int*) malloc(16 * sizeof(int));
c->n_args = 0;
}
void add_arg_callable(callable *c, int arg) {
c->args[c->n_args] = arg;
c->n_args++;
}
void ffi_closure_alloc(void) {}
void ffi_closure_free(void) {}
ffi_status ffi_prep_cif(
ffi_cif *cif,
ffi_abi abi,
unsigned int nargs,
void *ignored1,
void *ignored2
) {
cif->n_args = nargs;
return FFI_OK;
}
void ffi_call(ffi_cif *cif, void *fn, void *retval, void **args) {
unsigned int n_args = cif->n_args;
cif->func = fn;
init_callable(cif);
// actually add the arguments to the callable
for (int i = 0; i < n_args; i++) {
add_arg_callable(cif, *((int*) args[i]));
}
runtime_call((void*) cif, retval);
}
void ffi_prep_closure_loc(void) {}