merge upstream

This commit is contained in:
xushiwei
2024-06-12 21:02:26 +08:00
21 changed files with 6462 additions and 367 deletions

View File

@@ -166,6 +166,9 @@ func (b *Builder) TypeName(t types.Type) (ret string, pub bool) {
// PathOf returns the package path of the specified package.
func PathOf(pkg *types.Package) string {
if pkg == nil {
return ""
}
if pkg.Name() == "main" {
return "main"
}
@@ -174,6 +177,9 @@ func PathOf(pkg *types.Package) string {
// FullName returns the full name of a package member.
func FullName(pkg *types.Package, name string) string {
if pkg == nil {
return name
}
return PathOf(pkg) + "." + name
}

View File

@@ -118,11 +118,9 @@ func (b Builder) abiMethods(t *types.Named) (ret, pret int) {
}
// Method{name string, typ *FuncType, ifn, tfn abi.Text}
func (b Builder) abiMethodOf(m *types.Func /*, bg Background = InGo */) (mthd, ptrMthd Expr) {
func (b Builder) abiMethodOf(m types.Object, mSig *types.Signature /*, bg Background = InGo */) (mthd, ptrMthd Expr) {
prog := b.Prog
mPkg, mName := m.Pkg(), m.Name()
mSig := m.Type().(*types.Signature)
name := b.Str(mName).impl
if !token.IsExported(mName) {
name = b.Str(abi.FullName(mPkg, m.Name())).impl
@@ -217,8 +215,12 @@ func (b Builder) abiInitNamed(ret Expr, t *types.Named) func() Expr {
var mthds []Expr
var ptrMthds = make([]Expr, 0, n)
for i := 0; i < n; i++ {
m := mset[i].Obj().(*types.Func)
mthd, ptrMthd := b.abiMethodOf(m)
m := mset[i]
sig := m.Obj().(*types.Func).Type().(*types.Signature)
if _, ok := sig.Recv().Type().Underlying().(*types.Interface); ok {
sig = m.Type().(*types.Signature)
}
mthd, ptrMthd := b.abiMethodOf(m.Obj(), sig)
if !mthd.IsNil() {
mthds = append(mthds, mthd)
}

View File

@@ -421,6 +421,22 @@ func (b Builder) BinOp(op token.Token, x, y Expr) Expr {
ret.impl = llvm.CreateNot(b.impl, ret.impl)
return ret
}
case vkIface, vkEface:
prog := b.Prog
toEface := func(x Expr, emtpy bool) Expr {
if emtpy {
return x
}
return Expr{b.unsafeEface(b.faceAbiType(x).impl, b.faceData(x.impl)), prog.rtType("Eface")}
}
switch op {
case token.EQL:
return b.InlineCall(b.Pkg.rtFunc("EfaceEqual"), toEface(x, x.kind == vkEface), toEface(y, y.kind == vkEface))
case token.NEQ:
ret := b.InlineCall(b.Pkg.rtFunc("EfaceEqual"), toEface(x, x.kind == vkEface), toEface(y, y.kind == vkEface))
ret.impl = llvm.CreateNot(b.impl, ret.impl)
return ret
}
}
}
panic("todo")

View File

@@ -238,11 +238,7 @@ func (b Builder) TypeAssert(x Expr, assertedTyp Type, commaOk bool) Expr {
var eq Expr
var val func() Expr
if rawIntf, ok := assertedTyp.raw.Type.Underlying().(*types.Interface); ok {
if rawIntf.Empty() {
eq = b.Prog.BoolVal(true)
} else {
eq = b.InlineCall(b.Pkg.rtFunc("Implements"), tabi, tx)
}
eq = b.InlineCall(b.Pkg.rtFunc("Implements"), tabi, tx)
val = func() Expr { return Expr{b.unsafeInterface(rawIntf, tx, b.faceData(x.impl)), assertedTyp} }
} else {
eq = b.BinOp(token.EQL, tx, tabi)

View File

@@ -128,6 +128,7 @@ func (p goTypes) cvtNamed(t *types.Named) (raw *types.Named, cvt bool) {
named.SetUnderlying(tund)
return named, true
}
p.typs[unsafe.Pointer(t)] = unsafe.Pointer(t)
return t, false
}