internal/runtime: NewNamedInterface, InitNamedInterface

This commit is contained in:
visualfc
2024-12-16 12:02:22 +08:00
parent a05bda9fc3
commit e55a5d7486
8 changed files with 1222 additions and 1066 deletions

View File

@@ -224,6 +224,40 @@ func Func(in, out []*Type, variadic bool) *FuncType {
return ret
}
func NewNamedInterface(pkgPath, name string) *InterfaceType {
ret := &struct {
abi.InterfaceType
u abi.UncommonType
}{
abi.InterfaceType{
Type: Type{
Size_: unsafe.Sizeof(eface{}),
PtrBytes: 2 * pointerSize,
Hash: uint32(abi.Interface), // TODO(xsw): hash
Align_: uint8(pointerAlign),
FieldAlign_: uint8(pointerAlign),
Kind_: uint8(abi.Interface),
Str_: name,
TFlag: abi.TFlagNamed | abi.TFlagUncommon,
},
PkgPath_: pkgPath,
},
abi.UncommonType{
PkgPath_: pkgPath,
},
}
return &ret.InterfaceType
}
func InitNamedInterface(ret *InterfaceType, methods []Imethod) {
ret.Methods = methods
if len(methods) == 0 {
ret.Equal = nilinterequal
} else {
ret.Equal = interequal
}
}
// Interface returns an interface type.
// Don't call NewNamed for named interface type.
func Interface(pkgPath, name string, methods []Imethod) *InterfaceType {