Merge pull request #207 from xushiwei/q
py/std done; demo: max; llgen.Gen fix: use imp
This commit is contained in:
15
_pydemo/max/max.go
Normal file
15
_pydemo/max/max.go
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/goplus/llgo/py"
|
||||||
|
"github.com/goplus/llgo/py/std"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
x := std.Max(py.Float(3.0), py.Float(9.0), py.Float(23.0), py.Float(100.0))
|
||||||
|
std.Print(x)
|
||||||
|
|
||||||
|
// y := py.List(3.0, 9.0, 23.0, 100.0)
|
||||||
|
// ymax := std.Max(std.Iter(y))
|
||||||
|
// std.Print(ymax)
|
||||||
|
}
|
||||||
@@ -30,7 +30,6 @@ import (
|
|||||||
"golang.org/x/tools/go/ssa/ssautil"
|
"golang.org/x/tools/go/ssa/ssautil"
|
||||||
|
|
||||||
llssa "github.com/goplus/llgo/ssa"
|
llssa "github.com/goplus/llgo/ssa"
|
||||||
cpackages "golang.org/x/tools/go/packages"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
@@ -72,8 +71,13 @@ func Gen(pkgPath, inFile string, src any) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
prog := llssa.NewProgram(nil)
|
prog := llssa.NewProgram(nil)
|
||||||
initRtAndPy(prog, &cpackages.Config{
|
prog.SetRuntime(func() *types.Package {
|
||||||
Mode: loadSyntax | cpackages.NeedDeps,
|
ret, _ := imp.Import(llssa.PkgRuntime)
|
||||||
|
return ret
|
||||||
|
})
|
||||||
|
prog.SetPython(func() *types.Package {
|
||||||
|
ret, _ := imp.Import(llssa.PkgPython)
|
||||||
|
return ret
|
||||||
})
|
})
|
||||||
|
|
||||||
ret, err := cl.NewPackage(prog, ssaPkg, files)
|
ret, err := cl.NewPackage(prog, ssaPkg, files)
|
||||||
|
|||||||
@@ -25,6 +25,106 @@ import (
|
|||||||
// https://docs.python.org/3/library/functions.html
|
// https://docs.python.org/3/library/functions.html
|
||||||
// https://docs.python.org/3/library/constants.html
|
// https://docs.python.org/3/library/constants.html
|
||||||
|
|
||||||
|
//go:linkname Abs py.abs
|
||||||
|
func Abs(x *py.Object) *py.Object
|
||||||
|
|
||||||
|
// getattr(object, name)
|
||||||
|
//
|
||||||
|
//go:linkname GetAttr py.getattr
|
||||||
|
func GetAttr(object, name *py.Object) *py.Object
|
||||||
|
|
||||||
|
// getattr(object, name, default)
|
||||||
|
//
|
||||||
|
//go:linkname GetAttrEx py.getattr
|
||||||
|
func GetAttrEx(object, name, default_ *py.Object) *py.Object
|
||||||
|
|
||||||
|
// max(iterable, *, key=None)
|
||||||
|
// max(iterable, *, default, key=None)
|
||||||
|
// max(arg1, arg2, *args, key=None)
|
||||||
|
//
|
||||||
|
// If one positional argument is provided, it should be an iterable. The largest
|
||||||
|
// item in the iterable is returned. If two or more positional arguments are
|
||||||
|
// provided, the largest of the positional arguments is returned.
|
||||||
|
//
|
||||||
|
//go:linkname Max py.max
|
||||||
|
func Max(__llgo_va_list ...any) *py.Object
|
||||||
|
|
||||||
|
// min(iterable, *, key=None)
|
||||||
|
// min(iterable, *, default, key=None)
|
||||||
|
// min(arg1, arg2, *args, key=None)
|
||||||
|
//
|
||||||
|
//go:linkname Min py.min
|
||||||
|
func Min(__llgo_va_list ...any) *py.Object
|
||||||
|
|
||||||
|
// iter(object)
|
||||||
|
//
|
||||||
|
//go:linkname Iter py.iter
|
||||||
|
func Iter(object *py.Object) *py.Object
|
||||||
|
|
||||||
|
// next(iterator)
|
||||||
|
//
|
||||||
|
//go:linkname Next py.next
|
||||||
|
func Next(iterator *py.Object) *py.Object
|
||||||
|
|
||||||
|
// next(iterator, default)
|
||||||
|
//
|
||||||
|
// Retrieve the next item from the iterator by calling its __next__() method.
|
||||||
|
// If default is given, it is returned if the iterator is exhausted, otherwise
|
||||||
|
// StopIteration is raised.
|
||||||
|
//
|
||||||
|
//go:linkname NextEx py.next
|
||||||
|
func NextEx(iterator, default_ *py.Object) *py.Object
|
||||||
|
|
||||||
|
// awaitable anext(async_iterator)
|
||||||
|
//
|
||||||
|
//go:linkname Anext py.anext
|
||||||
|
func Anext(asyncIterator *py.Object) *py.Object
|
||||||
|
|
||||||
|
// awaitable anext(async_iterator, default)
|
||||||
|
//
|
||||||
|
// When awaited, return the next item from the given asynchronous iterator,
|
||||||
|
// or default if given and the iterator is exhausted.
|
||||||
|
//
|
||||||
|
// This is the async variant of the next() builtin, and behaves similarly.
|
||||||
|
//
|
||||||
|
// This calls the __anext__() method of async_iterator, returning an awaitable.
|
||||||
|
// Awaiting this returns the next value of the iterator. If default is given,
|
||||||
|
// it is returned if the iterator is exhausted, otherwise StopAsyncIteration is
|
||||||
|
// raised.
|
||||||
|
//
|
||||||
|
//go:linkname AnextEx py.anext
|
||||||
|
func AnextEx(asyncIterator, default_ *py.Object) *py.Object
|
||||||
|
|
||||||
|
// iter(object, sentinel)
|
||||||
|
//
|
||||||
|
//go:linkname IterEx py.iter
|
||||||
|
func IterEx(callable, sentinel *py.Object) *py.Object
|
||||||
|
|
||||||
|
// vars()
|
||||||
|
//
|
||||||
|
//go:linkname Vars py.vars
|
||||||
|
func Vars() *py.Object
|
||||||
|
|
||||||
|
// vars(object)
|
||||||
|
//
|
||||||
|
// Return the __dict__ attribute for a module, class, instance, or any other object
|
||||||
|
// with a __dict__ attribute.
|
||||||
|
//
|
||||||
|
// See https://docs.python.org/3/library/functions.html#vars
|
||||||
|
//
|
||||||
|
//go:linkname VarsEx py.vars
|
||||||
|
func VarsEx(object *py.Object) *py.Object
|
||||||
|
|
||||||
|
// dir()
|
||||||
|
//
|
||||||
|
//go:linkname Dir py.dir
|
||||||
|
func Dir() *py.Object
|
||||||
|
|
||||||
|
// dir(object)
|
||||||
|
//
|
||||||
|
//go:linkname DirEx py.dir
|
||||||
|
func DirEx(object *py.Object) *py.Object
|
||||||
|
|
||||||
// Invoke the built-in help system. (This function is intended for interactive
|
// Invoke the built-in help system. (This function is intended for interactive
|
||||||
// use.) If no argument is given, the interactive help system starts on the
|
// use.) If no argument is given, the interactive help system starts on the
|
||||||
// interpreter console. If the argument is a string, then the string is looked
|
// interpreter console. If the argument is a string, then the string is looked
|
||||||
@@ -38,3 +138,10 @@ import (
|
|||||||
//
|
//
|
||||||
//go:linkname Help py.help
|
//go:linkname Help py.help
|
||||||
func Help(object *py.Object)
|
func Help(object *py.Object)
|
||||||
|
|
||||||
|
// breakpoint(*args, **kws)
|
||||||
|
//
|
||||||
|
// See https://docs.python.org/3/library/functions.html#breakpoint
|
||||||
|
//
|
||||||
|
//go:linkname Breakpoint py.breakpoint
|
||||||
|
func Breakpoint(__llgo_va_list ...any)
|
||||||
|
|||||||
Reference in New Issue
Block a user