Skip to content

Commit 1b1bd32

Browse files
abelstukertolauwae
authored andcommitted
Fix overly complex WARDuino::invoke multivalue return handling
1 parent 5549e1b commit 1b1bd32

2 files changed

Lines changed: 12 additions & 26 deletions

File tree

src/WARDuino.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,8 @@ class WARDuino {
5959

6060
void update_module(Module *old_module, uint8_t *wasm, uint32_t wasm_len);
6161

62-
bool invoke(Module *m, uint32_t fidx, uint32_t arity = 0,
63-
StackValue *args = nullptr, uint32_t max_results = 0,
64-
StackValue *out_results = nullptr,
65-
uint32_t *out_result_count = nullptr);
62+
std::vector<StackValue> invoke(Module *m, uint32_t fidx, uint32_t arity = 0,
63+
StackValue *args = nullptr);
6664

6765
uint32_t get_export_fidx(Module *m, const char *name);
6866

src/WARDuino/WARDuino.cpp

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -920,9 +920,8 @@ WARDuino::WARDuino() {
920920
}
921921

922922
// Return value of false means exception occurred
923-
bool WARDuino::invoke(Module *m, uint32_t fidx, uint32_t arity,
924-
StackValue *args, uint32_t max_results,
925-
StackValue *out_results, uint32_t *out_result_count) {
923+
std::vector<StackValue> WARDuino::invoke(Module *m, uint32_t fidx,
924+
uint32_t arity, StackValue *args) {
926925
bool result;
927926
m->sp = -1;
928927
m->fp = -1;
@@ -942,23 +941,16 @@ bool WARDuino::invoke(Module *m, uint32_t fidx, uint32_t arity,
942941
dbg_dump_stack(m);
943942

944943
if (!result) {
945-
if (out_result_count) *out_result_count = 0;
946-
return false;
944+
return {};
947945
}
948946

949947
uint32_t rescount = 0;
950948
Type *ftype = m->functions[fidx].type;
951949
rescount = ftype->result_count;
952-
953-
if (out_result_count) {
954-
*out_result_count = rescount > max_results ? max_results : rescount;
955-
956-
for (uint32_t i = 0; i < *out_result_count; ++i) {
957-
out_results[i] = m->stack[m->sp - (rescount - 1) + i];
958-
}
959-
}
960-
961-
return true;
950+
std::vector<StackValue> out(rescount);
951+
for (uint32_t i = 0; i < rescount; ++i)
952+
out[i] = m->stack[m->sp - (rescount - 1) + i];
953+
return out;
962954
}
963955

964956
void WARDuino::setInterpreter(Interpreter *interpreter) {
@@ -970,13 +962,9 @@ int WARDuino::run_module(Module *m) {
970962

971963
// execute main
972964
if (fidx != UNDEF) {
973-
StackValue outputs[8];
974-
uint32_t out_count = 0;
975-
bool ok = this->invoke(m, fidx, 0, nullptr, 8, outputs, &out_count);
976-
if (!ok) {
977-
return 0;
978-
}
979-
return (int)outputs[0].value.uint32;
965+
auto results = this->invoke(m, fidx);
966+
if (results.empty()) return 0;
967+
return (int)results[0].value.uint32;
980968
}
981969
fflush(stdout);
982970

0 commit comments

Comments
 (0)