|
| 1 | +diff --git a/source/m3_env.c b/source/m3_env.c |
| 2 | +index 40ccf9b..bad855f 100644 |
| 3 | +--- a/source/m3_env.c |
| 4 | ++++ b/source/m3_env.c |
| 5 | +@@ -810,6 +810,58 @@ _ ((M3Result) Call (i_function->compiled, (m3stack_t) stack, runtime->memo |
| 6 | + _catch: return result; |
| 7 | + } |
| 8 | + |
| 9 | ++M3Result m3_CallProper (IM3Function i_function, uint32_t i_argc, const uint64_t* i_argv, unsigned *o_hasRet, uint64_t* o_ret) |
| 10 | ++{ |
| 11 | ++ M3Result result = m3Err_none; |
| 12 | ++ |
| 13 | ++ if (i_function->compiled) |
| 14 | ++ { |
| 15 | ++ IM3Module module = i_function->module; |
| 16 | ++ |
| 17 | ++ IM3Runtime runtime = module->runtime; |
| 18 | ++ // FIXME: support wasi? |
| 19 | ++ |
| 20 | ++ IM3FuncType ftype = i_function->funcType; |
| 21 | ++ |
| 22 | ++ if (i_argc != ftype->numArgs) { |
| 23 | ++ _throw("arguments count mismatch"); |
| 24 | ++ } |
| 25 | ++ |
| 26 | ++ // args are always 64-bit aligned |
| 27 | ++ u64 * stack = (u64 *) runtime->stack; |
| 28 | ++ |
| 29 | ++ for (u32 i = 0; i < ftype->numArgs; ++i) |
| 30 | ++ { |
| 31 | ++ stack[i] = i_argv[i]; |
| 32 | ++ |
| 33 | ++ switch (ftype->argTypes[i]) { |
| 34 | ++ case c_m3Type_i32: |
| 35 | ++ case c_m3Type_f32: |
| 36 | ++ case c_m3Type_i64: |
| 37 | ++ case c_m3Type_f64: break; |
| 38 | ++ default: _throw("unknown argument type"); |
| 39 | ++ } |
| 40 | ++ } |
| 41 | ++ |
| 42 | ++ m3StackCheckInit(); |
| 43 | ++_ ((M3Result) Call (i_function->compiled, (m3stack_t) stack, runtime->memory.mallocated, d_m3OpDefaultArgs)); |
| 44 | ++ |
| 45 | ++ *o_hasRet = 1; |
| 46 | ++ switch (ftype->returnType) { |
| 47 | ++ case c_m3Type_none: *o_hasRet = 0; break; |
| 48 | ++ case c_m3Type_i32: *o_ret = (uint64_t)(stack[0] & 0xffffffff); break; |
| 49 | ++ case c_m3Type_i64: *o_ret = (uint64_t)stack[0]; break; |
| 50 | ++ // FIXME: not sure what happens with f32 |
| 51 | ++ case c_m3Type_f32: *o_ret = (uint64_t)(f32)stack[0]; break; |
| 52 | ++ case c_m3Type_f64: *o_ret = (uint64_t)stack[0]; break; |
| 53 | ++ default: _throw("unknown return type"); |
| 54 | ++ } |
| 55 | ++ } |
| 56 | ++ else _throw (m3Err_missingCompiledCode); |
| 57 | ++ |
| 58 | ++ _catch: return result; |
| 59 | ++} |
| 60 | ++ |
| 61 | + #if 0 |
| 62 | + M3Result m3_CallMain (IM3Function i_function, uint32_t i_argc, const char * const * i_argv) |
| 63 | + { |
| 64 | +diff --git a/source/wasm3.h b/source/wasm3.h |
| 65 | +index 0c2b7ef..ebba7f4 100644 |
| 66 | +--- a/source/wasm3.h |
| 67 | ++++ b/source/wasm3.h |
| 68 | +@@ -217,6 +217,8 @@ d_m3ErrorConst (trapStackOverflow, "[trap] stack overflow") |
| 69 | + M3Result m3_Call (IM3Function i_function); |
| 70 | + M3Result m3_CallWithArgs (IM3Function i_function, uint32_t i_argc, const char * const * i_argv); |
| 71 | + |
| 72 | ++ M3Result m3_CallProper (IM3Function i_function, uint32_t i_argc, const uint64_t* i_argv, unsigned *o_hasRet, uint64_t* o_ret); |
| 73 | ++ |
| 74 | + // IM3Functions are valid during the lifetime of the originating runtime |
| 75 | + |
| 76 | + void m3_GetErrorInfo (IM3Runtime i_runtime, M3ErrorInfo* info); |
0 commit comments