monkey-lang: github.com/prologic/monkey-lang/object Index | Files

package object

import "github.com/prologic/monkey-lang/object"

Index

Package Files

array.go bool.go builtin.go closure.go environment.go error.go function.go hash.go int.go module.go null.go object.go state.go str.go

Constants

const (
    // INTEGER is the Integer object type
    INTEGER = "int"

    // STRING is the String object type
    STRING = "str"

    // BOOLEAN is the Boolean object type
    BOOLEAN = "bool"

    // NULL is the Null object type
    NULL = "null"

    // RETURN is the Return object type
    RETURN = "return"

    // ERROR is the Error object type
    ERROR = "error"

    // FUNCTION is the Function object type
    FUNCTION = "fn"

    // COMPILED_FUNCTION is the CompiledFunction object type
    COMPILED_FUNCTION = "COMPILED_FUNCTION"

    // BUILTIN is the Builtin object type
    BUILTIN = "builtin"

    // CLOSURE is the Closure object type
    CLOSURE = "closure"

    // ARRAY is the Array object type
    ARRAY = "array"

    // HASH is the Hash object type
    HASH = "hash"

    // MODULE is the Module object type
    MODULE = "module"
)

Variables

var (
    Arguments      []string
    StandardInput  io.Reader
    StandardOutput io.Writer
    ExitFunction   func(int)
)

type Array Uses

type Array struct {
    Elements []Object
}

Array is the array literal type that holds a slice of Object(s)

func (*Array) Append Uses

func (a *Array) Append(obj Object)

func (*Array) Bool Uses

func (a *Array) Bool() bool

func (*Array) Compare Uses

func (ao *Array) Compare(other Object) int

func (*Array) Copy Uses

func (a *Array) Copy() *Array

func (*Array) Inspect Uses

func (ao *Array) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*Array) Len Uses

func (a *Array) Len() int

func (*Array) Less Uses

func (a *Array) Less(i, j int) bool

func (*Array) PopLeft Uses

func (a *Array) PopLeft() Object

func (*Array) PopRight Uses

func (a *Array) PopRight() Object

func (*Array) Prepend Uses

func (a *Array) Prepend(obj Object)

func (*Array) Reverse Uses

func (a *Array) Reverse()

func (*Array) String Uses

func (ao *Array) String() string

func (*Array) Swap Uses

func (a *Array) Swap(i, j int)

func (*Array) Type Uses

func (ao *Array) Type() Type

Type returns the type of the object

type Boolean Uses

type Boolean struct {
    Value bool
}

Boolean is the boolean type and used to represent boolean literals and holds an interval bool value

func (*Boolean) Bool Uses

func (b *Boolean) Bool() bool

func (*Boolean) Clone Uses

func (b *Boolean) Clone() Object

Clone creates a new copy

func (*Boolean) Compare Uses

func (b *Boolean) Compare(other Object) int

func (*Boolean) HashKey Uses

func (b *Boolean) HashKey() HashKey

HashKey returns a HashKey object

func (*Boolean) Inspect Uses

func (b *Boolean) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*Boolean) Int Uses

func (b *Boolean) Int() int

func (*Boolean) String Uses

func (b *Boolean) String() string

func (*Boolean) Type Uses

func (b *Boolean) Type() Type

Type returns the type of the object

type Builtin Uses

type Builtin struct {
    Name string
    Fn   BuiltinFunction
}

Builtin is the builtin object type that simply holds a reference to a BuiltinFunction type that takes zero or more objects as arguments and returns an object.

func (*Builtin) Bool Uses

func (b *Builtin) Bool() bool

func (*Builtin) Inspect Uses

func (b *Builtin) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*Builtin) String Uses

func (b *Builtin) String() string

func (*Builtin) Type Uses

func (b *Builtin) Type() Type

Type returns the type of the object

type BuiltinFunction Uses

type BuiltinFunction func(args ...Object) Object

