Exec implements the InterpretableV2 interface method.
(frame *ExecutionFrame)
| 712 | |
| 713 | // Exec implements the InterpretableV2 interface method. |
| 714 | func (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. |
| 767 | func (bin *evalBinary) Eval(ctx Activation) ref.Val { |
nothing calls this directly
no test coverage detected