17 explicit TreeWalker(
Engine &engine);
20 void setMaxRecursionDepth(
int d) { maxRecursionDepth_ = d; }
23 int callDepth()
const {
return currentRecursionDepth_; }
35 std::vector<std::string> callerArgNames;
37 const std::vector<ActiveFrame> &activeFrames()
const {
return activeFrames_; }
48 std::vector<Value> callHandleMultiPublic(
const Value &handle,
70 FlowSignal flowSignal_ = FlowSignal::NONE;
71 int currentRecursionDepth_ = 0;
72 int maxRecursionDepth_ = 500;
76 const Value *array =
nullptr;
80 std::vector<IndexContext> indexContextStack_;
81 std::vector<Value> callArgsBuf_;
82 std::atomic<int> anonCounter_{0};
87 std::vector<ActiveFrame> activeFrames_;
92 FrameGuard(std::vector<ActiveFrame> &stack, Environment *env,
93 std::vector<std::string> argNames = {})
98 f.callerArgNames = std::move(argNames);
99 stack_.push_back(std::move(f));
101 ~FrameGuard() { stack_.pop_back(); }
102 FrameGuard(
const FrameGuard &) =
delete;
103 FrameGuard &operator=(
const FrameGuard &) =
delete;
106 std::vector<ActiveFrame> &stack_;
109 class IndexContextGuard
112 IndexContextGuard(std::vector<IndexContext> &stack, IndexContext ctx)
115 stack_.push_back(ctx);
117 ~IndexContextGuard() { stack_.pop_back(); }
118 IndexContextGuard(
const IndexContextGuard &) =
delete;
119 IndexContextGuard &operator=(
const IndexContextGuard &) =
delete;
122 std::vector<IndexContext> &stack_;
128 RecursionGuard(
int &depth,
int maxDepth)
131 if (++depth_ > maxDepth)
132 throw std::runtime_error(
"Maximum recursion depth (" + std::to_string(maxDepth)
135 ~RecursionGuard() { --depth_; }
136 RecursionGuard(
const RecursionGuard &) =
delete;
137 RecursionGuard &operator=(
const RecursionGuard &) =
delete;
144 void output(
const std::string &s);
145 void displayValue(
const std::string &name,
const Value &val);
153 Value execNode(
const ASTNode *node, Environment *env);
154 Value execNodeExpand(
const ASTNode *node, Environment *env);
155 Value execNodeInner(
const ASTNode *node, Environment *env);
156 Value execBlock(
const ASTNode *node, Environment *env);
157 bool tryEvalFast(
const ASTNode *expr, Environment *env, Value &out);
163 bool tryFusion(
const ASTNode *node, Environment *env, Value &out);
166 Value execIdentifier(
const ASTNode *node, Environment *env,
size_t nargout = 1);
167 Value execAssign(
const ASTNode *node, Environment *env);
168 Value execMultiAssign(
const ASTNode *node, Environment *env);
169 Value execBinaryOp(
const ASTNode *node, Environment *env);
170 Value execUnaryOp(
const ASTNode *node, Environment *env);
171 Value execCall(
const ASTNode *node, Environment *env,
size_t nargout = 1);
177 std::vector<Value> execSuperCall(
const ASTNode *superRef,
const ASTNode *callNode,
178 Environment *env,
size_t nargout);
179 Value execCellIndex(
const ASTNode *node, Environment *env);
184 std::vector<Value> cellBraceContents(
const ASTNode *node, Environment *env);
185 Value execFieldAccess(
const ASTNode *node, Environment *env);
186 Value execMatrixLiteral(
const ASTNode *node, Environment *env);
187 Value execCellLiteral(
const ASTNode *node, Environment *env);
188 Value execColonExpr(
const ASTNode *node, Environment *env);
189 Value execIf(
const ASTNode *node, Environment *env);
190 Value execFor(
const ASTNode *node, Environment *env);
191 Value execWhile(
const ASTNode *node, Environment *env);
192 Value execSwitch(
const ASTNode *node, Environment *env);
193 Value execFunctionDef(
const ASTNode *node, Environment *env);
194 Value execExprStmt(
const ASTNode *node, Environment *env);
195 Value execCommandCall(
const ASTNode *node, Environment *env);
196 Value execAnonFunc(
const ASTNode *node, Environment *env);
197 Value execTryCatch(
const ASTNode *node, Environment *env);
198 Value execDeleteAssign(
const ASTNode *node, Environment *env);
199 Value execGlobalPersistent(
const ASTNode *node, Environment *env);
205 void assignLValue(
const ASTNode *lhs,
const Value &rhs, Environment *env);
206 void execIndexedAssign(
const ASTNode *lhs,
const Value &rhs, Environment *env);
207 void execFieldAssign(
const ASTNode *lhs,
const Value &rhs, Environment *env);
208 void execCellAssign(
const ASTNode *lhs,
const Value &rhs, Environment *env);
216 Value &resolveObjectSlot(
const ASTNode *node, Environment *env);
217 Value &resolveCellSlot(
const ASTNode *node, Environment *env);
218 Value &resolveFieldLValue(
const ASTNode *node, Environment *env);
221 Value objectPropGet(
const Value &obj,
const std::string &name, Environment *env);
222 void objectPropSet(Value &objSlot,
const std::string &name,
const Value &rhs,
226 bool tryResolveScalarIndex(
const ASTNode *indexExpr,
232 std::vector<size_t> resolveIndex(
233 const ASTNode *indexExpr,
const Value &array,
int dim,
int ndims, Environment *env);
234 Value execIndexAccess(
const Value &var,
const ASTNode *callNode, Environment *env);
235 std::vector<Value> execCallMulti(
const ASTNode *node, Environment *env,
size_t nout);
240 Value callUserFunction(
const UserFunction &func, Span<const Value> args,
242 const ASTNode *callNode =
nullptr);
243 std::vector<Value> callUserFunctionMulti(
const UserFunction &func,
244 Span<const Value> args,
247 const ASTNode *callNode =
nullptr);
248 Value callFuncHandle(
const Value &handle, Span<const Value> args, Environment *env,
249 const ASTNode *callNode =
nullptr);
250 std::vector<Value> callFuncHandleMulti(
const Value &handle,
251 Span<const Value> args,
254 const ASTNode *callNode =
nullptr);
257 bool isKnownFunction(
const std::string &name)
const;
260 std::string topLevelName_{
"<script>"};
261 DebugController *debugCtl();