Documentation ¶
Index ¶
- Constants
- Variables
- type BreakpointFunc
- type Coordinator
- func (c *Coordinator) GetVariable(name string) (*Variable, bool)
- func (c *Coordinator) GetVariables() map[string]Variable
- func (c *Coordinator) Pause()
- func (c *Coordinator) Resume()
- func (c *Coordinator) Run()
- func (c *Coordinator) SetVariable(name string, value *Variable) error
- func (c *Coordinator) Terminate()
- func (c *Coordinator) WaitForTermination()
- type ErrorHandlerFunc
- type FinishHandlerFunc
- type LineExecutedHandlerFunc
- type RuntimeError
- type VM
- func (v *VM) AddBreakpoint(line int)
- func (v *VM) CurrentAstLine() int
- func (v *VM) CurrentSourceColoumn() int
- func (v *VM) CurrentSourceLine() int
- func (v *VM) GetExecutedLines() int
- func (v *VM) GetProgram() *ast.Program
- func (v *VM) GetVariable(name string) (*Variable, bool)
- func (v *VM) GetVariables() map[string]Variable
- func (v *VM) ListBreakpoints() []int
- func (v *VM) Pause()
- func (v *VM) PrintVariables() string
- func (v *VM) RemoveBreakpoint(line int)
- func (v *VM) Resume()
- func (v *VM) SetBreakpointHandler(f BreakpointFunc)
- func (v *VM) SetCoordinator(c *Coordinator)
- func (v *VM) SetErrorHandler(f ErrorHandlerFunc)
- func (v *VM) SetFinishHandler(f FinishHandlerFunc)
- func (v *VM) SetLineExecutedHandler(handler LineExecutedHandlerFunc)
- func (v *VM) SetMaxExecutedLines(lines int)
- func (v *VM) SetStepHandler(f FinishHandlerFunc)
- func (v *VM) SetVariable(name string, value *Variable) error
- func (v *VM) State() int
- func (v *VM) Step()
- func (v *VM) Terminate()
- func (v *VM) WaitForTermination()
- type Variable
- func (v *Variable) Bool() *Variable
- func (v *Variable) Equals(other *Variable) bool
- func (v *Variable) IsNumber() bool
- func (v *Variable) IsString() bool
- func (v *Variable) Itoa() string
- func (v *Variable) Number() number.Number
- func (v *Variable) Repr() string
- func (v *Variable) SameType(other *Variable) bool
- func (v *Variable) String() string
- func (v *Variable) TypeName() string
Constants ¶
const ( StatePaused = iota StateRunning = iota StateStepping = iota StateTerminated = iota )
The current state of the VM
const MaxStringLenght = 1024
Variables ¶
var TerminateOnDoneVar = func(vm *VM) bool { value, exists := vm.GetVariable(":done") wantnot, _ := VariableFromType(0) if exists && !value.Equals(wantnot) { go vm.Terminate() return false } return true }
TerminateOnDoneVar is a predefined LineExecutedHandlerFunc that can be used to terminate the VM once :done is set to 1
Functions ¶
This section is empty.
Types ¶
type BreakpointFunc ¶
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 (*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) Pause ¶ added in v0.1.10
func (c *Coordinator) Pause()
Pause all coordinated vms
func (*Coordinator) Resume ¶ added in v0.1.10
func (c *Coordinator) Resume()
Resume all coordinated vms
func (*Coordinator) Run ¶
func (c *Coordinator) Run()
Run starts the coordinated exection Once run has been called, no new VMs MUSt be added!!!
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) Terminate ¶
func (c *Coordinator) Terminate()
Terminate all coordinated vms Once all VMs terminate the coordinator-goroutine will also shut-down
func (*Coordinator) WaitForTermination ¶
func (c *Coordinator) WaitForTermination()
WaitForTermination blocks until all coordinated vms terminate
type ErrorHandlerFunc ¶
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 *VM)
FinishHandlerFunc is a function that is called when the programm finished execution (looping is disabled)
type LineExecutedHandlerFunc ¶ added in v0.0.22
LineExecutedHandlerFunc it the type for the handler that is called after a line has been executed
type RuntimeError ¶
RuntimeError represents an error encountered during execution
func (RuntimeError) Error ¶
func (e RuntimeError) Error() string
type VM ¶ added in v0.0.15
type VM struct {
// contains filtered or unexported fields
}
VM is a virtual machine to execute YOLOL-Code
func Create ¶ added in v0.0.15
Create creates a new VM to run the given program in a seperate goroutine. The returned VM is paused. Configure it using the setters and then call Resume()
func CreateFromSource ¶ added in v0.0.15
CreateFromSource creates a new VM to run the given program in a seperate goroutine. The returned VM is paused. Configure it using the setters and then call Resume()
func (*VM) AddBreakpoint ¶ added in v0.0.15
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 (*VM) CurrentAstLine ¶ added in v0.0.15
CurrentAstLine returns the current (=next to be executed) ast line of the program
func (*VM) CurrentSourceColoumn ¶ added in v0.0.15
CurrentSourceColoumn returns the current (=next to be executed) source column of the program
func (*VM) CurrentSourceLine ¶ added in v0.0.15
CurrentSourceLine returns the current (=next to be executed) source line of the program
func (*VM) GetExecutedLines ¶ added in v0.0.19
GetExecutedLines returns the number of lines executed by this VM
func (*VM) GetProgram ¶ added in v0.0.17
GetProgram returns the program that is run by the VM
func (*VM) GetVariable ¶ added in v0.0.15
GetVariable gets the current state of a variable
func (*VM) GetVariables ¶ added in v0.0.15
GetVariables gets the current state of all variables
func (*VM) ListBreakpoints ¶ added in v0.0.15
ListBreakpoints returns the list of active breakpoints
func (*VM) Pause ¶ added in v0.0.15
func (v *VM) Pause()
Pause pauses the execution Blocks until the VM reacts on the request
func (*VM) PrintVariables ¶ added in v0.0.15
PrintVariables gets an overview over the current variable state
func (*VM) RemoveBreakpoint ¶ added in v0.0.15
RemoveBreakpoint removes the breakpoint at the line
func (*VM) Resume ¶ added in v0.0.15
func (v *VM) Resume()
Resume resumes execution after a breakpoint or pause() or the initial stopped state Blocks until the VM reacts on the request
func (*VM) SetBreakpointHandler ¶ added in v0.0.15
func (v *VM) SetBreakpointHandler(f BreakpointFunc)
SetBreakpointHandler sets the function to be called when hitting a breakpoint
func (*VM) SetCoordinator ¶ added in v0.0.15
func (v *VM) SetCoordinator(c *Coordinator)
SetCoordinator sets the coordinator that is used to coordinate execution with other vms
func (*VM) SetErrorHandler ¶ added in v0.0.15
func (v *VM) SetErrorHandler(f ErrorHandlerFunc)
SetErrorHandler sets the function to be called when encountering an error
func (*VM) SetFinishHandler ¶ added in v0.0.15
func (v *VM) SetFinishHandler(f FinishHandlerFunc)
SetFinishHandler sets the function to be called when execution finishes
func (*VM) SetLineExecutedHandler ¶ added in v0.0.22
func (v *VM) SetLineExecutedHandler(handler LineExecutedHandlerFunc)
SetLineExecutedHandler registers a callback that is executed when a line has been completely executed When running coordinated, this handler is called before passing execution to the next VM
func (*VM) SetMaxExecutedLines ¶ added in v0.0.15
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 (*VM) SetStepHandler ¶ added in v0.0.15
func (v *VM) SetStepHandler(f FinishHandlerFunc)
SetStepHandler sets the function to be called when a step completes
func (*VM) SetVariable ¶ added in v0.0.15
SetVariable sets the current state of a variable
func (*VM) Step ¶ added in v0.0.15
func (v *VM) Step()
Step executes the next line and paused the execution Blocks until the VM reacts on the request
func (*VM) Terminate ¶ added in v0.0.15
func (v *VM) Terminate()
Terminate the vm goroutine (if running)
func (*VM) WaitForTermination ¶ added in v0.0.15
func (v *VM) WaitForTermination()
WaitForTermination blocks until the VM terminates
type Variable ¶
type Variable struct {
Value interface{}
}
Variable represents a yolol-variable during the execution
func RunBinaryOperation ¶
RunBinaryOperation executes the given operation with the given arguments and returns the result
func RunUnaryOperation ¶
RunUnaryOperation executes the given operation with the given argument and returns the result
func VariableFromString ¶ added in v0.0.17
VariableFromString tries to create a variable of the correct type from the given string. If the string is enclosed in quotes, the string between the quotes is used as string-value for the variable. Else, it tries to parse the given string into a number. If that also fails, the plain given string is used as value.
func VariableFromType ¶ added in v0.0.17
VariableFromType creates a new variable from the given input. The type of the variable is decided by the input-type.
func (*Variable) Repr ¶ added in v0.0.17
Repr returns the string-representation of the variable. If the variable is of type string, its value is enclosed in quotes.