Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ssa/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ type aProgram struct {
callNoArgs *types.Signature
callOneArg *types.Signature
callFOArgs *types.Signature
callArgs *types.Signature
loadPyModS *types.Signature
getAttrStr *types.Signature
pyUniStr *types.Signature
Expand Down
24 changes: 22 additions & 2 deletions ssa/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ func (p Package) pyFunc(fullName string, sig *types.Signature) Expr {
return p.NewFunc(fullName, sig, InC).Expr
}

func (p Package) pyGoFunc(fnName string) Expr {
p.NeedPyInit = true
fn := p.Prog.python().Scope().Lookup(fnName).(*types.Func)
name := FullName(fn.Pkg(), fnName)
sig := fn.Type().(*types.Signature)
return p.NewFunc(name, sig, InGo).Expr
Comment thread
visualfc marked this conversation as resolved.
Comment thread
visualfc marked this conversation as resolved.
}

func (p Program) paramObjPtr() *types.Var {
if p.paramObjPtr_ == nil {
objPtr := p.PyObjectPtr().raw.Type
Expand Down Expand Up @@ -126,7 +134,6 @@ func (p Program) tyCallFunctionObjArgs() *types.Signature {
return p.callFOArgs
}

/*
// func(*Object, *Object, *Object) *Object
func (p Program) tyCall() *types.Signature {
if p.callArgs == nil {
Expand All @@ -137,7 +144,6 @@ func (p Program) tyCall() *types.Signature {
}
return p.callArgs
}
*/

// func(*Object, uintptr, *Object) cint
func (p Program) tyListSetItem() *types.Signature {
Expand Down Expand Up @@ -342,6 +348,10 @@ func (b Builder) PyLoadModSyms(modName string, objs ...PyObjRef) Expr {
return b.Call(fnLoad, args...)
}

const (
pyKwargs = "github.com/goplus/lib/py.Kwargs"
)

func (b Builder) pyCall(fn Expr, args []Expr) (ret Expr) {
prog := b.Prog
pkg := b.Pkg
Expand All @@ -360,6 +370,16 @@ func (b Builder) pyCall(fn Expr, args []Expr) (ret Expr) {
}
fallthrough
default:
if sig.Variadic() {
if params := sig.Params(); params.At(params.Len()-1).Name() == NameValist &&
Comment thread
visualfc marked this conversation as resolved.
len(args) >= params.Len() && args[len(args)-1].Type.RawType().String() == pyKwargs {
kwargs := b.Call(b.Pkg.pyGoFunc("KwargsToDict"), args[len(args)-1])
call := pkg.pyFunc("PyObject_Call", prog.tyCall())
ret = b.Call(call, fn, b.PyTuple(args[:len(args)-1]...), kwargs)
return
}
}

call := pkg.pyFunc("PyObject_CallFunctionObjArgs", prog.tyCallFunctionObjArgs())
n = len(args)
callargs := make([]Expr, n+2)
Expand Down
Loading