mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-29 23:33:37 +00:00
vm: provide writer in PrintOps()
Make it more flexible and testable. Fallback to using stdout if no writer is provided.
This commit is contained in:
parent
9a4183abb9
commit
2f39701d76
4 changed files with 10 additions and 6 deletions
|
@ -678,7 +678,7 @@ func inspect(ctx *cli.Context) error {
|
|||
}
|
||||
v := vm.New()
|
||||
v.LoadScript(b)
|
||||
v.PrintOps()
|
||||
v.PrintOps(ctx.App.Writer)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -429,7 +429,9 @@ func handleOps(c *ishell.Context) {
|
|||
return
|
||||
}
|
||||
v := getVMFromContext(c)
|
||||
v.PrintOps()
|
||||
out := bytes.NewBuffer(nil)
|
||||
v.PrintOps(out)
|
||||
c.Println(out.String())
|
||||
}
|
||||
|
||||
func changePrompt(c ishell.Actions, v *vm.VM) {
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"math/big"
|
||||
|
@ -151,8 +152,11 @@ func (v *VM) LoadArgs(method []byte, args []stackitem.Item) {
|
|||
}
|
||||
|
||||
// PrintOps prints the opcodes of the current loaded program to stdout.
|
||||
func (v *VM) PrintOps() {
|
||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 4, ' ', 0)
|
||||
func (v *VM) PrintOps(out io.Writer) {
|
||||
if out == nil {
|
||||
out = os.Stdout
|
||||
}
|
||||
w := tabwriter.NewWriter(out, 0, 0, 4, ' ', 0)
|
||||
fmt.Fprintln(w, "INDEX\tOPCODE\tPARAMETER\t")
|
||||
realctx := v.Context()
|
||||
ctx := realctx.Copy()
|
||||
|
|
|
@ -225,8 +225,6 @@ func TestISTYPE(t *testing.T) {
|
|||
func testCONVERT(to stackitem.Type, item, res stackitem.Item) func(t *testing.T) {
|
||||
return func(t *testing.T) {
|
||||
prog := []byte{byte(opcode.CONVERT), byte(to)}
|
||||
v := load(prog)
|
||||
v.PrintOps()
|
||||
runWithArgs(t, prog, res, item)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue