builtin

package
v0.0.0-...-b932c77 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 30, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Right now golang doesn't have support map[] keying with complex types In ideal world I would prefer map[PyObject]PyObject as dictionary backend, but PyInt, PyTuple and PySet contains arrays in their implementation.

This implementation isn't optimized from perfomance/memory perspective and can be done in much more efficient manner.

Index

Constants

This section is empty.

Variables

View Source
var Builtin = map[string]PyObject{

	"print": &PyFunction{
		Callable:    PyPrint,
		StringValue: "<built-in function print>",
		ReprValue:   "<built-in function print>",
	},
	"hash": &PyFunction{
		Callable:    PyHash,
		StringValue: "<built-in function hash>",
		ReprValue:   "<built-in function hash>",
	},
}
View Source
var PyEq = NewPyString("==")
View Source
var PyFalse = &PyBool{Value: false}
View Source
var PyNone = &NoneType{}
View Source
var PyTrue = &PyBool{Value: true}

Functions

func GetPyHashSeed

func GetPyHashSeed() *maphash.Seed

func PyHashImplementation

func PyHashImplementation(obj PyObject) (int64, error)

func PyPrintImplementation

func PyPrintImplementation(
	args PyObject,
	sep PyObject,
	end PyObject,
	file PyObject,
	flush *PyBool,
)

https://github.com/python/cpython/blob/main/Python/bltinmodule.c#L1987 (builtin_print_impl)

Types

type NoneType

type NoneType struct{}

func (*NoneType) Equal

func (self *NoneType) Equal(b PyObject) *PyBool

func (*NoneType) Hash

func (self *NoneType) Hash() (int64, error)

func (*NoneType) Repr

func (*NoneType) Repr() string

func (*NoneType) String

func (*NoneType) String() string

type PyBinaryAdd

type PyBinaryAdd interface {
	PyObject
	BinaryAdd(PyObject) PyObject // __add__
}

type PyBinarySubstract

type PyBinarySubstract interface {
	PyObject
	BinarySubstract(PyObject) PyObject // __sub__
}

type PyBool

type PyBool struct {
	Value bool
}

func (*PyBool) BinaryAdd

func (self *PyBool) BinaryAdd(b PyObject) PyObject

func (*PyBool) BinarySubstract

func (self *PyBool) BinarySubstract(b PyObject) PyObject

func (*PyBool) Equal

func (self *PyBool) Equal(b PyObject) *PyBool

func (*PyBool) Hash

func (self *PyBool) Hash() (int64, error)

func (*PyBool) IntValue

func (self *PyBool) IntValue() *PyInt

func (*PyBool) Repr

func (self *PyBool) Repr() string

func (*PyBool) String

func (self *PyBool) String() string

type PyDict

type PyDict struct {
	Value map[int64][]*PyDictKeyValue
}

func (*PyDict) Equal

func (self *PyDict) Equal(b PyObject) *PyBool

func (*PyDict) GetItem

func (self *PyDict) GetItem(key PyObject) (PyObject, error)

func (*PyDict) Hash

func (self *PyDict) Hash() (int64, error)

func (*PyDict) Repr

func (self *PyDict) Repr() string

func (*PyDict) SetItem

func (self *PyDict) SetItem(key PyObject, value PyObject) error

func (*PyDict) String

func (self *PyDict) String() string

type PyDictKeyValue

type PyDictKeyValue struct {
	Key   PyObject
	Value PyObject
}

type PyFloat

type PyFloat struct {
	Value float64
}

func (*PyFloat) BinaryAdd

func (self *PyFloat) BinaryAdd(b PyObject) PyObject

func (*PyFloat) BinarySubstract

func (self *PyFloat) BinarySubstract(b PyObject) PyObject

func (*PyFloat) Equal

func (self *PyFloat) Equal(b PyObject) *PyBool

func (*PyFloat) Hash

func (self *PyFloat) Hash() (int64, error)

func (*PyFloat) Repr

func (self *PyFloat) Repr() string

func (*PyFloat) String

func (self *PyFloat) String() string

type PyFunction

type PyFunction struct {
	Callable    func(PyObject, PyObject) PyObject
	StringValue string
	ReprValue   string
}

func (*PyFunction) Equal

func (self *PyFunction) Equal(b PyObject) *PyBool

func (*PyFunction) Hash

func (self *PyFunction) Hash() (int64, error)

func (*PyFunction) Repr

func (self *PyFunction) Repr() string

func (*PyFunction) String

func (self *PyFunction) String() string

type PyGetItem

type PyGetItem interface {
	PyObject
	GetItem(PyObject) (PyObject, error) // __getitem__
}

type PyInt

type PyInt struct {
	Value *big.Int
}

func NewPyInt

func NewPyInt(value int64) *PyInt

func (*PyInt) BinaryAdd

func (self *PyInt) BinaryAdd(b PyObject) PyObject

func (*PyInt) BinarySubstract

func (self *PyInt) BinarySubstract(b PyObject) PyObject

func (*PyInt) Equal

func (self *PyInt) Equal(b PyObject) *PyBool

