forked from TrueCloudLab/neoneo-go
931388b687
* Virtual machine for the NEO blockhain. * fixed big.Int numeric operation pointer issue. * added appcall * Added README for vm package. * removed main.go * started VM cli (prompt) integration * added support for printing the stack. * moved cli to vm package * fixed vet errors * updated readme * added more test for VM and fixed some edge cases. * bumped version -> 0.37.0
25 lines
493 B
Go
25 lines
493 B
Go
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{
|
|
Value: e.value.Value(),
|
|
Type: e.value.String(),
|
|
}
|
|
i++
|
|
})
|
|
|
|
b, _ := json.MarshalIndent(items, "", " ")
|
|
return string(b)
|
|
}
|