ssa: chan send/recv

This commit is contained in:
visualfc
2024-07-02 20:12:12 +08:00
parent 0ead82ae21
commit 2153cf39b5
11 changed files with 190 additions and 1 deletions

View File

@@ -1001,6 +1001,8 @@ func (b Builder) BuiltinCall(fn string, args ...Expr) (ret Expr) {
return b.SliceLen(arg)
case vkString:
return b.StringLen(arg)
case vkChan:
return b.InlineCall(b.Pkg.rtFunc("ChanLen"), arg)
}
}
case "cap":
@@ -1009,6 +1011,8 @@ func (b Builder) BuiltinCall(fn string, args ...Expr) (ret Expr) {
switch arg.kind {
case vkSlice:
return b.SliceCap(arg)
case vkChan:
return b.InlineCall(b.Pkg.rtFunc("ChanCap"), arg)
}
}
case "append":
@@ -1047,6 +1051,14 @@ func (b Builder) BuiltinCall(fn string, args ...Expr) (ret Expr) {
}
}
}
case "close":
if len(args) == 1 {
arg := args[0]
switch arg.kind {
case vkChan:
return b.InlineCall(b.Pkg.rtFunc("ChanClose"), arg)
}
}
case "recover":
return b.Recover()
case "print", "println":
@@ -1114,6 +1126,9 @@ func (b Builder) PrintEx(ln bool, args ...Expr) (ret Expr) {
case vkComplex:
fn = "PrintComplex"
typ = prog.Complex128()
case vkChan:
fn = "PrintPointer"
typ = prog.VoidPtr()
default:
panic(fmt.Errorf("illegal types for operand: print %v", arg.RawType()))
}