1package starlark
2
3import "go.starlark.net/syntax"
4
5// This file defines an experimental API for the debugging tools.
6// Some of these declarations expose details of internal packages.
7// (The debugger makes liberal use of exported fields of unexported types.)
8// Breaking changes may occur without notice.
9
10// Local returns the value of the i'th local variable.
11// It may be nil if not yet assigned.
12//
13// Local may be called only for frames whose Callable is a *Function (a
14// function defined by Starlark source code), and only while the frame
15// is active; it will panic otherwise.
16//
17// This function is provided only for debugging tools.
18//
19// THIS API IS EXPERIMENTAL AND MAY CHANGE WITHOUT NOTICE.
20func (fr *frame) Local(i int) Value { return fr.locals[i] }
21
22// DebugFrame is the debugger API for a frame of the interpreter's call stack.
23//
24// Most applications have no need for this API; use CallFrame instead.
25//
26// Clients must not retain a DebugFrame nor call any of its methods once
27// the current built-in call has returned or execution has resumed
28// after a breakpoint as this may have unpredictable effects, including
29// but not limited to retention of object that would otherwise be garbage.
30type DebugFrame interface {
31	Callable() Callable        // returns the frame's function
32	Local(i int) Value         // returns the value of the (Starlark) frame's ith local variable
33	Position() syntax.Position // returns the current position of execution in this frame
34}
35
36// DebugFrame returns the debugger interface for
37// the specified frame of the interpreter's call stack.
38// Frame numbering is as for Thread.CallFrame.
39//
40// This function is intended for use in debugging tools.
41// Most applications should have no need for it; use CallFrame instead.
42func (thread *Thread) DebugFrame(depth int) DebugFrame { return thread.frameAt(depth) }
43