vm

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StateIdle    = iota
	StateRunning = iota
	StatePaused  = iota
	StateStep    = iota
	StateKill    = iota
	StateDone    = iota
)

The current state of the VM

Variables

This section is empty.

Functions

This section is empty.

Types

type BreakpointFunc

type BreakpointFunc func(vm *YololVM) bool

BreakpointFunc is a function that is called when a breakpoint is encountered. If true is returned the execution is resumed. Otherwise the vm remains paused

type Coordinator

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

Coordinator is responsible for coordinating the execution of multiple VMs It coordinates the line-by-line execution of the scripts and provides shared global variables

func NewCoordinator

func NewCoordinator() *Coordinator

NewCoordinator returns a new coordinator

func (*Coordinator) GetVariable

func (c *Coordinator) GetVariable(name string) (*Variable, bool)

GetVariable gets the current state of a global variable getting variables is case-insensitive

func (*Coordinator) GetVariables

func (c *Coordinator) GetVariables() map[string]Variable

GetVariables gets the current state of all global variables All returned variables have normalized (lowercased) names

func (*Coordinator) IsRunning

func (c *Coordinator) IsRunning() bool

IsRunning returns true if the sub-vms are allowed to run

func (*Coordinator) Run

func (c *Coordinator) Run()

Run starts the coordinated exection Run() on the VMs must have been called before

func (*Coordinator) SetVariable

func (c *Coordinator) SetVariable(name string, value *Variable) error

SetVariable sets the current state of a global variable setting variables is case-insensitive

func (*Coordinator) Stop

func (c *Coordinator) Stop()

Stop stops the execution

func (*Coordinator) Terminate

func (c *Coordinator) Terminate()

Terminate all coordinated vms

func (*Coordinator) WaitForTermination

func (c *Coordinator) WaitForTermination()

WaitForTermination blocks until all coordinated vms terminate

type ErrorHandlerFunc

type ErrorHandlerFunc func(vm *YololVM, err error) bool

ErrorHandlerFunc is a function that is called when a runtime-error is encountered. If true is returned the execution is resumed. Otherwise the vm remains paused

type FinishHandlerFunc

type FinishHandlerFunc func(vm *YololVM)

FinishHandlerFunc is a function that is called when the programm finished execution (looping is disabled)

type RuntimeError

type RuntimeError struct {
	Base error
	// The Node that caused the error
	Node ast.Node
}

RuntimeError represents an error encountered during execution

func (RuntimeError) Error

func (e RuntimeError) Error() string

type Variable

type Variable struct {
	Value interface{}
}

Variable represents a yolol-variable during the execution

func RunBinaryOperation

func RunBinaryOperation(arg1 *Variable, arg2 *Variable, operator string) (*Variable, error)

RunBinaryOperation executes the given operation with the given arguments and returns the result

func RunFunction

func RunFunction(arg *Variable, function string) (*Variable, error)

RunFunction executes the given yolol-function with the given argument and returns the result

func RunUnaryOperation

func RunUnaryOperation(arg *Variable, operator string) (*Variable, error)

RunUnaryOperation executes the given operation with the given argument and returns the result

func (*Variable) IsNumber

func (v *Variable) IsNumber() bool

IsNumber returns true if the variable represents a number

func (*Variable) IsString

func (v *Variable) IsString() bool

IsString returns true if the variable represents a string

func (*Variable) Itoa

func (v *Variable) Itoa() string

Itoa returns the string-representation of the number stored in the variable

func (*Variable) Number

func (v *Variable) Number() decimal.Decimal

Number returns the value of the variable as number

func (*Variable) SameType

func (v *Variable) SameType(other *Variable) bool

SameType returns true if the variable has the same type as the given variable

func (*Variable) String

func (v *Variable) String() string

type YololVM

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

YololVM is a virtual machine to execute YOLOL-Code

func NewYololVM

func NewYololVM() *YololVM

NewYololVM creates a new standalone VM

func NewYololVMCoordinated

func NewYololVMCoordinated(coordinator *Coordinator) *YololVM

NewYololVMCoordinated creates a new VM that is coordinated with other VMs using the given coordinator

func (*YololVM) AddBreakpoint

func (v *YololVM) AddBreakpoint(line int)

AddBreakpoint adds a breakpoint at the line. Breakpoint-lines always refer to the position recorded in the ast nodes, not the position of the Line in the Line-Slice of ast.Program.

func (*YololVM) CurrentAstLine

func (v *YololVM) CurrentAstLine() int

CurrentAstLine returns the current (=next to be executed) ast line of the program

func (*YololVM) CurrentSourceLine

func (v *YololVM) CurrentSourceLine() int

CurrentSourceLine returns the current (=next to be executed) source line of the program

func (*YololVM) GetVariable

func (v *YololVM) GetVariable(name string) (*Variable, bool)

GetVariable gets the current state of a variable

func (*YololVM) GetVariables

func (v *YololVM) GetVariables() map[string]Variable

GetVariables gets the current state of all variables

func (*YololVM) ListBreakpoints

func (v *YololVM) ListBreakpoints() []int

ListBreakpoints returns the list of active breakpoints

func (*YololVM) Pause

func (v *YololVM) Pause()

Pause pauses the execution

func (*YololVM) PrintVariables

func (v *YololVM) PrintVariables() string

PrintVariables gets an overview over the current variable state

func (*YololVM) RemoveBreakpoint

func (v *YololVM) RemoveBreakpoint(line int)

RemoveBreakpoint removes the breakpoint at the line

func (*YololVM) Resume

func (v *YololVM) Resume() error

Resume resumes execution after a breakpoint or pause()

func (*YololVM) Run

func (v *YololVM) Run(prog *ast.Program)

Run runs the compiled program prog in a new go-routine

func (*YololVM) RunSource

func (v *YololVM) RunSource(prog string)

RunSource compiles and runs the given YOLOL code

func (*YololVM) Running

func (v *YololVM) Running() bool

Running returns true if there is a running goroutine for this vm

func (*YololVM) SetBreakpointHandler

func (v *YololVM) SetBreakpointHandler(f BreakpointFunc)

SetBreakpointHandler sets the function to be called when hitting a breakpoint

func (*YololVM) SetErrorHandler

func (v *YololVM) SetErrorHandler(f ErrorHandlerFunc)

SetErrorHandler sets the function to be called when encountering an error

func (*YololVM) SetFinishHandler

func (v *YololVM) SetFinishHandler(f FinishHandlerFunc)

SetFinishHandler sets the function to be called when execution finishes

func (*YololVM) SetIterations

func (v *YololVM) SetIterations(reps int)

SetIterations sets the number of iterations to perform for the script 1 = run only once, <=0 run forever, >0 repeat x times default is 1

func (*YololVM) SetMaxExecutedLines

func (v *YololVM) SetMaxExecutedLines(lines int)

SetMaxExecutedLines sets the maximum number of lines to run if the amount is reached the VM terminates Can be used to prevent blocking by endless loops <= 0 disables this. Default is 0

func (*YololVM) SetVariable

func (v *YololVM) SetVariable(name string, value interface{}) error

SetVariable sets the current state of a variable

func (*YololVM) State

func (v *YololVM) State() int

State returns the current vm state

func (*YololVM) Step

func (v *YololVM) Step() error

Step executes the next line and stops the execution again

func (*YololVM) Terminate

func (v *YololVM) Terminate()

Terminate the vm goroutine (if running)

func (*YololVM) WaitForTermination

func (v *YololVM) WaitForTermination()

WaitForTermination blocks until the vm finished running

Jump to

Keyboard shortcuts

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