vm

package
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2022 License: BSD-2-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxDoCallSearch = 3
)

Variables

View Source
var (
	NotOperable   = fmt.Errorf("not operable")
	NotIndexable  = fmt.Errorf("not indexable")
	NotComparable = fmt.Errorf("not comparable")
)
View Source
var (
	NotHashable = fmt.Errorf("not hashable")
)
View Source
var (
	SymbolNotFoundError = "symbol not found: %s"
)

Functions

func Float

func Float[T constraints.Float](value *Value) T

func Int

func Int[T constraints.Integer](value *Value) T

Int interpret the Value as a go int64

Types

type Callback

type Callback func(argument ...*Value) (*Value, error)

type ClassInfo

type ClassInfo struct {
	Bases    []*Value
	Bytecode []byte
	// contains filtered or unexported fields
}

type FuncInfo

type FuncInfo struct {
	Arguments []string
	Bytecode  []byte
}

type Hash

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

func (*Hash) Copy

func (h *Hash) Copy() *Hash

Copy creates a copy of the hash

func (*Hash) Del

func (h *Hash) Del(key *Value) error

Del deletes a key from the hash

func (*Hash) Get

func (h *Hash) Get(key *Value) (*Value, error)

Get retrieves a value based on the key

func (*Hash) In

func (h *Hash) In(key *Value) (bool, error)

In verifies the key is inside the hash

func (*Hash) Set

func (h *Hash) Set(key, value *Value) error

Set sets a key value pair

func (*Hash) Size

func (h *Hash) Size() int64

Size Returns the internal size of the hash

type HashKeyValue

type HashKeyValue struct {
	Key   *Value
	Value *Value
}

type Loader

type Loader func(plasma *Plasma) *Value

type Plasma

type Plasma struct {
	Stdin          io.Reader
	Stdout, Stderr io.Writer
	// contains filtered or unexported fields
}

func NewVM

func NewVM(stdin io.Reader, stdout, stderr io.Writer) *Plasma

func (*Plasma) ArrayClass

func (plasma *Plasma) ArrayClass() *Value

func (*Plasma) BoolClass

func (plasma *Plasma) BoolClass() *Value

func (*Plasma) BytesClass

func (plasma *Plasma) BytesClass() *Value

func (*Plasma) Execute

func (plasma *Plasma) Execute(bytecode []byte) (result chan *Value, err chan error, stop chan struct{})

func (*Plasma) ExecuteString

func (plasma *Plasma) ExecuteString(scriptCode string) (result chan *Value, err chan error, stop chan struct{})

func (*Plasma) False

func (plasma *Plasma) False() *Value

func (*Plasma) FloatClass

func (plasma *Plasma) FloatClass() *Value

func (*Plasma) FromValue

func (plasma *Plasma) FromValue(value *Value) (any, error)

FromValue maps a Go value to a plasma Value, this function easy the work for interfacing with plasma

func (*Plasma) FunctionClass

func (plasma *Plasma) FunctionClass() *Value

func (*Plasma) HashClass

func (plasma *Plasma) HashClass() *Value

func (*Plasma) IntClass

func (plasma *Plasma) IntClass() *Value

func (*Plasma) Load

func (plasma *Plasma) Load(symbol string, loader Loader)

func (*Plasma) LoadGo added in v1.1.6

func (plasma *Plasma) LoadGo(symbol string, v any) error

func (*Plasma) MetaClass

func (plasma *Plasma) MetaClass() *Value

func (*Plasma) NewArray

func (plasma *Plasma) NewArray(values []*Value) *Value

NewArray Creates a new array Value

func (*Plasma) NewBool

func (plasma *Plasma) NewBool(b bool) *Value

NewBool Creates a new bool Value

func (*Plasma) NewBuiltInFunction

func (plasma *Plasma) NewBuiltInFunction(parent *Symbols, callback Callback) *Value

NewBuiltInFunction Creates a new built-in function Value

func (*Plasma) NewBytes

func (plasma *Plasma) NewBytes(contents []byte) *Value

NewBytes Creates a new bytes Value

func (*Plasma) NewClass

func (plasma *Plasma) NewClass() *Value

NewClass Creates a new class Value

func (*Plasma) NewFloat

func (plasma *Plasma) NewFloat(f float64) *Value

NewFloat creates a new float Value

func (*Plasma) NewHash

func (plasma *Plasma) NewHash(hash *Hash) *Value

NewHash Creates a new hash Value

func (*Plasma) NewInt

func (plasma *Plasma) NewInt(i int64) *Value

NewInt Creates a new int Value

func (*Plasma) NewInternalHash

func (plasma *Plasma) NewInternalHash() *Hash

NewInternalHash Creates a new Hash object to handle hashing operations

func (*Plasma) NewNone

func (plasma *Plasma) NewNone() *Value

NewNone Creates a new none Value

func (*Plasma) NewString

func (plasma *Plasma) NewString(contents []byte) *Value

NewString Creates a new string Value

func (*Plasma) NewTuple

func (plasma *Plasma) NewTuple(values []*Value) *Value

NewTuple Creates a new tuple Value

func (*Plasma) NewValue

func (plasma *Plasma) NewValue(parent *Symbols, typeId TypeId, class *Value) *Value

NewValue Creates a new Value

func (*Plasma) None

func (plasma *Plasma) None() *Value

func (*Plasma) NoneTypeClass

func (plasma *Plasma) NoneTypeClass() *Value

func (*Plasma) RootSymbols

