eval

package
v0.0.0-...-3085ebc Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NUMBER_OBJ       = "NUMBER"
	NIL_OBJ          = "NIL_OBJ"
	BOOLEAN_OBJ      = "BOOLEAN"
	STRING_OBJ       = "STRING"
	ERROR_OBJ        = "ERROR"
	RETURN_VALUE_OBJ = "RETURN_VALUE"
	FUNCTION_OBJ     = "FUNCTION"
	BUILTIN_OBJ      = "BUILTIN"
	ARRAY_OBJ        = "ARRAY"
	HASH_OBJ         = "HASH"
)

Variables

View Source
var (
	ERR_ARGUMENT     = "wrong number of arguments. expected=%d, got=%d"
	ERR_NOMETHOD     = "undefined method '%s' for object %s"
	ERR_INDEX        = "index error: '%d' out of range"
	ERR_KEY          = "key error: type %s is not hashable"
	ERR_PREFIXOP     = "unsupported operator for prefix expression:'%s' and type: %s"
	ERR_INFIXOP      = "unsupported operator for infix expression: %s '%s' %s"
	ERR_UNKNOWNIDENT = "unknown identifier: '%s' is not defined"
	ERR_DIVIDEBYZERO = "divide by zero"
	ERR_NOTFUNCTION  = "not a function: %s"
	ERR_NOINDEXABLE  = "index error: type %s is not indexable"
)
View Source
var (
	TRUE  = &Boolean{Bool: true}
	FALSE = &Boolean{Bool: false}
	NIL   = &Nil{}
)

Functions

func IsTrue

func IsTrue(obj Object) bool

Types

type Array

type Array struct {
	Members []Object
}

func (*Array) CallMethod

func (a *Array) CallMethod(line string, scope *Scope, method string, args ...Object) Object

func (*Array) Inspect

func (a *Array) Inspect() string

func (*Array) Type

func (a *Array) Type() ObjectType

type Boolean

type Boolean struct {
	Bool bool
}

func NewBooleanObj

func NewBooleanObj(b bool) *Boolean

func (*Boolean) CallMethod

func (b *Boolean) CallMethod(line string, scope *Scope, 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 Builtin

type Builtin struct {
	Fn BuiltinFunc
}

func (*Builtin) CallMethod

func (b *Builtin) CallMethod(line string, scope *Scope, method string, args ...Object) Object

func (*Builtin) Inspect

func (b *Builtin) Inspect() string

func (*Builtin) Type

func (b *Builtin) Type() ObjectType

type BuiltinFunc

type BuiltinFunc func(line string, scope *Scope, args ...Object) Object

type Error

type Error struct {
	Message string
}

func (*Error) CallMethod

func (e *Error) CallMethod(line string, scope *Scope, method string, args ...Object) Object

func (*Error) Inspect

func (e *Error) Inspect() string

func (*Error) Type

func (e *Error) Type() ObjectType

type Function

type Function struct {
	Literal *ast.FunctionLiteral
	Scope   *Scope
}

func (*Function) CallMethod

func (f *Function) CallMethod(line string, scope *Scope, method string, args ...Object) Object

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 NewHash

func NewHash() *Hash

func (*Hash) CallMethod

func (h *Hash) CallMethod(line string, scope *Scope, 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
}

type HashPair

type HashPair struct {
	Key   Object
	Value Object
}

type Hashable

type Hashable interface {
	HashKey() HashKey
}

type Nil

type Nil struct {
}

func NewNil

func NewNil(s string) *Nil

func (*Nil) CallMethod

func (n *Nil) CallMethod(line string, scope *Scope, method string, args ...Object) Object

func (*Nil) Inspect

func (n *Nil) Inspect() string

func (*Nil) Type

func (n *Nil) Type() ObjectType

type Number

type Number struct {
	Value float64
}

func NewNumber

func NewNumber(f float64) *Number

func (*Number) CallMethod

func (n *Number) CallMethod(line string, scope *Scope, method string, args ...Object) Object

func (*Number) HashKey

func (n *Number) HashKey() HashKey

func (*Number) Inspect

func (n *Number) Inspect() string

func (*Number) Type

func (n *Number) Type() ObjectType

type Object

type Object interface {
	Type() ObjectType
	Inspect() string
	CallMethod(line string, scope *Scope, method string, args ...Object) Object
}

func Eval

func Eval(node ast.Node, scope *Scope) (val Object)

type ObjectType

type ObjectType string

object

type ReturnValue

type ReturnValue struct {
	Value Object
}

func (*ReturnValue) CallMethod

func (rv *ReturnValue) CallMethod(line string, scope *Scope, method string, args ...Object) Object

func (*ReturnValue) Inspect

func (rv *ReturnValue) Inspect() string

func (*ReturnValue) Type

func (rv *ReturnValue) Type() ObjectType

type Scope

type Scope struct {
	Writer io.Writer
	// contains filtered or unexported fields
}

func NewScope

func NewScope(p *Scope, w io.Writer) *Scope

func (*Scope) DebugPrint

func (s *Scope) DebugPrint(indent string)

func (*Scope) Del

func (s *Scope) Del(name string)

func (*Scope) Get

func (s *Scope) Get(name string) (Object, bool)

func (*Scope) GetKeys

func (s *Scope) GetKeys() []string

Get all the keys of the scope.

func (*Scope) Set

func (s *Scope) Set(name string, val Object) Object

type String

type String struct {
	String string
}

func NewString

func NewString(s string) *String

func (*String) CallMethod

func (s *String) CallMethod(line string, scope *Scope, method string, args ...Object) Object

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