object

package
v0.0.0-...-e334538 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2021 License: MIT Imports: 5 Imported by: 5

Documentation

Index

Constants

View Source
const (
	NumberType   = "number"
	BooleanType  = "boolean"
	StringType   = "string"
	ListType     = "list"
	TupleType    = "tuple"
	MapType      = "map"
	NilType      = "nil"
	FunctionType = "function"
	MethodType   = "method"
	BuiltinType  = "builtin"
	ModelType    = "model"
	IterType     = "iter"
)

The set of available types in Radon.

Variables

View Source
var Builtins = make(map[string]*Builtin)

Builtins contains every builtin.

Functions

func IsTruthy

func IsTruthy(o Object) bool

IsTruthy checks whether or not an object is "truthy"

Types

type Boolean

type Boolean struct {
	Value bool
	// contains filtered or unexported fields
}

A Boolean is either true or false.

func (*Boolean) Equals

func (b *Boolean) Equals(other Object) bool

Equals checks whether or not two objects are equal to each other.

func (*Boolean) Infix

func (b *Boolean) Infix(op string, right Object) (Object, bool)

Infix applies a infix operator to an object, returning the result. If the operation cannot be performed, (nil, false) is returned.

func (*Boolean) Items

func (d *Boolean) Items() ([]Object, bool)

func (*Boolean) Iter

func (d *Boolean) Iter() (Iterable, bool)

func (*Boolean) Numeric

func (b *Boolean) Numeric() (float64, bool)

Numeric returns the numeric value of an object, or false if it can't be a number.

func (*Boolean) Prefix

func (b *Boolean) Prefix(op string) (Object, bool)

Prefix applies a prefix operator to an object, returning the result. If the operation cannot be performed, (nil, false) is returned.

func (*Boolean) SetSubscript

func (d *Boolean) SetSubscript(Object, Object) bool

func (*Boolean) String

func (b *Boolean) String() string

func (*Boolean) Subscript

func (d *Boolean) Subscript(Object) (Object, bool)

func (*Boolean) Type

func (b *Boolean) Type() Type

Type returns the type of an Object.

type Builtin

type Builtin struct {
	Name string
	Fn   func(args ...Object) (result Object, errorType string, errorMessage string)
	// contains filtered or unexported fields
}

A Builtin is a function which has been written in Go but is callable from a Radon program.

func (*Builtin) Equals

func (b *Builtin) Equals(other Object) bool

Equals checks if two builtins are equal to each-other. Two builtins are equal if their names are the same.

func (*Builtin) Infix

func (b *Builtin) Infix(op string, right Object) (Object, bool)

Infix applies a infix operator to an object, returning the result. If the operation cannot be performed, (nil, false) is returned.

func (*Builtin) Items

func (d *Builtin) Items() ([]Object, bool)

func (*Builtin) Iter

func (d *Builtin) Iter() (Iterable, bool)

func (*Builtin) Numeric

func (d *Builtin) Numeric() (float64, bool)

func (*Builtin) Prefix

func (b *Builtin) Prefix(op string) (Object, bool)

Prefix applies a prefix operator to an object, returning the result. If the operation cannot be performed, (nil, false) is returned.

func (*Builtin) SetSubscript

func (d *Builtin) SetSubscript(Object, Object) bool

func (*Builtin) String

func (b *Builtin) String() string

func (*Builtin) Subscript

func (d *Builtin) Subscript(Object) (Object, bool)

func (*Builtin) Type

func (b *Builtin) Type() Type

Type returns the type of an Object.

type Function

type Function struct {
	Parameters []string
	Code       bytecode.Code
	Constants  []Object
	Names      []string
	Jumps      []int
	Self       *Map
	// contains filtered or unexported fields
}

A Function is a piece of code which can be called from somewhere else, pushing a frame to the VM's frame stack. A Function is usually referred to as a Method if .Self != nil.

func (*Function) Equals

func (f *Function) Equals(other Object) bool

Equals checks whether or not two objects are equal to each other.

func (*Function) Infix

