code

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: May 23, 2022 License: Apache-2.0, MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Type1Pfx uint32 = 8 << 28
	Type2Pfx uint32 = 7 << 28
	Type3Pfx uint32 = 6 << 28
	Type4Pfx uint32 = 5 << 28
	Type5Pfx uint32 = 4 << 28
	Type6Pfx uint32 = 3 << 28
	Type0Pfx uint32 = 0
)
View Source
const (
	Register = RegType(iota)
	Upvalue
)

Register types

Variables

This section is empty.

Functions

This section is empty.

Types

type Addr

type Addr int

type BinOp

type BinOp uint8
const (
	OpAdd BinOp = iota
	OpSub
	OpMul
	OpDiv
	OpFloorDiv
	OpMod
	OpPow
	OpBitAnd
	OpBitOr
	OpBitXor
	OpShiftL
	OpShiftR
	OpEq
	OpLt
	OpLeq
	OpConcat
)

func (BinOp) ToX

func (op BinOp) ToX() uint32

type Bool

type Bool bool

func (Bool) ShortString

func (b Bool) ShortString() string

type Code

type Code struct {
	Name                   string
	StartOffset, EndOffset uint
	UpvalueCount           int16
	RegCount               int16
	UpNames                []string
}

func (Code) ShortString

func (c Code) ShortString() string

type Compiler

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

func NewCompiler

func NewCompiler(source string) *Compiler

func (*Compiler) Code

func (c *Compiler) Code() []Opcode

func (*Compiler) Emit

func (c *Compiler) Emit(opcode Opcode, line int)

func (*Compiler) EmitJump

func (c *Compiler) EmitJump(opcode Opcode, lbl Label, line int)

func (*Compiler) EmitLabel

func (c *Compiler) EmitLabel(lbl Label)

func (*Compiler) Lines

func (c *Compiler) Lines() []int32

func (*Compiler) Offset

func (c *Compiler) Offset() uint

func (*Compiler) Source

func (c *Compiler) Source() string

type Constant

type Constant interface {
	ShortString() string
}

type Flag

type Flag uint8
const (
	On  Flag = 1
	Off Flag = 0
)

func (Flag) ToF

func (f Flag) ToF() uint32

type Float

type Float float64

func (Float) ShortString

func (f Float) ShortString() string

type Int

type Int int64

func (Int) ShortString

func (i Int) ShortString() string

type JumpOp

type JumpOp uint8
const (
	OpCall JumpOp = iota
	OpJump
	OpJumpIf
	OpJumpIfForLoopDone // Extra opcode (3 registers needed)
)

func (JumpOp) ToY

func (op JumpOp) ToY() uint32

type Label

type Label uint

type Lit16

type Lit16 uint16

func (Lit16) ToN

func (l Lit16) ToN() uint32

type Lit8

type Lit8 uint8

func (Lit8) ToB

func (l Lit8) ToB() uint32

type NilType

type NilType struct{}

func (NilType) ShortString

func (n NilType) ShortString() string

type Opcode

type Opcode uint32

Opcode is the type of opcodes

func MkType0

func MkType0(f Flag, rA Reg) Opcode

func MkType1

func MkType1(op BinOp, rA, rB, rC Reg) Opcode

func MkType2

func MkType2(f Flag, rA, rB, rC Reg) Opcode

func MkType3

func MkType3(f Flag, op UnOpK16, rA Reg, k Lit16) Opcode

func MkType4a

func MkType4a(f Flag, op UnOp, rA, rB Reg) Opcode

func MkType4b

func MkType4b(f Flag, op UnOpK, rA Reg, k Lit8) Opcode

func MkType5

func MkType5(f Flag, op JumpOp, rA Reg, k Lit16) Opcode

func MkType6

func MkType6(f Flag, rA, rB Reg, m uint8) Opcode

func (Opcode) Disassemble

func (c Opcode) Disassemble(d *UnitDisassembler, i int) string

func (Opcode) GetA

func (c Opcode) GetA() Reg

func (Opcode) GetB