func (*PyInt) Hash

func (self *PyInt) Hash() (int64, error)

func (*PyInt) Int64

func (self *PyInt) Int64() int64

func (*PyInt) Repr

func (self *PyInt) Repr() string

func (*PyInt) String

func (self *PyInt) String() string

type PyIterable

type PyIterable interface {
	PyObject
	Iter() PyIterator // __iter__
}

type PyIterator

type PyIterator interface {
	PyIterable
	Next() (PyObject, error) // __next__
}

type PyList

type PyList struct {
	Value []PyObject
}

func (*PyList) Append

func (self *PyList) Append(value PyObject)

func (*PyList) BinaryAdd

func (self *PyList) BinaryAdd(b PyObject) PyObject

func (*PyList) Equal

func (self *PyList) Equal(b PyObject) *PyBool

func (*PyList) Extend

func (self *PyList) Extend(value PyIterable)

func (*PyList) GetItem

func (self *PyList) GetItem(index PyObject) (PyObject, error)

func (*PyList) Hash

func (self *PyList) Hash() (int64, error)

func (*PyList) Iter

func (self *PyList) Iter() PyIterator

func (*PyList) Pop

func (self *PyList) Pop() PyObject

func (*PyList) PopN

func (self *PyList) PopN(n int) []PyObject

func (*PyList) Repr

func (self *PyList) Repr() string

func (*PyList) SetItem

func (self *PyList) SetItem(index PyObject, value PyObject) error

func (*PyList) String

func (self *PyList) String() string

type PyListIterator

type PyListIterator struct {
	// contains filtered or unexported fields
}

func (*PyListIterator) Equal

func (self *PyListIterator) Equal(other PyObject) *PyBool

func (*PyListIterator) Hash

func (self *PyListIterator) Hash() (int64, error)

func (*PyListIterator) Iter

func (self *PyListIterator) Iter() PyIterator

func (*PyListIterator) Next

func (self *PyListIterator) Next() (PyObject, error)

func (*PyListIterator) Repr

func (self *PyListIterator) Repr() string

func (*PyListIterator) String

func (self *PyListIterator) String() string

type PyObject

type PyObject interface {
	Repr() string
	String() string
	Hash() (int64, error)   // __hash__
	Equal(PyObject) *PyBool // __eq__
}

func PyHash

func PyHash(args PyObject, kwnames PyObject) PyObject

func PyPrint

func PyPrint(args PyObject, kwnames PyObject) PyObject

type PySetItem

type PySetItem interface {
	PyObject
	SetItem(PyObject, PyObject) error // __setitem__
}

type PyString

type PyString struct {
	Value []rune
}

func NewPyString

func NewPyString(s string) *PyString

func (*PyString) BinaryAdd

func (self *PyString) BinaryAdd(b PyObject) PyObject

func (*PyString) Equal

func (self *PyString) Equal(b PyObject) *PyBool

func (*PyString) Hash

func (self *PyString) Hash() (int64, error)

func (*PyString) Repr

func (self *PyString) Repr() string

func (*PyString) String

func (self *PyString) String() string

type PyStringIterator

type PyStringIterator struct {
	// contains filtered or unexported fields
}

func (*PyStringIterator) Equal

func (self *PyStringIterator) Equal(other PyObject) *PyBool

func (*PyStringIterator) Hash

func (self *PyStringIterator) Hash() (int64, error)

func (*PyStringIterator) Iter

func (self *PyStringIterator) Iter() PyIterator

func (*PyStringIterator) Next

func (self *PyStringIterator) Next() (PyObject, error)

func (*PyStringIterator) Repr

func (self *PyStringIterator) Repr() string

func (*PyStringIterator) String

func (self *PyStringIterator) String() string

type PyTuple

type PyTuple struct {
	Value []PyObject
}

func (*PyTuple) BinaryAdd

func (self *PyTuple) BinaryAdd(b PyObject) PyObject

func (*PyTuple) Equal

func (self *PyTuple) Equal(b PyObject) *PyBool

func (*PyTuple) GetItem

func (self *PyTuple) GetItem(index PyObject) (PyObject, error)

func (*PyTuple) Hash

func (self *PyTuple) Hash() (int64, error)

func (*PyTuple) Iter

func (self *PyTuple) Iter() PyIterator

func (*PyTuple) Repr

func (self *PyTuple) Repr() string

func (*PyTuple) String

func (self *PyTuple) String() string

type PyTupleIterator

type PyTupleIterator struct {
	// contains filtered or unexported fields
}

func (*PyTupleIterator) Equal

func (self *PyTupleIterator) Equal(other PyObject) *PyBool

func (*PyTupleIterator) Hash

func (self *PyTupleIterator) Hash() (int64, error)

func (*PyTupleIterator) Iter

func (self *PyTupleIterator) Iter() PyIterator

func (*PyTupleIterator) Next

func (self *PyTupleIterator) Next() (PyObject, error)

func (*PyTupleIterator) Repr

func (self *PyTupleIterator) Repr() string

func (*PyTupleIterator) String

func (self *PyTupleIterator) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL