2013-05-17 14:25:48 -06:00
|
|
|
package ssa
|
|
|
|
|
2013-07-19 15:35:29 -06:00
|
|
|
// This file defines utilities for method-set computation including
|
|
|
|
// synthesis of wrapper methods.
|
2013-06-14 13:50:37 -06:00
|
|
|
//
|
|
|
|
// Wrappers include:
|
2013-07-26 09:22:34 -06:00
|
|
|
// - indirection/promotion wrappers for methods of embedded fields.
|
2013-06-14 13:50:37 -06:00
|
|
|
// - interface method wrappers for closures of I.f.
|
|
|
|
// - bound method wrappers, for uncalled obj.Method closures.
|
|
|
|
|
2013-07-19 15:35:29 -06:00
|
|
|
// TODO(adonovan): rename to wrappers.go.
|
2013-05-17 14:25:48 -06:00
|
|
|
|
|
|
|
import (
|
2013-05-30 07:59:17 -06:00
|
|
|
"fmt"
|
|
|
|
"go/token"
|
2013-05-17 14:25:48 -06:00
|
|
|
|
2013-07-19 15:35:29 -06:00
|
|
|
"code.google.com/p/go.tools/go/types"
|
|
|
|
)
|
2013-05-17 14:25:48 -06:00
|
|
|
|
2013-07-26 09:22:34 -06:00
|
|
|
// recvType returns the receiver type of method obj.
|
|
|
|
func recvType(obj *types.Func) types.Type {
|
|
|
|
return obj.Type().(*types.Signature).Recv().Type()
|
|
|
|
}
|
|
|
|
|
2013-06-14 13:50:37 -06:00
|
|
|
// MethodSet returns the method set for type typ, building wrapper
|
|
|
|
// methods as needed for embedded field promotion, and indirection for
|
|
|
|
// *T receiver types, etc.
|
2013-05-17 14:25:48 -06:00
|
|
|
// A nil result indicates an empty set.
|
|
|
|
//
|
2013-07-26 09:22:34 -06:00
|
|
|
// This function should only be called when you need to construct the
|
|
|
|
// entire method set, synthesizing all wrappers, for example during
|
|
|
|
// the processing of a MakeInterface instruction or when visiting all
|
|
|
|
// reachable functions.
|
|
|
|
//
|
|
|
|
// If you only need to look up a single method (obj), avoid this
|
|
|
|
// function and use LookupMethod instead:
|
|
|
|
//
|
|
|
|
// meth := types.MethodSet(typ).Lookup(pkg, name)
|
|
|
|
// m := prog.MethodSet(typ)[meth.Id()] // don't do this
|
|
|
|
// m := prog.LookupMethod(meth) // use this instead
|
|
|
|
//
|
|
|
|
// If you only need to enumerate the keys, use types.MethodSet
|
|
|
|
// instead.
|
|
|
|
//
|
|
|
|
// EXCLUSIVE_LOCKS_ACQUIRED(prog.methodsMu)
|
|
|
|
//
|
2013-05-17 14:25:48 -06:00
|
|
|
// Thread-safe.
|
2013-07-10 16:08:42 -06:00
|
|
|
//
|
2013-07-19 15:35:29 -06:00
|
|
|
func (prog *Program) MethodSet(typ types.Type) MethodSet {
|
2013-07-26 09:22:34 -06:00
|
|
|
return prog.populateMethodSet(typ, nil)
|
2013-07-23 11:38:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// populateMethodSet returns the method set for typ, ensuring that it
|
2013-07-26 09:22:34 -06:00
|
|
|
// contains at least the value for obj, if that is a key.
|
|
|
|
// If id is empty, the entire method set is populated.
|
2013-07-23 11:38:52 -06:00
|
|
|
//
|
2013-07-26 09:22:34 -06:00
|
|
|
// EXCLUSIVE_LOCKS_ACQUIRED(prog.methodsMu)
|
|
|
|
//
|
|
|
|
func (prog *Program) populateMethodSet(typ types.Type, meth *types.Method) MethodSet {
|
|
|
|
tmset := methodSet(typ)
|
2013-07-23 11:38:52 -06:00
|
|
|
n := tmset.Len()
|
|
|
|
if n == 0 {
|
2013-05-17 14:25:48 -06:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if prog.mode&LogSource != 0 {
|
2013-07-26 09:22:34 -06:00
|
|
|
defer logStack("populateMethodSet %s meth=%v", typ, meth)()
|
2013-05-17 14:25:48 -06:00
|
|
|
}
|
|
|
|
|
2013-07-19 15:35:29 -06:00
|
|
|
prog.methodsMu.Lock()
|
|
|
|
defer prog.methodsMu.Unlock()
|
2013-05-17 14:25:48 -06:00
|
|
|
|
2013-07-23 11:38:52 -06:00
|
|
|
mset, _ := prog.methodSets.At(typ).(MethodSet)
|
|
|
|
if mset == nil {
|
|
|
|
mset = make(MethodSet)
|
|
|
|
prog.methodSets.Set(typ, mset)
|
2013-05-17 14:25:48 -06:00
|
|
|
}
|
|
|
|
|
2013-07-23 11:38:52 -06:00
|
|
|
if len(mset) < n {
|
2013-07-26 09:22:34 -06:00
|
|
|
if meth != nil { // single method
|
|
|
|
id := meth.Id()
|
2013-07-23 11:38:52 -06:00
|
|
|
if mset[id] == nil {
|
2013-07-26 09:22:34 -06:00
|
|
|
mset[id] = findMethod(prog, meth)
|
2013-07-23 11:38:52 -06:00
|
|
|
}
|
2013-07-26 09:22:34 -06:00
|
|
|
} else {
|
|
|
|
// complete set
|
|
|
|
for i := 0; i < n; i++ {
|
|
|
|
meth := tmset.At(i)
|
|
|
|
if id := meth.Id(); mset[id] == nil {
|
|
|
|
mset[id] = findMethod(prog, meth)
|
|
|
|
}
|
2013-07-23 11:38:52 -06:00
|
|
|
}
|
|
|
|
}
|
2013-05-17 14:25:48 -06:00
|
|
|
}
|
2013-07-23 11:38:52 -06:00
|
|
|
|
2013-05-17 14:25:48 -06:00
|
|
|
return mset
|
|
|
|
}
|
|
|
|
|
2013-07-26 09:22:34 -06:00
|
|
|
func methodSet(typ types.Type) *types.MethodSet {
|
|
|
|
// TODO(adonovan): temporary workaround. Inline it away when fixed.
|
|
|
|
if _, ok := deref(typ).Underlying().(*types.Interface); ok && isPointer(typ) {
|
|
|
|
// TODO(gri): fix: go/types bug: pointer-to-interface
|
|
|
|
// has no methods---yet go/types says it has!
|
|
|
|
return new(types.MethodSet)
|
|
|
|
}
|
|
|
|
return typ.MethodSet()
|
|
|
|
}
|
|
|
|
|
2013-07-23 11:38:52 -06:00
|
|
|
// LookupMethod returns the method id of type typ, building wrapper
|
|
|
|
// methods on demand. It returns nil if the typ has no such method.
|
|
|
|
//
|
|
|
|
// Thread-safe.
|
|
|
|
//
|
2013-07-26 09:22:34 -06:00
|
|
|
// EXCLUSIVE_LOCKS_ACQUIRED(prog.methodsMu)
|
|
|
|
//
|
|
|
|
func (prog *Program) LookupMethod(meth *types.Method) *Function {
|
|
|
|
return prog.populateMethodSet(meth.Recv(), meth)[meth.Id()]
|
2013-07-23 11:38:52 -06:00
|
|
|
}
|
|
|
|
|
2013-07-26 09:22:34 -06:00
|
|
|
// concreteMethod returns the concrete method denoted by obj.
|
|
|
|
// Panic ensues if there is no such method (e.g. it's a standalone
|
|
|
|
// function).
|
|
|
|
//
|
|
|
|
func (prog *Program) concreteMethod(obj *types.Func) *Function {
|
|
|
|
fn := prog.concreteMethods[obj]
|
|
|
|
if fn == nil {
|
|
|
|
panic("no concrete method: " + obj.String())
|
|
|
|
}
|
|
|
|
return fn
|
|
|
|
}
|
|
|
|
|
|
|
|
// findMethod returns the concrete Function for the method meth,
|
|
|
|
// synthesizing wrappers as needed.
|
2013-05-17 14:25:48 -06:00
|
|
|
//
|
2013-07-19 15:35:29 -06:00
|
|
|
// EXCLUSIVE_LOCKS_REQUIRED(prog.methodsMu)
|
|
|
|
//
|
2013-07-26 09:22:34 -06:00
|
|
|
func findMethod(prog *Program, meth *types.Method) *Function {
|
|
|
|
needsPromotion := len(meth.Index()) > 1
|
|
|
|
needsIndirection := !isPointer(recvType(meth.Func)) && isPointer(meth.Recv())
|
2013-07-19 15:35:29 -06:00
|
|
|
|
2013-07-26 09:22:34 -06:00
|
|
|
if needsPromotion || needsIndirection {
|
|
|
|
return makeWrapper(prog, meth.Recv(), meth)
|
2013-05-17 14:25:48 -06:00
|
|
|
}
|
2013-07-19 15:35:29 -06:00
|
|
|
|
2013-07-26 09:22:34 -06:00
|
|
|
if _, ok := meth.Recv().Underlying().(*types.Interface); ok {
|
|
|
|
return interfaceMethodWrapper(prog, meth.Recv(), meth.Func)
|
2013-07-19 15:35:29 -06:00
|
|
|
}
|
|
|
|
|
2013-07-26 09:22:34 -06:00
|
|
|
// Invariant: fn.Signature.Recv().Type() == recvType(meth.Func)
|
|
|
|
return prog.concreteMethod(meth.Func)
|
2013-05-17 14:25:48 -06:00
|
|
|
}
|
|
|
|
|
2013-07-26 09:22:34 -06:00
|
|
|
// makeWrapper returns a synthetic wrapper Function that optionally
|
|
|
|
// performs receiver indirection, implicit field selections and then a
|
|
|
|
// tailcall of a "promoted" method. For example, given these decls:
|
2013-05-17 14:25:48 -06:00
|
|
|
//
|
|
|
|
// type A struct {B}
|
|
|
|
// type B struct {*C}
|
|
|
|
// type C ...
|
|
|
|
// func (*C) f()
|
|
|
|
//
|
2013-07-26 09:22:34 -06:00
|
|
|
// then makeWrapper(typ=A, obj={Func:(*C).f, Indices=[B,C,f]})
|
2013-06-14 13:50:37 -06:00
|
|
|
// synthesize this wrapper method:
|
2013-05-17 14:25:48 -06:00
|
|
|
//
|
|
|
|
// func (a A) f() { return a.B.C->f() }
|
|
|
|
//
|
|
|
|
// prog is the program to which the synthesized method will belong.
|
2013-07-19 15:35:29 -06:00
|
|
|
// typ is the receiver type of the wrapper method. obj is the
|
|
|
|
// type-checker's object for the promoted method; its Func may be a
|
|
|
|
// concrete or an interface method.
|
2013-05-17 14:25:48 -06:00
|
|
|
//
|
2013-07-19 15:35:29 -06:00
|
|
|
// EXCLUSIVE_LOCKS_REQUIRED(prog.methodsMu)
|
2013-07-10 16:08:42 -06:00
|
|
|
//
|
2013-07-26 09:22:34 -06:00
|
|
|
func makeWrapper(prog *Program, typ types.Type, meth *types.Method) *Function {
|
|
|
|
old := meth.Func.Type().(*types.Signature)
|
2013-07-23 22:21:37 -06:00
|
|
|
sig := types.NewSignature(nil, types.NewVar(token.NoPos, nil, "recv", typ), old.Params(), old.Results(), old.IsVariadic())
|
2013-05-17 14:25:48 -06:00
|
|
|
|
2013-07-26 09:22:34 -06:00
|
|
|
description := fmt.Sprintf("wrapper for (%s).%s", old.Recv(), meth.Func.Name())
|
2013-05-17 14:25:48 -06:00
|
|
|
if prog.mode&LogSource != 0 {
|
2013-07-19 15:35:29 -06:00
|
|
|
defer logStack("make %s to (%s)", description, typ)()
|
2013-05-17 14:25:48 -06:00
|
|
|
}
|
|
|
|
fn := &Function{
|
2013-07-26 09:22:34 -06:00
|
|
|
name: meth.Name(),
|
|
|
|
method: meth,
|
2013-05-17 15:02:47 -06:00
|
|
|
Signature: sig,
|
2013-07-19 15:35:29 -06:00
|
|
|
Synthetic: description,
|
2013-05-17 14:25:48 -06:00
|
|
|
Prog: prog,
|
2013-07-26 09:22:34 -06:00
|
|
|
pos: meth.Pos(),
|
2013-05-17 14:25:48 -06:00
|
|
|
}
|
|
|
|
fn.startBody()
|
2013-05-17 15:02:47 -06:00
|
|
|
fn.addSpilledParam(sig.Recv())
|
2013-05-17 14:25:48 -06:00
|
|
|
createParams(fn)
|
|
|
|
|
|
|
|
var v Value = fn.Locals[0] // spilled receiver
|
|
|
|
if isPointer(typ) {
|
2013-07-26 09:22:34 -06:00
|
|
|
// TODO(adonovan): consider emitting a nil-pointer check here
|
|
|
|
// with a nice error message, like gc does.
|
2013-05-17 14:25:48 -06:00
|
|
|
v = emitLoad(fn, v)
|
|
|
|
}
|
2013-07-19 15:35:29 -06:00
|
|
|
|
|
|
|
// Invariant: v is a pointer, either
|
|
|
|
// value of *A receiver param, or
|
|
|
|
// address of A spilled receiver.
|
|
|
|
|
|
|
|
// We use pointer arithmetic (FieldAddr possibly followed by
|
|
|
|
// Load) in preference to value extraction (Field possibly
|
|
|
|
// preceded by Load).
|
|
|
|
|
2013-07-26 09:22:34 -06:00
|
|
|
indices := meth.Index()
|
2013-07-19 15:35:29 -06:00
|
|
|
v = emitImplicitSelections(fn, v, indices[:len(indices)-1])
|
|
|
|
|
|
|
|
// Invariant: v is a pointer, either
|
|
|
|
// value of implicit *C field, or
|
|
|
|
// address of implicit C field.
|
2013-05-17 14:25:48 -06:00
|
|
|
|
|
|
|
var c Call
|
2013-07-19 17:38:16 -06:00
|
|
|
if _, ok := old.Recv().Type().Underlying().(*types.Interface); !ok { // concrete method
|
2013-07-19 15:35:29 -06:00
|
|
|
if !isPointer(old.Recv().Type()) {
|
|
|
|
v = emitLoad(fn, v)
|
|
|
|
}
|
2013-07-26 09:22:34 -06:00
|
|
|
c.Call.Func = prog.concreteMethod(meth.Func)
|
2013-05-17 14:25:48 -06:00
|
|
|
c.Call.Args = append(c.Call.Args, v)
|
|
|
|
} else {
|
2013-07-26 09:22:34 -06:00
|
|
|
c.Call.Method = meth.Func
|
2013-07-19 15:35:29 -06:00
|
|
|
c.Call.Recv = emitLoad(fn, v)
|
2013-05-17 14:25:48 -06:00
|
|
|
}
|
2013-05-22 15:56:18 -06:00
|
|
|
for _, arg := range fn.Params[1:] {
|
|
|
|
c.Call.Args = append(c.Call.Args, arg)
|
|
|
|
}
|
2013-05-17 14:25:48 -06:00
|
|
|
emitTailCall(fn, &c)
|
|
|
|
fn.finishBody()
|
|
|
|
return fn
|
|
|
|
}
|
|
|
|
|
2013-06-14 13:50:37 -06:00
|
|
|
// createParams creates parameters for wrapper method fn based on its
|
2013-06-13 12:43:35 -06:00
|
|
|
// Signature.Params, which do not include the receiver.
|
|
|
|
//
|
2013-05-17 14:25:48 -06:00
|
|
|
func createParams(fn *Function) {
|
|
|
|
var last *Parameter
|
2013-05-17 15:02:47 -06:00
|
|
|
tparams := fn.Signature.Params()
|
|
|
|
for i, n := 0, tparams.Len(); i < n; i++ {
|
2013-05-30 07:59:17 -06:00
|
|
|
last = fn.addParamObj(tparams.At(i))
|
2013-05-17 14:25:48 -06:00
|
|
|
}
|
2013-05-17 15:02:47 -06:00
|
|
|
if fn.Signature.IsVariadic() {
|
2013-05-30 07:59:17 -06:00
|
|
|
last.typ = types.NewSlice(last.typ)
|
2013-05-17 14:25:48 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-14 13:50:37 -06:00
|
|
|
// Wrappers for standalone interface methods ----------------------------------
|
2013-05-17 14:25:48 -06:00
|
|
|
|
2013-07-26 09:22:34 -06:00
|
|
|
// interfaceMethodWrapper returns a synthetic wrapper function
|
|
|
|
// permitting an abstract method obj to be called like a standalone
|
|
|
|
// function, e.g.:
|
2013-05-17 14:25:48 -06:00
|
|
|
//
|
|
|
|
// type I interface { f(x int) R }
|
2013-06-14 13:50:37 -06:00
|
|
|
// m := I.f // wrapper
|
2013-05-17 14:25:48 -06:00
|
|
|
// var i I
|
|
|
|
// m(i, 0)
|
|
|
|
//
|
2013-06-14 13:50:37 -06:00
|
|
|
// The wrapper is defined as if by:
|
2013-05-17 14:25:48 -06:00
|
|
|
//
|
|
|
|
// func I.f(i I, x int, ...) R {
|
|
|
|
// return i.f(x, ...)
|
|
|
|
// }
|
|
|
|
//
|
2013-07-26 09:22:34 -06:00
|
|
|
// typ is the type of the receiver (I here). It isn't necessarily
|
|
|
|
// equal to the recvType(obj) because one interface may embed another.
|
|
|
|
// TODO(adonovan): more tests.
|
|
|
|
//
|
2013-05-17 14:25:48 -06:00
|
|
|
// TODO(adonovan): opt: currently the stub is created even when used
|
|
|
|
// in call position: I.f(i, 0). Clearly this is suboptimal.
|
|
|
|
//
|
2013-07-26 09:22:34 -06:00
|
|
|
// EXCLUSIVE_LOCKS_REQUIRED(prog.methodsMu)
|
2013-05-17 14:25:48 -06:00
|
|
|
//
|
2013-07-26 09:22:34 -06:00
|
|
|
func interfaceMethodWrapper(prog *Program, typ types.Type, obj *types.Func) *Function {
|
2013-06-14 13:50:37 -06:00
|
|
|
// If one interface embeds another they'll share the same
|
|
|
|
// wrappers for common methods. This is safe, but it might
|
|
|
|
// confuse some tools because of the implicit interface
|
|
|
|
// conversion applied to the first argument. If this becomes
|
|
|
|
// a problem, we should include 'typ' in the memoization key.
|
2013-07-26 09:22:34 -06:00
|
|
|
fn, ok := prog.ifaceMethodWrappers[obj]
|
2013-06-14 13:50:37 -06:00
|
|
|
if !ok {
|
2013-07-26 09:22:34 -06:00
|
|
|
description := fmt.Sprintf("interface method wrapper for %s.%s", typ, obj)
|
2013-06-14 13:50:37 -06:00
|
|
|
if prog.mode&LogSource != 0 {
|
2013-07-26 09:22:34 -06:00
|
|
|
defer logStack("%s", description)()
|
2013-06-14 13:50:37 -06:00
|
|
|
}
|
|
|
|
fn = &Function{
|
2013-07-26 09:22:34 -06:00
|
|
|
name: obj.Name(),
|
|
|
|
object: obj,
|
|
|
|
Signature: obj.Type().(*types.Signature),
|
|
|
|
Synthetic: description,
|
|
|
|
pos: obj.Pos(),
|
2013-06-14 13:50:37 -06:00
|
|
|
Prog: prog,
|
|
|
|
}
|
|
|
|
fn.startBody()
|
|
|
|
fn.addParam("recv", typ, token.NoPos)
|
|
|
|
createParams(fn)
|
|
|
|
var c Call
|
2013-07-26 09:22:34 -06:00
|
|
|
|
|
|
|
c.Call.Method = obj
|
2013-06-14 13:50:37 -06:00
|
|
|
c.Call.Recv = fn.Params[0]
|
|
|
|
for _, arg := range fn.Params[1:] {
|
|
|
|
c.Call.Args = append(c.Call.Args, arg)
|
|
|
|
}
|
|
|
|
emitTailCall(fn, &c)
|
|
|
|
fn.finishBody()
|
|
|
|
|
2013-07-26 09:22:34 -06:00
|
|
|
prog.ifaceMethodWrappers[obj] = fn
|
2013-05-22 15:56:18 -06:00
|
|
|
}
|
|
|
|
return fn
|
|
|
|
}
|
|
|
|
|
2013-06-14 13:50:37 -06:00
|
|
|
// Wrappers for bound methods -------------------------------------------------
|
2013-05-22 15:56:18 -06:00
|
|
|
|
2013-06-14 13:50:37 -06:00
|
|
|
// boundMethodWrapper returns a synthetic wrapper function that
|
2013-07-26 09:22:34 -06:00
|
|
|
// delegates to a concrete or interface method.
|
|
|
|
// The wrapper has one free variable, the method's receiver.
|
|
|
|
// Use MakeClosure with such a wrapper to construct a bound-method
|
|
|
|
// closure. e.g.:
|
2013-05-22 15:56:18 -06:00
|
|
|
//
|
2013-07-26 09:22:34 -06:00
|
|
|
// type T int or: type T interface { meth() }
|
2013-05-22 15:56:18 -06:00
|
|
|
// func (t T) meth()
|
|
|
|
// var t T
|
|
|
|
// f := t.meth
|
|
|
|
// f() // calls t.meth()
|
|
|
|
//
|
2013-06-14 13:50:37 -06:00
|
|
|
// f is a closure of a synthetic wrapper defined as if by:
|
2013-05-22 15:56:18 -06:00
|
|
|
//
|
|
|
|
// f := func() { return t.meth() }
|
|
|
|
//
|
2013-06-14 13:50:37 -06:00
|
|
|
// EXCLUSIVE_LOCKS_ACQUIRED(meth.Prog.methodsMu)
|
2013-05-22 15:56:18 -06:00
|
|
|
//
|
2013-07-26 09:22:34 -06:00
|
|
|
func boundMethodWrapper(prog *Program, obj *types.Func) *Function {
|
2013-06-14 13:50:37 -06:00
|
|
|
prog.methodsMu.Lock()
|
|
|
|
defer prog.methodsMu.Unlock()
|
2013-07-26 09:22:34 -06:00
|
|
|
fn, ok := prog.boundMethodWrappers[obj]
|
2013-06-14 13:50:37 -06:00
|
|
|
if !ok {
|
2013-07-26 09:22:34 -06:00
|
|
|
description := fmt.Sprintf("bound method wrapper for %s", obj)
|
2013-06-14 13:50:37 -06:00
|
|
|
if prog.mode&LogSource != 0 {
|
2013-07-26 09:22:34 -06:00
|
|
|
defer logStack("%s", description)()
|
2013-06-14 13:50:37 -06:00
|
|
|
}
|
2013-07-26 09:22:34 -06:00
|
|
|
s := obj.Type().(*types.Signature)
|
2013-06-14 13:50:37 -06:00
|
|
|
fn = &Function{
|
2013-07-26 09:22:34 -06:00
|
|
|
name: "bound$" + obj.String(),
|
2013-07-23 22:21:37 -06:00
|
|
|
Signature: types.NewSignature(nil, nil, s.Params(), s.Results(), s.IsVariadic()), // drop recv
|
2013-07-26 09:22:34 -06:00
|
|
|
Synthetic: description,
|
2013-06-14 13:50:37 -06:00
|
|
|
Prog: prog,
|
2013-07-26 09:22:34 -06:00
|
|
|
pos: obj.Pos(),
|
2013-06-14 13:50:37 -06:00
|
|
|
}
|
2013-05-22 15:56:18 -06:00
|
|
|
|
2013-06-14 13:50:37 -06:00
|
|
|
cap := &Capture{name: "recv", typ: s.Recv().Type(), parent: fn}
|
|
|
|
fn.FreeVars = []*Capture{cap}
|
|
|
|
fn.startBody()
|
|
|
|
createParams(fn)
|
|
|
|
var c Call
|
2013-06-13 12:43:35 -06:00
|
|
|
|
2013-07-26 09:22:34 -06:00
|
|
|
if _, ok := recvType(obj).Underlying().(*types.Interface); !ok { // concrete
|
|
|
|
c.Call.Func = prog.concreteMethod(obj)
|
|
|
|
c.Call.Args = []Value{cap}
|
|
|
|
} else {
|
|
|
|
c.Call.Recv = cap
|
|
|
|
c.Call.Method = obj
|
2013-06-13 12:43:35 -06:00
|
|
|
}
|
2013-07-26 09:22:34 -06:00
|
|
|
for _, arg := range fn.Params {
|
2013-06-13 12:43:35 -06:00
|
|
|
c.Call.Args = append(c.Call.Args, arg)
|
|
|
|
}
|
|
|
|
emitTailCall(fn, &c)
|
|
|
|
fn.finishBody()
|
|
|
|
|
2013-07-26 09:22:34 -06:00
|
|
|
prog.boundMethodWrappers[obj] = fn
|
2013-06-13 12:43:35 -06:00
|
|
|
}
|
|
|
|
return fn
|
|
|
|
}
|