Merge pull request #518 from visualfc/ptrsize
runtime: init abi.Type.PtrBytes
This commit is contained in:
@@ -190,7 +190,8 @@ func doInitNamed(ret *Type, pkgPath, fullName string, underlying *Type, methods
|
|||||||
func Func(in, out []*Type, variadic bool) *FuncType {
|
func Func(in, out []*Type, variadic bool) *FuncType {
|
||||||
ret := &FuncType{
|
ret := &FuncType{
|
||||||
Type: Type{
|
Type: Type{
|
||||||
Size_: unsafe.Sizeof(uintptr(0)),
|
Size_: 2 * unsafe.Sizeof(uintptr(0)),
|
||||||
|
PtrBytes: 2 * pointerSize,
|
||||||
Hash: uint32(abi.Func), // TODO(xsw): hash
|
Hash: uint32(abi.Func), // TODO(xsw): hash
|
||||||
Align_: uint8(pointerAlign),
|
Align_: uint8(pointerAlign),
|
||||||
FieldAlign_: uint8(pointerAlign),
|
FieldAlign_: uint8(pointerAlign),
|
||||||
@@ -212,6 +213,7 @@ func Interface(pkgPath, name string, methods []Imethod) *InterfaceType {
|
|||||||
ret := &abi.InterfaceType{
|
ret := &abi.InterfaceType{
|
||||||
Type: Type{
|
Type: Type{
|
||||||
Size_: unsafe.Sizeof(eface{}),
|
Size_: unsafe.Sizeof(eface{}),
|
||||||
|
PtrBytes: 2 * pointerSize,
|
||||||
Hash: uint32(abi.Interface), // TODO(xsw): hash
|
Hash: uint32(abi.Interface), // TODO(xsw): hash
|
||||||
Align_: uint8(pointerAlign),
|
Align_: uint8(pointerAlign),
|
||||||
FieldAlign_: uint8(pointerAlign),
|
FieldAlign_: uint8(pointerAlign),
|
||||||
|
|||||||
@@ -72,8 +72,13 @@ func Basic(_kind Kind) *Type {
|
|||||||
kind := _kind & abi.KindMask
|
kind := _kind & abi.KindMask
|
||||||
if tyBasic[kind] == nil {
|
if tyBasic[kind] == nil {
|
||||||
name, size, align := basicTypeInfo(kind)
|
name, size, align := basicTypeInfo(kind)
|
||||||
|
var bytes uintptr
|
||||||
|
if kind == abi.String {
|
||||||
|
bytes = pointerSize
|
||||||
|
}
|
||||||
tyBasic[kind] = &Type{
|
tyBasic[kind] = &Type{
|
||||||
Size_: size,
|
Size_: size,
|
||||||
|
PtrBytes: bytes,
|
||||||
Hash: uint32(kind), // TODO(xsw): hash
|
Hash: uint32(kind), // TODO(xsw): hash
|
||||||
Align_: uint8(align),
|
Align_: uint8(align),
|
||||||
FieldAlign_: uint8(align),
|
FieldAlign_: uint8(align),
|
||||||
@@ -160,6 +165,9 @@ func Struct(pkgPath string, size uintptr, fields ...abi.StructField) *Type {
|
|||||||
if ft.Align_ > typalign {
|
if ft.Align_ > typalign {
|
||||||
typalign = ft.Align_
|
typalign = ft.Align_
|
||||||
}
|
}
|
||||||
|
if f.Typ.PtrBytes != 0 {
|
||||||
|
ret.PtrBytes = f.Offset + f.Typ.PtrBytes
|
||||||
|
}
|
||||||
comparable = comparable && (ft.Equal != nil)
|
comparable = comparable && (ft.Equal != nil)
|
||||||
}
|
}
|
||||||
ret.Align_ = typalign
|
ret.Align_ = typalign
|
||||||
@@ -207,6 +215,7 @@ func newPointer(elem *Type) *Type {
|
|||||||
ptr := &abi.PtrType{
|
ptr := &abi.PtrType{
|
||||||
Type: Type{
|
Type: Type{
|
||||||
Size_: unsafe.Sizeof(uintptr(0)),
|
Size_: unsafe.Sizeof(uintptr(0)),
|
||||||
|
PtrBytes: pointerSize,
|
||||||
Hash: uint32(abi.Pointer), // TODO(xsw): hash
|
Hash: uint32(abi.Pointer), // TODO(xsw): hash
|
||||||
Align_: pointerAlign,
|
Align_: pointerAlign,
|
||||||
FieldAlign_: pointerAlign,
|
FieldAlign_: pointerAlign,
|
||||||
@@ -230,6 +239,7 @@ func SliceOf(elem *Type) *Type {
|
|||||||
ret := &abi.SliceType{
|
ret := &abi.SliceType{
|
||||||
Type: Type{
|
Type: Type{
|
||||||
Size_: unsafe.Sizeof([]int{}),
|
Size_: unsafe.Sizeof([]int{}),
|
||||||
|
PtrBytes: pointerSize,
|
||||||
Hash: uint32(abi.Slice),
|
Hash: uint32(abi.Slice),
|
||||||
Align_: pointerAlign,
|
Align_: pointerAlign,
|
||||||
FieldAlign_: pointerAlign,
|
FieldAlign_: pointerAlign,
|
||||||
@@ -256,6 +266,9 @@ func ArrayOf(length uintptr, elem *Type) *Type {
|
|||||||
Slice: SliceOf(elem),
|
Slice: SliceOf(elem),
|
||||||
Len: length,
|
Len: length,
|
||||||
}
|
}
|
||||||
|
if length != 0 && elem.PtrBytes != 0 {
|
||||||
|
ret.PtrBytes = ret.Size_ - elem.Size_ + elem.PtrBytes
|
||||||
|
}
|
||||||
if eequal := elem.Equal; eequal != nil {
|
if eequal := elem.Equal; eequal != nil {
|
||||||
if elem.Size_ == 0 {
|
if elem.Size_ == 0 {
|
||||||
ret.Equal = memequal0
|
ret.Equal = memequal0
|
||||||
@@ -284,7 +297,8 @@ func ArrayOf(length uintptr, elem *Type) *Type {
|
|||||||
func ChanOf(dir int, strChan string, elem *Type) *Type {
|
func ChanOf(dir int, strChan string, elem *Type) *Type {
|
||||||
ret := &abi.ChanType{
|
ret := &abi.ChanType{
|
||||||
Type: Type{
|
Type: Type{
|
||||||
Size_: 8,
|
Size_: pointerSize,
|
||||||
|
PtrBytes: pointerSize,
|
||||||
Hash: uint32(abi.Chan),
|
Hash: uint32(abi.Chan),
|
||||||
Align_: pointerAlign,
|
Align_: pointerAlign,
|
||||||
TFlag: abi.TFlagRegularMemory,
|
TFlag: abi.TFlagRegularMemory,
|
||||||
@@ -303,6 +317,7 @@ func MapOf(key, elem *Type, bucket *Type, flags int) *Type {
|
|||||||
ret := &abi.MapType{
|
ret := &abi.MapType{
|
||||||
Type: Type{
|
Type: Type{
|
||||||
Size_: unsafe.Sizeof(uintptr(0)),
|
Size_: unsafe.Sizeof(uintptr(0)),
|
||||||
|
PtrBytes: pointerSize,
|
||||||
Hash: uint32(abi.Map),
|
Hash: uint32(abi.Map),
|
||||||
Align_: pointerAlign,
|
Align_: pointerAlign,
|
||||||
FieldAlign_: pointerAlign,
|
FieldAlign_: pointerAlign,
|
||||||
|
|||||||
Reference in New Issue
Block a user