object

package
v0.0.0-...-55fb52d Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InvalidArgLenError = "Wrong number of args to function %s. Want=%d. Got=%d."
	ConvertTypeError   = "Cannot convet type '%s' to type '%s'"
)

some pre defined errors for consistency.

Variables

View Source
var (
	FILE   = &FileHandler{}
	STDIN  = &File{os.NewFile(uintptr(syscall.Stdin), "/dev/stdin")}
	STDOUT = &File{os.NewFile(uintptr(syscall.Stdout), "/dev/stdout")}
	STDERR = &File{os.NewFile(uintptr(syscall.Stderr), "/dev/stderr")}
)

OS VARS

View Source
var (
	TRUE  = &Bool{Value: true}
	FALSE = &Bool{Value: false}
	NONE  = &None{}
)

”””””””””””””””””””””””””””””””””””””” Singleton objects : Only one instance of these needs to be created.

View Source
var BinaryOps = make(map[string]*binaryOp)

BinaryOps : binary operations available to the user.

View Source
var (
	// ZERO : is the number zero
	ZERO = NewInt(0)
)

Functions

This section is empty.

Types

type Array

type Array struct {
	Elements []Object
	Len      int
}

Array : Homogeneous array object, that can store objects of any type. Array conforms to the iterable interface.

func NewArray

func NewArray(elements []Object, length int) *Array

NewArray :

func (*Array) Concat

func (a *Array) Concat(other Object) Object

Concat : Add item to the current string creating a new string.

func (*Array) Contains

func (a *Array) Contains(item Object) Object

Contains :

func (*Array) ConvertType

func (a *Array) ConvertType(which TypeFlag) Object

ConvertType : return the conversion into the specified type

func (*Array) GetItem

func (a *Array) GetItem(key Object) Object

GetItem : return the item at the position provided by the index key

func (*Array) Inspect

func (a *Array) Inspect() string

Inspect : return a string representation of the objects value.

func (*Array) Iter

func (a *Array) Iter() <-chan Object

Iter : loop through items elements in order.

func (*Array) Length

func (a *Array) Length() Object

Length : return the number of items in the Array.

func (*Array) SetItem

func (a *Array) SetItem(key Object, val Object) Object

SetItem : set item at index except char or a string.

func (*Array) Slice

func (a *Array) Slice(start Object, end Object) Object

Slice : return a slice of an arrays elements.

func (*Array) Type

func (a *Array) Type() TypeFlag

Type : return objects type as a TypeFlag

type Bool

type Bool struct{ Value bool }

Bool : builtin bool type.

func NewBool

func NewBool(input bool) *Bool

NewBool : return a reference to either the true or false objects.

func (*Bool) ConvertType

func (b *Bool) ConvertType(which TypeFlag) Object

ConvertType : return the conversion into the specified type

func (*Bool) Hash

func (b *Bool) Hash() HashKey

Hash : hash value of bool

func (*Bool) Inspect

func (b *Bool) Inspect() string

Inspect : return a string representation of the objects value.

func (*Bool) Type

func (b *Bool) Type() TypeFlag

Type : return objects type as a TypeFlag

type Builtin

type Builtin struct {
	Fn      BuiltinFunction
	Name    string
	Info    string
	ArgC    int
	ArgT    []string
	ReturnT string
}

Builtin :

func (*Builtin) ConvertType

func (b *Builtin) ConvertType(which TypeFlag) Object

ConvertType : return the conversion into the specified type

func (*Builtin) Doc

func (b *Builtin) Doc() map[string]string

Doc documentation

func (*Builtin) Inspect

func (b *Builtin) Inspect() string

Inspect : return a string representation of the objects value.

func (*Builtin) Type

func (b *Builtin) Type() TypeFlag

Type : return objects type as a TypeFlag

type BuiltinFunction

type BuiltinFunction func(args ...Object) Object

BuiltinFunction :

type Char

type Char struct{ Value byte }

Char :

func NewChar

func NewChar(value byte) *Char

NewChar : return new initialized instance of the object.

func (*Char) Abs

func (c *Char) Abs() *Char

Abs : return the absolute value of an number

func (*Char) ConvertType

func (c *Char) ConvertType(which TypeFlag) Object

ConvertType : return the conversion into the specified type

func (*Char) Hash

func (c *Char) Hash() HashKey

Hash : hash value of char

func (*Char) Inspect

func (c *Char) Inspect() string

Inspect : return a string representation of the objects value.

func (*Char) Type

func (c *Char) Type() TypeFlag

Type : return objects type as a TypeFlag

type Dict

type Dict struct {
	Items map[HashKey]DictItem
	Len   int
}

Dict :

func NewDict

func NewDict() *Dict

NewDict : return new initialized instance of the object.

func (*Dict) Concat

func (d *Dict) Concat(other Object) Object

Concat : Add item to the current string creating a new string.

func (*Dict) Contains

func (d *Dict) Contains(key Object) Object

Contains :

func (*Dict) ConvertType

func (d *Dict) ConvertType(which TypeFlag) Object

ConvertType : return the conversion into the specified type

func (*Dict) GetItem

func (d *Dict) GetItem(key Object) Object

