X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=ts%2Fjs-wasm.h;h=aa5eec522d6d3fd7fbc2e2c2e3a48e4d88b6c08d;hb=HEAD;hp=abcb5b301babc34d0e325409fd762e350170b0aa;hpb=caf86199f09538269930ee679d2852a73671d46f;p=ldk-java diff --git a/ts/js-wasm.h b/ts/js-wasm.h index abcb5b30..c3fb7cf4 100644 --- a/ts/js-wasm.h +++ b/ts/js-wasm.h @@ -4,40 +4,53 @@ extern size_t strlen(const char *s); +// We only support two call types - u32 and u64. u32 is mapped to a JavaScript +// "number" whereas u64 is mapped to a JavaScript "bigint". Ultimately it all +// calls through to the same function, but at the FFI boundary itself we have +// to use proper types. + typedef uint32_t JSValue; -extern JSValue js_invoke_function(JSValue,JSValue,JSValue,JSValue,JSValue,JSValue,JSValue,JSValue,JSValue,JSValue,JSValue,JSValue) __attribute__((import_name("js_invoke_function"))); - -static inline JSValue js_invoke_function_0(JSValue obj, JSValue fn){ - return js_invoke_function(obj,fn,0,0,0,0,0,0,0,0,0,0); -} -static inline JSValue js_invoke_function_1(JSValue obj, JSValue fn, JSValue a){ - return js_invoke_function(obj,fn,a,0,0,0,0,0,0,0,0,0); -} -static inline JSValue js_invoke_function_2(JSValue obj, JSValue fn, JSValue a, JSValue b){ - return js_invoke_function(obj,fn,a,b,0,0,0,0,0,0,0,0); -} -static inline JSValue js_invoke_function_3(JSValue obj, JSValue fn, JSValue a, JSValue b, JSValue c){ - return js_invoke_function(obj,fn,a,b,c,0,0,0,0,0,0,0); -} -static inline JSValue js_invoke_function_4(JSValue obj, JSValue fn, JSValue a, JSValue b, JSValue c, JSValue d){ - return js_invoke_function(obj,fn,a,b,c,d,0,0,0,0,0,0); -} -static inline JSValue js_invoke_function_5(JSValue obj, JSValue fn, JSValue a, JSValue b, JSValue c, JSValue d, JSValue e){ - return js_invoke_function(obj,fn,a,b,c,d,e,0,0,0,0,0); -} -static inline JSValue js_invoke_function_6(JSValue obj, JSValue fn, JSValue a, JSValue b, JSValue c, JSValue d, JSValue e, JSValue f){ - return js_invoke_function(obj,fn,a,b,c,d,e,f,0,0,0,0); -} -static inline JSValue js_invoke_function_7(JSValue obj, JSValue fn, JSValue a, JSValue b, JSValue c, JSValue d, JSValue e, JSValue f, JSValue g){ - return js_invoke_function(obj,fn,a,b,c,d,e,f,g,0,0,0); -} -static inline JSValue js_invoke_function_8(JSValue obj, JSValue fn, JSValue a, JSValue b, JSValue c, JSValue d, JSValue e, JSValue f, JSValue g, JSValue h){ - return js_invoke_function(obj,fn,a,b,c,d,e,f,g,h,0,0); -} -static inline JSValue js_invoke_function_9(JSValue obj, JSValue fn, JSValue a, JSValue b, JSValue c, JSValue d, JSValue e, JSValue f, JSValue g, JSValue h, JSValue i){ - return js_invoke_function(obj,fn,a,b,c,d,e,f,g,h,i,0); -} -static inline JSValue js_invoke_function_10(JSValue obj, JSValue fn, JSValue a, JSValue b, JSValue c, JSValue d, JSValue e, JSValue f, JSValue g, JSValue h, JSValue i, JSValue j){ - return js_invoke_function(obj,fn,a,b,c,d,e,f,g,h,i,j); -} + +#define N_TYPE_u uint32_t +#define N_TYPE_b uint64_t + +#define TOK(a) a +#define R_CAT2(a, b) a ## b +#define CAT2(a, b) R_CAT2(a, b) +#define R_CAT3(a, b, c) a ## b ## c +#define CAT3(a, b, c) R_CAT3(a, b, c) +#define R_CAT4(a, b, c, d) a ## b ## c ## d +#define CAT4(a, b, c, d) R_CAT4(a, b, c, d) +#define R_CAT5(a, b, c, d, e) a ## b ## c ## d ## e +#define CAT5(a, b, c, d, e) R_CAT5(a, b, c, d, e) +#define R_CAT6(a, b, c, d, e, f) a ## b ## c ## d ## e ## f +#define CAT6(a, b, c, d, e, f) R_CAT6(a, b, c, d, e, f) + +#define _GET_CONCAT(_1, _2, _3, _4, _5, _6, CONC, ...) CONC +#define CAT(...) _GET_CONCAT(__VA_ARGS__, CAT6, CAT5, CAT4, CAT3, CAT2, TOK)(__VA_ARGS__) + +#define DO_STRING(a) #a +#define STRINGIZE(a) DO_STRING(a) + +#define DECL_IMPORT(A1, A2, A3, A4, A5, A6) \ + extern uint64_t CAT(js_invoke_function_, CAT(A1, A2, A3, A4, A5, A6)) \ + (JSValue obj, JSValue fn, N_TYPE_##A1, N_TYPE_##A2, N_TYPE_##A3, N_TYPE_##A4, N_TYPE_##A5, N_TYPE_##A6) \ + __attribute__((import_name(STRINGIZE(CAT(js_invoke_function_, CAT(A1, A2, A3, A4, A5, A6)))))); + +DECL_IMPORT(u, u, u, u, u, u) +DECL_IMPORT(b, u, u, u, u, u) +DECL_IMPORT(b, b, u, u, u, u) +DECL_IMPORT(b, b, b, u, u, u) +DECL_IMPORT(b, b, b, b, u, u) +DECL_IMPORT(b, b, b, b, b, u) +DECL_IMPORT(b, b, b, b, b, b) +DECL_IMPORT(u, b, u, u, b, u) +DECL_IMPORT(u, b, u, u, u, u) +DECL_IMPORT(u, b, b, u, u, u) +DECL_IMPORT(u, u, b, u, u, u) +DECL_IMPORT(u, u, b, b, u, u) +DECL_IMPORT(u, u, b, u, b, u) +DECL_IMPORT(u, b, u, b, u, u) +DECL_IMPORT(u, u, u, u, b, u) + #endif