object

package
v0.0.0-...-af76a4e Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2019 License: MIT Imports: 6 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// IntegerType represents a type of integers.
	IntegerType Type = "Integer"
	// FloatType represents a type of floating point numbers.
	FloatType = "Float"
	// BooleanType represents a type of booleans.
	BooleanType = "Boolean"
	// NilType represents a type of nil.
	NilType = "Nil"
	// ReturnValueType represents a type of return values.
	ReturnValueType = "ReturnValue"
	// ErrorType represents a type of errors.
	ErrorType = "Error"
	// FunctionType represents a type of functions.
	FunctionType = "Function"
	// StringType represents a type of strings.
	StringType = "String"
	// BuiltinType represents a type of builtin functions.
	BuiltinType = "Builtin"
	// ArrayType represents a type of arrays.
	ArrayType = "Array"
	// HashType represents a type of hashes.
	HashType = "Hash"
	// QuoteType represents a type of quotes used for macros.
	QuoteType = "Quote"
	// MacroType represents a type of macros.
	MacroType = "Macro"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

type Array struct {
	Elements []Object
}

Array represents an array.

func (*Array) Inspect

func (a *Array) Inspect() string

Inspect returns a string representation of the Array.

func (*Array) Type

func (*Array) Type() Type

Type returns the type of the Array.

type Boolean

type Boolean struct {
	Value bool
}

Boolean represents a boolean.

func (*Boolean) HashKey

func (b *Boolean) HashKey() HashKey

HashKey returns a hash key object for b.

func (*Boolean) Inspect

func (b *Boolean) Inspect() string

Inspect returns a string representation of the Boolean.

func (*Boolean) Type

func (b *Boolean) Type() Type

Type returns the type of the Boolean.

type Builtin

type Builtin struct {
	Fn BuiltinFunction
}

Builtin represents a builtin function.

func (*Builtin) Inspect

func (b *Builtin) Inspect() string

Inspect returns a string representation of the Builtin.

func (*Builtin) Type

func (b *Builtin) Type() Type

Type returns the type of the Builtin.

type BuiltinFunction

type BuiltinFunction func(args ...Object) Object

BuiltinFunction represents a function signature of builtin functions.

type Environment

type Environment interface {
	// Get retrieves the value of a variable named by the `name`.
	// If the variable is present in the environment the value is returned and the boolean is true.
	// Otherwise the returned value will be nil and the boolean will be false.
	Get(name string) (Object, bool)

	// Set sets the `val` of a variable named by the `name` and returns the `val` itself.
	Set(name string, val Object) Object
}

Environment associates values with variable names.

func NewEnclosedEnvironment

func NewEnclosedEnvironment(outer Environment) Environment

NewEnclosedEnvironment creates a new Environment which holds the given outer Environment.

func NewEnvironment

func NewEnvironment() Environment

NewEnvironment returns a new Environment.

type Error

type Error struct {
	Message string
}

Error represents an error.

func (*Error) Inspect

func (e *Error) Inspect() string

Inspect returns a string representation of the Error.

func (*Error) Type

func (e *Error) Type() Type

Type returns the type of the Error.

type Float

type Float struct {
	Value float64
}

Float represents an integer.

func (*Float) HashKey

func (f *Float) HashKey() HashKey

HashKey returns a hash key object for f.

func (*Float) Inspect

func (f *Float) Inspect() string

Inspect returns a string representation of f.

func (*Float) Type

func (f *Float) Type() Type

Type returns the type of f.

type Function

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

Function represents a function.

func (*Function) Inspect

func (f *Function) Inspect() string

Inspect returns a string representation of the Function.

func (*Function) Type

func (f *Function) Type() Type

Type returns the type of the Function.

type Hash

type Hash struct {
	Pairs map[HashKey]HashPair
}

Hash represents a hash.

func (*Hash) Inspect

func (h *Hash) Inspect() string

Inspect returns a string representation of the Hash.

func (*Hash) Type

func (*Hash) Type() Type

Type returns the type of the Hash.

type HashKey

type HashKey struct {
	Type  Type
	Value uint64
}

HashKey represents a key of a hash.

type HashPair

type HashPair struct {
	Key   Object
	Value Object
}

HashPair represents a key-value pair in a hash.

type Hashable

type Hashable interface {
	HashKey() HashKey
}

Hashable is the interface that is able to become a hash key.

type Integer

type Integer struct {
	Value int64
}

Integer represents an integer.

func (*Integer) HashKey

func (i *Integer) HashKey() HashKey

HashKey returns a hash key object for i.

func (*Integer) Inspect

func (i *Integer) Inspect() string

Inspect returns a string representation of the Integer.

func (*Integer) Type

func (i *Integer) Type() Type

Type returns the type of the Integer.

type Macro

type Macro struct {
	Parameters []*ast.Ident
	Body       *ast.BlockStatement
	Env        Environment
}

Macro represents a macro.

func (*Macro) Inspect

func (m *Macro) Inspect() string

Inspect returns a string representation of `m`.

func (*Macro) Type

func (m *Macro) Type() Type

Type returns the type of `m`.

type Nil

type Nil struct{}

Nil represents the absence of any value.

func (*Nil) Inspect

func (n *Nil) Inspect() string

Inspect returns a string representation of the Nil.

func (*Nil) Type

func (n *Nil) Type() Type

Type returns the type of the Nil.

type Object

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

Object represents an object of Monkey language.

type Quote

type Quote struct {
	ast.Node
}

Quote represents a quote, i.e. an unevaluated expression.

func (*Quote) Inspect

func (q *Quote) Inspect() string

Inspect returns a string representation of `q`.

func (*Quote) Type

func (q *Quote) Type() Type

Type returns the type of `q`.

type ReturnValue

type ReturnValue struct {
	Value Object
}

ReturnValue represents a return value.

func (*ReturnValue) Inspect

func (rv *ReturnValue) Inspect() string

Inspect returns a string representation of the ReturnValue.

func (*ReturnValue) Type

func (rv *ReturnValue) Type() Type

Type returns the type of the ReturnValue.

type String

type String struct {
	Value string
}

String represents a string.

func (*String) HashKey

func (s *String) HashKey() HashKey

HashKey returns a hash key object for s.

func (*String) Inspect

func (s *String) Inspect() string

Inspect returns a string representation of the String.

func (*String) Type

func (s *String) Type() Type

Type returns the type of the String.

type Type

type Type string

Type is a type of objects.

Jump to

Keyboard shortcuts

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