GetItem : return the item at the position provided by the hashkey

func (*Dict) Inspect

func (d *Dict) Inspect() string

Inspect : return a string representation of the objects value.

func (*Dict) Iter

func (d *Dict) Iter() <-chan Object

Iter : loop through items elements in order.

func (*Dict) Length

func (d *Dict) Length() Object

Length : return the number of items in the Array.

func (*Dict) SetItem

func (d *Dict) SetItem(key Object, val Object) Object

SetItem : set item at index except char or a string.

func (*Dict) Slice

func (d *Dict) Slice(start Object, end Object) Object

Slice : return a slice of an arrays elements.

func (*Dict) Type

func (d *Dict) Type() TypeFlag

Type : return objects type as a TypeFlag

type DictItem

type DictItem struct {
	Key   Object
	Value Object
}

DictItem :

type Environment

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

Environment : Holds the environment variables created by the user. Pretty much a symbol table.

func InitialEnvironment

func InitialEnvironment() *Environment

InitialEnvironment : Define the initial environment scope. with system variables etc.

func NewEnclosedEnvironment

func NewEnclosedEnvironment(outer *Environment) *Environment

NewEnclosedEnvironment : Define a new environment scope within another.

func NewEnvironment

func NewEnvironment() *Environment

NewEnvironment : Define a new environment scope.

func (*Environment) Get

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

Get : get a variable inside the current scope

func (*Environment) GetVar

func (e *Environment) GetVar(name string) (Variable, bool)

GetVar :

func (*Environment) Set

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

Set : set a variable inside the current scope.

type Error

type Error struct{ Message string }

Error : builtin Error type.

func NewError

func NewError(format string, a ...interface{}) *Error

NewError : return new initialized instance of the object.

func (*Error) ConvertType

func (e *Error) ConvertType(which TypeFlag) Object

ConvertType : return the conversion into the specified type

func (*Error) Inspect

func (e *Error) Inspect() string

Inspect : return a string representation of the objects value.

func (*Error) Type

func (e *Error) Type() TypeFlag

Type : return objects type as a TypeFlag

type File

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

File : wrapper around goes file system

func (*File) Close

func (f *File) Close() Object

Close :

func (*File) ConvertType

func (f *File) ConvertType(which TypeFlag) Object

ConvertType : return the conversion into the specified type

func (*File) Inspect

func (f *File) Inspect() string

Inspect : return a string representation of the objects value.

func (*File) Read

func (f *File) Read() Object

Read :

func (*File) Type

func (f *File) Type() TypeFlag

Type : return objects type as a TypeFlag

func (*File) Write

func (f *File) Write(str string) Object

Write :

type FileHandler

type FileHandler struct{}

FileHandler :

func (*FileHandler) Create

func (fh *FileHandler) Create(path string) Object

Create : return a new writable file

func (*FileHandler) Open

func (fh *FileHandler) Open(path string) Object

Open : return a new readable file

type Float

type Float struct{ Value float64 }

Float : builtin float type basically go's float64

func NewFloat

func NewFloat(value float64) *Float

NewFloat : return new initialized instance of the object.

func (*Float) Abs

func (f *Float) Abs() Object

Abs : return the absolute value of an number

func (*Float) ConvertType

func (f *Float) ConvertType(which TypeFlag) Object

ConvertType : return the conversion into the specified type

func (*Float) Hash

func (f *Float) Hash() HashKey

Hash : hash value of float

func (*Float) Inspect

func (f *Float) Inspect() string

Inspect : return a string representation of the objects value.

func (*Float) Type

func (f *Float) Type() TypeFlag

Type : return objects type as a TypeFlag

type Function

type Function struct {
	Parameters []*ast.Identifier
	Name       string
	Stmts      *ast.BlockStatement
	Env        *Environment
}

Function :

func NewFunction

func NewFunction(fn *ast.Function, env *Environment) *Function

NewFunction : ...

func (*Function) ConvertType

func (f *Function) ConvertType(which TypeFlag) Object

ConvertType : return the conversion into the specified type

func (*Function) Inspect

func (f *Function) Inspect() string

Inspect : return a string representation of the objects value.

func (*Function) Type

func (f *Function) Type() TypeFlag

Type : return objects type as a TypeFlag

type HashKey

type HashKey struct {
	Type  TypeFlag
	Value uint64
}

HashKey :

type Hashable

type Hashable interface {
	Object
	// Hash : returns the Hashkey for the objects value
	Hash() HashKey
}

Hashable : the requirements to enable the object to be used as a hash key.

type Int

type Int struct{ Value int }

Int : builtin integer type. -9223372036854775807 and 9223372036854775807

func NewInt

func NewInt(value int) *Int

NewInt : return new initialized instance of the object.

func (*Int) Abs

func (i *Int) Abs() Object

Abs : return the absolute value of an number

func (*Int) ConvertType

func (i *Int) ConvertType(which TypeFlag) Object

ConvertType : return the conversion into the specified type

func (*Int) Hash

func (i *Int) Hash() HashKey

Hash : hash value of int

func (*Int) Inspect

func (i *Int) Inspect() string

Inspect : return a string representation of the objects value.

func (*Int) Type

func (i *Int) Type() TypeFlag

Type : return objects type as a TypeFlag

type Iterable

type Iterable interface {
	Object
	// Length : return the number of items in the iterable
	Length() Object
	// IterItems : return a iterable channel to loop through the items in
	// order.
	Iter() <-chan Object
	// GetItem : get item at location of the provided key.
	GetItem(Object) Object
	// SetItem : set item at location of the provided key.
	SetItem(Object, Object) Object
	// Concat : concat two iterables together.
	Concat(Object) Object
	// Contains : is item in the iterable. would use 'in' operator.
	Contains(Object) Object
	// Slice : return a slice of an iterables elements
	Slice(Object, Object) Object
}

Iterable : the requirements needed for a Object to be an Iterable. eg: Array, String, Dict.

type Lambda

type Lambda struct {
	Parameters []*ast.Identifier
	Expr       ast.Expression
	Env        *Environment
}

Lambda :

func NewLambda

func NewLambda(params []*ast.Identifier, expr ast.Expression, env *Environment) *Lambda

NewLambda : return new initialised instance of the object.

func (*Lambda) ConvertType

func (l *Lambda) ConvertType(which TypeFlag) Object

ConvertType : return the conversion into the specified type

func (*Lambda) Inspect

func (l *Lambda) Inspect() string

Inspect : return a string representation of the objects value.

func (*Lambda) Type

func (l *Lambda) Type() TypeFlag

Type : return objects type as a TypeFlag

type None

type None struct{}

None : builtin None type.

func (*None) ConvertType

func (n *None) ConvertType(which TypeFlag) Object

ConvertType : return the conversion into the specified type

func (*None) Inspect

func (n *None) Inspect() string

Inspect : return a string representation of the objects value.

func (*None) Type

func (n *None) Type() TypeFlag

Type : return objects type as a TypeFlag

type Numeric

type Numeric interface {
	Object
	// Abs : return the absolute value of an number
	Abs() Object
}

Numeric : the requirements needed for a Object to be an Numeric.

type Object

type Object interface {
	// Type : type which is used internally and available to the user through the
	// builtin 'type' function at runtime.
	Type() TypeFlag
	// Inspect : returns the value of the object. Is used to display values to
	// the user.
	Inspect() string
	// ConvertType : Convert an objects type into another type. The default
	// behavior for incompatible conversions is to return an error object.
	ConvertType(which TypeFlag) Object
}

Object : defines the interface for the objects used in the dito programming language.

type ReturnValue

type ReturnValue struct{ Value Object }

ReturnValue : Packages other objects to determine the end objects of programs.

func (*ReturnValue) ConvertType

func (rv *ReturnValue) ConvertType(which TypeFlag) Object

ConvertType : return the conversion into the specified type

func (*ReturnValue) Inspect

func (rv *ReturnValue) Inspect() string

Inspect : return a string representation of the objects value.

func (*ReturnValue) Type

func (rv *ReturnValue) Type() TypeFlag

Type : return objects type as a string

type String

type String struct {
	Value string
}

String : builtin string type

func NewString

func NewString(value string) *String

NewString : return new initialized instance of the object.

func (*String) Concat

func (s *String) Concat(other Object) Object

Concat : Add item to the current string creating a new string.

func (*String) Contains

func (s *String) Contains(sub Object) Object

Contains :

func (*String) ConvertType

func (s *String) ConvertType(which TypeFlag) Object

ConvertType : return the conversion into the specified type

func (*String) GetItem

func (s *String) GetItem(key Object) Object

GetItem : return the char at index

func (*String) Hash

func (s *String) Hash() HashKey

Hash : hash value of string

func (*String) Inspect

func (s *String) Inspect() string

Inspect : return a string representation of the objects value.

func (*String) Iter

func (s *String) Iter() <-chan Object

Iter : loop through items elements in order.

func (*String) Length

func (s *String) Length() Object

Length : return the number of items in the String. An item is an ascii char like in C strings.

func (*String) SetItem

func (s *String) SetItem(key Object, val Object) Object

SetItem : set item at index except char or a string.

func (*String) Slice

func (s *String) Slice(start Object, end Object) Object

Slice : return a slice of an arrays elements.

func (*String) Type

func (s *String) Type() TypeFlag

Type : return objects type as a TypeFlag

type TypeFlag

type TypeFlag int

TypeFlag : type flag for what type of Dito object it is.

const (
	CharType TypeFlag = iota
	IntType
	FloatType
	BoolType
	StringType
	ArrayType
	NoneType
	ErrorType
	ReturnType
	LambdaType
	BultinType
	FunctionType
	DictType
	FileType
)

Define the strings used available to the user to describe objects. Values here will be returned when an objects type method is called.

func (TypeFlag) String

func (t TypeFlag) String() string

type Variable

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

Variable : symbol table entry, keeps track whether varible is mutable or not.

func (*Variable) IsMutable

func (v *Variable) IsMutable() bool

IsMutable : can it be changed

func (*Variable) Unpack

func (v *Variable) Unpack() Object

Unpack : can it be changed

Jump to

Keyboard shortcuts

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