BuiltinFunction represents the builtin function type

type Closure Uses

type Closure struct {
    Fn   *CompiledFunction
    Free []Object
}

Closure is the closure object type that holds a reference to a compiled functions and its free variables

func (*Closure) Bool Uses

func (c *Closure) Bool() bool

func (*Closure) Inspect Uses

func (c *Closure) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*Closure) String Uses

func (c *Closure) String() string

func (*Closure) Type Uses

func (c *Closure) Type() Type

Type returns the type of the object

type Comparable Uses

type Comparable interface {
    Compare(other Object) int
}

Comparable is the interface for comparing two Object and their underlying values. It is the responsibility of the caller (left) to check for types. Returns `true` iif the types and values are identical, `false` otherwise.

type CompiledFunction Uses

type CompiledFunction struct {
    Instructions  code.Instructions
    NumLocals     int
    NumParameters int
}

CompiledFunction is the compiled function type that holds the function's compiled body as bytecode instructions

func (*CompiledFunction) Bool Uses

func (cf *CompiledFunction) Bool() bool

func (*CompiledFunction) Inspect Uses

func (cf *CompiledFunction) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*CompiledFunction) String Uses

func (cf *CompiledFunction) String() string

func (*CompiledFunction) Type Uses

func (cf *CompiledFunction) Type() Type

Type returns the type of the object

type Environment Uses

type Environment struct {
    // contains filtered or unexported fields
}

Environment is an object that holds a mapping of names to bound objets

func NewEnvironment Uses

func NewEnvironment() *Environment

NewEnvironment constructs a new Environment object to hold bindings of identifiers to their names

func (*Environment) Clone Uses

func (e *Environment) Clone() *Environment

Clone returns a new Environment with the parent set to the current environment (enclosing environment)

func (*Environment) ExportedHash Uses

func (e *Environment) ExportedHash() *Hash

ExportedHash returns a new Hash with the names and values of every publically exported binding in the environment. That is every binding that starts with a capital letter. This is used by the module import system to wrap up the evaulated module into an object.

func (*Environment) Get Uses

func (e *Environment) Get(name string) (Object, bool)

Get returns the object bound by name

func (*Environment) Set Uses

func (e *Environment) Set(name string, val Object) Object

Set stores the object with the given name

type Error Uses

type Error struct {
    Message string
}

Error is the error type and used to hold a message denoting the details of error encountered. This object is trakced through the evaluator and when encountered stops evaulation of the program or body of a function.

func (*Error) Bool Uses

func (e *Error) Bool() bool

func (*Error) Clone Uses

func (e *Error) Clone() Object

Clone creates a new copy

func (*Error) Inspect Uses

func (e *Error) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*Error) String Uses

func (e *Error) String() string

func (*Error) Type Uses

func (e *Error) Type() Type

Type returns the type of the object

type Function Uses

type Function struct {
    Parameters []*ast.Identifier
    Body       *ast.BlockStatement
    Env        *Environment
}

Function is the function type that holds the function's formal parameters, body and an environment to support closures.

func (*Function) Bool Uses

func (f *Function) Bool() bool

func (*Function) Inspect Uses

func (f *Function) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*Function) String Uses

func (f *Function) String() string

func (*Function) Type Uses

func (f *Function) Type() Type

Type returns the type of the object

type Hash Uses

type Hash struct {
    Pairs map[HashKey]HashPair
}

Hash is a hash map and holds a map of HashKey to HashPair(s)

func (*Hash) Bool Uses

func (h *Hash) Bool() bool

func (*Hash) Compare Uses

func (h *Hash) Compare(other Object) int

func (*Hash) Inspect Uses

func (h *Hash) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*Hash) Len Uses

func (h *Hash) Len() int

func (*Hash) String Uses

func (h *Hash) String() string

func (*Hash) Type Uses

func (h *Hash) Type() Type

Type returns the type of the object

type HashKey Uses