func (f *Function) Infix(op string, right Object) (Object, bool)

Infix applies a infix operator to an object, returning the result. If the operation cannot be performed, (nil, false) is returned.

func (*Function) IsMethod

func (f *Function) IsMethod() bool

IsMethod checks whether on not a function is a method - i.e., a function is a method if Self != nil.

func (*Function) Items

func (d *Function) Items() ([]Object, bool)

func (*Function) Iter

func (d *Function) Iter() (Iterable, bool)

func (*Function) Numeric

func (d *Function) Numeric() (float64, bool)

func (*Function) Prefix

func (f *Function) Prefix(op string) (Object, bool)

Prefix applies a prefix operator to an object, returning the result. If the operation cannot be performed, (nil, false) is returned.

func (*Function) SetSubscript

func (d *Function) SetSubscript(Object, Object) bool

func (*Function) String

func (f *Function) String() string

func (*Function) Subscript

func (d *Function) Subscript(Object) (Object, bool)

func (*Function) Type

func (f *Function) Type() Type

Type returns the type of an Object.

type Iterable

type Iterable interface {
	Object
	Next() (Object, bool)
}

An Iterable object can be iterated and looped over in for-loops. It is a superset of the Object interface.

type List

type List struct {
	Value []Object
	// contains filtered or unexported fields
}

A List is a dynamic mutable linked list.

func (*List) Equals

func (l *List) Equals(other Object) bool

Equals checks whether or not two objects are equal to each other.

func (*List) Infix

func (l *List) Infix(op string, right Object) (Object, bool)

Infix applies a infix operator to an object, returning the result. If the operation cannot be performed, (nil, false) is returned.

func (*List) Items

func (l *List) Items() ([]Object, bool)

Items returns a slice containing all objects in an Object, or false otherwise.

func (*List) Iter

func (l *List) Iter() (Iterable, bool)

Iter creates an iterable from an Object.

func (*List) Numeric

func (d *List) Numeric() (float64, bool)

func (*List) Prefix

func (l *List) Prefix(op string) (Object, bool)

Prefix applies a prefix operator to an object, returning the result. If the operation cannot be performed, (nil, false) is returned.

func (*List) SetSubscript

func (l *List) SetSubscript(index Object, to Object) bool

SetSubscript sets the value of a subscript of an Object, e.g. foo[bar] = baz. Returns false if it can't be done.

func (*List) String

func (l *List) String() string

func (*List) Subscript

func (d *List) Subscript(Object) (Object, bool)

func (*List) Type

func (l *List) Type() Type

Type returns the type of an Object.

type ListIterable

type ListIterable struct {
	List  *List
	Index int
	// contains filtered or unexported fields
}

A ListIterable is an iterable which operates over each element in a list.

func (*ListIterable) Equals

func (i *ListIterable) Equals(_ Object) bool

Equals checks whether or not two objects are equal to each other.

func (*ListIterable) Infix

func (d *ListIterable) Infix(string, Object) (Object, bool)

func (*ListIterable) Items

func (d *ListIterable) Items() ([]Object, bool)

func (*ListIterable) Iter

func (i *ListIterable) Iter() (Iterable, bool)

Iter turns an object into an iterable.

func (*ListIterable) Next

func (i *ListIterable) Next() (Object, bool)

Next returns the next object from the iterable. If false is returned as the second return value, the iterable has finished.

func (*ListIterable) Numeric

func (d *ListIterable) Numeric() (float64, bool)

func (*ListIterable) Prefix

func (d *ListIterable) Prefix(string) (Object, bool)

func (*ListIterable) SetSubscript

func (d *ListIterable) SetSubscript(Object, Object) bool

func (*ListIterable) String

func (i *ListIterable) String() string

func (*ListIterable) Subscript

func (d *ListIterable) Subscript(Object) (Object, bool)

func (*ListIterable) Type

func (i *ListIterable) Type() Type

Type returns the type of an Object.

type Map

type Map struct {
	Keys   map[string]Object
	Values map[string]Object
	// contains filtered or unexported fields
}

