Exec implements the InterpretableV2 interface method.
(frame *ExecutionFrame)
| 927 | |
| 928 | // Exec implements the InterpretableV2 interface method. |
| 929 | func (fn *evalLateBoundFunc) Exec(frame *ExecutionFrame) ref.Val { |
| 930 | argVals := make([]ref.Val, len(fn.args)) |
| 931 | strict := !fn.nonStrict |
| 932 | var unk *types.Unknown |
| 933 | for i, arg := range fn.args { |
| 934 | argVals[i] = arg.Exec(frame) |
| 935 | if strict { |
| 936 | if types.IsError(argVals[i]) { |
| 937 | return argVals[i] |
| 938 | } |
| 939 | unk, _ = types.MaybeMergeUnknowns(argVals[i], unk) |
| 940 | } |
| 941 | } |
| 942 | if strict && unk != nil { |
| 943 | if costs := frame.CostTracker(); costs != nil { |
| 944 | costs.EvalVarArgs(frame, fn.id, fn, argVals, unk) |
| 945 | } |
| 946 | return unk |
| 947 | } |
| 948 | var res ref.Val |
| 949 | // A late-bound function is only invoked when the runtime arguments agree with a declared |
| 950 | // overload and the activation supplies a compatible implementation. Unlike other call |
| 951 | // types, there is no fallback to receiver-style dispatch on the operand: the function |
| 952 | // declaration promised a binding supplied at evaluation time, so a missing or mismatched |
| 953 | // binding is unambiguously an error. |
| 954 | if lateFn, found := fn.resolve(frame, argVals, strict); found { |
| 955 | res = types.LabelErrNode(fn.id, lateFn(argVals...)) |
| 956 | } else { |
| 957 | res = types.NewErrWithNodeID(fn.id, "no such overload: %s", fn.function) |
| 958 | } |
| 959 | switch len(argVals) { |
| 960 | case 0: |
| 961 | if costs := frame.CostTracker(); costs != nil { |
| 962 | costs.EvalZeroArity(frame, fn.id, fn, res) |
| 963 | } |
| 964 | case 1: |
| 965 | if costs := frame.CostTracker(); costs != nil { |
| 966 | costs.EvalUnary(frame, fn.id, fn, argVals[0], res) |
| 967 | } |
| 968 | case 2: |
| 969 | if costs := frame.CostTracker(); costs != nil { |
| 970 | costs.EvalBinary(frame, fn.id, fn, argVals[0], argVals[1], res) |
| 971 | } |
| 972 | default: |
| 973 | if costs := frame.CostTracker(); costs != nil { |
| 974 | costs.EvalVarArgs(frame, fn.id, fn, argVals, res) |
| 975 | } |
| 976 | } |
| 977 | return res |
| 978 | } |
| 979 | |
| 980 | // resolve determines which declared overload the runtime arguments satisfy and resolves its |
| 981 | // implementation from the activation. |
nothing calls this directly
no test coverage detected