diff --git a/internal/abi/llgo_autogen.lla b/internal/abi/llgo_autogen.lla index 7fed6350..f2db6c47 100644 Binary files a/internal/abi/llgo_autogen.lla and b/internal/abi/llgo_autogen.lla differ diff --git a/internal/abi/type.go b/internal/abi/type.go index 21f90142..e7ecaf8f 100644 --- a/internal/abi/type.go +++ b/internal/abi/type.go @@ -45,9 +45,9 @@ type Type struct { // GCData stores the GC type data for the garbage collector. // If the KindGCProg bit is set in kind, GCData is a GC program. // Otherwise it is a ptrmask bitmap. See mbitmap.go for details. - GCData *byte - Str NameOff // string form - PtrToThis TypeOff // type for pointer to this type, may be zero + GCData *byte + Str_ Name // string form + PtrToThis_ *Type // type for pointer to this type, may be nil } // A Kind represents the specific kind of type that a Type represents. @@ -127,12 +127,6 @@ const ( TFlagRegularMemory TFlag = 1 << 3 ) -// NameOff is the offset to a name from moduledata.types. See resolveNameOff in runtime. -type NameOff int32 - -// TypeOff is the offset to a type from moduledata.types. See resolveTypeOff in runtime. -type TypeOff int32 - // ----------------------------------------------------------------------------- // ArrayType represents a fixed array type. @@ -221,10 +215,45 @@ type InterfaceType struct { Methods []Imethod // sorted by hash } +type Text = unsafe.Pointer // TODO(xsw): to be confirmed + +// Method on non-interface type +type Method struct { + Name_ Name // name of method + Mtyp_ *Type // method type (without receiver) + Ifn_ Text // fn used in interface call (one-word receiver) + Tfn_ Text // fn used for normal method call +} + +// UncommonType is present only for defined types or types with methods +// (if T is a defined type, the uncommonTypes for T and *T have methods). +// Using a pointer to this struct reduces the overall size required +// to describe a non-defined type with no methods. +type UncommonType struct { + PkgPath_ Name // import path; empty for built-in types like int, string + Mcount uint16 // number of methods + Xcount uint16 // number of exported methods + Moff uint32 // offset from this uncommontype to [mcount]Method +} + +func (t *UncommonType) Methods() []Method { + if t.Mcount == 0 { + return nil + } + return (*[1 << 16]Method)(addChecked(unsafe.Pointer(t), uintptr(t.Moff), "t.mcount > 0"))[:t.Mcount:t.Mcount] +} + +func (t *UncommonType) ExportedMethods() []Method { + if t.Xcount == 0 { + return nil + } + return (*[1 << 16]Method)(addChecked(unsafe.Pointer(t), uintptr(t.Moff), "t.xcount > 0"))[:t.Xcount:t.Xcount] +} + // Imethod represents a method on an interface type type Imethod struct { - Name NameOff // name of method - Typ TypeOff // .(*FuncType) underneath + Name_ Name // name of method + Typ_ *FuncType // .(*FuncType) underneath } func (t *Type) Kind() Kind { return Kind(t.Kind_ & KindMask) } diff --git a/internal/runtime/llgo_autogen.lla b/internal/runtime/llgo_autogen.lla index bd66305d..0de68c73 100644 Binary files a/internal/runtime/llgo_autogen.lla and b/internal/runtime/llgo_autogen.lla differ diff --git a/internal/runtime/z_type.go b/internal/runtime/z_type.go index 93eb6420..99de71c5 100644 --- a/internal/runtime/z_type.go +++ b/internal/runtime/z_type.go @@ -35,6 +35,12 @@ type InterfaceType = abi.InterfaceType // ----------------------------------------------------------------------------- +// Named returns a named type. +func Named(name string, typ *Type) *Type { + ret := *typ // TODO(xsw): named type + return &ret +} + // Interface returns an interface type. func Interface(pkgPath string) *Type { // TODO(xsw): pkgPath @@ -160,10 +166,4 @@ func Pointer(elem *Type) *Type { return &ret.Type } -// Named returns a named type. -func Named(name string, typ *Type) *Type { - ret := *typ // TODO(xsw): named type - return &ret -} - // -----------------------------------------------------------------------------