object

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

* Package object helps represent the values encountered when evaluating the jaba program as an object. * Every value will be wrapped in a struct that fulfills the object interface. * The object system leverages on the host language (Go) data types and formatting methods to represent its values

* Package object helps represent the values encountered when evaluating the jaba program as an object. * Every value will be wrapped in a struct that fulfills the object interface. * The object system leverages on the host language (Go) data types and formatting methods to represent its values

Index

Constants

View Source
const (
	INTEGER_OBJECT      = "INTEGER"
	BOOLEAN_OBJECT      = "BOOLEAN"
	NULL_OBJECT         = "NULL"
	RETURN_VALUE_OBJECT = "RETURN_VALUE"
	ERROR_OBJECT        = "ERROR"
	FUNCTION_OBJECT     = "FUNCTION_OBJECT"
	STRING_OBJECT       = "STRING"
	BUILTIN_OBJECT      = "BUILTIN"
	ARRAY_OBJECT        = "ARRAY"
	HASH_OBJECT         = "HASH"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Array added in v0.0.6

type Array struct {
	Elements []Object
}

Array represents a jaba builtin array of objects it fulfills the Object interface by implementing the Type() and Inspect() methods

func (*Array) Inspect added in v0.0.6

func (a *Array) Inspect() string

Inspect returns the string representation of the object value, array

func (*Array) Type added in v0.0.6

func (a *Array) Type() ObjectType

Type returns the type of the object, array

type Boolean

type Boolean struct {
	Value bool
}

Boolean is a jaba data type that represents true or false It fulfills the object interface by implementing the Type() and Inspect() methods

func (*Boolean) HashKey added in v0.0.7

func (h *Boolean) HashKey() HashKey

HashKey implements boolean hash function

func (*Boolean) Inspect

func (b *Boolean) Inspect() string

Inspect returns the string representation of the object value, boolean

func (*Boolean) Type

func (b *Boolean) Type() ObjectType

Type returns the type of the object

type Builtin added in v0.0.3

type Builtin struct {
	Function BuiltinFunction
}

Builtin is a wrapper around golang function which is the host language it fulfills the Object interface by implementing the Type() and Inspect() methods

func (*Builtin) Inspect added in v0.0.3

func (b *Builtin) Inspect() string

Inspect returns the string representation of the object value, builtin

func (*Builtin) Type added in v0.0.3

func (b *Builtin) Type() ObjectType

Type returns the type of the object, builtin

type BuiltinFunction added in v0.0.3

type BuiltinFunction func(args ...Object) Object

BuiltinFunction represents a jaba builtin function which is from the host language that allows user to use host language functions

type Environment

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

Environment is a wrapper of the map implementation that helps associate a string key with an object

func NewEnclosedEnvironment

func NewEnclosedEnvironment(outer *Environment) *Environment

NewEnclosedEnvironment creates a new instance of an scoped environment it extends the Environment instance to cater for enclosed environments

func NewEnvironment

func NewEnvironment() *Environment

NewEnvironment creates a new instance of the environment

func (*Environment) Get

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

Get returns the object associated with the given key from the environment it also checks for values both in the inner and outer scopes

func (*Environment) Set

func (e *Environment) Set(key string, value Object) Object

Set creates an object in the environment hashmap and returns what was created

type Error

type Error struct {
	Message string
}

Error represents internal jaba error it fulfills the Object interface by implementing the Type() and Inspect() methods

func (*Error) Inspect

func (e *Error) Inspect() string

Inspect returns the string representation of the object value, error

func (*Error) Type

func (e *Error) Type() ObjectType

Type returns the type of the object, error

type Function

type Function struct {
	// Parameters is a list of identifiers that should be passed to the function call
	Parameters []*ast.Identifier

	// Body contains a list of function statements to be evaluated
	Body *ast.BlockStatement

	// Env keeps track of variables during interpreter execution
	Env *Environment
}

Function represents a jaba function and may include parameters and some statements to be executed it fulfills the Object interface by implementing the Type() and Inspect() methods

func (*Function) Inspect

func (f *Function) Inspect() string

Inspect returns the string representation of the function

func (*Function) Type

func (f *Function) Type() ObjectType

Type returns the type of the object, function

type Hash added in v0.0.7

type Hash struct {
	Pairs map[HashKey]HashPair
}

Hash represents a jaba hash it fulfills the Object interface by implementing the Type() and Inspect() methods

func (*Hash) Inspect added in v0.0.7

func (p *Hash) Inspect() string

Inspect returns the string representation of the object value, hash pair

func (*Hash) Type added in v0.0.7

func (p *Hash) Type() ObjectType

Type returns the type of the object, hash pair

type HashKey added in v0.0.7

type HashKey struct {
	// Type returns the type of the key (string, boolean, integer, ...)
	Type ObjectType

	// Value is hash used to represent the key
	Value uint64
}

HashKey represents a a comparison object used in hashing jaba maps(hashes)

type HashPair added in v0.0.7

type HashPair struct {
	Key   Object
	Value Object
}

HashPair represents the key and value pairs used in jaba hash

type Hashable added in v0.0.7

type Hashable interface {
	HashKey() HashKey
}

Hashable is an interface that can be used to evaluate if an object can be used as a hash key

type Integer

type Integer struct {
	Value int64
}

Integer is a jaba data type that represents numbers It fulfills the object interface by implementing the Type() and Inspect() methods

func (*Integer) HashKey added in v0.0.7

func (i *Integer) HashKey() HashKey

HashKey implements integer hash function

func (*Integer) Inspect

func (i *Integer) Inspect() string

Inspect returns the string representation of the object value, integer

func (*Integer) Type

func (i *Integer) Type() ObjectType

Type returns the type of the object

type Null

type Null struct {
	Value interface{}
}

Null represents absence of a value It fulfills the object interface by implementing the Type() and Inspect() methods

func (*Null) Inspect

func (n *Null) Inspect() string

Inspect returns the string representation of the object value, null

func (*Null) Type

func (n *Null) Type() ObjectType

Type returns the type of the object

type Object

type Object interface {
	// Type returns the type of the object
	Type() ObjectType

	// Inspect returns the string representation of the object value
	Inspect() string
}

Object is an interface that helps represent the values encountered when evaluating the jaba program

type ObjectType

type ObjectType string

ObjectType represents the category of the object

type ReturnValue

type ReturnValue struct {
	Value Object
}

ReturnValue represents a jaba return value It fulfills the object interface by implementing the Type() and Inspect() methods

func (*ReturnValue) Inspect

func (r *ReturnValue) Inspect() string

Inspect returns the string representation of the object value, return value

func (*ReturnValue) Type

func (r *ReturnValue) Type() ObjectType

Type returns the type of the object

type String

type String struct {
	// Value is the actual value of the string literal
	Value string
}

String represents a jaba string which is an expression which evaluates to a value it fulfills the Object interface by implementing the Type() and Inspect() methods

func (*String) HashKey added in v0.0.7

func (s *String) HashKey() HashKey

HashKey implements string hash function

func (*String) Inspect

func (s *String) Inspect() string

Inspect returns the string representation of the object value, string

func (*String) Type

func (s *String) Type() ObjectType

Type returns the type of the object, string

Jump to

Keyboard shortcuts

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