summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/shell-interface.h2
-rw-r--r--src/tools/wasm-ctor-eval.cpp2
-rw-r--r--src/wasm-interpreter.h37
3 files changed, 12 insertions, 29 deletions
diff --git a/src/shell-interface.h b/src/shell-interface.h
index 1efa31f79..6101df29a 100644
--- a/src/shell-interface.h
+++ b/src/shell-interface.h
@@ -191,7 +191,7 @@ struct ShellExternalInterface : ModuleRunner::ExternalInterface {
if (func->imported()) {
return callImport(func, arguments);
} else {
- return instance.callFunctionInternal(func->name, arguments);
+ return instance.callFunction(func->name, arguments);
}
}
diff --git a/src/tools/wasm-ctor-eval.cpp b/src/tools/wasm-ctor-eval.cpp
index 464654d4f..72ad459d3 100644
--- a/src/tools/wasm-ctor-eval.cpp
+++ b/src/tools/wasm-ctor-eval.cpp
@@ -350,7 +350,7 @@ struct CtorEvalExternalInterface : EvallingModuleRunner::ExternalInterface {
targetFunc.toString());
}
if (!func->imported()) {
- return instance.callFunctionInternal(targetFunc, arguments);
+ return instance.callFunction(targetFunc, arguments);
} else {
throw FailToEvalException(
std::string("callTable on imported function: ") +
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h
index c5019b2f3..5f20819a1 100644
--- a/src/wasm-interpreter.h
+++ b/src/wasm-interpreter.h
@@ -3028,6 +3028,8 @@ public:
: function(function), parent(parent) {
oldScope = parent.scope;
parent.scope = this;
+ parent.callDepth++;
+ parent.functionStack.push_back(function->name);
if (function->getParams().size() != arguments.size()) {
std::cerr << "Function `" << function->name << "` expects "
@@ -3053,7 +3055,11 @@ public:
}
}
- ~FunctionScope() { parent.scope = oldScope; }
+ ~FunctionScope() {
+ parent.scope = oldScope;
+ parent.callDepth--;
+ parent.functionStack.pop_back();
+ }
// The current delegate target, if delegation of an exception is in
// progress. If no delegation is in progress, this will be an empty Name.
@@ -3111,7 +3117,7 @@ public:
return Flow(RETURN_CALL_FLOW, std::move(arguments));
}
- Flow ret = callFunctionInternal(target, arguments);
+ Flow ret = callFunction(target, arguments);
#ifdef WASM_INTERPRETER_DEBUG
std::cout << "(returned to " << scope->function->name << ")\n";
#endif
@@ -3176,7 +3182,7 @@ public:
return Flow(RETURN_CALL_FLOW, std::move(arguments));
}
- Flow ret = callFunctionInternal(targetRef.getFunc(), arguments);
+ Flow ret = callFunction(targetRef.getFunc(), arguments);
#ifdef WASM_INTERPRETER_DEBUG
std::cout << "(returned to " << scope->function->name << ")\n";
#endif
@@ -4297,18 +4303,7 @@ public:
return value;
}
- // Call a function, starting an invocation.
- Literals callFunction(Name name, const Literals& arguments) {
- // If the last call ended in a jump up the stack, it might have left stuff
- // for us to clean up here
- callDepth = 0;
- functionStack.clear();
- return callFunctionInternal(name, arguments);
- }
-
- // Internal function call. Must be public so that callTable implementations
- // can use it (refactor?)
- Literals callFunctionInternal(Name name, Literals arguments) {
+ Literals callFunction(Name name, Literals arguments) {
if (callDepth > maxDepth) {
hostLimit("stack limit");
}
@@ -4332,11 +4327,6 @@ public:
return externalInterface->callImport(function, arguments);
}
- auto previousCallDepth = callDepth;
- callDepth++;
- auto previousFunctionStackSize = functionStack.size();
- functionStack.push_back(name);
-
FunctionScope scope(function, arguments, *self());
#ifdef WASM_INTERPRETER_DEBUG
@@ -4348,13 +4338,6 @@ public:
flow = self()->visit(function->body);
- // may decrease more than one, if we jumped up the stack
- callDepth = previousCallDepth;
- // if we jumped up the stack, we also need to pop higher frames
- // TODO can FunctionScope handle this automatically?
- while (functionStack.size() > previousFunctionStackSize) {
- functionStack.pop_back();
- }
#ifdef WASM_INTERPRETER_DEBUG
std::cout << "exiting " << function->name << " with " << flow.values
<< '\n';