compiler: merge &&
and ||
processing
This commit is contained in:
parent
59367c96d1
commit
1be1b8de9e
1 changed files with 8 additions and 13 deletions
|
@ -712,21 +712,16 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
|
|||
}
|
||||
|
||||
switch n.Op {
|
||||
case token.LAND:
|
||||
case token.LAND, token.LOR:
|
||||
end := c.newLabel()
|
||||
ast.Walk(c, n.X)
|
||||
emit.Instruction(c.prog.BinWriter, opcode.JMPIF, []byte{2 + 1 + 5})
|
||||
emit.Opcode(c.prog.BinWriter, opcode.PUSHF)
|
||||
emit.Jmp(c.prog.BinWriter, opcode.JMPL, end)
|
||||
ast.Walk(c, n.Y)
|
||||
c.setLabel(end)
|
||||
return nil
|
||||
|
||||
case token.LOR:
|
||||
end := c.newLabel()
|
||||
ast.Walk(c, n.X)
|
||||
emit.Instruction(c.prog.BinWriter, opcode.JMPIFNOT, []byte{2 + 1 + 5})
|
||||
emit.Opcode(c.prog.BinWriter, opcode.PUSHT)
|
||||
if n.Op == token.LAND {
|
||||
emit.Instruction(c.prog.BinWriter, opcode.JMPIF, []byte{2 + 1 + 5})
|
||||
emit.Opcode(c.prog.BinWriter, opcode.PUSHF)
|
||||
} else {
|
||||
emit.Instruction(c.prog.BinWriter, opcode.JMPIFNOT, []byte{2 + 1 + 5})
|
||||
emit.Opcode(c.prog.BinWriter, opcode.PUSHT)
|
||||
}
|
||||
emit.Jmp(c.prog.BinWriter, opcode.JMPL, end)
|
||||
ast.Walk(c, n.Y)
|
||||
c.setLabel(end)
|
||||
|
|
Loading…
Reference in a new issue