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"`
|
|
|
|
}
|
|
|
|
|
2019-10-29 15:26:59 +00:00
|
|
|
func stackToArray(s *Stack) []stackItem {
|
2018-11-26 15:56:45 +00:00
|
|
|
items := make([]stackItem, 0, s.Len())
|
2018-03-30 16:15:06 +00:00
|
|
|
s.Iter(func(e *Element) {
|
2018-11-26 15:56:45 +00:00
|
|
|
items = append(items, stackItem{
|
2018-04-02 15:04:42 +00:00
|
|
|
Value: e.value,
|
2018-03-30 16:15:06 +00:00
|
|
|
Type: e.value.String(),
|
2018-11-26 15:56:45 +00:00
|
|
|
})
|
2018-03-30 16:15:06 +00:00
|
|
|
})
|
2019-10-29 15:26:59 +00:00
|
|
|
return items
|
|
|
|
}
|
2018-03-30 16:15:06 +00:00
|
|
|
|
2019-10-29 15:26:59 +00:00
|
|
|
func buildStackOutput(s *Stack) string {
|
|
|
|
b, _ := json.MarshalIndent(stackToArray(s), "", " ")
|
2018-03-30 16:15:06 +00:00
|
|
|
return string(b)
|
|
|
|
}
|