Skip to content

Commit

Permalink
add exec_push_vals/exec_pop_vals
Browse files Browse the repository at this point in the history
  • Loading branch information
yamt committed Jul 10, 2023
1 parent 0a92b7f commit 67412fc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,32 @@ exec_expr_continue(struct exec_context *ctx)
return 0;
}

int
exec_push_vals(struct exec_context *ctx, const struct resulttype *rt,
const struct val *vals)
{
uint32_t ncells = resulttype_cellsize(rt);
int ret = stack_prealloc(ctx, ncells);
if (ret != 0) {
return ret;
}
struct cell *cells = &VEC_NEXTELEM(ctx->stack);
vals_to_cells(vals, cells, rt);
ctx->stack.lsize += ncells;
return 0;
}

void
exec_pop_vals(struct exec_context *ctx, const struct resulttype *rt,
struct val *vals)
{
uint32_t ncells = resulttype_cellsize(rt);
assert(ctx->stack.lsize >= ncells);
ctx->stack.lsize -= ncells;
const struct cell *cells = &VEC_NEXTELEM(ctx->stack);
vals_from_cells(vals, cells, rt);
}

bool
skip_expr(const uint8_t **pp, bool goto_else)
{
Expand Down
5 changes: 5 additions & 0 deletions lib/exec.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ int exec_expr_continue(struct exec_context *ctx);
int exec_const_expr(const struct expr *expr, enum valtype type,
struct val *result, struct exec_context *ctx);

int exec_push_vals(struct exec_context *ctx, const struct resulttype *rt,
const struct val *params);
void exec_pop_vals(struct exec_context *ctx, const struct resulttype *rt,
struct val *results);

int memory_init(struct exec_context *ctx, uint32_t memidx, uint32_t dataidx,
uint32_t d, uint32_t s, uint32_t n);
uint32_t memory_grow(struct exec_context *ctx, uint32_t memidx, uint32_t sz);
Expand Down

0 comments on commit 67412fc

Please sign in to comment.