forked from TrueCloudLab/neoneo-go
compiler: convert unary operators properly
Imported from CityOfZion/neo-storm#62 PR.
This commit is contained in:
parent
05c07a8567
commit
2daebdfce2
1 changed files with 16 additions and 1 deletions
|
@ -484,7 +484,22 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
|
||||||
|
|
||||||
case *ast.UnaryExpr:
|
case *ast.UnaryExpr:
|
||||||
ast.Walk(c, n.X)
|
ast.Walk(c, n.X)
|
||||||
c.convertToken(n.Op)
|
// From https://golang.org/ref/spec#Operators
|
||||||
|
// there can be only following unary operators
|
||||||
|
// "+" | "-" | "!" | "^" | "*" | "&" | "<-" .
|
||||||
|
// of which last three are not used in SC
|
||||||
|
switch n.Op {
|
||||||
|
case token.ADD:
|
||||||
|
// +10 == 10, no need to do anything in this case
|
||||||
|
case token.SUB:
|
||||||
|
emitOpcode(c.prog, vm.NEGATE)
|
||||||
|
case token.NOT:
|
||||||
|
emitOpcode(c.prog, vm.NOT)
|
||||||
|
case token.XOR:
|
||||||
|
emitOpcode(c.prog, vm.INVERT)
|
||||||
|
default:
|
||||||
|
log.Fatalf("invalid unary operator: %s", n.Op)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
case *ast.IncDecStmt:
|
case *ast.IncDecStmt:
|
||||||
|
|
Loading…
Reference in a new issue