toLLVMFunc: closure

This commit is contained in:
xushiwei
2024-05-04 07:47:18 +08:00
parent 06d6b447e4
commit f07a62d136
7 changed files with 11 additions and 20 deletions

View File

@@ -16,6 +16,7 @@
package runtime package runtime
/*
import ( import (
"unsafe" "unsafe"
) )
@@ -40,3 +41,4 @@ func ClosureF(c Closure) unsafe.Pointer {
func ClosureData(c Closure) unsafe.Pointer { func ClosureData(c Closure) unsafe.Pointer {
return c.data return c.data
} }
*/

View File

@@ -26,7 +26,7 @@ import (
) )
func TestFromTestrt(t *testing.T) { func TestFromTestrt(t *testing.T) {
cltest.FromDir(t, "", "../cl/_testrt", true) cltest.FromDir(t, "intgen", "../cl/_testrt", true)
} }
func TestFromTestdata(t *testing.T) { func TestFromTestdata(t *testing.T) {

View File

@@ -1029,7 +1029,7 @@ func (b Builder) Call(fn Expr, args ...Expr) (ret Expr) {
sig := t.(*types.Signature) sig := t.(*types.Signature)
ret.Type = prog.retType(sig) ret.Type = prog.retType(sig)
default: default:
panic("todo") panic("unreachable")
} }
ret.impl = llvm.CreateCall(b.impl, fn.ll, fn.impl, llvmValues(args)) ret.impl = llvm.CreateCall(b.impl, fn.ll, fn.impl, llvmValues(args))
return return

View File

@@ -114,11 +114,10 @@ type aProgram struct {
voidType llvm.Type voidType llvm.Type
voidPtrTy llvm.Type voidPtrTy llvm.Type
rtClosureTy llvm.Type rtStringTy llvm.Type
rtStringTy llvm.Type rtIfaceTy llvm.Type
rtIfaceTy llvm.Type rtSliceTy llvm.Type
rtSliceTy llvm.Type rtMapTy llvm.Type
rtMapTy llvm.Type
anyTy Type anyTy Type
voidTy Type voidTy Type
@@ -188,13 +187,6 @@ func (p Program) rtType(name string) Type {
return p.Type(p.rtNamed(name)) return p.Type(p.rtNamed(name))
} }
func (p Program) rtClosure() llvm.Type {
if p.rtClosureTy.IsNil() {
p.rtClosureTy = p.rtType("Closure").ll
}
return p.rtClosureTy
}
func (p Program) rtIface() llvm.Type { func (p Program) rtIface() llvm.Type {
if p.rtIfaceTy.IsNil() { if p.rtIfaceTy.IsNil() {
p.rtIfaceTy = p.rtType("Interface").ll p.rtIfaceTy = p.rtType("Interface").ll

View File

@@ -126,11 +126,6 @@ func (p Program) Field(typ Type, i int) Type {
} }
func (p Program) Type(typ types.Type) Type { func (p Program) Type(typ types.Type) Type {
/* TODO(xsw): no need?
if sig, ok := typ.(*types.Signature); ok { // should methodToFunc
return p.llvmSignature(sig, true)
}
*/
if v := p.typs.At(typ); v != nil { if v := p.typs.At(typ); v != nil {
return v.(Type) return v.(Type)
} }
@@ -339,7 +334,9 @@ func (p Program) toLLVMFunc(sig *types.Signature, inC, isDecl bool) Type {
types.NewField(token.NoPos, nil, "f", (*CFuncPtr)(sig), false), types.NewField(token.NoPos, nil, "f", (*CFuncPtr)(sig), false),
types.NewField(token.NoPos, nil, "data", types.Typ[types.UnsafePointer], false), types.NewField(token.NoPos, nil, "data", types.Typ[types.UnsafePointer], false),
} }
return &aType{p.rtClosure(), types.NewStruct(flds, nil), vkClosure} t := types.NewStruct(flds, nil)
ll := p.ctx.StructType(p.toLLVMFields(t), false)
return &aType{ll, t, vkClosure}
} }
func (p Program) retType(sig *types.Signature) Type { func (p Program) retType(sig *types.Signature) Type {