Documentation ¶
Index ¶
- func EmitConstant(c *CodeBuilder, k Constant, reg Register, line int)
- func EmitMove(c *CodeBuilder, dst Register, src Register, line int)
- func EmitMoveNoLine(c *CodeBuilder, dst Register, src Register)
- func FoldMoveReg(i1, i2 Instruction, regs []RegData) (Instruction, Instruction)
- func FoldTakeRelease(i1, i2 Instruction, regs []RegData) (Instruction, Instruction)
- type AdvForLoop
- type Bool
- type Call
- type ClearReg
- type Code
- type CodeBuilder
- func (c *CodeBuilder) Close() (uint, []Register)
- func (c *CodeBuilder) DeclareGotoLabel(name Name, line int) Label
- func (c *CodeBuilder) DeclareGotoLabelNoLine(name Name) Label
- func (c *CodeBuilder) DeclareLocal(name Name, reg Register)
- func (c *CodeBuilder) DeclareUniqueGotoLabel(name Name, line int) (Label, error)
- func (c *CodeBuilder) Dump()
- func (c *CodeBuilder) Emit(instr Instruction, line int)
- func (c *CodeBuilder) EmitGotoLabel(name Name) error
- func (c *CodeBuilder) EmitJump(lblName Name, line int) bool
- func (c *CodeBuilder) EmitLabel(lbl Label, line int) error
- func (c *CodeBuilder) EmitLabelNoLine(lbl Label) error
- func (c *CodeBuilder) EmitNoLine(instr Instruction)
- func (c *CodeBuilder) GetFreeRegister() Register
- func (c *CodeBuilder) GetNewLabel() Label
- func (c *CodeBuilder) GetRegister(name Name) (Register, bool)
- func (c *CodeBuilder) HasPendingCloseActions() bool
- func (c *CodeBuilder) IsConstantReg(reg Register) bool
- func (c *CodeBuilder) MarkConstantReg(reg Register)
- func (c *CodeBuilder) NewChild(chunkName string) *CodeBuilder
- func (c *CodeBuilder) PopContext()
- func (c *CodeBuilder) PushCloseAction(reg Register)
- func (c *CodeBuilder) PushContext()
- func (c *CodeBuilder) ReleaseRegister(reg Register)
- func (c *CodeBuilder) TakeRegister(reg Register)
- type Combine
- type Constant
- type ConstantPool
- type ConstantProcessor
- type DeclareLabel
- type EtcLookup
- type FillTable
- type Float
- type FoldFunc
- type InstrProcessor
- type Instruction
- type Int
- type Jump
- type JumpIf
- type Label
- type LoadConst
- type Lookup
- type MkClosure
- type MkCont
- type MkTable
- type Name
- type NilType
- type PrepForLoop
- type Push
- type PushCloseStack
- type Receive
- type ReceiveEtc
- type RegData
- type Register
- type ReleaseRegister
- type SetIndex
- type SetRegInstruction
- type String
- type TakeRegister
- type Transform
- type TruncateCloseStack
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EmitConstant ¶
func EmitConstant(c *CodeBuilder, k Constant, reg Register, line int)
func EmitMoveNoLine ¶
func EmitMoveNoLine(c *CodeBuilder, dst Register, src Register)
func FoldMoveReg ¶
func FoldMoveReg(i1, i2 Instruction, regs []RegData) (Instruction, Instruction)
FoldMoveReg folds the following
(r1 <- X; r2 <- r1) ==> r2 <- X
func FoldTakeRelease ¶
func FoldTakeRelease(i1, i2 Instruction, regs []RegData) (Instruction, Instruction)
FoldTakeRelease folds the following
(take r1; release r1) ==> ()
Types ¶
type AdvForLoop ¶
type AdvForLoop struct {
Start, Stop, Step Register
}
func (AdvForLoop) ProcessInstr ¶
func (i AdvForLoop) ProcessInstr(p InstrProcessor)
func (AdvForLoop) String ¶
func (i AdvForLoop) String() string
type Bool ¶
type Bool bool
A Bool is a constant representing a boolean literal.
func (Bool) ProcessConstant ¶
func (b Bool) ProcessConstant(p ConstantProcessor)
ProcessConstant uses the given ConstantProcessor to process the receiver.
type Call ¶
Call moves execution to the given continuation
func (Call) ProcessInstr ¶
func (c Call) ProcessInstr(p InstrProcessor)
ProcessInstr makes the InstrProcessor process this instruction.
type ClearReg ¶
type ClearReg struct {
Dst Register
}
ClearReg resets the given register to nil (if it contained a cell, this cell is removed).
func (ClearReg) ProcessInstr ¶
func (i ClearReg) ProcessInstr(p InstrProcessor)
ProcessInstr makes the InstrProcessor process this instruction.
type Code ¶
type Code struct { Instructions []Instruction Lines []int Constants []Constant UpvalueDests []Register Registers []RegData UpNames []string Name string }
Code is the type of code literals (i.e. function definitions).
func FoldCode ¶
FoldCode uses the given FoldFunc to fold the instructions in the given code. Returns a new Code instande with folded code.
func (Code) ProcessConstant ¶
func (c Code) ProcessConstant(p ConstantProcessor)
ProcessConstant uses the given ConstantProcessor to process the receiver.
type CodeBuilder ¶
type CodeBuilder struct {
// contains filtered or unexported fields
}
func NewCodeBuilder ¶
func NewCodeBuilder(chunkName string, constantPool *ConstantPool) *CodeBuilder
func (*CodeBuilder) Close ¶
func (c *CodeBuilder) Close() (uint, []Register)
func (*CodeBuilder) DeclareGotoLabel ¶
func (c *CodeBuilder) DeclareGotoLabel(name Name, line int) Label
func (*CodeBuilder) DeclareGotoLabelNoLine ¶
func (c *CodeBuilder) DeclareGotoLabelNoLine(name Name) Label
func (*CodeBuilder) DeclareLocal ¶
func (c *CodeBuilder) DeclareLocal(name Name, reg Register)
func (*CodeBuilder) DeclareUniqueGotoLabel ¶
func (c *CodeBuilder) DeclareUniqueGotoLabel(name Name, line int) (Label, error)
func (*CodeBuilder) Dump ¶
func (c *CodeBuilder) Dump()
func (*CodeBuilder) Emit ¶
func (c *CodeBuilder) Emit(instr Instruction, line int)
func (*CodeBuilder) EmitGotoLabel ¶
func (c *CodeBuilder) EmitGotoLabel(name Name) error
func (*CodeBuilder) EmitLabelNoLine ¶
func (c *CodeBuilder) EmitLabelNoLine(lbl Label) error
func (*CodeBuilder) EmitNoLine ¶
func (c *CodeBuilder) EmitNoLine(instr Instruction)
func (*CodeBuilder) GetFreeRegister ¶
func (c *CodeBuilder) GetFreeRegister() Register
func (*CodeBuilder) GetNewLabel ¶
func (c *CodeBuilder) GetNewLabel() Label
func (*CodeBuilder) GetRegister ¶
func (c *CodeBuilder) GetRegister(name Name) (Register, bool)
func (*CodeBuilder) HasPendingCloseActions ¶
func (c *CodeBuilder) HasPendingCloseActions() bool
HasPendingCloseActions returns true if there are close actions in the current context. In this case tail calls are disabled in order to allow the close actions to take place after the call.
func (*CodeBuilder) IsConstantReg ¶
func (c *CodeBuilder) IsConstantReg(reg Register) bool
func (*CodeBuilder) MarkConstantReg ¶
func (c *CodeBuilder) MarkConstantReg(reg Register)
func (*CodeBuilder) NewChild ¶
func (c *CodeBuilder) NewChild(chunkName string) *CodeBuilder
func (*CodeBuilder) PopContext ¶
func (c *CodeBuilder) PopContext()
func (*CodeBuilder) PushCloseAction ¶
func (c *CodeBuilder) PushCloseAction(reg Register)
PushCloseAction emits a PushCloseStack instruction and updates the current lexical context accordingly
func (*CodeBuilder) PushContext ¶
func (c *CodeBuilder) PushContext()
func (*CodeBuilder) ReleaseRegister ¶
func (c *CodeBuilder) ReleaseRegister(reg Register)
func (*CodeBuilder) TakeRegister ¶
func (c *CodeBuilder) TakeRegister(reg Register)
type Combine ¶
type Combine struct { Op ops.Op // Operator to apply to Lsrc and Rsrc Dst Register // Destination register Lsrc Register // Left operand register Rsrc Register // Right operand register }
Combine applies the binary operator Op to Lsrc and Rsrc and stores the result in Dst.
func (Combine) ProcessInstr ¶
func (c Combine) ProcessInstr(p InstrProcessor)
ProcessInstr makes the InstrProcessor process this instruction.
func (Combine) WithDestReg ¶
func (c Combine) WithDestReg(r Register) Instruction
WithDestReg returns the same isntruction with a new destination register.
type Constant ¶
type Constant interface {
ProcessConstant(p ConstantProcessor)
}
Constant is the interface implemented by constant values (e.g. numbers, strings, but also code chunks).
func FoldConstants ¶
FoldConstants uses the given FoldFunc to fold the code items in the given constant slice.
type ConstantPool ¶
type ConstantPool struct {
// contains filtered or unexported fields
}
A ConstantPool accumulates constants and associates a stable integer with each constant.
func NewConstantPool ¶
func NewConstantPool() *ConstantPool
func (*ConstantPool) Constants ¶
func (c *ConstantPool) Constants() []Constant
Constants returns the list of all constants registered with this pool.
func (*ConstantPool) GetConstantIndex ¶
func (c *ConstantPool) GetConstantIndex(k Constant) uint
GetConstantIndex returns the index associated with a given constant. If there is none, the constant is registered in the pool and the new index is returned.
type ConstantProcessor ¶
type ConstantProcessor interface { ProcessFloat(Float) ProcessInt(Int) ProcessBool(Bool) ProcessString(String) ProcessNil(NilType) ProcessCode(Code) }
A ConstantProcessor is able to process all the different types of constant using the various ProcessXXX methods.
type DeclareLabel ¶
type DeclareLabel struct {
Label Label
}
DeclareLabel is not a real IR instruction. It is a placeholder for the destination location of a jump label. Being an instruction makes it easier to perform IR code transformations and keep the labels in correct locations.
func (DeclareLabel) ProcessInstr ¶
func (l DeclareLabel) ProcessInstr(p InstrProcessor)
ProcessInstr makes the InstrProcessor process this instruction.
func (DeclareLabel) String ¶
func (l DeclareLabel) String() string
type EtcLookup ¶
EtcLookup finds the value at index Idx in the Etc register and puts it in Dst.
func (EtcLookup) ProcessInstr ¶
func (l EtcLookup) ProcessInstr(p InstrProcessor)
ProcessInstr makes the InstrProcessor process this instruction.
func (EtcLookup) WithDestReg ¶
func (l EtcLookup) WithDestReg(r Register) Instruction
WithDestReg returns the same isntruction with a new destination register.
type FillTable ¶
FillTable fills Dst (which must contain a table) with the contents of Etc (which must be an etc value) starting from the given index.
func (FillTable) ProcessInstr ¶
func (f FillTable) ProcessInstr(p InstrProcessor)
ProcessInstr makes the InstrProcessor process this instruction.
type Float ¶
type Float float64
A Float is a constant representing a literal floating point number.
func (Float) ProcessConstant ¶
func (f Float) ProcessConstant(p ConstantProcessor)
ProcessConstant uses the given ConstantProcessor to process the receiver.
type FoldFunc ¶
type FoldFunc func(i1, i2 Instruction, regs []RegData) (Instruction, Instruction)
A FoldFunc can turn 2 instructions into fewer instructions (in which case some of the returned instructions are nil).
func ComposeFolds ¶
ComposeFolds takes several fold functions are composes them into one single function applying all the folds.
type InstrProcessor ¶
type InstrProcessor interface { // Real instructions ProcessCombineInstr(Combine) ProcessTransformInstr(Transform) ProcessLoadConstInstr(LoadConst) ProcessPushInstr(Push) ProcessJumpInstr(Jump) ProcessJumpIfInstr(JumpIf) ProcessCallInstr(Call) ProcessMkClosureInstr(MkClosure) ProcessMkContInstr(MkCont) ProcessClearRegInstr(ClearReg) ProcessMkTableInstr(MkTable) ProcessLookupInstr(Lookup) ProcessSetIndexInstr(SetIndex) ProcessReceiveInstr(Receive) ProcessReceiveEtcInstr(ReceiveEtc) ProcessEtcLookupInstr(EtcLookup) ProcessFillTableInstr(FillTable) ProcessTruncateCloseStackInstr(TruncateCloseStack) ProcessPushCloseStackInstr(PushCloseStack) ProcessPrepForLoopInstr(PrepForLoop) ProcessAdvForLoopInstr(AdvForLoop) // These are hints that a register is needed or no longer needed. ProcessTakeRegisterInstr(TakeRegister) ProcessReleaseRegisterInstr(ReleaseRegister) // A label (for jumping to) ProcessDeclareLabelInstr(DeclareLabel) }
An InstrProcessor can process any instruction.
type Instruction ¶
type Instruction interface { fmt.Stringer ProcessInstr(InstrProcessor) }
Instruction is the interface that all ir instruction types must implement.
type Int ¶
type Int int64
An Int is a constant representing an integer literal.
func (Int) ProcessConstant ¶
func (n Int) ProcessConstant(p ConstantProcessor)
ProcessConstant uses the given ConstantProcessor to process the receiver.
type Jump ¶
type Jump struct {
Label Label
}
Jump jumps to the givel label.
func (Jump) ProcessInstr ¶
func (j Jump) ProcessInstr(p InstrProcessor)
ProcessInstr makes the InstrProcessor process this instruction.
type JumpIf ¶
JumpIf jumps to the given label if the boolean value in Cond is different from Not.
func (JumpIf) ProcessInstr ¶
func (j JumpIf) ProcessInstr(p InstrProcessor)
ProcessInstr makes the InstrProcessor process this instruction.
type LoadConst ¶
type LoadConst struct { Dst Register // Destination register Kidx uint // Index of the constant to load }
LoadConst loads a constant into a register.
func (LoadConst) ProcessInstr ¶
func (l LoadConst) ProcessInstr(p InstrProcessor)
ProcessInstr makes the InstrProcessor process this instruction.
func (LoadConst) WithDestReg ¶
func (l LoadConst) WithDestReg(r Register) Instruction
WithDestReg returns the same isntruction with a new destination register.
type Lookup ¶
Lookup finds the value associated with the key Index in Table and puts it in Dst.
func (Lookup) ProcessInstr ¶
func (s Lookup) ProcessInstr(p InstrProcessor)
ProcessInstr makes the InstrProcessor process this instruction.
func (Lookup) WithDestReg ¶
func (s Lookup) WithDestReg(r Register) Instruction
WithDestReg returns the same isntruction with a new destination register.
type MkClosure ¶
MkClosure creates a new closure with the given code and upvalues and puts it in Dst.
func (MkClosure) ProcessInstr ¶
func (m MkClosure) ProcessInstr(p InstrProcessor)
ProcessInstr makes the InstrProcessor process this instruction.
func (MkClosure) WithDestReg ¶
func (m MkClosure) WithDestReg(r Register) Instruction
WithDestReg returns the same isntruction with a new destination register.
type MkCont ¶
MkCont creates a new continuation for the given closure and puts it in Dst.
func (MkCont) ProcessInstr ¶
func (m MkCont) ProcessInstr(p InstrProcessor)
ProcessInstr makes the InstrProcessor process this instruction.
func (MkCont) WithDestReg ¶
func (m MkCont) WithDestReg(r Register) Instruction
WithDestReg returns the same isntruction with a new destination register.
type MkTable ¶
type MkTable struct {
Dst Register
}
MkTable creates a new empty table and puts it i Dst.
func (MkTable) ProcessInstr ¶
func (m MkTable) ProcessInstr(p InstrProcessor)
ProcessInstr makes the InstrProcessor process this instruction.
type NilType ¶
type NilType struct{}
NilType is the type of the nil literal.
func (NilType) ProcessConstant ¶
func (n NilType) ProcessConstant(p ConstantProcessor)
ProcessConstant uses the given ConstantProcessor to process the receiver.
type PrepForLoop ¶
type PrepForLoop struct {
Start, Stop, Step Register
}
PrepForLoop prepares a for loop
func (PrepForLoop) ProcessInstr ¶
func (i PrepForLoop) ProcessInstr(p InstrProcessor)
func (PrepForLoop) String ¶
func (i PrepForLoop) String() string
type Push ¶
type Push struct { Cont Register // Destination register (should contain a continuation) Item Register // Register containing item to push Etc bool // True if the Item is an etc value. }
Push pushes the contents of a register into a continuation.
func (Push) ProcessInstr ¶
func (p Push) ProcessInstr(ip InstrProcessor)
ProcessInstr makes the InstrProcessor process this instruction.
type PushCloseStack ¶
type PushCloseStack struct {
Src Register
}
PushCloseStack truncates pushes the value Src to the close stack. This instruction was introduced to support to-be-closed variables which are part of Lua 5.4
func (PushCloseStack) ProcessInstr ¶
func (i PushCloseStack) ProcessInstr(p InstrProcessor)
ProcessInstr makes the InstrProcessor process this instruction.
func (PushCloseStack) String ¶
func (i PushCloseStack) String() string
type Receive ¶
type Receive struct {
Dst []Register
}
Receive will put the result of pushes in the given registers.
func (Receive) ProcessInstr ¶
func (r Receive) ProcessInstr(p InstrProcessor)
ProcessInstr makes the InstrProcessor process this instruction.
type ReceiveEtc ¶
ReceiveEtc will put the result of pushes into the given registers. Extra pushes will be accumulated into the Etc register.
func (ReceiveEtc) ProcessInstr ¶
func (r ReceiveEtc) ProcessInstr(p InstrProcessor)
ProcessInstr makes the InstrProcessor process this instruction.
func (ReceiveEtc) String ¶
func (r ReceiveEtc) String() string
type Register ¶
type Register uint
A Register is an IR register. The number of IR registers is not bounded (other than the bounds of the underling type).
type ReleaseRegister ¶
type ReleaseRegister struct {
Reg Register
}
ReleaseRegister is not a real instruction. It is a hint to the next stage that the value in this register no longer needs to be used, so can be overwritten. It should be preceded by a TakeRegister for the same register.
func (ReleaseRegister) ProcessInstr ¶
func (r ReleaseRegister) ProcessInstr(p InstrProcessor)
ProcessInstr makes the InstrProcessor process this instruction.
func (ReleaseRegister) String ¶
func (r ReleaseRegister) String() string
type SetIndex ¶
SetIndex associates Index with Src in the table Table.
func (SetIndex) ProcessInstr ¶
func (s SetIndex) ProcessInstr(p InstrProcessor)
ProcessInstr makes the InstrProcessor process this instruction.
type SetRegInstruction ¶
type SetRegInstruction interface { DestReg() Register WithDestReg(Register) Instruction }
SetRegInstruction is the interface that instructions that set the value of a register must implement.
type String ¶
type String string
A String is a constant representing a string literal.
func (String) ProcessConstant ¶
func (s String) ProcessConstant(p ConstantProcessor)
ProcessConstant uses the given ConstantProcessor to process the receiver.
type TakeRegister ¶
type TakeRegister struct {
Reg Register
}
TakeRegister is not a real instruction. It is a hint to the next stage that the value in this register will need to be used, so not to overwrite it. A ReleaseRegister for the same register should be emitted some time later.
func (TakeRegister) ProcessInstr ¶
func (t TakeRegister) ProcessInstr(p InstrProcessor)
ProcessInstr makes the InstrProcessor process this instruction.
func (TakeRegister) String ¶
func (t TakeRegister) String() string
type Transform ¶
type Transform struct { Op ops.Op // Operator to apply to Src Dst Register // Destination register Src Register // Operand register }
Transform applies a unary operator Op to Src and stores the result in Dst.
func (Transform) ProcessInstr ¶
func (t Transform) ProcessInstr(p InstrProcessor)
ProcessInstr makes the InstrProcessor process this instruction.
func (Transform) WithDestReg ¶
func (t Transform) WithDestReg(r Register) Instruction
WithDestReg returns the same isntruction with a new destination register.
type TruncateCloseStack ¶
type TruncateCloseStack struct {
Height int
}
TruncateCloseStack truncates the close stack to Height (which should be >= 0). This instruction was introduced to support to-be-closed variables which are part of Lua 5.4
func (TruncateCloseStack) ProcessInstr ¶
func (t TruncateCloseStack) ProcessInstr(p InstrProcessor)
ProcessInstr makes the InstrProcessor process this instruction.
func (TruncateCloseStack) String ¶
func (t TruncateCloseStack) String() string