Skip to content

Commit de97c7f

Browse files
committed
runtime/vam/expr: move NewArith and NewCompare op param
The op param follows the lhs and rhs params, which feels odd. Move op ahead of lhs and rhs.
1 parent b2b8889 commit de97c7f

File tree

7 files changed

+10
-11
lines changed

7 files changed

+10
-11
lines changed

compiler/rungen/vexpr.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ func (b *Builder) compileVamBinary(e *dag.BinaryExpr) (vamexpr.Evaluator, error)
102102
case "in":
103103
return vamexpr.NewIn(b.sctx(), lhs, rhs), nil
104104
case "==", "!=", "<", "<=", ">", ">=":
105-
return vamexpr.NewCompare(b.sctx(), lhs, rhs, op), nil
105+
return vamexpr.NewCompare(b.sctx(), op, lhs, rhs), nil
106106
case "+", "-", "*", "/", "%":
107-
return vamexpr.NewArith(b.sctx(), lhs, rhs, op), nil
107+
return vamexpr.NewArith(b.sctx(), op, lhs, rhs), nil
108108
default:
109109
return nil, fmt.Errorf("invalid binary operator %s", op)
110110
}

runtime/vam/expr/arith.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type Arith struct {
2020
rhs Evaluator
2121
}
2222

23-
func NewArith(sctx *super.Context, lhs, rhs Evaluator, op string) *Arith {
23+
func NewArith(sctx *super.Context, op string, lhs, rhs Evaluator) *Arith {
2424
return &Arith{sctx, vector.ArithOpFromString(op), lhs, rhs}
2525
}
2626

runtime/vam/expr/arith_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestArithOpsAndForms(t *testing.T) {
3535
for _, c := range cases {
3636
f := func(expected []int64, lhs, rhs vector.Any) {
3737
t.Helper()
38-
cmp := NewArith(super.NewContext(), &testEval{lhs}, &testEval{rhs}, c.op)
38+
cmp := NewArith(super.NewContext(), c.op, &testEval{lhs}, &testEval{rhs})
3939
assert.Equal(t, expected, cmp.Eval(nil).(*vector.Int).Values, "op: %s", c.op)
4040
}
4141

@@ -59,7 +59,7 @@ func TestArithOpsAndForms(t *testing.T) {
5959
f(c.expectedForConstLHS, Const, rhsView)
6060

6161
// Arithmetic on two vector.Consts returns another vector.Const.
62-
cmp := NewArith(super.NewContext(), &testEval{Const}, &testEval{Const}, c.op)
62+
cmp := NewArith(super.NewContext(), c.op, &testEval{Const}, &testEval{Const})
6363
val := cmp.Eval(nil).(*vector.Const)
6464
assert.Equal(t, uint32(3), val.Len(), "op: %s", c.op)
6565
expected := super.NewInt64(c.expectedForConstLHS[0])

runtime/vam/expr/compare.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type Compare struct {
1919
rhs Evaluator
2020
}
2121

22-
func NewCompare(sctx *super.Context, lhs, rhs Evaluator, op string) *Compare {
22+
func NewCompare(sctx *super.Context, op string, lhs, rhs Evaluator) *Compare {
2323
return &Compare{sctx, vector.CompareOpFromString(op), lhs, rhs}
2424
}
2525

runtime/vam/expr/compare_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestCompareOpsAndForms(t *testing.T) {
4343
for _, c := range cases {
4444
f := func(expected string, lhs, rhs vector.Any) {
4545
t.Helper()
46-
cmp := NewCompare(super.NewContext(), &testEval{lhs}, &testEval{rhs}, c.op)
46+
cmp := NewCompare(super.NewContext(), c.op, &testEval{lhs}, &testEval{rhs})
4747
assert.Equal(t, expected, cmp.Eval(nil).(*vector.Bool).Bits.String(), "op: %s", c.op)
4848
}
4949

@@ -67,11 +67,10 @@ func TestCompareOpsAndForms(t *testing.T) {
6767
f(c.expectedForConstLHS, Const, rhsView)
6868

6969
// Comparing two vector.Consts yields another vector.Const.
70-
cmp := NewCompare(super.NewContext(), &testEval{Const}, &testEval{Const}, c.op)
70+
cmp := NewCompare(super.NewContext(), c.op, &testEval{Const}, &testEval{Const})
7171
val := cmp.Eval(nil).(*vector.Const)
7272
assert.Equal(t, uint32(3), val.Len(), "op: %s", c.op)
7373
expected := super.NewBool(c.expectedForConstLHS == "111")
7474
assert.Equal(t, expected, val.Value(), "op: %s", c.op)
7575
}
76-
7776
}

runtime/vam/expr/logic.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ type In struct {
198198
}
199199

200200
func NewIn(sctx *super.Context, lhs, rhs Evaluator) *In {
201-
return &In{sctx, lhs, rhs, NewPredicateWalk(NewCompare(sctx, nil, nil, "==").eval)}
201+
return &In{sctx, lhs, rhs, NewPredicateWalk(NewCompare(sctx, "==", nil, nil).eval)}
202202
}
203203

204204
func (i *In) Eval(this vector.Any) vector.Any {

runtime/vam/expr/search.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func NewSearch(s string, val super.Value, e Evaluator) Evaluator {
2727
if val.Type().ID() == super.IDNet {
2828
net = super.DecodeNet(val.Bytes())
2929
}
30-
eq := NewCompare(super.NewContext() /* XXX */, nil, nil, "==")
30+
eq := NewCompare(super.NewContext() /* XXX */, "==", nil, nil)
3131
vectorPred := func(vec vector.Any) vector.Any {
3232
if net.IsValid() && vector.KindOf(vec) == vector.KindIP {
3333
out := vector.NewFalse(vec.Len())

0 commit comments

Comments
 (0)