-
Notifications
You must be signed in to change notification settings - Fork 171
/
inspection_methods.go
83 lines (64 loc) · 1.88 KB
/
inspection_methods.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package vm
import (
"bytes"
"fmt"
"strings"
)
// Polymorphic helper functions for inspecting internal info.
func (i *instruction) inspect() string {
var params []string
for _, param := range i.Params {
params = append(params, fmt.Sprint(param))
}
return fmt.Sprintf("%s: %s. source line: %d", i.action.name, strings.Join(params, ", "), i.sourceLine)
}
func (is *instructionSet) inspect() string {
var out bytes.Buffer
for _, i := range is.instructions {
out.WriteString(i.inspect())
out.WriteString("\n")
}
return out.String()
}
func (cf *goMethodCallFrame) inspect() string {
return fmt.Sprintf("Go method frame. File name: %s. Method name: %s.", cf.FileName(), cf.name)
}
func (cf *normalCallFrame) inspect() string {
if cf.ep != nil {
return fmt.Sprintf("Normal frame. File name: %s. IS name: %s. is block: %t. ep: %d. source line: %d", cf.FileName(), cf.instructionSet.name, cf.isBlock, len(cf.ep.locals), cf.SourceLine())
}
return fmt.Sprintf("Normal frame. File name: %s. IS name: %s. is block: %t. source line: %d", cf.FileName(), cf.instructionSet.name, cf.isBlock, cf.SourceLine())
}
func (cfs *callFrameStack) inspect() string {
var out bytes.Buffer
for _, cf := range cfs.callFrames {
if cf != nil {
out.WriteString(fmt.Sprintln(cf.inspect()))
}
}
return out.String()
}
func (s *Stack) inspect() string {
var out bytes.Buffer
datas := []string{}
for i, p := range s.data {
if p != nil {
o := p.Target
if i == s.pointer {
datas = append(datas, fmt.Sprintf("%s (%T) %d <----", o.toString(), o, i))
} else {
datas = append(datas, fmt.Sprintf("%s (%T) %d", o.toString(), o, i))
}
} else {
if i == s.pointer {
datas = append(datas, "nil <----")
} else {
datas = append(datas, "nil")
}
}
}
out.WriteString("-----------\n")
out.WriteString(strings.Join(datas, "\n"))
out.WriteString("\n---------\n")
return out.String()
}