@@ -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
964956void 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