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 {
|
switch n.Op {
|
||||||
case token.LAND:
|
case token.LAND, token.LOR:
|
||||||
end := c.newLabel()
|
end := c.newLabel()
|
||||||
ast.Walk(c, n.X)
|
ast.Walk(c, n.X)
|
||||||
emit.Instruction(c.prog.BinWriter, opcode.JMPIF, []byte{2 + 1 + 5})
|
if n.Op == token.LAND {
|
||||||
emit.Opcode(c.prog.BinWriter, opcode.PUSHF)
|
emit.Instruction(c.prog.BinWriter, opcode.JMPIF, []byte{2 + 1 + 5})
|
||||||
emit.Jmp(c.prog.BinWriter, opcode.JMPL, end)
|
emit.Opcode(c.prog.BinWriter, opcode.PUSHF)
|
||||||
ast.Walk(c, n.Y)
|
} else {
|
||||||
c.setLabel(end)
|
emit.Instruction(c.prog.BinWriter, opcode.JMPIFNOT, []byte{2 + 1 + 5})
|
||||||
return nil
|
emit.Opcode(c.prog.BinWriter, opcode.PUSHT)
|
||||||
|
}
|
||||||
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)
|
|
||||||
emit.Jmp(c.prog.BinWriter, opcode.JMPL, end)
|
emit.Jmp(c.prog.BinWriter, opcode.JMPL, end)
|
||||||
ast.Walk(c, n.Y)
|
ast.Walk(c, n.Y)
|
||||||
c.setLabel(end)
|
c.setLabel(end)
|
||||||
|
|
Loading…
Reference in a new issue