object

package
v0.0.0-...-a130a8b Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	INTEGER_OBJ      = "INTEGER"
	BOOLEAN_OBJ      = "BOOLEAN"
	NULL_OBJ         = "NULL"
	RETURN_VALUE_OBJ = "RETURN_VALUE"
	ERROR_OBJ        = "ERROR"
	FUNCTION_OBJ     = "FUNCTION"
	STRING_OBJ       = "STRING"
	BUILTIN_OBJ      = "BUILTIN"
	ARRAY_OBJ        = "ARRAY"
	HASH_OBJ         = "HASH"
	// TODO: see if this ever gets printed, if so we should call it a `notaclass` or `NAC`
	STRUCT_OBJ = "STRUCT"
	METHOD_OBJ = "METHOD"
	LAZY_OBJ   = "LAZY"
)

Variables

View Source
var (
	NULL  = &Null{}
	TRUE  = &Boolean{Value: true}
	FALSE = &Boolean{Value: false}
)

Functions

This section is empty.

Types

type Array

type Array struct {
	Elements []Object
}

func (*Array) Inspect

func (ao *Array) Inspect() string

func (*Array) Type

func (ao *Array) Type() ObjectType

type Boolean

type Boolean struct {
	Value bool
}

func (*Boolean) HashKey

func (b *Boolean) HashKey() HashKey

func (*Boolean) Inspect

func (b *Boolean) Inspect() string

func (*Boolean) Type

func (b *Boolean) Type() ObjectType

type Builtin

type Builtin struct {
	Fn BuiltinFunction
}

func (*Builtin) Inspect

func (b *Builtin) Inspect() string

func (*Builtin) Type

func (b *Builtin) Type() ObjectType

type BuiltinFunction

type BuiltinFunction func(args ...Object) Object

type Environment

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

func NewEnclosedEnvironment

func NewEnclosedEnvironment(outer *Environment) *Environment

func NewEnvironment

func NewEnvironment() *Environment

func OnlyStructs

func OnlyStructs(env *Environment) *Environment

Hack for now that allows us to access all the defined structs without accessing any variables. A better solution would be to store that in a separate environment

func (*Environment) AddAcknowledgement

func (e *Environment) AddAcknowledgement(ack string)

func (*Environment) AllowsPrivateAccess

func (e *Environment) AllowsPrivateAccess(str *ast.Struct) bool

func (*Environment) Assign

func (e *Environment) Assign(name string, val Object) (Object, error)

assign expects the variable to be declared and findable in the environment chain somewhere. Wherever it's found in the chain we'll store the new value

func (*Environment) Get

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

func (*Environment) GetStruct

func (e *Environment) GetStruct(name string) (*ast.Struct, bool)

func (*Environment) IsCurrentStructInstance

func (e *Environment) IsCurrentStructInstance(structInstance *StructInstance) bool

func (*Environment) Set

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

Set is for declaring variables and then assigning to them in the current environment. If the variable is declared in a parent environment, that variable will now be shadowed

func (*Environment) SetCurrentStructInstance

func (e *Environment) SetCurrentStructInstance(structInstance *StructInstance)

func (*Environment) SetStruct

func (e *Environment) SetStruct(structDef *ast.Struct) *ast.Struct

func (*Environment) String

func (e *Environment) String() string

type Error

type Error struct {
	Message string
}

func NewError

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

func (*Error) Inspect

func (e *Error) Inspect() string

func (*Error) Type

func (e *Error) Type() ObjectType

type Function

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

func (*Function) Inspect

func (f *Function) Inspect() string

func (*Function) Type

func (f *Function) Type() ObjectType

type Hash

type Hash struct {
	Pairs map[HashKey]HashPair
}

func (*Hash) Inspect

func (h *Hash) Inspect() string

func (*Hash) Type

func (h *Hash) Type() ObjectType

type HashKey

type HashKey struct {
	Type  ObjectType
	Value uint64
}

type HashPair

type HashPair struct {
	Key   Object
	Value Object
}

type Hashable

type Hashable interface {
	HashKey() HashKey
}

type Integer

type Integer struct {
	Value int64
}

func (*Integer) HashKey

func (i *Integer) HashKey() HashKey

func (*Integer) Inspect

func (i *Integer) Inspect() string

func (*Integer) Type

func (i *Integer) Type() ObjectType

type LazyObject

type LazyObject struct {
	Right ast.Node
}

func (*LazyObject) Inspect

func (self *LazyObject) Inspect() string

func (*LazyObject) Type

func (self *LazyObject) Type() ObjectType

type Method

type Method struct {
	Name         string
	StructMethod ast.StructMethod

	// not sure if we need an env here, or if we do which env to pass.
	Env *Environment

	StructInstance *StructInstance
}

func (*Method) Inspect

func (self *Method) Inspect() string

func (*Method) Type

func (self *Method) Type() ObjectType

type Null

type Null struct{}

func (*Null) Inspect

func (n *Null) Inspect() string

func (*Null) Type

func (n *Null) Type() ObjectType

type Object

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

type ObjectType

type ObjectType string

type ReturnValue

type ReturnValue struct {
	Value Object
}

func (*ReturnValue) Inspect

func (rv *ReturnValue) Inspect() string

func (*ReturnValue) Type

func (rv *ReturnValue) Type() ObjectType

type String

type String struct {
	Value string
}

func (*String) HashKey

func (s *String) HashKey() HashKey

func (*String) Inspect

func (s *String) Inspect() string

func (*String) Type

func (s *String) Type() ObjectType

type StructInstance

type StructInstance struct {
	Fields map[string]Object
	Struct *ast.Struct
}

func (*StructInstance) EvolveInto

func (self *StructInstance) EvolveInto(other *StructInstance)

func (*StructInstance) GetFieldValue

func (self *StructInstance) GetFieldValue(fieldName string) Object

func (*StructInstance) GetMethod

func (self *StructInstance) GetMethod(methodName string) Object

func (*StructInstance) Inspect

func (self *StructInstance) Inspect() string

func (*StructInstance) IsField

func (self *StructInstance) IsField(fieldName string) bool

func (*StructInstance) IsMethod

func (self *StructInstance) IsMethod(methodName string) bool

func (*StructInstance) IsPublicField

func (self *StructInstance) IsPublicField(fieldName string) bool

assumes we've already determined that the field exists

func (*StructInstance) IsPublicMethod

func (self *StructInstance) IsPublicMethod(methodName string) bool

assumes we've already determined that the method exists

func (*StructInstance) SetFieldValue

func (self *StructInstance) SetFieldValue(fieldName string, value Object) Object

func (*StructInstance) Type

func (self *StructInstance) Type() ObjectType

Jump to

Keyboard shortcuts

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