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