object

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 19, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
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"
)

Variables

View Source
var (
	Arguments      []string
	StandardInput  io.Reader
	StandardOutput io.Writer
	ExitFunction   func(int)
)
View Source
var Builtins = map[string]*Builtin{
	"len":    &Builtin{Name: "len", Fn: Len},
	"input":  &Builtin{Name: "input", Fn: Input},
	"print":  &Builtin{Name: "print", Fn: Print},
	"first":  &Builtin{Name: "first", Fn: First},
	"last":   &Builtin{Name: "last", Fn: Last},
	"rest":   &Builtin{Name: "rest", Fn: Rest},
	"push":   &Builtin{Name: "push", Fn: Push},
	"pop":    &Builtin{Name: "pop", Fn: Pop},
	"exit":   &Builtin{Name: "exit", Fn: Exit},
	"assert": &Builtin{Name: "assert", Fn: Assert},
	"bool":   &Builtin{Name: "bool", Fn: Bool},
	"int":    &Builtin{Name: "int", Fn: Int},
	"str":    &Builtin{Name: "str", Fn: Str},
	"typeof": &Builtin{Name: "typeof", Fn: TypeOf},
	"args":   &Builtin{Name: "args", Fn: Args},
	"lower":  &Builtin{Name: "lower", Fn: Lower},
	"upper":  &Builtin{Name: "upper", Fn: Upper},
	"join":   &Builtin{Name: "join", Fn: Join},
	"split":  &Builtin{Name: "split", Fn: Split},
	"find":   &Builtin{Name: "find", Fn: Find},
	"read":   &Builtin{Name: "read", Fn: Read},
	"write":  &Builtin{Name: "write", Fn: Write},
}

Builtins ...

View Source
var BuiltinsIndex []*Builtin

BuiltinsIndex ...

Functions

This section is empty.

Types

type Array

type Array struct {
	Elements []Object
}

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

func (*Array) Equal

func (ao *Array) Equal(other Object) bool

func (*Array) Inspect

func (ao *Array) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*Array) String

func (ao *Array) String() string

func (*Array) Type

func (ao *Array) Type() Type

Type returns the type of the object

type Boolean

type Boolean struct {
	Value bool
}

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

func (*Boolean) Clone

func (b *Boolean) Clone() Object

Clone creates a new copy

func (*Boolean) Equal

func (b *Boolean) Equal(other Object) bool

func (*Boolean) HashKey

func (b *Boolean) HashKey() HashKey

HashKey returns a HashKey object

func (*Boolean) Inspect

func (b *Boolean) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*Boolean) String

func (b *Boolean) String() string

func (*Boolean) Type

func (b *Boolean) Type() Type

Type returns the type of the object

type Builtin

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) Inspect

func (b *Builtin) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*Builtin) String

func (b *Builtin) String() string

func (*Builtin) Type

func (b *Builtin) Type() Type

Type returns the type of the object

type BuiltinFunction

type BuiltinFunction func(args ...Object) Object

BuiltinFunction represents the builtin function type

type Closure

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) Inspect

func (c *Closure) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*Closure) String

func (c *Closure) String() string

func (*Closure) Type

func (c *Closure) Type() Type

Type returns the type of the object

type Comparable

type Comparable interface {
	Equal(other Object) bool
}

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

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) Inspect

func (cf *CompiledFunction) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*CompiledFunction) String

func (cf *CompiledFunction) String() string

func (*CompiledFunction) Type

func (cf *CompiledFunction) Type() Type

Type returns the type of the object

type Environment

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

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

func NewEnvironment

func NewEnvironment() *Environment

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

func (*Environment) Clone

func (e *Environment) Clone() *Environment

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

func (*Environment) Get

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

Get returns the object bound by name

func (*Environment) Set

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

Set stores the object with the given name

type Error

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) Clone

func (e *Error) Clone() Object

Clone creates a new copy

func (*Error) Inspect

func (e *Error) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*Error) String

func (e *Error) String() string

func (*Error) Type

func (e *Error) Type() Type

Type returns the type of the object

type Function

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) Inspect

func (f *Function) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*Function) String

func (f *Function) String() string

func (*Function) Type

func (f *Function) Type() Type

Type returns the type of the object

type Hash

type Hash struct {
	Pairs map[HashKey]HashPair
}

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

func (*Hash) Equal

func (h *Hash) Equal(other Object) bool

func (*Hash) Inspect

func (h *Hash) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*Hash) String

func (h *Hash) String() string

func (*Hash) Type

func (h *Hash) Type() Type

Type returns the type of the object

type HashKey

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

type HashPair struct {
	Key   Object
	Value Object
}

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

type Hashable

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

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

type Integer struct {
	Value int64
}

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

func (*Integer) Clone

func (i *Integer) Clone() Object

Clone creates a new copy

func (*Integer) Equal

func (i *Integer) Equal(other Object) bool

func (*Integer) HashKey

func (i *Integer) HashKey() HashKey

HashKey returns a HashKey object

func (*Integer) Inspect

func (i *Integer) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*Integer) String

func (i *Integer) String() string

func (*Integer) Type

func (i *Integer) Type() Type

Type returns the type of the object

type Null

type Null struct{}

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

func (*Null) Equal

func (n *Null) Equal(other Object) bool

func (*Null) Inspect

func (n *Null) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*Null) String

func (n *Null) String() string

func (*Null) Type

func (n *Null) Type() Type

Type returns the type of the object

type Object

type Object interface {
	Type() Type
	String() string
	Inspect() string
}

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

func Args

func Args(args ...Object) Object

Args ...

func Assert

func Assert(args ...Object) Object

Assert ...

func Bool

func Bool(args ...Object) Object

Bool ...

func Exit

func Exit(args ...Object) Object

Exit ...

func Find

func Find(args ...Object) Object

Find ...

func First

func First(args ...Object) Object

First ...

func Input

func Input(args ...Object) Object

Input ...

func Int

func Int(args ...Object) Object

Int ...

func Join

func Join(args ...Object) Object

Join ...

func Last

func Last(args ...Object) Object

Last ...

func Len

func Len(args ...Object) Object

Len ...

func Lower

func Lower(args ...Object) Object

Lower ...

func Pop

func Pop(args ...Object) Object

Pop ...

func Print

func Print(args ...Object) Object

Print ...

func Push

func Push(args ...Object) Object

Push ...

func Read added in v1.0.1

func Read(args ...Object) Object

Read ...

func Rest

func Rest(args ...Object) Object

Rest ...

func Split

func Split(args ...Object) Object

Split ...

func Str

func Str(args ...Object) Object

Str ...

func TypeOf

func TypeOf(args ...Object) Object

TypeOf ...

func Upper

func Upper(args ...Object) Object

Upper ...

func Write added in v1.0.1

func Write(args ...Object) Object

Write ...

type Return

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) Inspect

func (rv *Return) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*Return) String

func (rv *Return) String() string

func (*Return) Type

func (rv *Return) Type() Type

Type returns the type of the object

type String

type String struct {
	Value string
}

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

func (*String) Clone

func (s *String) Clone() Object

Clone creates a new copy

func (*String) Equal

func (s *String) Equal(other Object) bool

func (*String) HashKey

func (s *String) HashKey() HashKey

HashKey returns a HashKey object

func (*String) Inspect

func (s *String) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*String) String

func (s *String) String() string

func (*String) Type

func (s *String) Type() Type

Type returns the type of the object

type Type

type Type string

Type represents the type of an object

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL