From 1be1b8de9e4abe1725a149a776db623019ae7f64 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Sun, 23 Aug 2020 13:29:48 +0300 Subject: [PATCH] compiler: merge `&&` and `||` processing --- pkg/compiler/codegen.go | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/pkg/compiler/codegen.go b/pkg/compiler/codegen.go index 24669b72d..44cee3b30 100644 --- a/pkg/compiler/codegen.go +++ b/pkg/compiler/codegen.go @@ -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)