Documentation ¶
Index ¶
- Variables
- type BaseObject
- type CallFuncType
- type ConvertFuncType
- type Environment
- type Object
- func (o *Object) Call(self BaseObject, args ...BaseObject) (BaseObject, error)
- func (o *Object) Class() *RClass
- func (o *Object) EqualTo(object BaseObject) bool
- func (o *Object) Inspect() string
- func (o *Object) InstanceVariableGet(s string) (BaseObject, bool)
- func (o *Object) InstanceVariables() *Environment
- func (o *Object) IsTruthy() bool
- func (o *Object) Parent() BaseObject
- func (o *Object) SetParent(parent BaseObject)
- func (o *Object) ToString() string
- func (o *Object) Value() interface{}
- type RClass
- func (R *RClass) Call(a BaseObject, b ...BaseObject) (BaseObject, error)
- func (R *RClass) Class() *RClass
- func (R *RClass) EqualTo(object BaseObject) bool
- func (R *RClass) GetInstance(s string) (BaseObject, bool)
- func (R *RClass) Inspect() string
- func (R *RClass) InstanceVariableGet(s string) (BaseObject, bool)
- func (R *RClass) InstanceVariables() *Environment
- func (R *RClass) IsTruthy() bool
- func (R *RClass) Parent() BaseObject
- func (R *RClass) SetParent(_ BaseObject)
- func (R *RClass) ToString() string
- func (R *RClass) Value() interface{}
- type VM
Constants ¶
This section is empty.
Variables ¶
View Source
var GoFuncClass = MakeClassFromSuper("Native Function", NumericClass, NotCallable, goFuncIns)
View Source
var NotCallable = func(self BaseObject, args ...BaseObject) (BaseObject, error) { return nil, fmt.Errorf(fmt.Sprintf("'%s' is not callable", self.ToString())) }
View Source
var Null = &Object{ RClass: NullClass, InternalValue: nil, ToStringFunc: func(self *Object) string { return "null" }, InspectFunc: func(self *Object) string { return "null" }, IsTruthyFunc: func(self *Object) bool { return false }, EqualToFunc: func(self *Object, other BaseObject) bool { v, o := other.(*Object) if !o { return false } return self == v }, CallFunc: NotCallable, ParentObj: nil, }
View Source
var NullClass = MakeClassFromSuper("Null", NumericClass, func(self BaseObject, args ...BaseObject) (BaseObject, error) { return nil, fmt.Errorf("cannot convert %s to null", args[0].Class().Name) }, nullIns)
View Source
var NumericClass = MakeClass("Numeric", NotCallable, NewEnvironment())
View Source
var ReservedKW = []string{
"null",
"print",
}
Functions ¶
This section is empty.
Types ¶
type BaseObject ¶
type BaseObject interface { Class() *RClass Value() interface{} ToString() string Inspect() string InstanceVariableGet(string) (BaseObject, bool) InstanceVariables() *Environment IsTruthy() bool EqualTo(BaseObject) bool Call(self BaseObject, args ...BaseObject) (BaseObject, error) Parent() BaseObject SetParent(object BaseObject) }
Every Gorilla Object and Class inherits from this
type CallFuncType ¶
type CallFuncType func(self BaseObject, args ...BaseObject) (BaseObject, error)
type ConvertFuncType ¶
type ConvertFuncType func(x BaseObject) (*Object, error)
var GorillaToInteger ConvertFuncType
var GorillaToString ConvertFuncType
type Environment ¶
type Environment struct {
Store storeType
}
Environment storage of Gorilla
var Global *Environment
Global is the global runtime storage
func NewEnvironment ¶
func NewEnvironment() *Environment
func NewEnvironmentWithStore ¶
func NewEnvironmentWithStore(store storeType) *Environment
func (*Environment) Copy ¶
func (e *Environment) Copy() *Environment
func (*Environment) Get ¶
func (e *Environment) Get(name string) (BaseObject, bool)
func (*Environment) Names ¶
func (e *Environment) Names() []string
func (*Environment) Set ¶
func (e *Environment) Set(name string, val BaseObject) BaseObject
type Object ¶
type Object struct { RClass *RClass InternalValue interface{} ToStringFunc func(self *Object) string InspectFunc func(self *Object) string IsTruthyFunc func(self *Object) bool EqualToFunc func(self *Object, other BaseObject) bool CallFunc CallFuncType ParentObj BaseObject }
Object struct holds a normal object
func NewGoFunc ¶
func NewGoFunc(function CallFuncType) *Object
func NewInteger ¶
func (*Object) Call ¶
func (o *Object) Call(self BaseObject, args ...BaseObject) (BaseObject, error)
func (*Object) EqualTo ¶
func (o *Object) EqualTo(object BaseObject) bool
func (*Object) InstanceVariableGet ¶
func (o *Object) InstanceVariableGet(s string) (BaseObject, bool)
func (*Object) InstanceVariables ¶
func (o *Object) InstanceVariables() *Environment
func (*Object) Parent ¶
func (o *Object) Parent() BaseObject
func (*Object) SetParent ¶
func (o *Object) SetParent(parent BaseObject)
type RClass ¶
type RClass struct { Name string Instances *Environment // For children InstanceVars *Environment NewFunc CallFuncType // contains filtered or unexported fields }
Defines a Class, or Type
var IntegerClass *RClass
var StringClass *RClass
func MakeClass ¶
func MakeClass( Name string, NewFunc CallFuncType, InstanceVars *Environment, ) *RClass
func MakeClassFromSuper ¶
func MakeClassFromSuper( Name string, super *RClass, NewFunc CallFuncType, InstanceVars *Environment, ) *RClass
func (*RClass) Call ¶
func (R *RClass) Call(a BaseObject, b ...BaseObject) (BaseObject, error)
func (*RClass) EqualTo ¶
func (R *RClass) EqualTo(object BaseObject) bool
func (*RClass) GetInstance ¶
func (R *RClass) GetInstance(s string) (BaseObject, bool)
GetInstance gets instance variables for its children
func (*RClass) InstanceVariableGet ¶
func (R *RClass) InstanceVariableGet(s string) (BaseObject, bool)
func (*RClass) InstanceVariables ¶
func (R *RClass) InstanceVariables() *Environment
func (*RClass) Parent ¶
func (R *RClass) Parent() BaseObject
func (*RClass) SetParent ¶
func (R *RClass) SetParent(_ BaseObject)
type VM ¶
type VM struct { Error *errors.VMERROR LastPopped BaseObject Environment *Environment // contains filtered or unexported fields }
The Base VM struct
func NewVMWithStore ¶
func NewVMWithStore(source []byte, env *Environment) *VM
NewVMWithStore is NewVM but with set environment
Click to show internal directories.
Click to hide internal directories.