object

package
v0.2.10 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NULL_OBJ         = "NULL"
	ERROR_OBJ        = "ERROR"
	RETURN_VALUE_OBJ = "RETURN_VALUE"
	BREAK_VALUE_OBJ  = "BREAK_VALUE"
	ENUM_OBJ         = "ENUM"
	FUNCTION_OBJ     = "FUNCTION"
	BUILTIN_OBJ      = "BUILTIN"
	INTEGER_OBJ      = "INTEGER"
	FLOAT_OBJ        = "FLOAT"
	BOOLEAN_OBJ      = "BOOLEAN"
	STRING_OBJ       = "STRING"
	ARRAY_OBJ        = "ARRAY"
	HASH_OBJ         = "HASH"
)

Variables

View Source
var (
	TRUE  = &Boolean{Value: true}
	FALSE = &Boolean{Value: false}
)
View Source
var (
	// Arguments is argument that is passed from CLI arguments
	Arguments []string

	// StandardInput where is standard input
	StandardInput io.Reader

	// StandardOutput where is standard output
	StandardOutput io.Writer

	// ExitFunction where function responsible for exit
	ExitFunction func(int)
)
View Source
var EPSILON float64 = 0.00000001

EPSILON is used only for internally usage only for now.

View Source
var (
	NULL = &Null{}
)

Functions

func Check

func Check(name string, args []Object, checks ...CheckFunc) error

Check arguments passed to object call we can pass many CheckFunc as you want

func InspectObject

func InspectObject(args ...Object) string

func IsArray

func IsArray(o Object) bool

func IsError

func IsError(o Object) bool

func IsHash

func IsHash(o Object) bool

func IsNumber

func IsNumber(o Object) bool

func IsString

func IsString(o Object) bool

func IsTruthy

func IsTruthy(o Object) bool

Types

type Array

type Array struct {
	Elements []Object
}

func (*Array) Call

func (s *Array) Call(method string, args ...Object) Object

func (*Array) Clone

func (s *Array) Clone() 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) Call

func (s *Boolean) Call(method string, args ...Object) Object

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 Break

type Break struct {
	Value Object
}

func (*Break) Inspect

func (b *Break) Inspect() string

func (*Break) Type

func (b *Break) Type() ObjectType

type Builtin

type Builtin struct {
	Fn BuiltinFunction
}

func NewBuiltin

func NewBuiltin(function BuiltinFunction) *Builtin

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 CallableMethod

type CallableMethod interface {
	Call(method string, args ...Object) Object
}

CallableMethod is use for calling method in data type.

type CheckFunc

type CheckFunc func(name string, args []Object) error

CheckFunc signature for check arguments function

func ExactArgs

func ExactArgs(n int) CheckFunc

ExactArgs expect exact nums arguments

func MinimumArgs

func MinimumArgs(n int) CheckFunc

MinimumArgs check if have at least n arguments

func OneOfType

func OneOfType(types ...ObjectType) CheckFunc

OneOfType almost same as WithTypes but check one of type of ObjectType

func RangeOfArgs

func RangeOfArgs(n, m int) CheckFunc

RangeOfArgs expect n until m arguments

func WithTypes

func WithTypes(types ...ObjectType) CheckFunc

WithTypes combined with ExactArgs it will check if we got ObjectType by it is order.

type Cloneable

type Cloneable interface {
	Clone() Object
}

type Comparable

type Comparable interface {
	Compare(right Object) int8
}

Comparable is the interface for comparing two Object and their underlying values. It is the responsibility of the caller (left) to check for types. E.g.: 1 > 1, it will return -1. left isn't greater than 1.

type Enum

type Enum struct {
	Branches map[string]Object
}

func (*Enum) Inspect

func (en *Enum) Inspect() string

func (*Enum) Type

func (en *Enum) Type() ObjectType

type Environment

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

func NewEnclosedEnvironment

func NewEnclosedEnvironment(outer *Environment) *Environment

func NewEnvironment

func NewEnvironment() *Environment

func (*Environment) Get

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

func (*Environment) Set

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

type Error

type Error struct {
	Message string
}

func NewError

func NewError(message string) *Error

func NewErrorFormat

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

func (*Error) Inspect

func (e *Error) Inspect() string

func (*Error) Type

func (e *Error) Type() ObjectType

type Float

type Float struct {
	Value float64
	// contains filtered or unexported fields
}

func (*Float) Call

func (f *Float) Call(method string, args ...Object) Object

func (*Float) Compare

func (f *Float) Compare(right Object) int8

func (*Float) HashKey

func (f *Float) HashKey() HashKey

func (*Float) Inspect

func (f *Float) Inspect() string

func (*Float) Type

func (f *Float) Type() ObjectType

type FunctionLiteral

type FunctionLiteral struct {
	Parameters []ast.Expression
	Body       *ast.BlockStatement
	Env        *Environment
}

func (*FunctionLiteral) Inspect

func (f *FunctionLiteral) Inspect() string

func (*FunctionLiteral) Type

func (f *FunctionLiteral) Type() ObjectType

type Hash

type Hash struct {
	Pairs map[HashKey]HashPair
}

func (*Hash) Call

func (s *Hash) Call(method string, args ...Object) Object

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
}

HashKey hold "key" on Hash

type HashPair

type HashPair struct {
	Key   Object
	Value Object
}

type Hashable

type Hashable interface {
	HashKey() HashKey
}

Hashable exist for object implement it in order to be used in Hash object

type Integer

type Integer struct {
	Value int64
}

func (*Integer) Call

func (s *Integer) Call(method string, args ...Object) Object

func (*Integer) Compare

func (i *Integer) Compare(right Object) int8

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 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
	// contains filtered or unexported fields
}

func (*String) Call

func (s *String) Call(method string, args ...Object) Object

func (*String) Compare

func (s *String) Compare(right Object) int8

func (*String) HashKey

func (s *String) HashKey() HashKey

func (*String) Inspect

func (s *String) Inspect() string

func (*String) Type

func (s *String) Type() ObjectType

Jump to

Keyboard shortcuts

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