runtime: newNamed; llgo/ssa: abiMethodOf
This commit is contained in:
Binary file not shown.
@@ -103,7 +103,7 @@ func hdrSizeOf(kind abi.Kind) uintptr {
|
||||
}
|
||||
|
||||
// Named returns a named type.
|
||||
func Named(pkgPath, name string, underlying *Type, methods []Method) *Type {
|
||||
func Named(pkgPath, name string, underlying *Type, methods, ptrMethods []Method) *Type {
|
||||
tflag := underlying.TFlag
|
||||
if tflag&abi.TFlagUncommon != 0 {
|
||||
panic("runtime: underlying type is already named")
|
||||
@@ -121,6 +121,16 @@ func Named(pkgPath, name string, underlying *Type, methods []Method) *Type {
|
||||
return &ret.Type
|
||||
}
|
||||
|
||||
ret := newNamed(pkgPath, name, underlying, methods)
|
||||
ret.PtrToThis_ = newNamed(pkgPath, "*"+name, newPointer(ret), ptrMethods)
|
||||
return ret
|
||||
}
|
||||
|
||||
func newNamed(pkgPath, name string, underlying *Type, methods []Method) *Type {
|
||||
tflag := underlying.TFlag
|
||||
kind := underlying.Kind()
|
||||
n := len(methods)
|
||||
|
||||
baseSize := hdrSizeOf(kind)
|
||||
extraSize := uintptr(0)
|
||||
if kind == abi.Func {
|
||||
@@ -164,6 +174,8 @@ func Named(pkgPath, name string, underlying *Type, methods []Method) *Type {
|
||||
|
||||
data := (*abi.Method)(c.Advance(ptr, extraOff))
|
||||
copy(unsafe.Slice(data, n), methods)
|
||||
|
||||
println("==> Named:", pkgPath, name, ret, ret.Uncommon())
|
||||
return ret
|
||||
}
|
||||
|
||||
@@ -216,6 +228,7 @@ func NewItab(inter *InterfaceType, typ *Type) *Itab {
|
||||
ret.hash = typ.Hash
|
||||
|
||||
u := typ.Uncommon()
|
||||
println("==> NewItab Uncommon:", typ, u)
|
||||
if u == nil {
|
||||
ret.fun[0] = 0
|
||||
} else {
|
||||
@@ -228,6 +241,7 @@ func NewItab(inter *InterfaceType, typ *Type) *Itab {
|
||||
break
|
||||
}
|
||||
*c.Advance(data, i) = uintptr(fn)
|
||||
println("==> NewItab:", ret, i, fn)
|
||||
}
|
||||
}
|
||||
return ret
|
||||
@@ -238,6 +252,7 @@ func findMethod(mthds []abi.Method, im abi.Imethod) abi.Text {
|
||||
for _, m := range mthds {
|
||||
mName := m.Name_
|
||||
if mName >= imName {
|
||||
println("==> findMethod:", mName, imName, m.Mtyp_, im.Typ_, m.Ifn_)
|
||||
if mName == imName && m.Mtyp_ == im.Typ_ {
|
||||
println("==> findMethod", mName, m.Ifn_)
|
||||
return m.Ifn_
|
||||
|
||||
@@ -116,20 +116,25 @@ func Struct(pkgPath string, size uintptr, fields ...abi.StructField) *Type {
|
||||
func PointerTo(elem *Type) *Type {
|
||||
ret := elem.PtrToThis_
|
||||
if ret == nil {
|
||||
ptr := &abi.PtrType{
|
||||
Type: Type{
|
||||
Size_: unsafe.Sizeof(uintptr(0)),
|
||||
Hash: uint32(abi.Pointer), // TODO(xsw): hash
|
||||
Kind_: uint8(abi.Pointer),
|
||||
},
|
||||
Elem: elem,
|
||||
}
|
||||
ret = &ptr.Type
|
||||
ret = newPointer(elem)
|
||||
elem.PtrToThis_ = ret
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func newPointer(elem *Type) *Type {
|
||||
ptr := &abi.PtrType{
|
||||
Type: Type{
|
||||
Size_: unsafe.Sizeof(uintptr(0)),
|
||||
Hash: uint32(abi.Pointer), // TODO(xsw): hash
|
||||
Kind_: uint8(abi.Pointer),
|
||||
},
|
||||
Elem: elem,
|
||||
}
|
||||
return &ptr.Type
|
||||
}
|
||||
|
||||
// SliceOf returns the slice type with element elem.
|
||||
func SliceOf(elem *Type) *Type {
|
||||
ret := &abi.SliceType{
|
||||
Type: Type{
|
||||
@@ -142,6 +147,7 @@ func SliceOf(elem *Type) *Type {
|
||||
return &ret.Type
|
||||
}
|
||||
|
||||
// ArrayOf returns the array type with element elem and length.
|
||||
func ArrayOf(length uintptr, elem *Type) *Type {
|
||||
ret := &abi.ArrayType{
|
||||
Type: Type{
|
||||
|
||||
Reference in New Issue
Block a user