Commit 53385e11 authored by Juergen Nickelsen's avatar Juergen Nickelsen
Browse files

don't print env[0]'s bindings in stack trace

These made the stack trace unreadble and were not particularly
helpful.
parent aecdd8b3
......@@ -39,15 +39,19 @@ func EvalLevel() int {
func printEnv(env *lob.Environment) string {
buf := bytes.NewBufferString(env.ValueString(nil))
buf.WriteRune('{')
first := true
for key, value := range env.Varmap() {
if !first {
buf.WriteString("; ")
if env.Level() == 0 {
buf.WriteString("...")
} else {
first := true
for key, value := range env.Varmap() {
if !first {
buf.WriteString("; ")
}
buf.WriteString(key.ValueString(nil))
buf.WriteRune('=')
buf.WriteString(value.ValueString(nil))
first = false
}
buf.WriteString(key.ValueString(nil))
buf.WriteRune('=')
buf.WriteString(value.ValueString(nil))
first = false
}
buf.WriteRune('}')
return buf.String()
......@@ -58,7 +62,7 @@ func printEnv(env *lob.Environment) string {
func PrintStack() {
for i := 0; i < len(evalStack); i += 2 {
// take care to indent the environment line as appropriate
levelStr := fmt.Sprintf("#%d ", i/2)
levelStr := fmt.Sprintf(":%d ", i/2)
fmt.Printf("%s%s\n%*s%s\n", levelStr, evalStack[i],
len(levelStr), "",
printEnv(evalStack[i+1].(*lob.Environment)))
......
......@@ -101,6 +101,10 @@ func (env *Environment) Varmap() VarMap {
return env.val
}
func (env *Environment) Level() int {
return env.level
}
func (env *Environment) Vars(noparents bool) Object {
vars := env.allvarmap(noparents)
var result Object = Nil
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment