Merge pull request #232 from xushiwei/q

NameOff => Name; TypeOff => *Type; TextOff => Text
This commit is contained in:
xushiwei
2024-05-25 22:00:24 +08:00
committed by GitHub
5 changed files with 49 additions and 19 deletions

View File

@@ -1,7 +1,8 @@
; ModuleID = 'main'
source_filename = "main"
%"github.com/goplus/llgo/internal/abi.Type" = type { i64, i64, i32, i8, i8, i8, i8, { ptr, ptr }, ptr, i32, i32 }
%"github.com/goplus/llgo/internal/abi.Type" = type { i64, i64, i32, i8, i8, i8, i8, { ptr, ptr }, ptr, %"github.com/goplus/llgo/internal/abi.Name", ptr }
%"github.com/goplus/llgo/internal/abi.Name" = type { ptr }
@main.basicTypes = global [25 x ptr] undef
@"main.init$guard" = global ptr null
@@ -19,7 +20,7 @@ _llgo_0:
define ptr @main.basicType(i64 %0) {
_llgo_0:
%1 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 56)
%1 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 64)
%2 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %1, i32 0, i32 0
%3 = getelementptr inbounds i64, ptr @main.sizeBasicTypes, i64 %0
%4 = load i64, ptr %3, align 4

Binary file not shown.

View File

@@ -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) }

Binary file not shown.

View File

@@ -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
}
// -----------------------------------------------------------------------------