WebAssembly / wasm-c-api

Wasm C API prototype
Apache License 2.0
534 stars 77 forks source link

Definition of wasm_functype_new_x_y helpers - use of a macro prevents coding errors when extending. #142

Closed adv-sw closed 4 years ago

adv-sw commented 4 years ago

Suggest macro helper in the intializer as follows to make it even easier :)

define ARRAY_LENGTH(x) sizeof(x)/sizeof(x[0])

static inline wasm_functype_t wasm_functype_new_5_1(wasm_valtype_t p1, wasm_valtype_t p2, wasm_valtype_t p3, wasm_valtype_t p4, wasm_valtype_t p5, wasm_valtype_t r) { wasm_valtype_t ps[5] = {p1, p2, p3, p4, p5}; wasm_valtype_t* rs[1] = {r}; wasm_valtype_vec_t params, results; wasm_valtype_vec_new(&params, ARRAY_LENGTH(ps), ps); wasm_valtype_vec_new(&results, ARRAY_LENGTH(rs), rs); ....

rossberg commented 4 years ago

I believe this is implemented/superseded by #145.