diff --git a/internal/runtime/type.go b/internal/runtime/type.go index 36ce1a0f..8e8b4332 100644 --- a/internal/runtime/type.go +++ b/internal/runtime/type.go @@ -12,11 +12,9 @@ import ( type _type = abi.Type -type interfacetype = abi.InterfaceType - +/* type maptype = abi.MapType -/* type arraytype = abi.ArrayType type chantype = abi.ChanType diff --git a/internal/runtime/z_face.go b/internal/runtime/z_face.go index 28409f1e..01907b0a 100644 --- a/internal/runtime/z_face.go +++ b/internal/runtime/z_face.go @@ -21,6 +21,8 @@ type iface struct { data unsafe.Pointer } +type interfacetype = abi.InterfaceType + // layout of Itab known to compilers // allocated in non-garbage-collected memory // Needs to be in sync with @@ -126,12 +128,10 @@ func Named(pkgPath, name Name, underlying *Type, methods []abi.Method) *Type { } uncommon := (*abi.UncommonType)(c.Advance(ptr, int(typeHdrSize))) - *uncommon = abi.UncommonType{ - PkgPath_: pkgPath, - Mcount: uint16(n), - Xcount: uint16(xcount), - Moff: uint32(uncommonTypeHdrSize), - } + uncommon.PkgPath_ = pkgPath + uncommon.Mcount = uint16(n) + uncommon.Xcount = uint16(xcount) + uncommon.Moff = uint32(uncommonTypeHdrSize) data := (*abi.Method)(c.Advance(ptr, int(typeHdrSize+uncommonTypeHdrSize))) copy(unsafe.Slice(data, n), methods) @@ -139,18 +139,14 @@ func Named(pkgPath, name Name, underlying *Type, methods []abi.Method) *Type { } // Interface returns an interface type. -func Interface(pkgPath string, methods []abi.Imethod) *Type { - var npkg abi.Name - if len(pkgPath) > 0 { - npkg = abi.NewName(pkgPath, "", false, false) - } +func Interface(pkgPath Name, methods []abi.Imethod) *Type { ret := &abi.InterfaceType{ Type: Type{ Size_: unsafe.Sizeof(eface{}), Hash: uint32(abi.Interface), // TODO(xsw): hash Kind_: uint8(abi.Interface), }, - PkgPath: npkg, + PkgPath: pkgPath, Methods: methods, } return &ret.Type diff --git a/ssa/expr.go b/ssa/expr.go index 0258755c..9ff69d84 100644 --- a/ssa/expr.go +++ b/ssa/expr.go @@ -221,6 +221,11 @@ func (b Builder) Str(v string) (ret Expr) { return Expr{aggregateValue(b.impl, prog.rtString(), data, size), prog.String()} } +func (b Builder) pkgName(pkgPath string) Expr { + // TODO(xsw): use a global cache + return b.Call(b.Pkg.rtFunc("NewPkgName"), b.Str(pkgPath)) +} + // unsafeString(data *byte, size int) string func (b Builder) unsafeString(data, size llvm.Value) Expr { prog := b.Prog diff --git a/ssa/interface.go b/ssa/interface.go index 6d33fc44..b1ab1535 100644 --- a/ssa/interface.go +++ b/ssa/interface.go @@ -84,7 +84,7 @@ func (b Builder) abiStructOf(t *types.Struct) Expr { off := uintptr(prog.OffsetOf(typ, i)) flds[i] = b.structField(sfAbi, prog, f, off, t.Tag(i)) } - pkgPath := b.Str(pkg.Path()) + pkgPath := b.pkgName(pkg.Path()) params := strucAbi.raw.Type.(*types.Signature).Params() tSlice := prog.rawType(params.At(params.Len() - 1).Type().(*types.Slice)) fldSlice := b.SliceLit(tSlice, flds...)