Skip to content

Commit

Permalink
remove VM.Stack() function
Browse files Browse the repository at this point in the history
  • Loading branch information
d5 committed Jan 12, 2019
1 parent 94b0d52 commit b802132
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 29 deletions.
13 changes: 6 additions & 7 deletions runtime/vm.go
Expand Up @@ -699,20 +699,19 @@ func (v *VM) Run() error {
}
}

// check if stack still has some objects left
if v.sp > 0 && !v.aborting {
return fmt.Errorf("non empty stack after execution")
}

return nil
}

func (v *VM) Globals() []*objects.Object {
return v.globals
}

// for tests
func (v *VM) Stack() []*objects.Object {
return v.stack[:v.sp]
}

// for tests
func (v *VM) FrameDebug() (frameIndex int, ip int) {
func (v *VM) FrameInfo() (frameIndex int, ip int) {
return v.framesIndex - 1, v.frames[v.framesIndex-1].ip
}

Expand Down
23 changes: 1 addition & 22 deletions runtime/vm_test.go
@@ -1,7 +1,6 @@
package runtime_test

import (
"errors"
"fmt"
"reflect"
_runtime "runtime"
Expand Down Expand Up @@ -148,7 +147,7 @@ func traceCompileRun(file *ast.File, symbols map[string]objects.Object) (res map

var ipstr string
if v != nil {
frameIdx, ip := v.FrameDebug()
frameIdx, ip := v.FrameInfo()
ipstr = fmt.Sprintf("\n (Frame=%d, IP=%d)", frameIdx, ip)
}
trace = append(trace, fmt.Sprintf("[Panic]\n\n %v%s\n", e, ipstr))
Expand Down Expand Up @@ -217,31 +216,11 @@ func traceCompileRun(file *ast.File, symbols map[string]objects.Object) (res map
}
}
trace = append(trace, fmt.Sprintf("\n[Globals]\n\n%s", strings.Join(globalsStr, "\n")))
var stack []string
for sidx, s := range v.Stack() {
if s == nil {
continue
}

if cmFn, ok := (*s).(*objects.Closure); ok {
stack = append(stack, fmt.Sprintf("[% 3d] (Closure|%p)", sidx, s))
for _, l := range compiler.FormatInstructions(cmFn.Fn.Instructions, 0) {
stack = append(stack, fmt.Sprintf(" %s", l))
}
} else {
stack = append(stack, fmt.Sprintf("[% 3d] %s (%s|%p)", sidx, *s, reflect.TypeOf(*s).Name(), s))
}
}
trace = append(trace, fmt.Sprintf("\n[Stack]\n\n%s", strings.Join(stack, "\n")))
}
if err != nil {
return
}

if len(v.Stack()) > 0 {
err = errors.New("value left in the stack")
}

return
}

Expand Down

0 comments on commit b802132

Please sign in to comment.