Documentation
¶
Index ¶
- Constants
- Variables
- func IsHTML(obj Object) bool
- func IsNull(obj Object) bool
- func ToGo(obj Object) interface{}
- type Array
- type Boolean
- type Builtin
- type BuiltinFunction
- type Closure
- type CompiledFunction
- type Control
- type ControlKind
- type Error
- type Float
- type FunctionLiteral
- type Hash
- type HashKey
- type HashPair
- type Hashable
- type InlineCacheSlot
- type Integer
- type Native
- type Null
- type Object
- type ObjectType
- type PropertyAccess
- type String
Constants ¶
View Source
const ( NULL_OBJ = "NULL" ERROR_OBJ = "ERROR" INTEGER_OBJ = "INTEGER" FLOAT_OBJ = "FLOAT" BOOLEAN_OBJ = "BOOLEAN" STRING_OBJ = "STRING" BUILTIN_OBJ = "BUILTIN" FUNCTION_OBJ = "FUNCTION" ARRAY_OBJ = "ARRAY" HASH_OBJ = "HASH" COMPILED_FUNCTION_OBJ = "COMPILED_FUNCTION" CLOSURE_OBJ = "CLOSURE" NATIVE_OBJ = "NATIVE" CONTROL_OBJ = "CONTROL" )
Variables ¶
View Source
var ( NullObject = &Null{} TrueObject = &Boolean{Value: true} FalseObject = &Boolean{Value: false} )
View Source
var Builtins = []struct { Name string Builtin *Builtin }{ { "len", &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 `len` not supported, got %s", args[0].Type()) } }}, }, { "puts", &Builtin{Fn: func(args ...Object) Object { for _, arg := range args { fmt.Println(arg.Inspect()) } return nil }}, }, { "first", &Builtin{Fn: func(args ...Object) Object { if len(args) != 1 { return NewError("wrong number of arguments. got=%d, want=1", len(args)) } if args[0].Type() != ARRAY_OBJ { return NewError("argument to `first` must be ARRAY, got %s", args[0].Type()) } arr := args[0].(*Array) if len(arr.Elements) > 0 { return arr.Elements[0] } return nil }}, }, { "last", &Builtin{Fn: func(args ...Object) Object { if len(args) != 1 { return NewError("wrong number of arguments. got=%d, want=1", len(args)) } if args[0].Type() != ARRAY_OBJ { return NewError("argument to `last` must be ARRAY, got %s", args[0].Type()) } arr := args[0].(*Array) if len(arr.Elements) > 0 { return arr.Elements[len(arr.Elements)-1] } return nil }}, }, { "rest", &Builtin{Fn: func(args ...Object) Object { if len(args) != 1 { return NewError("wrong number of arguments. got=%d, want=1", len(args)) } if args[0].Type() != ARRAY_OBJ { return NewError("argument to `rest` must be ARRAY, got %s", args[0].Type()) } arr := args[0].(*Array) if len(arr.Elements) > 0 { newElements := make([]Object, len(arr.Elements)-1) copy(newElements, arr.Elements[1:]) return &Array{Elements: newElements} } return nil }}, }, { "push", &Builtin{Fn: func(args ...Object) Object { if len(args) != 2 { return NewError("wrong number of arguments. got=%d, want=2", len(args)) } if args[0].Type() != ARRAY_OBJ { return NewError("argument to `push` must be ARRAY, got %s", args[0].Type()) } arr := args[0].(*Array) newElements := make([]Object, len(arr.Elements)+1) copy(newElements, arr.Elements) newElements[len(newElements)-1] = args[1] return &Array{Elements: newElements} }}, }, }
Functions ¶
Types ¶
type Array ¶
type Array struct {
Elements []Object
}
func (*Array) Type ¶
func (ao *Array) Type() ObjectType
type Boolean ¶
type Boolean struct {
Value bool
}
func (*Boolean) Type ¶
func (b *Boolean) Type() ObjectType
type Builtin ¶
type Builtin struct {
Fn BuiltinFunction
}
func GetBuiltinByName ¶
func (*Builtin) Type ¶
func (b *Builtin) Type() ObjectType
type BuiltinFunction ¶
type Closure ¶
type Closure struct {
Fn *CompiledFunction
Free []Object
}
func (*Closure) Type ¶
func (c *Closure) Type() ObjectType
type CompiledFunction ¶
type CompiledFunction struct {
Instructions code.Instructions
CallNames map[int]string
LocalNames map[int]string
LineNumbers map[int]int
Properties map[int]PropertyAccess
PropertyCaches []InlineCacheSlot
CallCaches []InlineCacheSlot
NumLocals int
NumParameters int
}
func (*CompiledFunction) Inspect ¶
func (cf *CompiledFunction) Inspect() string
func (*CompiledFunction) Type ¶
func (cf *CompiledFunction) Type() ObjectType
type Control ¶
type Control struct {
Kind ControlKind
Value []Object
}
func (*Control) Type ¶
func (c *Control) Type() ObjectType
type ControlKind ¶
type ControlKind string
const ( ControlBreak ControlKind = "break" ControlContinue ControlKind = "continue" )
type Error ¶
type Error struct {
Message string
}
func (*Error) Type ¶
func (e *Error) Type() ObjectType
type Float ¶
type Float struct {
Value float64
}
func (*Float) Type ¶
func (f *Float) Type() ObjectType
type FunctionLiteral ¶
type FunctionLiteral struct {
Parameters []*ast.Identifier
Body *ast.BlockStatement
}
func (*FunctionLiteral) Inspect ¶
func (f *FunctionLiteral) Inspect() string
func (*FunctionLiteral) Type ¶
func (f *FunctionLiteral) Type() ObjectType
type HashKey ¶
type HashKey struct {
Type ObjectType
Value uint64
}
type InlineCacheSlot ¶
type InlineCacheSlot struct {
// contains filtered or unexported fields
}
func NewInlineCacheSlots ¶
func NewInlineCacheSlots(size int) []InlineCacheSlot
func (*InlineCacheSlot) Load ¶
func (s *InlineCacheSlot) Load() interface{}
func (*InlineCacheSlot) Store ¶
func (s *InlineCacheSlot) Store(value interface{})
type Integer ¶
type Integer struct {
Value int64
}
func (*Integer) Type ¶
func (i *Integer) Type() ObjectType
type Native ¶
type Native struct {
Value interface{}
}
func (*Native) Type ¶
func (n *Native) Type() ObjectType
type Object ¶
type Object interface {
Type() ObjectType
Inspect() string
}
type ObjectType ¶
type ObjectType string
type PropertyAccess ¶
Click to show internal directories.
Click to hide internal directories.