ssa: PyVal support pyfunc
This commit is contained in:
@@ -2,10 +2,12 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goplus/lib/py"
|
"github.com/goplus/lib/py"
|
||||||
|
"github.com/goplus/lib/py/math"
|
||||||
"github.com/goplus/lib/py/std"
|
"github.com/goplus/lib/py/std"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
x := py.List(true, false, 1, float32(2.1), 3.1, uint(4), 1+2i, complex64(3+4i), "hello", []byte("world"))
|
x := py.List(true, false, 1, float32(2.1), 3.1, uint(4), 1+2i, complex64(3+4i), "hello", []byte("world"))
|
||||||
std.Print(x)
|
y := py.List(std.Abs, std.Print, math.Pi)
|
||||||
|
std.Print(x, y)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,9 +7,13 @@ source_filename = "github.com/goplus/llgo/cl/_testpy/list"
|
|||||||
@"github.com/goplus/llgo/cl/_testpy/list.init$guard" = global i1 false, align 1
|
@"github.com/goplus/llgo/cl/_testpy/list.init$guard" = global i1 false, align 1
|
||||||
@0 = private unnamed_addr constant [5 x i8] c"world", align 1
|
@0 = private unnamed_addr constant [5 x i8] c"world", align 1
|
||||||
@1 = private unnamed_addr constant [5 x i8] c"hello", align 1
|
@1 = private unnamed_addr constant [5 x i8] c"hello", align 1
|
||||||
|
@__llgo_py.math = external global ptr, align 8
|
||||||
|
@2 = private unnamed_addr constant [3 x i8] c"pi\00", align 1
|
||||||
|
@__llgo_py.builtins.abs = linkonce global ptr null, align 8
|
||||||
@__llgo_py.builtins.print = linkonce global ptr null, align 8
|
@__llgo_py.builtins.print = linkonce global ptr null, align 8
|
||||||
@__llgo_py.builtins = external global ptr, align 8
|
@__llgo_py.builtins = external global ptr, align 8
|
||||||
@2 = private unnamed_addr constant [6 x i8] c"print\00", align 1
|
@3 = private unnamed_addr constant [4 x i8] c"abs\00", align 1
|
||||||
|
@4 = private unnamed_addr constant [6 x i8] c"print\00", align 1
|
||||||
|
|
||||||
define void @"github.com/goplus/llgo/cl/_testpy/list.init"() {
|
define void @"github.com/goplus/llgo/cl/_testpy/list.init"() {
|
||||||
_llgo_0:
|
_llgo_0:
|
||||||
@@ -18,9 +22,10 @@ _llgo_0:
|
|||||||
|
|
||||||
_llgo_1: ; preds = %_llgo_0
|
_llgo_1: ; preds = %_llgo_0
|
||||||
store i1 true, ptr @"github.com/goplus/llgo/cl/_testpy/list.init$guard", align 1
|
store i1 true, ptr @"github.com/goplus/llgo/cl/_testpy/list.init$guard", align 1
|
||||||
|
call void @"github.com/goplus/lib/py/math.init"()
|
||||||
call void @"github.com/goplus/lib/py/std.init"()
|
call void @"github.com/goplus/lib/py/std.init"()
|
||||||
%1 = load ptr, ptr @__llgo_py.builtins, align 8
|
%1 = load ptr, ptr @__llgo_py.builtins, align 8
|
||||||
call void (ptr, ...) @llgoLoadPyModSyms(ptr %1, ptr @2, ptr @__llgo_py.builtins.print, ptr null)
|
call void (ptr, ...) @llgoLoadPyModSyms(ptr %1, ptr @3, ptr @__llgo_py.builtins.abs, ptr @4, ptr @__llgo_py.builtins.print, ptr null)
|
||||||
br label %_llgo_2
|
br label %_llgo_2
|
||||||
|
|
||||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||||
@@ -53,11 +58,21 @@ _llgo_0:
|
|||||||
%21 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %0, 1
|
%21 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %0, 1
|
||||||
%22 = call ptr @PyByteArray_FromStringAndSize(ptr %20, i64 %21)
|
%22 = call ptr @PyByteArray_FromStringAndSize(ptr %20, i64 %21)
|
||||||
%23 = call i32 @PyList_SetItem(ptr %1, i64 9, ptr %22)
|
%23 = call i32 @PyList_SetItem(ptr %1, i64 9, ptr %22)
|
||||||
%24 = load ptr, ptr @__llgo_py.builtins.print, align 8
|
%24 = load ptr, ptr @__llgo_py.math, align 8
|
||||||
%25 = call ptr (ptr, ...) @PyObject_CallFunctionObjArgs(ptr %24, ptr %1, ptr null)
|
%25 = call ptr @PyObject_GetAttrString(ptr %24, ptr @2)
|
||||||
|
%26 = call ptr @PyList_New(i64 3)
|
||||||
|
%27 = load ptr, ptr @__llgo_py.builtins.abs, align 8
|
||||||
|
%28 = call i32 @PyList_SetItem(ptr %26, i64 0, ptr %27)
|
||||||
|
%29 = load ptr, ptr @__llgo_py.builtins.print, align 8
|
||||||
|
%30 = call i32 @PyList_SetItem(ptr %26, i64 1, ptr %29)
|
||||||
|
%31 = call i32 @PyList_SetItem(ptr %26, i64 2, ptr %25)
|
||||||
|
%32 = load ptr, ptr @__llgo_py.builtins.print, align 8
|
||||||
|
%33 = call ptr (ptr, ...) @PyObject_CallFunctionObjArgs(ptr %32, ptr %1, ptr %26, ptr null)
|
||||||
ret void
|
ret void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare void @"github.com/goplus/lib/py/math.init"()
|
||||||
|
|
||||||
declare void @"github.com/goplus/lib/py/std.init"()
|
declare void @"github.com/goplus/lib/py/std.init"()
|
||||||
|
|
||||||
declare %"github.com/goplus/llgo/runtime/internal/runtime.Slice" @"github.com/goplus/llgo/runtime/internal/runtime.StringToBytes"(%"github.com/goplus/llgo/runtime/internal/runtime.String")
|
declare %"github.com/goplus/llgo/runtime/internal/runtime.Slice" @"github.com/goplus/llgo/runtime/internal/runtime.StringToBytes"(%"github.com/goplus/llgo/runtime/internal/runtime.String")
|
||||||
@@ -80,6 +95,8 @@ declare ptr @PyUnicode_FromStringAndSize(ptr, i64)
|
|||||||
|
|
||||||
declare ptr @PyByteArray_FromStringAndSize(ptr, i64)
|
declare ptr @PyByteArray_FromStringAndSize(ptr, i64)
|
||||||
|
|
||||||
|
declare ptr @PyObject_GetAttrString(ptr, ptr)
|
||||||
|
|
||||||
declare ptr @PyObject_CallFunctionObjArgs(ptr, ...)
|
declare ptr @PyObject_CallFunctionObjArgs(ptr, ...)
|
||||||
|
|
||||||
declare void @llgoLoadPyModSyms(ptr, ...)
|
declare void @llgoLoadPyModSyms(ptr, ...)
|
||||||
|
|||||||
@@ -463,6 +463,9 @@ func (b Builder) PyVal(v Expr) (ret Expr) {
|
|||||||
if v.Type == b.Prog.PyObjectPtr() {
|
if v.Type == b.Prog.PyObjectPtr() {
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
if v.kind == vkPyFuncRef {
|
||||||
|
return b.Load(v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
panic("PyVal: todo " + v.raw.Type.String())
|
panic("PyVal: todo " + v.raw.Type.String())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user