type HashKey struct {
    Type  Type
    Value uint64
}

HashKey represents a hash key object and holds the Type of Object hashed and its hash value in Value

type HashPair Uses

type HashPair struct {
    Key   Object
    Value Object
}

HashPair is an object that holds a key and value of type Object

type Hashable Uses

type Hashable interface {
    HashKey() HashKey
}

Hashable is the interface for all hashable objects which must implement the HashKey() method which reutrns a HashKey result.

type Immutable Uses

type Immutable interface {
    Clone() Object
}

Immutable is the interface for all immutable objects which must implement the Clone() method used by binding names to values.

type Integer Uses

type Integer struct {
    Value int64
}

Integer is the integer type used to represent integer literals and holds an internal int64 value

func (*Integer) Bool Uses

func (i *Integer) Bool() bool

func (*Integer) Clone Uses

func (i *Integer) Clone() Object

Clone creates a new copy

func (*Integer) Compare Uses

func (i *Integer) Compare(other Object) int

func (*Integer) HashKey Uses

func (i *Integer) HashKey() HashKey

HashKey returns a HashKey object

func (*Integer) Inspect Uses

func (i *Integer) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*Integer) String Uses

func (i *Integer) String() string

func (*Integer) Type Uses

func (i *Integer) Type() Type

Type returns the type of the object

type Module Uses

type Module struct {
    Name  string
    Attrs Object
}

Module is the module type used to represent a collection of variabels.

func (*Module) Bool Uses

func (m *Module) Bool() bool

func (*Module) Compare Uses

func (m *Module) Compare(other Object) int

func (*Module) Inspect Uses

func (m *Module) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*Module) String Uses

func (m *Module) String() string

func (*Module) Type Uses

func (m *Module) Type() Type

Type returns the type of the object

type Null Uses

type Null struct{}

Null is the null type and used to represent the absence of a value

func (*Null) Bool Uses

func (n *Null) Bool() bool

func (*Null) Compare Uses

func (n *Null) Compare(other Object) int

func (*Null) Inspect Uses

func (n *Null) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*Null) String Uses

func (n *Null) String() string

func (*Null) Type Uses

func (n *Null) Type() Type

Type returns the type of the object

type Object Uses

type Object interface {
    fmt.Stringer
    Type() Type
    Bool() bool
    Inspect() string
}

Object represents a value and implementations are expected to implement `Type()` and `Inspect()` functions

type Return Uses

type Return struct {
    Value Object
}

Return is the return type and used to hold the value of another object. This is used for `return` statements and this object is tracked through the evalulator and when encountered stops evaluation of the program, or body of a function.

func (*Return) Bool Uses

func (rv *Return) Bool() bool

func (*Return) Inspect Uses

func (rv *Return) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*Return) String Uses

func (rv *Return) String() string

func (*Return) Type Uses

func (rv *Return) Type() Type

Type returns the type of the object

type Sizeable Uses

type Sizeable interface {
    Len() int
}

Sizeable is the interface for returning the size of an Object. Object(s) that have a valid size must implement this interface and the Len() method.

type String Uses

type String struct {
    Value string
}

String is the string type used to represent string literals and holds an internal string value

func (*String) Bool Uses

func (s *String) Bool() bool

func (*String) Clone Uses

func (s *String) Clone() Object

Clone creates a new copy

func (*String) Compare Uses

func (s *String) Compare(other Object) int

func (*String) HashKey Uses

func (s *String) HashKey() HashKey

HashKey returns a HashKey object

func (*String) Inspect Uses

func (s *String) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*String) Len Uses

func (s *String) Len() int

func (*String) String Uses

func (s *String) String() string

func (*String) Type Uses

func (s *String) Type() Type

Type returns the type of the object

type Type Uses

type Type string

Type represents the type of an object

Package object imports 9 packages (graph) and is imported by 8 packages. Updated 2019-04-05. Refresh now. Tools for package owners.