func (plasma *Plasma) RootSymbols() *Symbols

func (*Plasma) StringClass

func (plasma *Plasma) StringClass() *Value

func (*Plasma) ToValue

func (plasma *Plasma) ToValue(symbols *Symbols, v any) (*Value, error)

ToValue maps a Plasma Value to a Go value, this function easy the work for interfacing with plasma

func (*Plasma) True

func (plasma *Plasma) True() *Value

func (*Plasma) TupleClass

func (plasma *Plasma) TupleClass() *Value

func (*Plasma) ValueClass

func (plasma *Plasma) ValueClass() *Value

func (*Plasma) ZeroCopyArray

func (plasma *Plasma) ZeroCopyArray(vt *Symbols, v any) *Value

ZeroCopyArray transform a slice Integers or Floats to a readonly array

type PlasmaCallback

type PlasmaCallback func(arg ...any) (any, error)

type Symbols

type Symbols struct {
	Parent *Symbols
	// contains filtered or unexported fields
}

func NewSymbols

func NewSymbols(parent *Symbols) *Symbols

NewSymbols creates a new symbol table

func (*Symbols) Del

func (symbols *Symbols) Del(name string) error

Del deletes a symbol

func (*Symbols) Get

func (symbols *Symbols) Get(name string) (*Value, error)

Get retrieves a value based on the symbol

func (*Symbols) Set

func (symbols *Symbols) Set(name string, value *Value)

Set Assigns a value to a symbol

type TypeId

type TypeId int
const (
	ValueId TypeId = iota
	StringId
	BytesId
	BoolId
	NoneId
	IntId
	FloatId
	ArrayId
	TupleId
	HashId
	BuiltInFunctionId
	FunctionId
	BuiltInClassId
	ClassId
)

type Value

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

func (*Value) ArrayEqual

func (value *Value) ArrayEqual(other *Value) bool

func (*Value) Bool

func (value *Value) Bool() bool

Bool interpret the Value as a go bool

func (*Value) BoolEqual

func (value *Value) BoolEqual(other *Value) bool

func (*Value) BuiltInClassEqual

func (value *Value) BuiltInClassEqual(other *Value) bool

func (*Value) BuiltInFunctionEqual

func (value *Value) BuiltInFunctionEqual(other *Value) bool

func (*Value) Bytes

func (value *Value) Bytes() []byte

Bytes interpret the Value as a go []byte

func (*Value) BytesEqual

func (value *Value) BytesEqual(other *Value) bool

func (*Value) Call

func (value *Value) Call(argument ...*Value) (*Value, error)

func (*Value) ClassEqual

func (value *Value) ClassEqual(other *Value) bool

func (*Value) Del

func (value *Value) Del(symbol string) error

Del deletes the reference of the value named by the symbol

func (*Value) Equal

func (value *Value) Equal(other *Value) bool

func (*Value) FloatEqual

func (value *Value) FloatEqual(other *Value) bool

func (*Value) FunctionEqual

func (value *Value) FunctionEqual(other *Value) bool

func (*Value) Get

func (value *Value) Get(symbol string) (*Value, error)

Get Retrieves the value named as the symbol

func (*Value) GetAny

func (value *Value) GetAny() any

GetAny returns whatever the internal value contains

func (*Value) GetBool

func (value *Value) GetBool() bool

GetBool cast the internal value to bool

func (*Value) GetBytes

func (value *Value) GetBytes() []byte

GetBytes cast the internal value to []byte

func (*Value) GetCallback

func (value *Value) GetCallback() Callback

GetCallback cast the internal value to Callback

func (*Value) GetClass

func (value *Value) GetClass() *Value

func (*Value) GetClassInfo

func (value *Value) GetClassInfo() *ClassInfo

GetClassInfo cast the internal value to *ClassInfo

func (*Value) GetFloat64

func (value *Value) GetFloat64() float64

GetFloat64 cast the internal value to float64

func (*Value) GetFuncInfo

func (value *Value) GetFuncInfo() FuncInfo

GetFuncInfo cast the internal value to FuncInfo

func (*Value) GetHash

func (value *Value) GetHash() *Hash

GetHash cast the internal value to *Hash

func (*Value) GetInt64

func (value *Value) GetInt64() int64

GetInt64 cast the internal value to int64

func (*Value) GetValues

func (value *Value) GetValues() []*Value

GetValues cast the internal value to []*Value

func (*Value) HashEqual

func (value *Value) HashEqual(other *Value) bool

func (*Value) Implements

func (value *Value) Implements(class *Value) bool

func (*Value) IntEqual

func (value *Value) IntEqual(other *Value) bool

func (*Value) NoneEqual

func (value *Value) NoneEqual(other *Value) bool

func (*Value) Set

func (value *Value) Set(symbol string, v *Value)

Set a plasma *Value to a symbol inside the Object

func (*Value) SetAny

func (value *Value) SetAny(v any)

func (*Value) String

func (value *Value) String() string

String interpret the Value as a go string

func (*Value) StringEqual

func (value *Value) StringEqual(other *Value) bool

func (*Value) TupleEqual

func (value *Value) TupleEqual(other *Value) bool

func (*Value) TypeId

func (value *Value) TypeId() TypeId

func (*Value) ValueEqual

func (value *Value) ValueEqual(other *Value) bool

func (*Value) Values

func (value *Value) Values() []*Value

func (*Value) VirtualTable

func (value *Value) VirtualTable() *Symbols

Jump to

Keyboard shortcuts

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