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 := vm.New()
|
||||||
v.LoadScript(b)
|
v.LoadScript(b)
|
||||||
v.PrintOps()
|
v.PrintOps(ctx.App.Writer)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -429,7 +429,9 @@ func handleOps(c *ishell.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
v := getVMFromContext(c)
|
v := getVMFromContext(c)
|
||||||
v.PrintOps()
|
out := bytes.NewBuffer(nil)
|
||||||
|
v.PrintOps(out)
|
||||||
|
c.Println(out.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func changePrompt(c ishell.Actions, v *vm.VM) {
|
func changePrompt(c ishell.Actions, v *vm.VM) {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math"
|
"math"
|
||||||
"math/big"
|
"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.
|
// PrintOps prints the opcodes of the current loaded program to stdout.
|
||||||
func (v *VM) PrintOps() {
|
func (v *VM) PrintOps(out io.Writer) {
|
||||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 4, ' ', 0)
|
if out == nil {
|
||||||
|
out = os.Stdout
|
||||||
|
}
|
||||||
|
w := tabwriter.NewWriter(out, 0, 0, 4, ' ', 0)
|
||||||
fmt.Fprintln(w, "INDEX\tOPCODE\tPARAMETER\t")
|
fmt.Fprintln(w, "INDEX\tOPCODE\tPARAMETER\t")
|
||||||
realctx := v.Context()
|
realctx := v.Context()
|
||||||
ctx := realctx.Copy()
|
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) {
|
func testCONVERT(to stackitem.Type, item, res stackitem.Item) func(t *testing.T) {
|
||||||
return func(t *testing.T) {
|
return func(t *testing.T) {
|
||||||
prog := []byte{byte(opcode.CONVERT), byte(to)}
|
prog := []byte{byte(opcode.CONVERT), byte(to)}
|
||||||
v := load(prog)
|
|
||||||
v.PrintOps()
|
|
||||||
runWithArgs(t, prog, res, item)
|
runWithArgs(t, prog, res, item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue