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

Method Exec

interpreter/interpretable.go:813–868  ·  view source on GitHub ↗

Exec implements the InterpretableV2 interface method.

(frame *ExecutionFrame)

Source from the content-addressed store, hash-verified

811
812// Exec implements the InterpretableV2 interface method.
813func (fn *evalVarArgs) Exec(frame *ExecutionFrame) ref.Val {
814 argVals := make([]ref.Val, len(fn.args))
815 strict := !fn.nonStrict
816 var unk *types.Unknown
817 for i, arg := range fn.args {
818 argVal := arg.Exec(frame)
819 if strict {
820 switch v := argVal.(type) {
821 case *types.Err:
822 return v
823 case *types.Unknown:
824 if unk == nil {
825 unk = v
826 } else {
827 unk = types.MergeUnknowns(unk, v)
828 }
829 }
830 }
831 argVals[i] = argVal
832 }
833 if strict && unk != nil {
834 if costs := frame.CostTracker(); costs != nil {
835 costs.EvalVarArgs(frame, fn.id, fn, argVals, unk)
836 }
837 return unk
838 }
839 if len(argVals) == 0 {
840 var res ref.Val
841 if fn.impl != nil {
842 res = labelErrNode(fn.id, fn.impl())
843 } else {
844 res = types.NewErrWithNodeID(fn.id, "no such overload: %s %d", fn.function, fn.id)
845 }
846 if costs := frame.CostTracker(); costs != nil {
847 costs.EvalZeroArity(frame, fn.id, fn, res)
848 }
849 return res
850 }
851 var res ref.Val
852 // If the implementation is bound and the argument value has the right traits required to
853 // invoke it, then call the implementation.
854 arg0 := argVals[0]
855 if fn.impl != nil && matchOperandTrait(fn.trait, strict, arg0) {
856 res = labelErrNode(fn.id, fn.impl(argVals...))
857 } else if arg0.Type().HasTrait(traits.ReceiverType) {
858 // Otherwise, if the argument is a ReceiverType attempt to invoke the receiver method on the
859 // operand (arg0).
860 res = labelErrNode(fn.id, arg0.(traits.Receiver).Receive(fn.function, fn.overload, argVals[1:]))
861 } else {
862 res = types.NewErrWithNodeID(fn.id, "no such overload: %s %d", fn.function, fn.id)
863 }
864 if costs := frame.CostTracker(); costs != nil {
865 costs.EvalVarArgs(frame, fn.id, fn, argVals, res)
866 }
867 return res
868}
869
870// Eval implements the Interpretable interface method.

Callers

nothing calls this directly

Calls 11

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

Tested by

no test coverage detected