A Map maps keys to values, where keys and values can be any type.

Keys maps the hashes to the keys they were hashed from, and Values maps the hashes to the keys' corresponding values.

func (*Map) Equals

func (m *Map) Equals(o Object) bool

Equals checks whether or not two objects are equal to each other.

func (*Map) Infix

func (m *Map) Infix(op string, right Object) (Object, bool)

Infix applies a infix operator to an object, returning the result. If the operation cannot be performed, (nil, false) is returned.

func (*Map) Items

func (m *Map) Items() ([]Object, bool)

Items returns a slice containing all objects in an Object, or false otherwise.

func (*Map) Iter

func (d *Map) Iter() (Iterable, bool)

func (*Map) Numeric

func (d *Map) Numeric() (float64, bool)

func (*Map) Prefix

func (m *Map) Prefix(op string) (Object, bool)

Prefix applies a prefix operator to an object, returning the result. If the operation cannot be performed, (nil, false) is returned.

func (*Map) SetSubscript

func (m *Map) SetSubscript(key Object, val Object) bool

SetSubscript sets the value of a subscript of an Object, e.g. foo[bar] = baz. Returns false if it can't be done.

func (*Map) String

func (m *Map) String() string

func (*Map) Subscript

func (m *Map) Subscript(key Object) (Object, bool)

Subscript subscrips an Object, e.g. foo[bar], or returns false if it can't be done.

func (*Map) Type

func (m *Map) Type() Type

Type returns the type of an Object.

type Nil

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

Nil represents the absence of any useful value.

func (*Nil) Equals

func (n *Nil) Equals(other Object) bool

Equals checks whether or not two objects are equal to each other.

func (*Nil) Infix

func (n *Nil) Infix(op string, right Object) (Object, bool)

Infix applies a infix operator to an object, returning the result. If the operation cannot be performed, (nil, false) is returned.

func (*Nil) Items

func (d *Nil) Items() ([]Object, bool)

func (*Nil) Iter

func (d *Nil) Iter() (Iterable, bool)

func (*Nil) Numeric

func (n *Nil) Numeric() (float64, bool)

Numeric returns the numeric value of an object, or false if it can't be a number.

func (*Nil) Prefix

func (n *Nil) Prefix(op string) (Object, bool)

Prefix applies a prefix operator to an object, returning the result. If the operation cannot be performed, (nil, false) is returned.

func (*Nil) SetSubscript

func (d *Nil) SetSubscript(Object, Object) bool

func (*Nil) String

func (n *Nil) String() string

func (*Nil) Subscript

func (d *Nil) Subscript(Object) (Object, bool)

func (*Nil) Type

func (n *Nil) Type() Type

Type returns the type of an Object.

type Number

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

A Number is a 64-bit floating point decimal.

func (*Number) Equals

func (n *Number) Equals(other Object) bool

Equals checks whether or not two objects are equal to each other.

func (*Number) Infix

func (n *Number) Infix(op string, right Object) (Object, bool)

Infix applies a infix operator to an object, returning the result. If the operation cannot be performed, (nil, false) is returned.

func (*Number) Items

func (d *Number) Items() ([]Object, bool)

func (*Number) Iter

func (d *Number) Iter() (Iterable, bool)

func (*Number) Numeric

func (n *Number) Numeric() (float64, bool)

Numeric returns the numeric value of an object, or false if it can't be a number.

func (*Number) Prefix

func (n *Number) Prefix(op string) (Object, bool)

Prefix applies a prefix operator to an object, returning the result. If the operation cannot be performed, (nil, false) is returned.

func (*Number) SetSubscript

func (d *Number) SetSubscript(Object, Object) bool

func (*Number) String

func (n *Number) String() string

func (*Number) Subscript

func (d *Number) Subscript(Object) (Object, bool)

func (*Number) Type

func (n *Number) Type() Type

Type returns the type of an Object.

type Object

