Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

starlark: add debug API for Locals and FreeVars #539

Merged
merged 1 commit into from
Apr 11, 2024
Merged

Conversation

adonovan
Copy link
Collaborator

This change adds the following new API to allow debugging tools and built-in functions access to the internals of Function values and call frames:

package starlark

type Binding struct {
Name string
Pos syntax.Position
}

func (fr *frame) NumLocals() int
func (fr *frame) Local(i int) (Binding, Value)

type DebugFrame interface {
...
NumLocals() int
Local(i int) (Binding, Value)
}

func (fn *Function) NumFreeVars() int
func (fn *Function) FreeVar(i int) (Binding, Value)

This is strictly a breaking change, but the changed functions (the Local methods) were previously documented as experimental. The fix is straightforward.

Also, a test of DebugFrame to write an 'env' function in a similar vein to Python's 'dir' function.

Fixes #538

This change adds the following new API to allow debugging tools
and built-in functions access to the internals of Function values
and call frames:

package starlark

type Binding struct {
       Name string
       Pos  syntax.Position
}

func (fr *frame) NumLocals() int
func (fr *frame) Local(i int) (Binding, Value)

type DebugFrame interface {
    ...
    NumLocals() int
    Local(i int) (Binding, Value)
}

func (fn *Function) NumFreeVars() int
func (fn *Function) FreeVar(i int) (Binding, Value)

This is strictly a breaking change, but the changed functions
(the Local methods) were previously documented as experimental.
The fix is straightforward.

Also, a test of DebugFrame to write an 'env' function in
a similar vein to Python's 'dir' function.

Fixes #538
@adonovan adonovan requested a review from jayconrod April 11, 2024 17:53
@adonovan adonovan merged commit 9b43f0a into master Apr 11, 2024
27 checks passed
@adonovan adonovan deleted the debug-api2 branch April 11, 2024 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

need API to enumerate names/bindings of a Function's local variables
2 participants