runtime: fix map len and chan len/cap

This commit is contained in:
visualfc
2024-09-25 20:51:58 +08:00
parent 32f41a04ac
commit c184dc8d2f
7 changed files with 487 additions and 161 deletions

View File

@@ -145,18 +145,6 @@ func (b Builder) SliceCap(x Expr) Expr {
return Expr{ptr, b.Prog.Int()}
}
func (b Builder) MapLen(x Expr) Expr {
if debugInstr {
log.Printf("MapLen %v\n", x.impl)
}
prog := b.Prog
if x.impl.IsNull() {
return prog.Val(0)
}
x.Type = prog.Pointer(prog.Int())
return b.Load(x)
}
// -----------------------------------------------------------------------------
// The IndexAddr instruction yields the address of the element at

View File

@@ -1083,7 +1083,7 @@ func (b Builder) BuiltinCall(fn string, args ...Expr) (ret Expr) {
case vkChan:
return b.InlineCall(b.Pkg.rtFunc("ChanLen"), arg)
case vkMap:
return b.MapLen(arg)
return b.InlineCall(b.Pkg.rtFunc("MapLen"), arg)
}
}
case "cap":