-
Notifications
You must be signed in to change notification settings - Fork 16
/
log_and.go
45 lines (39 loc) · 789 Bytes
/
log_and.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package dynaml
import (
"fmt"
"github.com/mandelsoft/spiff/debug"
)
const (
OpAnd = "-and"
)
type LogAndExpr struct {
A Expression
B Expression
}
func (e LogAndExpr) Evaluate(binding Binding, locally bool) (interface{}, EvaluationInfo, bool) {
a, b, info, resolved, first_ok, all_ok := resolveLOperands(e.A, e.B, binding)
if !first_ok {
return nil, info, false
}
if !resolved {
return e, info, true
}
debug.Debug("AND: %#v, %#v\n", a, b)
inta, ok := a.(int64)
if ok {
if !all_ok {
return nil, info, false
}
return inta & b.(int64), info, true
}
if !toBool(a) {
return false, info, true
}
if !all_ok {
return nil, info, false
}
return toBool(b), info, true
}
func (e LogAndExpr) String() string {
return fmt.Sprintf("%s %s %s", e.A, OpAnd, e.B)
}