vkPyFunc => vkPyFuncRef
This commit is contained in:
16
ssa/decl.go
16
ssa/decl.go
@@ -285,16 +285,16 @@ func (p Function) Block(idx int) BasicBlock {
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
type aPyObject struct {
|
||||
type aPyObjRef struct {
|
||||
Expr
|
||||
Obj Global
|
||||
}
|
||||
|
||||
// PyObject represents a python object.
|
||||
type PyObject = *aPyObject
|
||||
// PyObjRef represents a python object reference.
|
||||
type PyObjRef = *aPyObjRef
|
||||
|
||||
// NewPyFunc creates a new python function.
|
||||
func (p Package) NewPyFunc(name string, sig *types.Signature, doInit bool) PyObject {
|
||||
func (p Package) NewPyFunc(name string, sig *types.Signature, doInit bool) PyObjRef {
|
||||
if v, ok := p.pyobjs[name]; ok {
|
||||
return v
|
||||
}
|
||||
@@ -305,20 +305,20 @@ func (p Package) NewPyFunc(name string, sig *types.Signature, doInit bool) PyObj
|
||||
obj.Init(prog.Null(obj.Type))
|
||||
obj.impl.SetLinkage(llvm.LinkOnceAnyLinkage)
|
||||
}
|
||||
ty := &aType{obj.ll, rawType{sig}, vkPyFunc}
|
||||
ty := &aType{obj.ll, rawType{types.NewPointer(sig)}, vkPyFuncRef}
|
||||
expr := Expr{obj.impl, ty}
|
||||
ret := &aPyObject{expr, obj}
|
||||
ret := &aPyObjRef{expr, obj}
|
||||
p.pyobjs[name] = ret
|
||||
return ret
|
||||
}
|
||||
|
||||
// PyObjOf returns a python object by name.
|
||||
func (p Package) PyObjOf(name string) PyObject {
|
||||
func (p Package) PyObjOf(name string) PyObjRef {
|
||||
return p.pyobjs[name]
|
||||
}
|
||||
|
||||
// PyObjs returns all used python objects in this project.
|
||||
func (p Package) PyObjs() map[string]PyObject {
|
||||
func (p Package) PyObjs() map[string]PyObjRef {
|
||||
return p.pyobjs
|
||||
}
|
||||
|
||||
|
||||
@@ -1238,7 +1238,7 @@ func (b Builder) Call(fn Expr, args ...Expr) (ret Expr) {
|
||||
log.Println(b.String())
|
||||
}
|
||||
var kind = fn.kind
|
||||
if kind == vkPyFunc {
|
||||
if kind == vkPyFuncRef {
|
||||
return b.pyCall(fn, args)
|
||||
}
|
||||
var ll llvm.Type
|
||||
|
||||
@@ -258,7 +258,7 @@ func (p Program) NewPackage(name, pkgPath string) Package {
|
||||
gbls := make(map[string]Global)
|
||||
fns := make(map[string]Function)
|
||||
stubs := make(map[string]Function)
|
||||
pyobjs := make(map[string]PyObject)
|
||||
pyobjs := make(map[string]PyObjRef)
|
||||
pymods := make(map[string]Global)
|
||||
p.NeedRuntime = false
|
||||
// Don't need reset p.needPyInit here
|
||||
@@ -367,7 +367,7 @@ type aPackage struct {
|
||||
vars map[string]Global
|
||||
fns map[string]Function
|
||||
stubs map[string]Function
|
||||
pyobjs map[string]PyObject
|
||||
pyobjs map[string]PyObjRef
|
||||
pymods map[string]Global
|
||||
Prog Program
|
||||
}
|
||||
@@ -552,7 +552,7 @@ func (b Builder) ImportPyMod(path string) Expr {
|
||||
}
|
||||
|
||||
// LoadPyModSyms loads python objects from specified module.
|
||||
func (b Builder) LoadPyModSyms(modName string, objs ...PyObject) Expr {
|
||||
func (b Builder) LoadPyModSyms(modName string, objs ...PyObjRef) Expr {
|
||||
pkg := b.Func.Pkg
|
||||
fnLoad := pkg.pyFunc("llgoLoadPyModSyms", b.Prog.tyLoadPyModSyms())
|
||||
modPtr := pkg.NewPyModVar(modName, false).Expr
|
||||
@@ -574,6 +574,7 @@ func (b Builder) LoadPyModSyms(modName string, objs ...PyObject) Expr {
|
||||
func (b Builder) pyCall(fn Expr, args []Expr) (ret Expr) {
|
||||
prog := b.Prog
|
||||
pkg := b.Func.Pkg
|
||||
fn = b.Load(fn)
|
||||
sig := fn.raw.Type.(*types.Signature)
|
||||
params := sig.Params()
|
||||
n := params.Len()
|
||||
|
||||
@@ -43,7 +43,7 @@ const (
|
||||
vkFuncDecl
|
||||
vkFuncPtr
|
||||
vkClosure
|
||||
vkPyFunc
|
||||
vkPyFuncRef
|
||||
vkTuple
|
||||
vkPhisExpr = -1
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user