ssa: map delete, map eql nil

This commit is contained in:
visualfc
2024-06-29 21:35:20 +08:00
parent 28ebce6b65
commit 439e377111
7 changed files with 239 additions and 83 deletions

View File

@@ -596,6 +596,13 @@ func (b Builder) BinOp(op token.Token, x, y Expr) Expr {
case token.NEQ:
return Expr{b.impl.CreateICmp(llvm.IntNE, dx, dy, ""), tret}
}
case vkMap:
switch op {
case token.EQL:
return b.Prog.BoolVal(x.impl.IsNull() == y.impl.IsNull())
case token.NEQ:
return b.Prog.BoolVal(x.impl.IsNull() != y.impl.IsNull())
}
case vkIface, vkEface:
toEface := func(x Expr, emtpy bool) Expr {
if emtpy {
@@ -1082,6 +1089,21 @@ func (b Builder) BuiltinCall(fn string, args ...Expr) (ret Expr) {
return b.StringData(args[0]) // TODO(xsw): check return type
case "SliceData":
return b.SliceData(args[0]) // TODO(xsw): check return type
case "delete":
if len(args) == 2 && args[0].kind == vkMap {
m := args[0]
t := b.abiType(m.raw.Type)
ptr := b.mapKeyPtr(args[1])
b.Call(b.Pkg.rtFunc("MapDelete"), t, m, ptr)
return
}
case "clear":
if len(args) == 1 && args[0].kind == vkMap {
m := args[0]
t := b.abiType(m.raw.Type)
b.Call(b.Pkg.rtFunc("MapClear"), t, m)
return
}
}
panic("todo: " + fn)
}