const wasm_module::Instruction* InterpreterThread::callFunction( const std::string& moduleName, const std::string& functionName, std::vector<wasm_module::Variable> parameters) { if (functionStack_.size() >= functionStackLimit) throw StackLimitReached(std::to_string(functionStack_.size())); const wasm_module::Function* func = nullptr; wasm_module::Module& module = env_.getModule(moduleName); func = &env_.getFunction(moduleName, functionName); if (func->variadic()) { std::vector<const wasm_module::Type*> types; for (auto& parameter : parameters) { types.push_back(¶meter.type()); } functionStack_.push_back(FunctionState(*func, types)); } else { // We push the new locals to the functionStack_ before entering. functionStack_.push_back(FunctionState(*func)); } for (uint32_t i = 0; i < parameters.size(); i++) { variable(i) = parameters.at(i); } return func->mainInstruction(); }
void Thread::enterFunction(wasm_module::Function& function) { if (stack.size() >= stackLimit) throw StackLimitReached(std::to_string(stack.size())); // We push the new locals to the stack before entering. stack.push(FunctionState(function)); }