Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc small changes #70

Merged
merged 3 commits into from
Jul 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cli/repl.c
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,7 @@ exec_func(struct exec_context *ctx, uint32_t funcidx,
*/
ctx->user_intr_delay = 1;
}
assert(ctx->stack.lsize == 0);
ret = exec_push_vals(ctx, ptype, param);
if (ret != 0) {
goto fail;
Expand Down Expand Up @@ -904,6 +905,7 @@ exec_func(struct exec_context *ctx, uint32_t funcidx,
*trapp = trap;
} else if (ret == 0) {
exec_pop_vals(ctx, rtype, result);
assert(ctx->stack.lsize == 0);
}
fail:
return ret;
Expand Down
27 changes: 5 additions & 22 deletions lib/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1235,21 +1235,14 @@ skip_expr(const uint8_t **pp, bool goto_else)
}
}

const struct resulttype g_empty_rt = {
.ntypes = 0, .is_static = true, CELLIDX_NONE};

int
exec_const_expr(const struct expr *expr, enum valtype type, struct val *result,
struct exec_context *ctx)
{
uint32_t saved_height = ctx->frames.lsize;
static struct resulttype empty = {
.ntypes = 0,
.is_static = true,
#if defined(TOYWASM_USE_RESULTTYPE_CELLIDX)
.cellidx =
{
NULL,
},
#endif
};
static const struct localtype no_locals = {
.nlocals = 0,
.nlocalchunks = 0,
Expand All @@ -1263,7 +1256,7 @@ exec_const_expr(const struct expr *expr, enum valtype type, struct val *result,
};
int ret;
uint32_t csz = valtype_cellsize(type);
ret = exec_expr(FUNCIDX_INVALID, expr, &no_locals, &empty, csz, NULL,
ret = exec_expr(FUNCIDX_INVALID, expr, &no_locals, empty_rt, csz, NULL,
ctx);
/*
* it's very unlikely for a const expr to use a restart.
Expand All @@ -1277,17 +1270,7 @@ exec_const_expr(const struct expr *expr, enum valtype type, struct val *result,
if (ret != 0) {
return ret;
}
struct resulttype rt = {
.types = &type,
.ntypes = 1,
.is_static = true,
#if defined(TOYWASM_USE_RESULTTYPE_CELLIDX)
.cellidx =
{
NULL,
},
#endif
};
DEFINE_RESULTTYPE(, rt, &type, 1);
exec_pop_vals(ctx, &rt, result);
assert(ctx->frames.lsize == saved_height);
return 0;
Expand Down
2 changes: 2 additions & 0 deletions lib/exec_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,11 @@ struct exec_context {
unsigned int user_intr_delay;
uint32_t check_interval;

#if defined(TOYWASM_USE_USER_SCHED)
/* scheduler */
struct sched *sched;
LIST_ENTRY(struct exec_context) rq;
#endif

/* Trap */
bool trapped; /* for sanity check. apps should check ETOYWASMTRAP. */
Expand Down
24 changes: 2 additions & 22 deletions lib/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,28 +208,8 @@ int
read_const_expr(const uint8_t **pp, const uint8_t *ep, struct expr *expr,
enum valtype type, struct load_context *lctx)
{
static struct resulttype empty = {
.ntypes = 0,
.is_static = true,
#if defined(TOYWASM_USE_RESULTTYPE_CELLIDX)
.cellidx =
{
NULL,
},
#endif
};
struct resulttype resulttype = {
.ntypes = 1,
.types = &type,
.is_static = true,
#if defined(TOYWASM_USE_RESULTTYPE_CELLIDX)
.cellidx =
{
NULL,
},
#endif
};
DEFINE_RESULTTYPE(, resulttype, &type, 1);

return read_expr_common(pp, ep, expr, 0, NULL, &empty, &resulttype,
return read_expr_common(pp, ep, expr, 0, NULL, empty_rt, &resulttype,
true, lctx);
}
10 changes: 1 addition & 9 deletions lib/insn.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,15 +321,7 @@ get_functype(struct module *m, uint32_t typeidx, struct functype **ftp)
}

static const struct resulttype rt_empty = {
.ntypes = 0,
.is_static = true,
#if defined(TOYWASM_USE_RESULTTYPE_CELLIDX)
.cellidx =
{
NULL,
},
#endif
};
.ntypes = 0, .is_static = true, CELLIDX_NONE};

#define BYTE_AS_S33(b) ((int)(signed char)((b) + 0x80))

Expand Down
20 changes: 20 additions & 0 deletions lib/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,26 @@ struct resulttype {
#endif
};

#define DEFINE_TYPES(QUAL, NAME, ...) QUAL enum valtype NAME[] = {__VA_ARGS__}

#if defined(TOYWASM_USE_RESULTTYPE_CELLIDX)
#define CELLIDX_NONE \
.cellidx = { \
NULL, \
},
#else
#define CELLIDX_NONE
#endif

#define DEFINE_RESULTTYPE(QUAL, NAME, TYPES, NTYPES) \
QUAL struct resulttype NAME = {.types = (void *)TYPES, \
.ntypes = NTYPES, \
.is_static = true, \
CELLIDX_NONE}

extern const struct resulttype g_empty_rt;
#define empty_rt ((struct resulttype *)&g_empty_rt)

struct functype {
struct resulttype parameter;
struct resulttype result;
Expand Down
7 changes: 3 additions & 4 deletions libwasi/wasi_threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,9 @@ exec_thread_start_func(struct exec_context *ctx, const struct thread_arg *arg)
* wasi_threads_instance_set_thread_spawn_args.
*/
const uint32_t funcidx = wasi->thread_start_funcidx;
const struct functype *ft =
module_functype(ctx->instance->module, funcidx);
const struct resulttype *rt = &ft->parameter;
int ret = exec_push_vals(ctx, rt, param);
DEFINE_TYPES(static const, types, TYPE_i32, TYPE_i32);
DEFINE_RESULTTYPE(static const, rt, &types, 2);
int ret = exec_push_vals(ctx, &rt, param);
if (ret != 0) {
return ret;
}
Expand Down
Loading