starlark: API additions for improved debugging (#76)
This change adds a number of small features to improve debugging.
The actual debugger API will come in a later change.
- Thread.Name : an optional string field that describes the purpose of
the thread, for use in debugging.
- (*Program).Filename: a method that reports the file of the program.
Also, a String method that returns the same thing.
Also, a test that it reports the correct location even for
an empty file (a special case of the previous implementation).
- (*Frame).Local(i int): a method to return the value of a local
variable of an active frame, such as one might use in debugger's
stack trace.
- ExprFunc: creates a starlark.Function from a given expression,
such as one might use in a debugger REPL.
diff --git a/starlark/example_test.go b/starlark/example_test.go
index fc2fee0..9df9d36 100644
--- a/starlark/example_test.go
+++ b/starlark/example_test.go
@@ -28,6 +28,7 @@
`
thread := &starlark.Thread{
+ Name: "example",
Print: func(_ *starlark.Thread, msg string) { fmt.Println(msg) },
}
predeclared := starlark.StringDict{
@@ -90,7 +91,7 @@
// Load and initialize the module in a new thread.
data := fakeFilesystem[module]
- thread := &starlark.Thread{Load: load}
+ thread := &starlark.Thread{Name: "exec " + module, Load: load}
globals, err := starlark.ExecFile(thread, module, data, nil)
e = &entry{globals, err}
@@ -100,7 +101,7 @@
return e.globals, e.err
}
- thread := &starlark.Thread{Load: load}
+ thread := &starlark.Thread{Name: "exec c.star", Load: load}
globals, err := load(thread, "c.star")
if err != nil {
log.Fatal(err)
@@ -250,6 +251,7 @@
func (c *cache) doLoad(cc *cycleChecker, module string) (starlark.StringDict, error) {
thread := &starlark.Thread{
+ Name: "exec " + module,
Print: func(_ *starlark.Thread, msg string) { fmt.Println(msg) },
Load: func(_ *starlark.Thread, module string) (starlark.StringDict, error) {
// Tunnel the cycle-checker state for this "thread of loading".