vm

package
v0.0.0-...-2cdba53 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2019 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoundedType

type BoundedType interface {
	Type
	MinVal() *big.Rat // MinVal returns the smallest value of this type.
	MaxVal() *big.Rat // MaxVal returns the largest value of this type.
}

BoundedType represents a numeric type with boundaries on its value.

type Code

type Code []CodeInstruction

func (Code) Exec

func (code Code) Exec(t *Thread)

type CodeInstruction

type CodeInstruction func(*Thread)

type DivByZeroError

type DivByZeroError struct{}

DivByZeroError is used to abort a thread when a division by zero occurs.

func (DivByZeroError) Error

func (DivByZeroError) Error() string

type EvalFunc

type EvalFunc struct {
	Outer     *Frame
	FrameSize int
	Code      Code
}

EvalFunc is used for user-defined functions.

func (*EvalFunc) Call

func (f *EvalFunc) Call(t *Thread)

func (*EvalFunc) NewFrame

func (f *EvalFunc) NewFrame() *Frame

type Frame

type Frame struct {
	Outer *Frame
	Vars  []Value
}

func (*Frame) Get

func (f *Frame) Get(level int, index int) Value

Get the Value at the specified slot in the specified parent level frame.

func (*Frame) NewChild

func (f *Frame) NewChild(numVars int) *Frame

NewChild creates a new child frame with the specified number of variable slots.

type IndexError

type IndexError struct {
	Idx, Len int64
}

IndexError is used to abort a thread when an indexed expression is out of bounds.

func (IndexError) Error

func (e IndexError) Error() string

type KeyError

type KeyError struct {
	Key interface{}
}

KeyError is used to abort a thread when invalid key indices are used in a map expression.

func (KeyError) Error

func (e KeyError) Error() string

type NegativeCapacityError

type NegativeCapacityError struct {
	Len int64
}

NegativeCapacityError is used to abort a thread when a negative capacity is used when creating a Slice.

func (NegativeCapacityError) Error

func (e NegativeCapacityError) Error() string

type NegativeLengthError

type NegativeLengthError struct {
	Len int64
}

NegativeLengthError is used to abort a thread when a negative length is used when creating a Slice.

func (NegativeLengthError) Error

func (e NegativeLengthError) Error() string

type NilPointerError

type NilPointerError struct{}

NilPointerError is used to abort a thread when a nil pointer is dereferenced.

func (NilPointerError) Error

func (NilPointerError) Error() string

type SliceError

type SliceError struct {
	Lo, Hi, Cap int64
}

SliceError is used to abort a thread when invalid indices are used for a slice manipulation of a Slice, Array or String.

func (SliceError) Error

func (e SliceError) Error() string

type Thread

type Thread struct {
	PC    uint   // Program Counter
	Frame *Frame // The execution frame of this function. This remains the same throughout a function invocation.
	// contains filtered or unexported fields
}

func (*Thread) Abort

func (t *Thread) Abort(err error)

Abort aborts the thread's current computation, causing the innermost Try to return err.

func (*Thread) Try

func (t *Thread) Try(f func(t *Thread)) error

Try executes a computation; if the computation Aborts, Try returns the error passed to abort.

type Type

type Type interface {
	// Compat returns whether this type is compatible with another type.
	// If conv is false, this is normal compatibility, where two named types are compatible only if they are the same named type.
	// If conv if true, this is conversion compatibility, where two named types are conversion compatible if their definitions are conversion compatible.
	Compat(t Type, conv bool) bool // TODO: Deal with recursive types

	// Lit returns this type's literal.
	// If this is a named type, this is the unnamed underlying type.
	// Otherwise, this is an identity operation.
	Lit() Type

	// IsBoolean returns true if this is a boolean type.
	IsBoolean() bool

	// IsInteger returns true if this is an integer type.
	IsInteger() bool

	// IsFloat returns true if this is a floating type.
	IsFloat() bool

	// IsIdeal returns true if this represents an ideal value.
	IsIdeal() bool

	// Zero returns a new zero value of this type.
	Zero() Value

	// String returns the string representation of this type.
	String() string
}

Type is the common interface for all supported types

type Value

type Value interface {
	// String returns the string representation of this value.
	String() string

	// Assign copies another value into this one.
	// It should assume that the other value satisfies the same specific value interface (BoolValue, etc.),
	// but must not assume anything about its specific type.
	Assign(t *Thread, v Value)
}

Jump to

Keyboard shortcuts

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