示例#1
0
    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(&parameter.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();
    }
示例#2
0
文件: Thread.cpp 项目: tgfjt/wasmint
    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));
    }