| 239 | |
| 240 | template <typename I> |
| 241 | inline TrapResult<std::vector<Val>> |
| 242 | Func::call(Store::Context cx, const I &begin, const I &end) const { |
| 243 | std::vector<wasmtime_val_t> raw_params; |
| 244 | raw_params.reserve(end - begin); |
| 245 | for (auto i = begin; i != end; i++) { |
| 246 | raw_params.push_back(i->val); |
| 247 | } |
| 248 | size_t nresults = this->type(cx)->results().size(); |
| 249 | std::vector<wasmtime_val_t> raw_results(nresults); |
| 250 | |
| 251 | wasm_trap_t *trap = nullptr; |
| 252 | auto *error = |
| 253 | wasmtime_func_call(cx.ptr, &func, raw_params.data(), raw_params.size(), |
| 254 | raw_results.data(), raw_results.capacity(), &trap); |
| 255 | if (error != nullptr) { |
| 256 | return TrapError(Error(error)); |
| 257 | } |
| 258 | if (trap != nullptr) { |
| 259 | return TrapError(Trap(trap)); |
| 260 | } |
| 261 | |
| 262 | std::vector<Val> results; |
| 263 | results.reserve(nresults); |
| 264 | for (size_t i = 0; i < nresults; i++) { |
| 265 | results.push_back(raw_results[i]); |
| 266 | } |
| 267 | return results; |
| 268 | } |
| 269 | |
| 270 | inline TrapResult<std::vector<Val>> |
| 271 | Func::call(Store::Context cx, const std::initializer_list<Val> ¶ms) const { |