protoverse

A metaverse protocol
git clone git://jb55.com/protoverse
Log | Files | Refs | README | LICENSE

commit c99420b27435b3ae59c520ba54dd80fd5155dac0
parent 1eefbbb0be93b44f777ec31af0b9139689670792
Author: William Casarin <jb55@jb55.com>
Date:   Sat, 31 Jul 2021 11:45:04 -0700

add get_params

Diffstat:
Msrc/wasm.c | 23+++++++++++++++++++++++
1 file changed, 23 insertions(+), 0 deletions(-)

diff --git a/src/wasm.c b/src/wasm.c @@ -140,6 +140,29 @@ static INLINE struct val *get_local(struct wasm_interp *interp, u32 ind) return get_fn_local(interp, frame->fn, ind); } +static INLINE int get_params(struct wasm_interp *interp, + struct val** vals, u32 num_vals) +{ + struct callframe *frame; + struct func *fn; + + if (unlikely(!(frame = top_callframe(&interp->callframes)))) + return interp_error(interp, "no callframe?"); + + if (unlikely(!(fn = get_fn(interp->module, frame->fn)))) + return interp_error(interp, "invalid fn %d", frame->fn); + + if (unlikely(num_vals != fn->functype->params.num_valtypes)) { + return interp_error(interp, + "requested %d params, but there are %d", + num_vals, fn->functype->params.num_valtypes); + } + + *vals = fn->locals; + + return 1; +} + static INLINE int stack_popval(struct wasm_interp *interp, struct val *val) { return cursor_popval(&interp->stack, val);