2018-03-30 16:15:06 +00:00
|
|
|
package vm
|
|
|
|
|
|
|
|
import "encoding/json"
|
|
|
|
|
|
|
|
// StackOutput holds information about the stack, used for pretty printing
|
|
|
|
// the stack.
|
|
|
|
type stackItem struct {
|
|
|
|
Value interface{} `json:"value"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func buildStackOutput(s *Stack) string {
|
|
|
|
items := make([]stackItem, s.Len())
|
|
|
|
i := 0
|
|
|
|
s.Iter(func(e *Element) {
|
|
|
|
items[i] = stackItem{
|
2018-04-02 15:04:42 +00:00
|
|
|
Value: e.value,
|
2018-03-30 16:15:06 +00:00
|
|
|
Type: e.value.String(),
|
|
|
|
}
|
|
|
|
i++
|
|
|
|
})
|
|
|
|
|
|
|
|
b, _ := json.MarshalIndent(items, "", " ")
|
|
|
|
return string(b)
|
|
|
|
}
|