Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrWrongNumberArguments = errors.New("wrong number of argument(s)") ErrUnsupportedArgumentType = errors.New("unsupported argument type") )
View Source
var ( INTEGER_OBJ = ObjectType("INTEGER") BOOLEAN_OBJ = ObjectType("BOOLEAN") STRING_OBJ = ObjectType("STRING") ARRAY_OBJ = ObjectType("ARRAY") HASH_OBJ = ObjectType("HASH") NIL_OBJ = ObjectType("NIL") RETURN_VALUE_OBJ = ObjectType("RETURN_VALUE") ERROR_OBJ = ObjectType("ERROR") FUNCTION_OBJ = ObjectType("FUNCTION") BUILTINFUNC_OBJ = ObjectType("BUILTINFUNC") )
View Source
var ( TRUE = NewBoolean(true) FALSE = NewBoolean(false) NIL = NewNil() )
boolean literal objects
View Source
var BuiltinFuncs = map[string]BuiltinFunc{ "len": func(args ...Object) (Object, error) { if len(args) != 1 { return NIL, ErrWrongNumberArguments } switch arg := args[0].(type) { case *String: return NewInteger(int64(len(arg.Value))), nil case *Array: return NewInteger(int64(len(arg.Elements))), nil default: return NIL, ErrUnsupportedArgumentType } }, "print": func(args ...Object) (Object, error) { strToPrint := []string{} for _, arg := range args { strToPrint = append(strToPrint, arg.Inspect()) } fmt.Println(strings.Join(strToPrint, " ")) return NIL, nil }, }
all built-in functions
Functions ¶
This section is empty.
Types ¶
type Array ¶ added in v0.15.0
type Array struct {
Elements []Object
}
the array object
func (*Array) Type ¶ added in v0.15.0
func (a *Array) Type() ObjectType
type Boolean ¶
type Boolean struct {
Value bool
}
the boolean object
func NewBoolean ¶
func (*Boolean) Type ¶
func (b *Boolean) Type() ObjectType
type BuiltinFunc ¶ added in v0.13.0
BuiltinFunc represents a builtin function object
func (BuiltinFunc) Inspect ¶ added in v0.13.0
func (b BuiltinFunc) Inspect() string
func (BuiltinFunc) IsTruthy ¶ added in v0.13.0
func (b BuiltinFunc) IsTruthy() bool
FIXME: this behavior is undined, not sure whether a builtin function is truthy or not
func (BuiltinFunc) Type ¶ added in v0.13.0
func (b BuiltinFunc) Type() ObjectType
type Environment ¶
type Environment interface { Keys() []string Get(name string) (Object, bool) Set(name string, val Object) // contains filtered or unexported methods }
func NewClosureEnvironment ¶
func NewClosureEnvironment(env Environment) Environment
func NewEnvironment ¶
func NewEnvironment() Environment
type Error ¶
type Error struct {
Message string
}
Error represents an error Note: this is not necessary for the interpreter to work, we do error handling in Go's native way
func (*Error) Type ¶
func (e *Error) Type() ObjectType
type Func ¶
type Func struct { Parameters []*ast.IdentifierExpression Body *ast.BlockStatement }
Func represents a function object
func NewFunc ¶
func NewFunc(params []*ast.IdentifierExpression, body *ast.BlockStatement, env Environment) *Func
func (*Func) IsTruthy ¶
FIXME: this behavior is undined, not sure whether a function is truthy or not
func (*Func) Type ¶
func (f *Func) Type() ObjectType
type Hash ¶ added in v0.16.0
the hash object
func (*Hash) Type ¶ added in v0.16.0
func (h *Hash) Type() ObjectType
type HashKey ¶ added in v0.16.0
type HashKey struct { Type ObjectType ObjectLiteral string Value uint64 }
type Integer ¶
type Integer struct {
Value int64
}
Integer
func NewInteger ¶
func (*Integer) Type ¶
func (i *Integer) Type() ObjectType
type Nil ¶
type Nil struct{}
Nil represents the absence of any value
func (*Nil) Type ¶
func (n *Nil) Type() ObjectType
type Object ¶
type Object interface { Type() ObjectType Inspect() string IsTruthy() bool }
type ObjectType ¶
type ObjectType string
type ReturnValue ¶
type ReturnValue struct {
Value Object
}
ReturnValue represents a return value of a function
func NewReturnValue ¶
func NewReturnValue(value Object) *ReturnValue
func (*ReturnValue) Inspect ¶
func (rv *ReturnValue) Inspect() string
func (*ReturnValue) IsTruthy ¶
func (rv *ReturnValue) IsTruthy() bool
func (*ReturnValue) Type ¶
func (rv *ReturnValue) Type() ObjectType
Click to show internal directories.
Click to hide internal directories.