func (c Opcode) GetB() Reg

func (Opcode) GetC

func (c Opcode) GetC() Reg

func (Opcode) GetF

func (c Opcode) GetF() bool

func (Opcode) GetM

func (c Opcode) GetM() uint8

func (Opcode) GetN

func (c Opcode) GetN() uint16

func (Opcode) GetR

func (c Opcode) GetR() uint8

func (Opcode) GetType

func (c Opcode) GetType() uint8

func (Opcode) GetX

func (c Opcode) GetX() BinOp

func (Opcode) GetY

func (c Opcode) GetY() uint8

func (Opcode) GetZ

func (c Opcode) GetZ() UnOp

func (Opcode) HasSubtypeFlagSet

func (c Opcode) HasSubtypeFlagSet() bool

func (Opcode) HasType0

func (c Opcode) HasType0() bool

func (Opcode) HasType1

func (c Opcode) HasType1() bool

func (Opcode) HasType2or4

func (c Opcode) HasType2or4() bool

func (Opcode) HasType4a

func (c Opcode) HasType4a() bool

func (Opcode) HasType6

func (c Opcode) HasType6() bool

func (Opcode) SetN

func (c Opcode) SetN(n uint16) Opcode

func (Opcode) TypePfx

func (c Opcode) TypePfx() uint32

type Reg

type Reg uint16

Reg is a register

func MkRegister

func MkRegister(idx uint8) Reg

func MkUpvalue

func MkUpvalue(idx uint8) Reg

func (Reg) Idx

func (r Reg) Idx() uint8

func (Reg) String

func (r Reg) String() string

func (Reg) ToA

func (r Reg) ToA() uint32

func (Reg) ToB

func (r Reg) ToB() uint32

func (Reg) ToC

func (r Reg) ToC() uint32

func (Reg) Tp

func (r Reg) Tp() RegType

type RegType

type RegType uint8

RegType represents the type of a register

type String

type String string

func (String) ShortString

func (s String) ShortString() string

type UnOp

type UnOp uint8
const (
	OpNeg UnOp = iota
	OpBitNot
	OpLen
	OpClosure
	OpCont
	OpTailCont
	OpID
	OpTruth // Turn operand to boolean
	OpCell  // ?
	OpNot   // Added afterwards - why did I not have it in the first place?
	OpUpvalue
	OpEtcID
	OpToNumber
)

func (UnOp) ToC

func (op UnOp) ToC() uint32

type UnOpK

type UnOpK uint8
const (
	OpNil UnOpK = iota
	OpStr0
	OpTable
	OpStr1
	OpBool
	OpCC
	OpClear
	OpInt   // Extra 64 bits (2 opcodes)
	OpFloat // Extra 64 bits (2 opcodes)
	OpStrN  // Extra [n / 4] opcodes
)

func (UnOpK) ToC

func (op UnOpK) ToC() uint32

type UnOpK16

type UnOpK16 uint8
const (
	OpInt16 UnOpK16 = iota
	OpK
	OpClosureK
	OpStr2
)

func (UnOpK16) ToY

func (op UnOpK16) ToY() uint32

type Unit

type Unit struct {
	Source    string
	Code      []Opcode
	Lines     []int32
	Constants []Constant
}

func NewUnit

func NewUnit(source string, code []Opcode, lines []int32, constants []Constant) *Unit

func (*Unit) Disassemble

func (u *Unit) Disassemble(w io.Writer)

type UnitDisassembler

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

func NewUnitDisassembler

func NewUnitDisassembler(unit *Unit) *UnitDisassembler

func (*UnitDisassembler) Disassemble

func (d *UnitDisassembler) Disassemble(w io.Writer)

func (*UnitDisassembler) GetLabel

func (d *UnitDisassembler) GetLabel(offset int) string

func (*UnitDisassembler) SetLabel

func (d *UnitDisassembler) SetLabel(offset int, lbl string)

func (*UnitDisassembler) ShortKString

func (d *UnitDisassembler) ShortKString(ki uint16) string

Jump to

Keyboard shortcuts

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