From 1414853fce62d67dbe6bcc7c3b9ad9ca3ae1b2d0 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Sat, 11 May 2024 06:44:45 +0800 Subject: [PATCH] LLGoPackage: PkgPyModule --- cl/compile.go | 1 + cl/import.go | 2 ++ internal/build/build.go | 2 +- py/math/math.go | 5 ++++- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cl/compile.go b/cl/compile.go index aedc0b01..d98ac674 100644 --- a/cl/compile.go +++ b/cl/compile.go @@ -123,6 +123,7 @@ type instrOrValue interface { const ( PkgNormal = iota PkgLLGo + PkgPyModule // py. PkgNoInit // noinit: a package that don't need to be initialized PkgDeclOnly // decl: a package that only have declarations PkgLinkIR // link llvm ir (.ll) diff --git a/cl/import.go b/cl/import.go index 5e2b23e7..81e628bb 100644 --- a/cl/import.go +++ b/cl/import.go @@ -101,6 +101,8 @@ func pkgKind(v string) (int, string) { // return PkgLinkBitCode if strings.HasPrefix(v, "link:") { // "link: " return PkgLinkExtern, v[5:] + } else if strings.HasPrefix(v, "py.") { // "py." + return PkgPyModule, v[3:] } } return PkgLLGo, "" diff --git a/internal/build/build.go b/internal/build/build.go index 2f80c9f8..9a7644d8 100644 --- a/internal/build/build.go +++ b/internal/build/build.go @@ -172,7 +172,7 @@ func buildAllPkgs(prog llssa.Program, initial []*packages.Package, mode Mode, ve // skip packages that only contain declarations // and set no export file pkg.ExportFile = "" - case cl.PkgLinkIR: + case cl.PkgLinkIR, cl.PkgPyModule: // skip packages that don't need to be compiled but need to be linked pkgPath := pkg.PkgPath if isPkgInLLGo(pkgPath) { diff --git a/py/math/math.go b/py/math/math.go index 0af8edd8..7bfd8ebe 100644 --- a/py/math/math.go +++ b/py/math/math.go @@ -14,7 +14,6 @@ * limitations under the License. */ -// llgo:import py.math package math import ( @@ -23,5 +22,9 @@ import ( "github.com/goplus/llgo/py" ) +const ( + LLGoPackage = "py.math" +) + //go:linkname Sqrt py.sqrt func Sqrt(x *py.Object) *py.Object