Documentation ¶
Index ¶
- Constants
- Variables
- type Array
- func (obj *Array) Equals(other Object) bool
- func (obj *Array) GetMember(name string) Object
- func (obj *Array) InfixOperation(operator string, other Object) Object
- func (ao *Array) Inspect() string
- func (ao *Array) MarshalJSON() (text []byte, err error)
- func (obj *Array) Native() interface{}
- func (obj *Array) SetMember(name string, value Object) Object
- func (ao *Array) String() string
- func (ao *Array) Type() ObjectType
- type Boolean
- func (obj *Boolean) Equals(other Object) bool
- func (obj *Boolean) GetMember(name string) Object
- func (b *Boolean) HashKey() HashKey
- func (obj *Boolean) InfixOperation(operator string, other Object) Object
- func (b *Boolean) Inspect() string
- func (b *Boolean) MarshalJSON() (text []byte, err error)
- func (obj *Boolean) Native() interface{}
- func (obj *Boolean) SetMember(name string, value Object) Object
- func (b *Boolean) String() string
- func (b *Boolean) Type() ObjectType
- type Builtin
- type BuiltinFunction
- type Bytes
- func (obj *Bytes) Equals(other Object) bool
- func (obj *Bytes) GetMember(name string) Object
- func (obj *Bytes) InfixOperation(operator string, other Object) Object
- func (s *Bytes) Inspect() string
- func (obj *Bytes) Native() interface{}
- func (obj *Bytes) SetMember(name string, value Object) Object
- func (s *Bytes) String() string
- func (s *Bytes) Type() ObjectType
- type Closure
- type CompiledFunction
- func (obj *CompiledFunction) Equals(other Object) bool
- func (obj *CompiledFunction) GetMember(name string) Object
- func (cf *CompiledFunction) Inspect() string
- func (obj *CompiledFunction) SetMember(name string, value Object) Object
- func (cf *CompiledFunction) String() string
- func (cf *CompiledFunction) Type() ObjectType
- type Error
- type Float
- func (obj *Float) Equals(other Object) bool
- func (obj *Float) GetMember(name string) Object
- func (i *Float) HashKey() HashKey
- func (obj *Float) InfixOperation(operator string, other Object) Object
- func (i *Float) Inspect() string
- func (i *Float) MarshalJSON() (text []byte, err error)
- func (obj *Float) Native() interface{}
- func (obj *Float) SetMember(name string, value Object) Object
- func (i *Float) String() string
- func (i *Float) Type() ObjectType
- type Hash
- func (obj *Hash) Equals(other Object) bool
- func (obj *Hash) GetMember(name string) Object
- func (h *Hash) Inspect() string
- func (h *Hash) MarshalJSON() (text []byte, err error)
- func (obj *Hash) Native() interface{}
- func (obj *Hash) SetMember(name string, value Object) Object
- func (h *Hash) String() string
- func (h *Hash) Type() ObjectType
- type HashKey
- type HashPair
- type Hashable
- type InfixOperatorObject
- type Integer
- func (obj *Integer) Equals(other Object) bool
- func (obj *Integer) GetMember(name string) Object
- func (i *Integer) HashKey() HashKey
- func (obj *Integer) InfixOperation(operator string, other Object) Object
- func (i *Integer) Inspect() string
- func (i *Integer) MarshalJSON() (text []byte, err error)
- func (obj *Integer) Native() interface{}
- func (obj *Integer) SetMember(name string, value Object) Object
- func (i *Integer) String() string
- func (i *Integer) Type() ObjectType
- type MemberFn
- func (obj *MemberFn) Equals(other Object) bool
- func (obj *MemberFn) GetMember(name string) Object
- func (b *MemberFn) Inspect() string
- func (obj *MemberFn) Native() interface{}
- func (obj *MemberFn) SetMember(name string, value Object) Object
- func (b *MemberFn) String() string
- func (b *MemberFn) Type() ObjectType
- type MemberFunction
- type NativeObject
- type Null
- func (obj *Null) Equals(other Object) bool
- func (obj *Null) GetMember(name string) Object
- func (obj *Null) InfixOperation(operator string, other Object) Object
- func (n *Null) Inspect() string
- func (n *Null) MarshalJSON() (text []byte, err error)
- func (obj *Null) Native() interface{}
- func (obj *Null) SetMember(name string, value Object) Object
- func (n *Null) String() string
- func (n *Null) Type() ObjectType
- type Object
- type ObjectType
- type ReturnValue
- func (obj *ReturnValue) Equals(other Object) bool
- func (obj *ReturnValue) GetMember(name string) Object
- func (obj *ReturnValue) InfixOperation(operator string, other Object) Object
- func (rv *ReturnValue) Inspect() string
- func (obj *ReturnValue) SetMember(name string, value Object) Object
- func (rv *ReturnValue) String() string
- func (rv *ReturnValue) Type() ObjectType
- type Scope
- func (obj *Scope) Equals(other Object) bool
- func (obj *Scope) GetMember(name string) Object
- func (obj *Scope) InfixOperation(operator string, other Object) Object
- func (cf *Scope) Inspect() string
- func (obj *Scope) Native() interface{}
- func (obj *Scope) SetMember(name string, value Object) Object
- func (cf *Scope) String() string
- func (cf *Scope) Type() ObjectType
- type String
- func (obj *String) Equals(other Object) bool
- func (obj *String) GetMember(name string) Object
- func (s *String) HashKey() HashKey
- func (obj *String) InfixOperation(operator string, other Object) Object
- func (s *String) Inspect() string
- func (s *String) MarshalJSON() (text []byte, err error)
- func (obj *String) Native() interface{}
- func (obj *String) SetMember(name string, value Object) Object
- func (s *String) String() string
- func (s *String) Type() ObjectType
Constants ¶
View Source
const ( BuiltinFuncNameLen = "len" BuiltinFuncNamePrint = "print" // Type conversions BuiltinFuncNameInt = "int" BuiltinFuncNameFloat = "float" BuiltinFuncNameString = "string" BuiltinFuncNameBytes = "bytes" )
View Source
const ( IntegerObj = "Integer" FloatObj = "Float" BooleanObj = "Boolean" NullObj = "Null" ReturnValueObj = "ReturnValue" ErrorObj = "Error" FunctionObj = "Function" BytesObj = "Bytes" StringObj = "String" BuiltinObj = "Builtin" ArrayObj = "Array" HashObj = "Hash" CompiledFunctionObj = "CompiledFunction" ClosureObj = "Closure" ScopeObj = "Scope" ClassObj = "Class" )
Variables ¶
View Source
var ( NullValue = NullObject True = &Boolean{Value: true} False = &Boolean{Value: false} )
View Source
var Builtins = []struct { Name string Builtin *Builtin }{ { BuiltinFuncNameLen, &Builtin{Fn: func(args ...Object) Object { if len(args) != 1 { return newError("wrong number of arguments. got=%d, want=1", len(args)) } switch arg := args[0].(type) { case *Array: return &Integer{Value: int64(len(arg.Elements))} case *String: return &Integer{Value: int64(len(arg.Value))} default: return newError("argument to %q not supported, got %s", BuiltinFuncNameLen, args[0].Type()) } }, }, }, { BuiltinFuncNamePrint, &Builtin{Fn: func(args ...Object) Object { for _, arg := range args { fmt.Print(arg.Inspect()) } fmt.Println() return nil }, }, }, { BuiltinFuncNameInt, &Builtin{Fn: func(args ...Object) Object { if len(args) != 1 { return newError("wrong number of arguments. got=%d, want=1", len(args)) } switch arg := args[0].(type) { case *Integer: return arg case *Float: return &Integer{Value: int64(arg.Value)} case *String: val, err := strconv.ParseInt(arg.Value, 10, 64) if err != nil { return newError("Conversion to int failed!") } return &Integer{Value: val} default: return newError("argument to %q not supported, got %s", BuiltinFuncNameLen, args[0].Type()) } }, }, }, { BuiltinFuncNameFloat, &Builtin{Fn: func(args ...Object) Object { if len(args) != 1 { return newError("wrong number of arguments. got=%d, want=1", len(args)) } switch arg := args[0].(type) { case *Integer: return &Float{Value: float64(arg.Value)} case *Float: return arg case *String: val, err := strconv.ParseFloat(arg.Value, 64) if err != nil { return newError("Conversion to float failed!") } return &Float{Value: val} default: return newError("argument to %q not supported, got %s", BuiltinFuncNameLen, args[0].Type()) } }, }, }, { BuiltinFuncNameString, &Builtin{Fn: func(args ...Object) Object { if len(args) != 1 { return newError("wrong number of arguments. got=%d, want=1", len(args)) } return &String{Value: args[0].String()} }, }, }, { BuiltinFuncNameBytes, &Builtin{Fn: func(args ...Object) Object { if len(args) != 1 { return newError("wrong number of arguments. got=%d, want=1", len(args)) } switch val := args[0].(type) { case *String: return &Bytes{Value: []byte(val.Value)} } return newError("couldn't convert to bytes!") }, }, }, }
View Source
var NullObject = &Null{}
Functions ¶
This section is empty.
Types ¶
type Array ¶
type Array struct {
Elements []Object
}
func (*Array) InfixOperation ¶
func (*Array) MarshalJSON ¶ added in v0.0.4
func (*Array) Type ¶
func (ao *Array) Type() ObjectType
type Boolean ¶
type Boolean struct {
Value bool
}
func (*Boolean) InfixOperation ¶
func (*Boolean) MarshalJSON ¶ added in v0.0.4
func (*Boolean) Type ¶
func (b *Boolean) Type() ObjectType
type Builtin ¶
type Builtin struct {
Fn BuiltinFunction
}
func (*Builtin) Type ¶
func (b *Builtin) Type() ObjectType
type BuiltinFunction ¶
type Bytes ¶ added in v0.0.2
type Bytes struct {
Value []byte
}
func (*Bytes) InfixOperation ¶ added in v0.0.2
func (*Bytes) Type ¶ added in v0.0.2
func (s *Bytes) Type() ObjectType
type Closure ¶
type Closure struct { Fn *CompiledFunction Free []Object Exports map[string]Object }
func (*Closure) Type ¶
func (c *Closure) Type() ObjectType
type CompiledFunction ¶
type CompiledFunction struct { Instructions code.Instructions NumLocals int NumParameters int }
func (*CompiledFunction) Equals ¶ added in v0.0.2
func (obj *CompiledFunction) Equals(other Object) bool
func (*CompiledFunction) GetMember ¶
func (obj *CompiledFunction) GetMember(name string) Object
func (*CompiledFunction) Inspect ¶
func (cf *CompiledFunction) Inspect() string
func (*CompiledFunction) SetMember ¶ added in v0.0.2
func (obj *CompiledFunction) SetMember(name string, value Object) Object
func (*CompiledFunction) String ¶
func (cf *CompiledFunction) String() string
func (*CompiledFunction) Type ¶
func (cf *CompiledFunction) Type() ObjectType
type Error ¶
type Error struct {
Message string
}
func (*Error) Type ¶
func (e *Error) Type() ObjectType
type Float ¶
type Float struct {
Value float64
}
func (*Float) InfixOperation ¶
func (*Float) MarshalJSON ¶ added in v0.0.4
func (*Float) Type ¶
func (i *Float) Type() ObjectType
type Hash ¶
func (*Hash) MarshalJSON ¶ added in v0.0.4
func (*Hash) Type ¶
func (h *Hash) Type() ObjectType
type HashKey ¶
type HashKey struct { Type ObjectType Value string }
type HashPair ¶
func (HashPair) MarshalJSON ¶ added in v0.0.4
type InfixOperatorObject ¶ added in v0.0.2
type Integer ¶
type Integer struct {
Value int64
}
func (*Integer) InfixOperation ¶
func (*Integer) MarshalJSON ¶ added in v0.0.4
func (*Integer) Type ¶
func (i *Integer) Type() ObjectType
type MemberFn ¶
type MemberFn struct { Obj Object Fn MemberFunction }
func (*MemberFn) Type ¶
func (b *MemberFn) Type() ObjectType
type MemberFunction ¶
type NativeObject ¶ added in v0.0.2
type NativeObject interface { Object Native() interface{} }
type Null ¶
type Null struct{}
func (*Null) MarshalJSON ¶ added in v0.0.4
func (*Null) Type ¶
func (n *Null) Type() ObjectType
type ObjectType ¶
type ObjectType string
type ReturnValue ¶
type ReturnValue struct {
Value Object
}
func (*ReturnValue) Equals ¶ added in v0.0.2
func (obj *ReturnValue) Equals(other Object) bool
func (*ReturnValue) GetMember ¶
func (obj *ReturnValue) GetMember(name string) Object
func (*ReturnValue) InfixOperation ¶
func (obj *ReturnValue) InfixOperation(operator string, other Object) Object
func (*ReturnValue) Inspect ¶
func (rv *ReturnValue) Inspect() string
func (*ReturnValue) SetMember ¶ added in v0.0.2
func (obj *ReturnValue) SetMember(name string, value Object) Object
func (*ReturnValue) String ¶
func (rv *ReturnValue) String() string
func (*ReturnValue) Type ¶
func (rv *ReturnValue) Type() ObjectType
type Scope ¶
type Scope struct { Name string Constants []Object Instructions code.Instructions NumLocals int Exports map[string]Object }
func (*Scope) InfixOperation ¶
func (*Scope) Type ¶
func (cf *Scope) Type() ObjectType
type String ¶
type String struct {
Value string
}
func (*String) InfixOperation ¶
func (*String) MarshalJSON ¶ added in v0.0.4
func (*String) Type ¶
func (s *String) Type() ObjectType
Source Files ¶
- builtins.go
- helpers.go
- object.go
- object_array.go
- object_bool.go
- object_bytes.go
- object_closure.go
- object_error.go
- object_float.go
- object_function_builtin.go
- object_function_compiled.go
- object_function_member.go
- object_hash.go
- object_int.go
- object_null.go
- object_return_value.go
- object_scope.go
- object_string.go
Click to show internal directories.
Click to hide internal directories.