Documentation ¶
Index ¶
- Variables
- func Catch(o Object, h func(BaseException), e func())
- func CatchMulti(e func(), catchers ...*Catcher)
- func CollectUsedSymbols(c bool)
- func Contains(o Object, needle Object) bool
- func DelAttr(o Object, name string)
- func DelItem(o Object, key Object)
- func FinalizeGenerators()
- func GetUsedSymbols() []string
- func HasAttr(o Object, name string) bool
- func InitModule(init func())
- func InitModules()
- func IsInstance(o Object, classinfo Object) bool
- func IsSubclass(o Object, classinfo Object) bool
- func IsTrue(o Object) bool
- func Print(objects []Object, sep Str, end Str)
- func SetAttr(o Object, name string, value Object)
- func SetItem(o Object, key Object, value Object)
- func UnwrapNative(o Object) interface{}
- type Args
- type BaseException
- type Bytes
- type Catcher
- type Codec
- type Dict
- type Float
- type FloatLiteral
- type Function
- type Generator
- type Int
- type IntLiteral
- type KWArg
- type KWArgs
- type List
- type Method
- type Native
- type Object
- func Add(a, b Object) Object
- func And(a, b Object) Object
- func Cal(o Object, args ...Object) Object
- func Call(o Object, args Args, kwArgs KWArgs) Object
- func Calm(o Object, attr string, args ...Object) Object
- func FloorDiv(a, b Object) Object
- func GetAttr(o Object, name string, def Object) (value Object)
- func GetItem(o Object, key Object) Object
- func IAdd(a, b Object) Object
- func IFloorDiv(a, b Object) Object
- func IMod(a, b Object) Object
- func IMul(a, b Object) Object
- func IPow(a, b Object) Object
- func ISub(a, b Object) Object
- func ITrueDiv(a, b Object) Object
- func Iter(o Object) Object
- func LShift(a, b Object) Object
- func Mod(a, b Object) Object
- func Mul(a, b Object) Object
- func Neg(o Object) Object
- func Next(o Object) Object
- func NextDefault(o Object, def Object) (ret Object)
- func Or(a, b Object) Object
- func Placeholder(name string, reason string) Object
- func Pos(o Object) Object
- func Pow(a, b Object) Object
- func RShift(a, b Object) Object
- func Raise(o Object) Object
- func RaiseType(t Type, msg string) Object
- func Sub(a, b Object) Object
- func TrueDiv(a, b Object) Object
- func Unpack(elems ...Object) []Object
- func UnpackIterable(o Object, cnt int) Object
- func UsedSymbol(name string, v Object) Object
- func Xor(a, b Object) Object
- type Param
- type Property
- type Range
- type RangeIterator
- type Seq
- type Set
- type Slice
- type Starred
- type Str
- type StrLiteral
- type Super
- type Tuple
- type Type
- type Yielder
Constants ¶
This section is empty.
Variables ¶
var ( // BlockExitNormally .. BlockExitNormally = newObject(ObjectType) // BlockExitReturn .. BlockExitReturn = newObject(ObjectType) // BlockExitContinue .. BlockExitContinue = newObject(ObjectType) // BlockExitBreak .. BlockExitBreak = newObject(ObjectType) )
var ( // Eq .. Eq = makeCompareFn(compare, compareEq) // Ne .. Ne = makeCompareFn(compare, compareNe) // Lt .. Lt = makeCompareFn(compare, compareLt) // Gt .. Gt = makeCompareFn(compare, compareGt) // Le .. Le = makeCompareFn(compare, compareLe) // Ge .. Ge = makeCompareFn(compare, compareGe) )
var ( // True .. True = newInt(BoolType, 1) // False .. False = newInt(BoolType, 0) )
var ( // ExceptionType .. ExceptionType = newBuiltinType("Exception", BaseExceptionType) // TypeErrorType .. TypeErrorType = newBuiltinType("TypeError", ExceptionType) // ValueErrorType .. ValueErrorType = newBuiltinType("ValueError", ExceptionType) // RuntimeErrorType .. RuntimeErrorType = newBuiltinType("RuntimeError", ExceptionType) // NotImplementedErrorType .. NotImplementedErrorType = newBuiltinType("NotImplementedError", RuntimeErrorType) // LookupErrorType .. LookupErrorType = newBuiltinType("LookupError", ExceptionType) // KeyErrorType .. KeyErrorType = newBuiltinType("KeyError", LookupErrorType) // IndexErrorType .. IndexErrorType = newBuiltinType("IndexError", LookupErrorType) // StopIterationType .. StopIterationType = newBuiltinType("StopIteration", ExceptionType) // AttributeErrorType .. AttributeErrorType = newBuiltinType("AttributeError", ExceptionType) // AssertionErrorType .. AssertionErrorType = newBuiltinType("AssertionError", ExceptionType) // ImportErrorType .. ImportErrorType = newBuiltinType("ImportError", ExceptionType) // UnicodeErrorType .. UnicodeErrorType = newBuiltinType("UnicodeError", ValueErrorType) // UnicodeEncodeErrorType .. UnicodeEncodeErrorType = newBuiltinType("UnicodeEncodeError", UnicodeErrorType) // UnicodeDecodeErrorType .. UnicodeDecodeErrorType = newBuiltinType("UnicodeDecodeError", UnicodeErrorType) // OSErrorType .. OSErrorType = newBuiltinType("OSError", ExceptionType) // ArithmeticErrorType .. ArithmeticErrorType = newBuiltinType("ArithmeticError", ExceptionType) // OverflowErrorType .. OverflowErrorType = newBuiltinType("OverflowError", ArithmeticErrorType) // ZeroDivisionErrorType .. ZeroDivisionErrorType = newBuiltinType("ZeroDivisionError", ArithmeticErrorType) )
var ( // NoneType .. NoneType = newBuiltinType("NoneType") // None .. None = newObject(NoneType) )
var ( // NotImplementedType .. NotImplementedType = newBuiltinType("NotImplementedType") // NotImplemented .. NotImplemented = newObject(NotImplementedType) )
var AfterLast = newObject(ObjectType)
AfterLast is a singleton object used to signal iteration end in Next(iter, AfterLast) calls.
var BaseExceptionType = newBuiltinType("BaseException")
BaseExceptionType ..
var BoolType = newBuiltinType("bool", IntType)
BoolType ..
var BuiltinAll = newBuiltinFunction("all", func(args Args, kwArgs KWArgs) Object { checkFunctionArgs("all", args, kwArgs, ObjectType) hasFalse := seqFindFirst(args[0], func(o Object) bool { return !IsTrue(o) }) return NewBool(!hasFalse) })
BuiltinAll ..
var BuiltinAny = newBuiltinFunction("any", func(args Args, kwArgs KWArgs) Object { checkFunctionArgs("any", args, kwArgs, ObjectType) hasTrue := seqFindFirst(args[0], func(o Object) bool { return IsTrue(o) }) return NewBool(hasTrue) })
BuiltinAny ..
var BuiltinCallable = newBuiltinFunction("callable", func(args Args, kwArgs KWArgs) Object { checkFunctionArgs("callable", args, kwArgs, ObjectType) callFn := args[0].Type().Slots().Call return NewBool(callFn != nil) })
BuiltinCallable ..
var BuiltinChr = newBuiltinFunction("chr", func(args Args, kwArgs KWArgs) Object { checkFunctionArgs("ord", args, kwArgs, IntType) i := args[0].(Int).Value() if i < 0 || i >= 0x110000 { panic(RaiseType(ValueErrorType, "chr() arg not in range(0x110000)")) } return NewStr(string(rune(i))) })
BuiltinChr ..
var BuiltinGetAttr = newBuiltinFunction("getattr", func(args Args, kwArgs KWArgs) Object { checkFunctionArgsMin("getattr", args, kwArgs, 2, ObjectType, StrType, ObjectType) o := args[0] name := args[1].(Str).Value() var def Object if len(args) >= 3 { def = args[2] } return GetAttr(o, name, def) })
BuiltinGetAttr ..
var BuiltinHasAttr = newBuiltinFunction("hasattr", func(args Args, kwArgs KWArgs) Object { checkFunctionArgs("hasattr", args, kwArgs, ObjectType, StrType) o := args[0] name := args[1].(Str).Value() return NewBool(HasAttr(o, name)) })
BuiltinHasAttr ..
var BuiltinHash = newBuiltinFunction("hash", func(args Args, kwArgs KWArgs) Object { checkFunctionArgs("hash", args, kwArgs, ObjectType) return Hash(args[0]) })
BuiltinHash ..
var BuiltinIsInstance = newBuiltinFunction("isinstance", func(args Args, kwArgs KWArgs) Object { checkFunctionArgs("isinstance", args, kwArgs, ObjectType, ObjectType) return NewBool(IsInstance(args[0], args[1])) })
BuiltinIsInstance ..
var BuiltinIsSubclass = newBuiltinFunction("issubclass", func(args Args, kwArgs KWArgs) Object { checkFunctionArgs("issubclass", args, kwArgs, ObjectType, ObjectType) return NewBool(IsSubclass(args[0], args[1])) })
BuiltinIsSubclass ..
var BuiltinIter = newBuiltinFunction("iter", func(args Args, kwArgs KWArgs) Object { checkFunctionArgsMin("iter", args, kwArgs, 1, ObjectType, ObjectType) if len(args) == 2 { panic(RaiseType(NotImplementedErrorType, "iter(callable, sentinel) not implemented")) } return Iter(args[0]) })
BuiltinIter ..
var BuiltinLen = newBuiltinFunction("len", func(args Args, kwArgs KWArgs) Object { checkFunctionArgs("len", args, kwArgs, ObjectType) return Len(args[0]) })
BuiltinLen ..
var BuiltinMax = newBuiltinFunction("max", func(args Args, kwArgs KWArgs) Object { return builtinMinMax(true, args, kwArgs) })
BuiltinMax ..
var BuiltinMin = newBuiltinFunction("min", func(args Args, kwArgs KWArgs) Object { return builtinMinMax(false, args, kwArgs) })
BuiltinMin ..
var BuiltinNext = newBuiltinFunction("next", func(args Args, kwArgs KWArgs) Object { checkFunctionArgsMin("next", args, kwArgs, 1, ObjectType, ObjectType) if len(args) == 2 { return NextDefault(args[0], args[1]) } return Next(args[0]) })
BuiltinNext ..
var BuiltinOpen = newBuiltinFunction("open", func(args Args, kwArgs KWArgs) Object { checkFunctionArgs("open", args, nil, ObjectType) panic(RaiseType(NotImplementedErrorType, "open() not implemented")) })
BuiltinOpen ..
var BuiltinOrd = newBuiltinFunction("ord", func(args Args, kwArgs KWArgs) Object { checkFunctionArgs("ord", args, kwArgs, ObjectType) o := args[0] errLen := "ord() expected a character, but string of length %d found" if o.IsInstance(StrType) { r := []rune(o.(Str).Value()) if len(r) != 1 { panic(RaiseType(TypeErrorType, fmt.Sprintf(errLen, len(r)))) } return NewInt(int(r[0])) } else if o.IsInstance(BytesType) { b := o.(Bytes).Value() if len(b) != 1 { panic(RaiseType(TypeErrorType, fmt.Sprintf(errLen, len(b)))) } return NewInt(int(b[0])) } else { panic(RaiseType(TypeErrorType, fmt.Sprintf( "ord() expected string of length 1, but %s found", o.Type().Name()))) } })
BuiltinOrd ..
var BuiltinPrint = newBuiltinFunction("print", func(args Args, kwArgs KWArgs) Object { checkFunctionKWArgs("print", kwArgs, map[string]Type{ "sep": StrType, "end": StrType, }) sep := kwArgs.get("sep", NewStr(" ")).(Str) end := kwArgs.get("end", NewStr("\n")).(Str) Print(args, sep, end) return None })
BuiltinPrint ..
var BuiltinRepr = newBuiltinFunction("repr", func(args Args, kwArgs KWArgs) Object { checkFunctionArgs("repr", args, kwArgs, ObjectType) return Repr(args[0]) })
BuiltinRepr ..
var BuiltinSetAttr = newBuiltinFunction("setattr", func(args Args, kwArgs KWArgs) Object { checkFunctionArgs("setattr", args, kwArgs, ObjectType, StrType, ObjectType) o := args[0] name := args[1].(Str).Value() value := args[2] SetAttr(o, name, value) return None })
BuiltinSetAttr ..
var BuiltinSorted = newBuiltinFunction("sorted", func(args Args, kwArgs KWArgs) Object { checkFunctionArgs("sorted", args, nil, ObjectType) checkFunctionKWArgs("sorted", kwArgs, map[string]Type{ "key": ObjectType, "reverse": IntType, }) l := Cal(ListType, args[0]) listSort(Args{l}, kwArgs) return l })
BuiltinSorted ..
var BuiltinSum = newBuiltinFunction("sum", func(args Args, kwArgs KWArgs) Object { checkFunctionArgsMin("sum", args, kwArgs, 1, ObjectType, ObjectType) var res Object if len(args) == 1 { res = NewInt(0) } else { res = args[1] } seqForEach(args[0], func(o Object) { res = Add(res, o) }) return res })
BuiltinSum ..
var BytesType = newBuiltinType("bytes")
BytesType ..
var ClassMethodType = newBuiltinType("classmethod")
ClassMethodType ..
var DictType = newBuiltinType("dict")
DictType ..
var EnumerateIteratorType = newBuiltinType("enumerate")
EnumerateIteratorType ..
var FilterIteratorType = newBuiltinType("filter")
FilterIteratorType ..
var FloatType = newBuiltinType("float")
FloatType ..
var FunctionType = newBuiltinType("function")
FunctionType ..
var GeneratorType = newBuiltinType("generator")
GeneratorType ..
var IntType = newBuiltinType("int")
IntType ..
var ListType = newBuiltinType("list")
ListType ..
var MapIteratorType = newBuiltinType("map")
MapIteratorType ..
var MethodType = newBuiltinType("method")
MethodType ..
var NativeType = newBuiltinType("native")
NativeType is the type object of Native objects
var ObjectType = &typeStruct{ name: "object", builtin: true, }
ObjectType ..
var ( // PrintingEnabled .. PrintingEnabled = true )
var PropertyType = newBuiltinType("property")
PropertyType ..
var RangeIteratorType = newBuiltinType("range_iterator")
RangeIteratorType ..
var RangeType = newBuiltinType("range")
RangeType ..
var ReversedIteratorType = newBuiltinType("reversed")
ReversedIteratorType ..
var SetType = newBuiltinType("set")
SetType ..
var SliceType = newBuiltinType("slice")
SliceType ..
var StaticMethodType = newBuiltinType("staticmethod")
StaticMethodType ..
var StrType = newBuiltinType("str")
StrType ..
var SuperType = newBuiltinType("super")
SuperType ..
var TupleType = newBuiltinType("tuple")
TupleType ..
var TypeType = &typeStruct{ name: "type", bases: []Type{ObjectType}, builtin: true, }
TypeType ..
var ZipIteratorType = newBuiltinType("zip")
ZipIteratorType ..
Functions ¶
func CollectUsedSymbols ¶
func CollectUsedSymbols(c bool)
CollectUsedSymbols sets whether used symbol collection is enabled.
func FinalizeGenerators ¶
func FinalizeGenerators()
FinalizeGenerators kills all running generators.
func GetUsedSymbols ¶
func GetUsedSymbols() []string
GetUsedSymbols returns the set of used symbols.
func InitModule ¶
func InitModule(init func())
InitModule registers the supplied module initializer.
Types ¶
type BaseException ¶
type BaseException interface { Object Args() Tuple String() string // contains filtered or unexported methods }
BaseException ..
type Codec ¶
type Codec interface { Name() string Encode(obj Object, errors Str) (Object, Int) Decode(obj Object, errors Str) (Object, Int) }
Codec ..
type Dict ¶
type Dict interface { Object GetItem(key Object) Object SetItem(key Object, value Object) DelItem(key Object) Object SetDefault(key Object, value Object) Object Len() int Iterator() hashtableIterator Keys() []Object Update(iterable Object) }
Dict ..
type Function ¶
type Function interface { Object Name() string Params() []Param NumKWOnly() int HasVarArgs() bool HasKWArgs() bool Fn() fun }
Function ..
func NewFunction ¶
func NewFunction(name string, params []Param, numKWOnly int, hasVarArgs bool, hasKwArgs bool, fn fun) Function
NewFunction ..
func NewSimpleFunction ¶
NewSimpleFunction ..
type Object ¶
type Object interface { Type() Type Dict() Dict IsInstance(t Type) bool // contains filtered or unexported methods }
Object ..
func UsedSymbol ¶
UsedSymbol marks the symbol having the specified name, as used.
type Property ¶
type Property interface { Object Get() Object Set() Object Del() Object // contains filtered or unexported methods }
Property ..
type Range ¶
type Range interface { Object Start() int Stop() int Step() int // contains filtered or unexported methods }
Range ..
type RangeIterator ¶
type RangeIterator interface { Object Curr() int Stop() int Step() int // contains filtered or unexported methods }
RangeIterator ..
type Slice ¶
type Slice interface { Object Start() Object Stop() Object Step() Object CalcSlice(elems int) (start, stop, step, len int) }
Slice ..
Source Files ¶
- base.go
- bool.go
- builtiniters.go
- builtins.go
- bytes.go
- codecs.go
- descriptor.go
- dict.go
- exception.go
- float.go
- function.go
- generator.go
- int.go
- list.go
- literal.go
- method.go
- minify.go
- module.go
- native.go
- none.go
- notimplemented.go
- object.go
- range.go
- seq.go
- set.go
- slice.go
- slimming_off.go
- slots.go
- starred.go
- str.go
- super.go
- tuple.go
- type.go
- util.go