MCPcopy Create free account
hub / github.com/cel-expr/cel-go / Exec

Method Exec

interpreter/interpretable.go:714–764  ·  view source on GitHub ↗

Exec implements the InterpretableV2 interface method.

(frame *ExecutionFrame)

Source from the content-addressed store, hash-verified

712
713// Exec implements the InterpretableV2 interface method.
714func (bin *evalBinary) Exec(frame *ExecutionFrame) ref.Val {
715 lVal := bin.lhs.Exec(frame)
716 strict := !bin.nonStrict
717 if strict {
718 switch lVal.(type) {
719 case *types.Err:
720 return lVal
721 case *types.Unknown:
722 rVal := bin.rhs.Exec(frame)
723 if unk, ok := rVal.(*types.Unknown); ok {
724 res := types.MergeUnknowns(lVal.(*types.Unknown), unk)
725 if costs := frame.CostTracker(); costs != nil {
726 costs.EvalBinary(frame, bin.id, bin, lVal, rVal, res)
727 }
728 return res
729 }
730 if costs := frame.CostTracker(); costs != nil {
731 costs.EvalBinary(frame, bin.id, bin, lVal, rVal, lVal)
732 }
733 return lVal
734 }
735 }
736 rVal := bin.rhs.Exec(frame)
737 if strict {
738 switch rVal.(type) {
739 case *types.Err:
740 return rVal
741 case *types.Unknown:
742 if costs := frame.CostTracker(); costs != nil {
743 costs.EvalBinary(frame, bin.id, bin, lVal, rVal, rVal)
744 }
745 return rVal
746 }
747 }
748 var res ref.Val
749 // If the implementation is bound and the argument value has the right traits required to
750 // invoke it, then call the implementation.
751 if bin.impl != nil && (bin.trait == 0 || matchOperandTrait(bin.trait, strict, lVal)) {
752 res = labelErrNode(bin.id, bin.impl(lVal, rVal))
753 } else if lVal.Type().HasTrait(traits.ReceiverType) {
754 // Otherwise, if the argument is a ReceiverType attempt to invoke the receiver method on the
755 // operand (arg0).
756 res = labelErrNode(bin.id, lVal.(traits.Receiver).Receive(bin.function, bin.overload, []ref.Val{rVal}))
757 } else {
758 res = types.NewErrWithNodeID(bin.id, "no such overload: %s", bin.function)
759 }
760 if costs := frame.CostTracker(); costs != nil {
761 costs.EvalBinary(frame, bin.id, bin, lVal, rVal, res)
762 }
763 return res
764}
765
766// Eval implements the Interpretable interface method.
767func (bin *evalBinary) Eval(ctx Activation) ref.Val {

Callers

nothing calls this directly

Calls 10

MergeUnknownsFunction · 0.92
NewErrWithNodeIDFunction · 0.92
labelErrNodeFunction · 0.85
CostTrackerMethod · 0.80
EvalBinaryMethod · 0.80
matchOperandTraitFunction · 0.70
ExecMethod · 0.65
HasTraitMethod · 0.65
TypeMethod · 0.65
ReceiveMethod · 0.65

Tested by

no test coverage detected