aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2025-04-08 22:36:15 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2025-04-08 22:36:15 +0300
commit9e367e1824d62d3759cb19b7c9a433b67b96bd99 (patch)
tree907639a6c42297040c2cfc472cd31011c92482a9 /src
parent69283b1c2c5a7b088566a86ec89d131ab569d8e4 (diff)
downloadejit-alloca.tar.gz
ejit-alloca.zip
clean up interpreter a bitalloca
Diffstat (limited to 'src')
-rw-r--r--src/ejit.c4
-rw-r--r--src/interp.c35
2 files changed, 13 insertions, 26 deletions
diff --git a/src/ejit.c b/src/ejit.c
index c997a01..571a274 100644
--- a/src/ejit.c
+++ b/src/ejit.c
@@ -459,7 +459,7 @@ void ejit_patch(struct ejit_func *f, struct ejit_reloc r, struct ejit_label l)
void ejit_calli_i(struct ejit_func *s, struct ejit_func *f, size_t argc,
const struct ejit_operand args[argc])
{
- f->max_args = argc > f->max_args ? argc : f->max_args;
+ s->max_args = argc > s->max_args ? argc : s->max_args;
check_operands(f, argc, args);
for (size_t i = 0; i < argc; ++i) {
@@ -479,7 +479,7 @@ void ejit_calli_l(struct ejit_func *s, struct ejit_func *f, size_t argc,
const struct ejit_operand args[argc])
{
s->use_64 = true;
- f->max_args = argc > f->max_args ? argc : f->max_args;
+ s->max_args = argc > s->max_args ? argc : s->max_args;
check_operands(f, argc, args);
for (size_t i = 0; i < argc; ++i) {
diff --git a/src/interp.c b/src/interp.c
index 57dbfbe..6ef414d 100644
--- a/src/interp.c
+++ b/src/interp.c
@@ -228,7 +228,7 @@ union interp_ret ejit_run(struct ejit_func *f, size_t paramc, struct ejit_arg pa
if (!run) {
*labels_wb = labels;
- goto zero_out;
+ return (union interp_ret){.i = 0};
}
assert(f->size && "trying to run a function that hasn't been compiled");
@@ -262,9 +262,9 @@ union interp_ret ejit_run(struct ejit_func *f, size_t paramc, struct ejit_arg pa
};
size_t argc = 0;
- int64_t *gpr = alloca(sizeof(int64_t) * gpr_stats_len(&f->gpr));
- union fpr *fpr = alloca(sizeof(int64_t) * fpr_stats_len(&f->fpr));
- struct ejit_arg *args = alloca(sizeof(struct ejit_arg) * f->max_args);
+ int64_t gpr[gpr_stats_len(&f->gpr)];
+ union fpr fpr[fpr_stats_len(&f->fpr)];
+ struct ejit_arg args[f->max_args];
struct ejit_insn *insns = f->insns.buf;
/* retval is kind of an unfortunate extra bit of state to keep track of,
@@ -282,7 +282,7 @@ union interp_ret ejit_run(struct ejit_func *f, size_t paramc, struct ejit_arg pa
DISPATCH();
DO(END);
- goto zero_out;
+ return (union interp_ret){.i = 0};
DISPATCH();
DO(MOVI);
@@ -1109,45 +1109,32 @@ union interp_ret ejit_run(struct ejit_func *f, size_t paramc, struct ejit_arg pa
/* dispatch is technically unnecessary for returns, but keep it for
* symmetry */
DO(RETR);
- retval = gpr[i.r1];
- goto out_int;
+ return (union interp_ret){.i = gpr[i.r1]};
DISPATCH();
DO(RETI);
- retval = i.o;
- goto out_int;
+ return (union interp_ret){.i = i.o};
DISPATCH();
DO(RETR_F);
- retval_f = fpr[i.r1].f;
- goto out_float;
+ return (union interp_ret){.f = fpr[i.r1].f};
DISPATCH();
DO(RETR_D);
- retval_f = fpr[i.r1].d;
- goto out_float;
+ return (union interp_ret){.f = fpr[i.r1].d};
DISPATCH();
DO(RETI_F);
- retval_f = i.f;
- goto out_float;
+ return (union interp_ret){.f = i.f};
DISPATCH();
DO(RETI_D);
- retval_f = i.d;
- goto out_float;
+ return (union interp_ret){.f = i.d};
DISPATCH();
#undef DISPATCH
#undef JUMP
#undef DO
-out_float:
- return (union interp_ret){.f = retval_f};
-
-out_int:
- return (union interp_ret){.i = retval};
-
-zero_out:
return (union interp_ret){.i = 0};
}