type Object interface {
	String() string
	Equals(Object) bool
	Type() Type

	// Prefix performs a prefix operation on an Object.
	// operator can be one of:
	// + - ! ,
	// If the 2nd return value is false, an error is raised.
	Prefix(operator string) (Object, bool)

	// Infix performs an infix operation on an Object.
	// operator can be one of:
	// + - * / == != < > || && | & ^ // % <= >= . ,
	// If the 2nd return value is false, an error is raised.
	Infix(operator string, right Object) (Object, bool)

	// Numeric returns the numeric value of an Object.
	// If the 2nd return value is false, an error is raised.
	Numeric() (float64, bool)

	// Items returns a slice of Objects representing an Object.
	// If the 2nd return value is false, an error is raised.
	Items() ([]Object, bool)

	// Subscript implements the [] operator, e.g. list[5]
	Subscript(Object) (Object, bool)

	// SetSubscript implements assigning to the [] operator, e.g. list[5] = "foo"
	SetSubscript(index Object, to Object) bool

	// Iter makes an iterable from the object if possible
	Iter() (Iterable, bool)
}

An Object is the interface which every Radon object implements.

type String

type String struct {
	Value string
	// contains filtered or unexported fields
}

A String is a UTF-8 encoded Unicode string.

func (*String) Equals

func (s *String) Equals(other Object) bool

Equals checks whether or not two objects are equal to each other.

func (*String) Infix

func (s *String) Infix(op string, right Object) (Object, bool)

Infix applies a infix operator to an object, returning the result. If the operation cannot be performed, (nil, false) is returned.

func (*String) Items

func (s *String) Items() ([]Object, bool)

Items returns a slice containing all objects in an Object, or false otherwise.

func (*String) Iter

func (s *String) Iter() (Iterable, bool)

Iter creates an iterable from an Object.

func (*String) Numeric

func (d *String) Numeric() (float64, bool)

func (*String) Prefix

func (s *String) Prefix(op string) (Object, bool)

Prefix applies a prefix operator to an object, returning the result. If the operation cannot be performed, (nil, false) is returned.

func (*String) SetSubscript

func (s *String) SetSubscript(index Object, to Object) bool

SetSubscript sets the value of a subscript of an Object, e.g. foo[bar] = baz. Returns false if it can't be done.

func (*String) String

func (s *String) String() string

func (*String) Subscript

func (d *String) Subscript(Object) (Object, bool)

func (*String) Type

func (s *String) Type() Type

Type returns the type of an Object.

type Tuple

type Tuple struct {
	Value []Object
	// contains filtered or unexported fields
}

A Tuple is an statically-sized collection of items.

func (*Tuple) Equals

func (t *Tuple) Equals(other Object) bool

Equals checks whether or not two objects are equal to each other.

func (*Tuple) Infix

func (t *Tuple) Infix(op string, right Object) (Object, bool)

Infix applies a infix operator to an object, returning the result. If the operation cannot be performed, (nil, false) is returned.

func (*Tuple) Items

func (t *Tuple) Items() ([]Object, bool)

Items returns a slice containing all objects in an Object, or false otherwise.

func (*Tuple) Iter

func (d *Tuple) Iter() (Iterable, bool)

func (*Tuple) Numeric

func (d *Tuple) Numeric() (float64, bool)

func (*Tuple) Prefix

func (t *Tuple) Prefix(op string) (Object, bool)

Prefix applies a prefix operator to an object, returning the result. If the operation cannot be performed, (nil, false) is returned.

func (*Tuple) SetSubscript

func (t *Tuple) SetSubscript(index Object, to Object) bool

SetSubscript sets the value of a subscript of an Object, e.g. foo[bar] = baz. Returns false if it can't be done.

func (*Tuple) String

func (t *Tuple) String() string

func (*Tuple) Subscript

func (d *Tuple) Subscript(Object) (Object, bool)

func (*Tuple) Type

func (t *Tuple) Type() Type

Type returns the type of an Object.

type Type

type Type string

The Type of an Object indicates what type of object it is.

Jump to

Keyboard shortcuts

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