object

package
v0.0.0-...-bf9f4d5 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package object contains the various implementations of the object.Object interface List of the supported object

  • Array
  • Boolean
  • Builtin (function)
  • Environment (for variable definition and such)
  • Error (for parser handling)
  • Function (user defined, not builtins)
  • Hash
  • Integer
  • Null
  • Repo (a go-git git repository)
  • Return
  • String
  • Tag (a go-git tag object)

Index

Constants

View Source
const (
	IntegerObj     = "INTEGER"
	BooleanObj     = "BOOLEAN"
	NullObj        = "NULL"
	ReturnValueObj = "RETURN_VALUE"
	ErrorObj       = "ERROR"
	FunctionObj    = "FUNCTION"
	StringObj      = "STRING"
	BuiltinObj     = "BUILTIN"
	ArrayObj       = "ARRAY"
	HashObj        = "HASH"
	RepoObj        = "REPO"
	TagObj         = "TAG"
)

Definition of constants for "Type"

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

type Array struct {
	Elements []Object
}

Array represent a standard collection of object

func (*Array) Inspect

func (a *Array) Inspect() string

Inspect the content the Array type

func (*Array) Type

func (a *Array) Type() Type

Type returns ArrayObj (ARRAY)

type Boolean

type Boolean struct {
	Value bool
}

Boolean is a wrapper on a native bool type

func (*Boolean) HashKey

func (b *Boolean) HashKey() HashKey

HashKey returns the hashkey of a boolean TODO optimize perf by caching their return values

func (*Boolean) Inspect

func (b *Boolean) Inspect() string

Inspect the native bool value

func (*Boolean) Type

func (b *Boolean) Type() Type

Type returns BooleanObj (BOOLEAN)

type Builtin

type Builtin struct {
	Fn         BuiltinFunction
	RequireEnv bool
	EnvName    string
}

Builtin represent a builtin construct of the interpreter

func (*Builtin) Inspect

func (b *Builtin) Inspect() string

Inspect simply returns the string "builtin function"

func (*Builtin) Type

func (b *Builtin) Type() Type

Type returns BuiltinObj (BUILTIN)

type BuiltinFunction

type BuiltinFunction func(args ...Object) Object

BuiltinFunction represent a function builtin to the interpreter (meaning not user-defined)

type Environment

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

Environment is the construct that holds the variables (and associated values) declared by the user It also has a reference to its outer environement (if any); allowing for some scoping

func NewEnclosedEnvironment

func NewEnclosedEnvironment(outer *Environment) *Environment

NewEnclosedEnvironment creates new instance that's enclosed in an existing one.

func NewEnvironment

func NewEnvironment() *Environment

NewEnvironment creates new instance with no outer environement (top-level)

func NewEnvironmentWithParams

func NewEnvironmentWithParams(tickets string) *Environment

NewEnvironmentWithParams creates a new instance with some predefined values

func (*Environment) Get

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

Get returns the value of the specified variable name

func (*Environment) Set

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

Set adds an entry to the environment internal store for a new or existing variable

type Error

type Error struct {
	Message string
}

Error is an object that encloses an error message and allows error management within the interpreter

func (*Error) Inspect

func (e *Error) Inspect() string

Inspect returns the error message enclosed in the error object

func (*Error) Type

func (e *Error) Type() Type

Type returns ErrorObj (ERROR)

type Function

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

Function is an executable block

func (*Function) Inspect

func (f *Function) Inspect() string

Inspect the body and parameters of the Function type

func (*Function) Type

func (f *Function) Type() Type

Type returns FunctionObj (FUNCTION)

type Hash

type Hash struct {
	Pairs map[HashKey]HashPair
}

Hash is a simple map, mapping HashKey to HashPair

func (*Hash) Inspect

func (h *Hash) Inspect() string

Inspect returns the string value of the pairs contained in the hash

func (*Hash) Type

func (h *Hash) Type() Type

Type returns HashObj (HASH)

type HashKey

type HashKey struct {
	Type  Type
	Value uint64
}

HashKey is the value (unsigned integer) of the hash key

type HashPair

type HashPair struct {
	Key   Object
	Value Object
}

HashPair is an object that can be inserted into the Hash construct

type Hashable

type Hashable interface {
	HashKey() HashKey
}

Hashable is an interface to be implemented by object that can by hashed

type Integer

type Integer struct {
	Value int64
}

Integer is a wrapper on a native int64 type

func (*Integer) HashKey

func (i *Integer) HashKey() HashKey

HashKey returns the hashkey of an integer TODO optimize perf by caching their return values

func (*Integer) Inspect

func (i *Integer) Inspect() string

Inspect the native int64 tyoe

func (*Integer) Type

func (i *Integer) Type() Type

Type returns IntegerObj (INTEGER)

type Null

type Null struct {
}

Null is the construct used to represent null values in the AST

func (*Null) Inspect

func (n *Null) Inspect() string

Inspect simply returns "null"

func (*Null) Type

func (n *Null) Type() Type

Type returns NullObj (NULL)

type Object

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

Object is the interface to be implement for any and all object that will be stored in the AST

type Repo

type Repo struct {
	Repo scl.GlifRepo
	Path Object
}

Repo is a wrapper for the interpreter of scl.GlifRepo object which itself wraps the *git.Repository

func (*Repo) Inspect

func (r *Repo) Inspect() string

Inspect the specified path (string) of the repo

func (*Repo) Type

func (r *Repo) Type() Type

Type returns RepoObj (REPO)

type ReturnValue

type ReturnValue struct {
	Value Object
}

ReturnValue is a wrapper for whatever value is passed by a return call

func (*ReturnValue) Inspect

func (rv *ReturnValue) Inspect() string

Inspect the inner value of the Object (any object implementing the interface Object)

func (*ReturnValue) Type

func (rv *ReturnValue) Type() Type

Type returns ReturnValueObj (RETURN_VALUE)

type String

type String struct {
	Value string
}

String is a wraper on a native string type

func (*String) HashKey

func (s *String) HashKey() HashKey

HashKey returns the hashkey of a string TODO optimize perf by caching their return values

func (*String) Inspect

func (s *String) Inspect() string

Inspect the native string value

func (*String) Type

func (s *String) Type() Type

Type returns StringObj (STRING)

type Tag

type Tag struct {
	Value Object
	Tag   *object.Tag
}

Tag is a wrapper for the interpreter of the *object.Tag (go-git) object

func (*Tag) Inspect

func (t *Tag) Inspect() string

Inspect the value which is the name of the git tag

func (*Tag) Type

func (t *Tag) Type() Type

Type returns TagObj (TAG)

type Type

type Type string

Type refers to the constant which defines an internal type

Jump to

Keyboard shortcuts

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