mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-25 23:42:23 +00:00
Fixed bug in else stmts (CityOfZion/neo-storm#42)
* Fixed bug in else stmts * Fixed if else bug * Back to %v for formatting instructions Imported from CityOfZion/neo-storm (ea8440e1454207753c8d209ce7c2cf724fd4ea16).
This commit is contained in:
parent
b97e5aafec
commit
0880e88fa5
2 changed files with 11 additions and 10 deletions
|
@ -173,8 +173,7 @@ func testInvoke(ctx *cli.Context) error {
|
|||
// On the long term the internal VM will run the script.
|
||||
// TODO: remove RPC dependency, hardcoded node.
|
||||
endpoint := "http://seed5.bridgeprotocol.io:10332"
|
||||
opts := rpc.ClientOptions{}
|
||||
client, err := rpc.NewClient(context.TODO(), endpoint, opts)
|
||||
client, err := rpc.NewClient(context.TODO(), endpoint, rpc.ClientOptions{})
|
||||
if err != nil {
|
||||
return cli.NewExitError(err, 1)
|
||||
}
|
||||
|
|
|
@ -257,11 +257,7 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
|
|||
log.Fatal("multiple returns not supported.")
|
||||
}
|
||||
|
||||
// @OPTIMIZE: We could skip these 3 instructions for each return statement.
|
||||
// To be backwards compatible we will put them them in.
|
||||
// See issue #65 (https://github.com/CityOfZion/neo-go/issues/65)
|
||||
l := c.newLabel()
|
||||
// emitJmp(c.prog, vm.JMP, int16(l))
|
||||
c.setLabel(l)
|
||||
|
||||
if len(n.Results) > 0 {
|
||||
|
@ -276,6 +272,8 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
|
|||
case *ast.IfStmt:
|
||||
lIf := c.newLabel()
|
||||
lElse := c.newLabel()
|
||||
lElseEnd := c.newLabel()
|
||||
|
||||
if n.Cond != nil {
|
||||
ast.Walk(c, n.Cond)
|
||||
emitJmp(c.prog, vm.JMPIFNOT, int16(lElse))
|
||||
|
@ -283,15 +281,15 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
|
|||
|
||||
c.setLabel(lIf)
|
||||
ast.Walk(c, n.Body)
|
||||
|
||||
if n.Else != nil {
|
||||
// TODO: handle else statements.
|
||||
// emitJmp(c.prog, vm.JMP, int16(lEnd))
|
||||
emitJmp(c.prog, vm.JMP, int16(lElseEnd))
|
||||
}
|
||||
|
||||
c.setLabel(lElse)
|
||||
if n.Else != nil {
|
||||
ast.Walk(c, n.Else)
|
||||
}
|
||||
c.setLabel(lElseEnd)
|
||||
return nil
|
||||
|
||||
case *ast.BasicLit:
|
||||
|
@ -659,7 +657,11 @@ func (c *codegen) convertToken(tok token.Token) {
|
|||
case token.GEQ:
|
||||
emitOpcode(c.prog, vm.GTE)
|
||||
case token.EQL:
|
||||
emitOpcode(c.prog, vm.NUMEQUAL)
|
||||
// It seems that (looking to the python compiler) that comparing for
|
||||
// equal (==) needs to return the instruction EQUAL. Where comparing
|
||||
// (anything) to not equal (!=) needs to use the opcode NUMNOTEQUAL
|
||||
// even for comparing strings.
|
||||
emitOpcode(c.prog, vm.EQUAL)
|
||||
case token.NEQ:
|
||||
emitOpcode(c.prog, vm.NUMNOTEQUAL)
|
||||
case token.DEC:
|
||||
|
|
Loading…
Reference in a new issue