Skip to content

Commit 1ea2781

Browse files
committed
refactor: rename Op.Execute() to Op.EvalExpr()
1 parent a773d5d commit 1ea2781

File tree

7 files changed

+14
-11
lines changed

7 files changed

+14
-11
lines changed

dsl/ops/func_do.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (*doOp) InvertExpr(args []types.Value) (types.Value, error) {
5050
return DoOp.Bind(newargs...)
5151
}
5252

53-
func (*doOp) Execute(ctx context.Context, args []types.Value) (val types.Value, rollback func(), err error) {
53+
func (*doOp) EvalExpr(ctx context.Context, args []types.Value) (val types.Value, rollback func(), err error) {
5454
g := util.FuncGuard(DoOp.String())
5555
defer func() { err = g.Rollback(recover()) }()
5656
rollback = g.RollbackForcefully

dsl/ops/macro_array.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ type arrayOp struct {
1818
var ArrayOp = &arrayOp{macroBase("$array")}
1919

2020
func (op *arrayOp) InvertExpr(args []types.Value) (types.Value, error) {
21-
return op.macroInvertExpr(op.Execute(context.Background(), args))
21+
return op.macroInvertExpr(op.EvalExpr(context.Background(), args))
2222
}
2323

2424
func (*arrayOp) Bind(args ...types.Value) (*types.Expr, error) {
2525
expr := types.NewExpr(ArrayOp, args, types.NewArrayType(types.AnyValue))
2626
return expr, nil
2727
}
2828

29-
func (*arrayOp) Execute(ctx context.Context, args []types.Value) (types.Value, func(), error) {
29+
func (*arrayOp) EvalExpr(ctx context.Context, args []types.Value) (types.Value, func(), error) {
3030
return types.NewArray(args, types.AnyValue), NoRollback, nil
3131
}

dsl/ops/macro_eval.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ type evalOp struct {
1919
var EvalOp = &evalOp{macroBase("$eval")}
2020

2121
func (op *evalOp) InvertExpr(args []types.Value) (types.Value, error) {
22-
return op.macroInvertExpr(op.Execute(context.Background(), args))
22+
return op.macroInvertExpr(op.EvalExpr(context.Background(), args))
2323
}
2424

2525
func (*evalOp) Bind(args ...types.Value) (*types.Expr, error) {
2626
expr := types.NewExpr(ArrayOp, args, types.NewArrayType(types.AnyValue))
2727
return expr, nil
2828
}
2929

30-
func (*evalOp) Execute(ctx context.Context, args []types.Value) (types.Value, func(), error) {
30+
func (*evalOp) EvalExpr(ctx context.Context, args []types.Value) (types.Value, func(), error) {
3131
if err := util.Signature(types.AnyValue).Check(args); err != nil {
3232
return nil, NoRollback, err
3333
}

dsl/ops/macro_invert.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ type invertOp struct {
1919
var InvertOp = &invertOp{macroBase("$invert")}
2020

2121
func (op *invertOp) InvertExpr(args []types.Value) (types.Value, error) {
22-
return op.macroInvertExpr(op.Execute(context.Background(), args))
22+
return op.macroInvertExpr(op.EvalExpr(context.Background(), args))
2323
}
2424

2525
func (*invertOp) Bind(args ...types.Value) (*types.Expr, error) {
2626
expr := types.NewExpr(ArrayOp, args, types.NewArrayType(types.AnyValue))
2727
return expr, nil
2828
}
2929

30-
func (*invertOp) Execute(ctx context.Context, args []types.Value) (types.Value, func(), error) {
30+
func (*invertOp) EvalExpr(ctx context.Context, args []types.Value) (types.Value, func(), error) {
3131
if err := util.Signature(types.AnyValue).Check(args); err != nil {
3232
return nil, NoRollback, err
3333
}

dsl/parse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func parseArray(array []interface{}) (types.Value, error) {
5858
}
5959
// Expand macro's expression at parsing time
6060
if op.IsMacro() {
61-
val, _, err := op.Execute(context.Background(), args)
61+
val, _, err := op.EvalExpr(context.Background(), args)
6262
return val, err
6363
}
6464
return op.Bind(args...)

dsl/types/expr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func NewExpr(op Op, args []Value, retType Type) *Expr {
3131

3232
// Eval evaluates given expression expr with given transaction ID trxID.
3333
func (expr *Expr) Eval(ctx context.Context) (val Value, rollback func(), err error) {
34-
return expr.op.Execute(ctx, expr.args)
34+
return expr.op.EvalExpr(ctx, expr.args)
3535
}
3636

3737
// Invert inverts this expression.

dsl/types/op.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ type Op interface {
1313
// Bind binds its arguments, and check if the types of values are correct
1414
Bind(args ...Value) (*Expr, error)
1515

16-
// Execute executes this operation and returns its result value and error
17-
Execute(ctx context.Context, args []Value) (ret Value, rollback func(), err error)
16+
// EvalExpr evaluates expression (this operator + given arguments).
17+
// If this operator is a function, it executes the operation and returns its
18+
// result and error.
19+
// If this operator is a macro, this expands expression.
20+
EvalExpr(ctx context.Context, args []Value) (ret Value, rollback func(), err error)
1821

1922
// IsMacro returns true if this operator is a macro
2023
IsMacro() bool

0 commit comments

Comments
 (0)