xgo/compiler/compiler_logical.go

31 lines
547 B
Go
Raw Normal View History

2019-01-09 10:17:42 +03:00
package compiler
import (
2019-01-11 13:27:28 +03:00
"github.com/d5/tengo/compiler/ast"
"github.com/d5/tengo/compiler/token"
2019-01-09 10:17:42 +03:00
)
func (c *Compiler) compileLogical(node *ast.BinaryExpr) error {
// left side term
if err := c.Compile(node.LHS); err != nil {
2019-01-09 10:17:42 +03:00
return err
}
// jump position
var jumpPos int
if node.Token == token.LAnd {
jumpPos = c.emit(OpAndJump, 0)
} else {
jumpPos = c.emit(OpOrJump, 0)
}
// right side term
if err := c.Compile(node.RHS); err != nil {
2019-01-09 10:17:42 +03:00
return err
}
c.changeOperand(jumpPos, len(c.currentInstructions()))
return nil
}