Documentation ¶
Overview ¶
Package instruction contains all the instructions created by the compiler and executed by the VM.
Index ¶
- Variables
- type Add
- type And
- type Append
- type ArrayAlloc
- type ArrayGet
- type ArraySet
- type Assert
- type Assign
- type Call
- type CastChar
- type CastNumber
- type CastString
- type Combine
- type CompiledFunc
- type CompiledTest
- type Concat
- type Divide
- type Equal
- type EqualNumber
- type GreaterThanEqualNumber
- type GreaterThanEqualString
- type GreaterThanNumber
- type GreaterThanString
- type Instruction
- type InternalDefinition
- type Interpolate
- type Jump
- type JumpUnless
- type Len
- type LessThanEqualNumber
- type LessThanEqualString
- type LessThanNumber
- type LessThanString
- type Log
- type MapAllocNumber
- type MapGet
- type MapSet
- type Multiply
- type NextArray
- type NextMap
- type NextString
- type Not
- type NotEqual
- type NotEqualNumber
- type On
- type Or
- type Power
- type Print
- type Raise
- type Remainder
- type Return
- type StringIndex
- type Subtract
- type VM
Constants ¶
This section is empty.
Variables ¶
var Lib map[string]*InternalDefinition
These are populated with the generated lib.go file. See Makefile.
var Packages map[string]bool
Functions ¶
This section is empty.
Types ¶
type Append ¶ added in v0.14.2
type Append struct {
A, B, Result string
}
Append returns an array by combining two other arrays.
type ArrayAlloc ¶ added in v0.14.2
ArrayAlloc allocates a "[]number" of fixed size.
type ArrayGet ¶
type ArrayGet struct {
Array, Index, Result string
}
ArrayGet gets a value from the array by its index.
type ArraySet ¶
type ArraySet struct {
Array, Index, Value string
}
ArraySet sets a number value to an index.
type CastChar ¶ added in v0.14.2
type CastChar struct {
X, Result string
}
CastChar returns a char value of a value.
type CastNumber ¶ added in v0.14.2
type CastNumber struct {
X, Result string
}
CastNumber returns a number value of a value.
type CastString ¶ added in v0.14.2
type CastString struct {
X, Result string
}
CastString returns a string value of a value.
type Combine ¶
type Combine struct {
Left, Right, Result string
}
Combine will create a new data by joining two other datas.
type CompiledFunc ¶
type CompiledFunc struct { Arguments []string Instructions []Instruction Registers int Variables map[string]string ObjectRegister string }
func (*CompiledFunc) Append ¶
func (c *CompiledFunc) Append(instruction Instruction)
func (*CompiledFunc) NewVariable ¶
func (c *CompiledFunc) NewVariable(variableName string, kind string)
func (*CompiledFunc) NextRegister ¶
func (c *CompiledFunc) NextRegister() string
type CompiledTest ¶
type CompiledTest struct { *CompiledFunc TestName string }
CompiledTest is a runnable test.
type Concat ¶
type Concat struct {
Left, Right, Result string
}
Concat will create a new string by joining two other strings.
type Equal ¶
type Equal struct {
Left, Right, Result string
}
Equal will compare two non-numbers for equality. This works for every other type because every other type is stored as a string. When optimizations are made in the future this will need to be expanded to one instruction per type.
type EqualNumber ¶
type EqualNumber struct {
Left, Right, Result string
}
EqualNumber will compare two numbers for equality.
type GreaterThanEqualNumber ¶
type GreaterThanEqualNumber struct {
Left, Right, Result string
}
GreaterThanEqualNumber will compare two numbers.
type GreaterThanEqualString ¶
type GreaterThanEqualString struct {
Left, Right, Result string
}
GreaterThanEqualString will compare two strings.
type GreaterThanNumber ¶
type GreaterThanNumber struct {
Left, Right, Result string
}
GreaterThanNumber will compare two numbers.
type GreaterThanString ¶
type GreaterThanString struct {
Left, Right, Result string
}
GreaterThanString will compare two strings.
type Instruction ¶
type Instruction interface {
Execute(registers map[string]*ast.Literal, currentInstruction *int, vm *VM) error
}
An Instruction can be executed by the VM.
type InternalDefinition ¶
type InternalDefinition struct { CompiledFunc *CompiledFunc FuncDef *ast.Func }
InternalDefinition is used by Lib to hold the definitions and compiled code for internal functions.
type Interpolate ¶ added in v0.13.2
Interpolate combines strings and expressions into one string result.
type JumpUnless ¶
JumpUnless will jump to the instruction if the expression is false.
type Len ¶
type Len struct {
Argument, Result string
}
Len is used to determine the size of an array or map.
type LessThanEqualNumber ¶
type LessThanEqualNumber struct {
Left, Right, Result string
}
LessThanEqualNumber will compare two numbers.
type LessThanEqualString ¶
type LessThanEqualString struct {
Left, Right, Result string
}
LessThanEqualString will compare two strings.
type LessThanNumber ¶
type LessThanNumber struct {
Left, Right, Result string
}
LessThanNumber will compare two numbers.
type LessThanString ¶
type LessThanString struct {
Left, Right, Result string
}
LessThanString will compare two strings.
type Log ¶ added in v0.12.1
type Log struct {
X, Result string
}
Log is a natural logarithm (base e).
type MapAllocNumber ¶
type MapAllocNumber struct {
Size, Result string
}
MapAllocNumber allocates a "{}number" of fixed size.
type MapGet ¶
type MapGet struct {
Map, Key, Result string
}
MapGet gets a value from the map by its key.
type Multiply ¶
type Multiply struct {
Left, Right, Result string
}
Multiply will multiply two numbers.
type NextArray ¶
type NextArray struct { Array string // Register In (array): Containing the iterating array. Cursor string // Register In (number): Containing the current position. KeyResult string // Register Out (any): Load the key into this register. ValueResult string // Register Out (any): Load the value into this register. Result string // Register Out (bool): Still more items? }
NextArray is used to tick an array iterator forward.
type NextMap ¶
type NextMap struct { Map string // Register In (map): Containing the iterating map. Cursor string // Register In (number): Containing the current position. KeyResult string // Register Out (any): Load the key into this register. ValueResult string // Register Out (any): Load the value into this register. Result string // Register Out (bool): Still more items? }
NextMap is used to tick a map iterator forward.
type NextString ¶ added in v0.14.2
type NextString struct { String string // Register In (string): Containing the iterating string. Cursor string // Register In (number): Containing the current position. KeyResult string // Register Out (any): Load the key into this register. ValueResult string // Register Out (any): Load the value into this register. Result string // Register Out (bool): Still more items? }
NextString is used to tick a string iterator forward.
type NotEqual ¶
type NotEqual struct {
Left, Right, Result string
}
NotEqual will compare two non-numbers for non-equality. This works for every other type because every other type is stored as a string. When optimizations are made in the future this will need to be expanded to one instruction per type.
type NotEqualNumber ¶
type NotEqualNumber struct {
Left, Right, Result string
}
NotEqualNumber will compare two numbers for equality.
type On ¶ added in v0.15.0
type On struct { // Type will be the name of the error, or it can be empty to signal there // are no more errors to check. If the VM hits an empty Type it will return // and pass the error up to the caller. Type string }
On is a pragma for the vm to handle errors. It can also be used to indicate the end of the on's so that the VM can send the error up to the caller.
type Power ¶ added in v0.11.2
type Power struct {
Base, Power, Result string
}
Power is Left to the power of Right.
type Raise ¶ added in v0.15.0
type Raise struct { // Err is the register containing the error. Err string // Type is used to match the handler. Type string }
Raise put the VM into an error mode. The VM will look for an error handler.
type Remainder ¶
type Remainder struct {
Left, Right, Result string
}
Remainder will return the remainder when dividing two numbers. This is not the same as a modulo. A remainder may be negative.
type Return ¶
type Return struct {
Results []string
}
Return tells the VM to jump out of this function.
type StringIndex ¶ added in v0.14.2
type StringIndex struct {
String, Index, Result string
}
StringIndex returns a character from an index of a string.
type Subtract ¶
type Subtract struct {
Left, Right, Result string
}
Subtract will subtract two numbers.
type VM ¶
type VM struct { Return []string Stdout io.Writer // Stats when running tests. TestsPass, TestsFailed int TotalAssertions int CurrentTestName string CurrentTestPassed bool // ErrType will be non-empty once an error is raised. It contains the type // to match for a handler. ErrValue contains the actual error. ErrType string ErrValue *ast.Literal // contains filtered or unexported fields }
VM is an instance of a virtual machine to run ok instructions.
func NewVM ¶
func NewVM(fns map[string]*CompiledFunc, tests []*CompiledTest, pkg string) *VM
NewVM will create a new VM ready to run the provided instructions.
Source Files ¶
- add.go
- and.go
- append.go
- array_alloc.go
- array_get.go
- array_set.go
- assert.go
- assign.go
- call.go
- cast.go
- combine.go
- concat.go
- divide.go
- doc.go
- equal.go
- error_scope.go
- func.go
- greater_than.go
- greater_than_equal.go
- instruction.go
- interpolate.go
- jump.go
- jump_unless.go
- len.go
- less_than.go
- less_than_equal.go
- log.go
- map_alloc.go
- map_get.go
- map_set.go
- multiply.go
- next_array.go
- next_map.go
- next_string.go
- not.go
- not_equal.go
- or.go
- power.go
- print.go
- raise.go
- remainder.go
- return.go
- string_index.go
- subtract.go
- vm.go