Documentation ¶
Overview ¶
Package instruction contains all the instructions created by the compiler and executed by the VM.
Index ¶
- Variables
- type Add
- type And
- type ArrayAllocNumber
- type ArrayGet
- type ArraySet
- type Assert
- type Assign
- type Call
- 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 Jump
- type JumpUnless
- type Len
- type LessThanEqualNumber
- type LessThanEqualString
- type LessThanNumber
- type LessThanString
- type MapAllocNumber
- type MapGet
- type MapSet
- type Multiply
- type NextArray
- type NextMap
- type Not
- type NotEqual
- type NotEqualNumber
- type Or
- type Print
- type Remainder
- type Return
- type Subtract
- type VM
Constants ¶
This section is empty.
Variables ¶
var Lib map[string]*InternalDefinition
Lib is populated with the generated lib.go file. See Makefile.
Functions ¶
This section is empty.
Types ¶
type ArrayAllocNumber ¶
type ArrayAllocNumber struct {
Size, Result string
}
ArrayAllocNumber 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 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 }
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 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 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 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 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 Subtract ¶
type Subtract struct {
Left, Right, Result string
}
Subtract will subtract two numbers.
type VM ¶
type VM struct { Return []string // Stats when running tests. TestsPass, TestsFailed int TotalAssertions int CurrentTestName string CurrentTestPassed bool // 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
- array_alloc.go
- array_get.go
- array_set.go
- assert.go
- assign.go
- call.go
- combine.go
- concat.go
- divide.go
- doc.go
- equal.go
- func.go
- greater_than.go
- greater_than_equal.go
- instruction.go
- jump.go
- jump_unless.go
- len.go
- less_than.go
- less_than_equal.go
- map_alloc.go
- map_get.go
- map_set.go
- multiply.go
- next_array.go
- next_map.go
- not.go
- not_equal.go
- or.go
- print.go
- remainder.go
- return.go
- subtract.go
- vm.go