merge Field/Extract; prog.Tuple/Zero; TypeAssert refactor

This commit is contained in:
xushiwei
2024-05-23 01:10:13 +08:00
parent 6442ab2f20
commit a4c4324ba3
5 changed files with 174 additions and 68 deletions

View File

@@ -137,6 +137,7 @@ type aProgram struct {
intTy Type
uintTy Type
f64Ty Type
f32Ty Type
byteTy Type
i32Ty Type
u32Ty Type
@@ -293,6 +294,16 @@ func (p Program) NewPackage(name, pkgPath string) Package {
return ret
}
// Tuple returns a tuple type.
func (p Program) Tuple(typs ...Type) Type {
n := len(typs)
els := make([]*types.Var, n)
for i, t := range typs {
els[i] = types.NewParam(token.NoPos, nil, "", t.raw.Type)
}
return p.rawType(types.NewTuple(els...))
}
// Eface returns the empty interface type.
func (p Program) Eface() Type {
if p.efaceTy == nil {
@@ -418,6 +429,14 @@ func (p Program) Float64() Type {
return p.f64Ty
}
// Float32 returns float32 type.
func (p Program) Float32() Type {
if p.f32Ty == nil {
p.f32Ty = p.rawType(types.Typ[types.Float32])
}
return p.f32Ty
}
// Byte returns byte type.
func (p Program) Byte() Type {
if p.byteTy == nil {