private closureCtx/closureStub

This commit is contained in:
xushiwei
2024-06-15 10:41:28 +08:00
parent 94d567bf8f
commit 1599ba0294
4 changed files with 12 additions and 10 deletions

View File

@@ -22,6 +22,10 @@ import (
"github.com/goplus/llgo/c"
)
const (
LLGoPackage = true
)
//go:linkname Acos C.acos
func Acos(x float64) float64

View File

@@ -26,13 +26,6 @@ import (
// -----------------------------------------------------------------------------
const (
ClosureCtx = "__llgo_ctx"
ClosureStub = "__llgo_stub."
)
// -----------------------------------------------------------------------------
const (
NameValist = "__llgo_va_list"
)

View File

@@ -564,6 +564,11 @@ func (p Package) cFunc(fullName string, sig *types.Signature) Expr {
return p.NewFunc(fullName, sig, InC).Expr
}
const (
closureCtx = "__llgo_ctx"
closureStub = "__llgo_stub."
)
func (p Package) closureStub(b Builder, t *types.Struct, v Expr) Expr {
name := v.impl.Name()
prog := b.Prog
@@ -574,9 +579,9 @@ func (p Package) closureStub(b Builder, t *types.Struct, v Expr) Expr {
sig := v.raw.Type.(*types.Signature)
n := sig.Params().Len()
nret := sig.Results().Len()
ctx := types.NewParam(token.NoPos, nil, ClosureCtx, types.Typ[types.UnsafePointer])
ctx := types.NewParam(token.NoPos, nil, closureCtx, types.Typ[types.UnsafePointer])
sig = FuncAddCtx(ctx, sig)
fn := p.NewFunc(ClosureStub+name, sig, InC)
fn := p.NewFunc(closureStub+name, sig, InC)
fn.impl.SetLinkage(llvm.LinkOnceAnyLinkage)
args := make([]Expr, n)
for i := 0; i < n; i++ {

View File

@@ -133,7 +133,7 @@ func (p goTypes) cvtNamed(t *types.Named) (raw *types.Named, cvt bool) {
}
func (p goTypes) cvtClosure(sig *types.Signature) *types.Struct {
ctx := types.NewParam(token.NoPos, nil, ClosureCtx, types.Typ[types.UnsafePointer])
ctx := types.NewParam(token.NoPos, nil, closureCtx, types.Typ[types.UnsafePointer])
raw := p.cvtFunc(sig, ctx)
flds := []*types.Var{
types.NewField(token.NoPos, nil, "f", raw, false),