toLLVMFunc: closure
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package runtime
|
||||
|
||||
/*
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
@@ -40,3 +41,4 @@ func ClosureF(c Closure) unsafe.Pointer {
|
||||
func ClosureData(c Closure) unsafe.Pointer {
|
||||
return c.data
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
)
|
||||
|
||||
func TestFromTestrt(t *testing.T) {
|
||||
cltest.FromDir(t, "", "../cl/_testrt", true)
|
||||
cltest.FromDir(t, "intgen", "../cl/_testrt", true)
|
||||
}
|
||||
|
||||
func TestFromTestdata(t *testing.T) {
|
||||
|
||||
@@ -1029,7 +1029,7 @@ func (b Builder) Call(fn Expr, args ...Expr) (ret Expr) {
|
||||
sig := t.(*types.Signature)
|
||||
ret.Type = prog.retType(sig)
|
||||
default:
|
||||
panic("todo")
|
||||
panic("unreachable")
|
||||
}
|
||||
ret.impl = llvm.CreateCall(b.impl, fn.ll, fn.impl, llvmValues(args))
|
||||
return
|
||||
|
||||
@@ -114,11 +114,10 @@ type aProgram struct {
|
||||
voidType llvm.Type
|
||||
voidPtrTy llvm.Type
|
||||
|
||||
rtClosureTy llvm.Type
|
||||
rtStringTy llvm.Type
|
||||
rtIfaceTy llvm.Type
|
||||
rtSliceTy llvm.Type
|
||||
rtMapTy llvm.Type
|
||||
rtStringTy llvm.Type
|
||||
rtIfaceTy llvm.Type
|
||||
rtSliceTy llvm.Type
|
||||
rtMapTy llvm.Type
|
||||
|
||||
anyTy Type
|
||||
voidTy Type
|
||||
@@ -188,13 +187,6 @@ func (p Program) rtType(name string) Type {
|
||||
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 {
|
||||
if p.rtIfaceTy.IsNil() {
|
||||
p.rtIfaceTy = p.rtType("Interface").ll
|
||||
|
||||
@@ -126,11 +126,6 @@ func (p Program) Field(typ Type, i int) 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 {
|
||||
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, "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 {
|
||||
|
||||
Reference in New Issue
Block a user