forked from bytecodealliance/wasmtime-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shims.c
74 lines (66 loc) · 1.91 KB
/
shims.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "_cgo_export.h"
#include "shims.h"
wasmtime_store_t *go_store_new(wasm_engine_t *engine, size_t env) {
return wasmtime_store_new(engine, (void*) env, goFinalizeStore);
}
static wasm_trap_t* trampoline(
void *env,
wasmtime_caller_t *caller,
const wasmtime_val_t *args,
size_t nargs,
wasmtime_val_t *results,
size_t nresults
) {
return goTrampolineNew(caller, (size_t) env,
(wasmtime_val_t*) args, nargs,
results, nresults);
}
static wasm_trap_t* wrap_trampoline(
void *env,
wasmtime_caller_t *caller,
const wasmtime_val_t *args,
size_t nargs,
wasmtime_val_t *results,
size_t nresults
) {
return goTrampolineWrap(caller, (size_t) env,
(wasmtime_val_t*) args, nargs,
results, nresults);
}
void go_func_new(
wasmtime_context_t *store,
wasm_functype_t *ty,
size_t env,
int wrap,
wasmtime_func_t *ret
) {
wasmtime_func_callback_t callback = trampoline;
if (wrap)
callback = wrap_trampoline;
return wasmtime_func_new(store, ty, callback, (void*) env, NULL, ret);
}
wasmtime_error_t *go_linker_define_func(
wasmtime_linker_t *linker,
const char *module,
size_t module_len,
const char *name,
size_t name_len,
const wasm_functype_t *ty,
int wrap,
size_t env
) {
wasmtime_func_callback_t cb = trampoline;
void(*finalizer)(void*) = goFinalizeFuncNew;
if (wrap) {
cb = wrap_trampoline;
finalizer = goFinalizeFuncWrap;
}
return wasmtime_linker_define_func(linker, module, module_len, name, name_len, ty, cb, (void*) env, finalizer);
}
wasmtime_externref_t *go_externref_new(size_t env) {
return wasmtime_externref_new((void*) env, goFinalizeExternref);
}
#define UNION_ACCESSOR(name, field, ty) \
ty go_##name##_##field##_get(const name##_t *val) { return val->of.field; } \
void go_##name##_##field##_set(name##_t *val, ty i) { val->of.field = i; }
EACH_UNION_ACCESSOR(UNION_ACCESSOR)