instruction

package
v0.0.0-...-025acd7 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2021 License: Unlicense Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConstantKindInt = iota
	ConstantKindDouble
	ConstantKindString
)
View Source
const (
	Nop     = 0x0
	Bipush  = 0x1
	Ipush   = 0x2
	Pop     = 0x4
	Pop2    = 0x5
	Popn    = 0x6
	Dup     = 0x7
	Dup2    = 0x8
	Loadc   = 0x9
	Loada   = 0xa
	New     = 0xb
	Snew    = 0xc
	Iload   = 0x10
	Dload   = 0x11
	Aload   = 0x12
	Iaload  = 0x18
	Daload  = 0x19
	Aaload  = 0x1a
	Istore  = 0x20
	Dstore  = 0x21
	Astore  = 0x22
	Iastore = 0x28
	Dastore = 0x29
	Aastore = 0x2a
	Iadd    = 0x30
	Dadd    = 0x31
	Isub    = 0x34
	Dsub    = 0x35
	Imul    = 0x38
	Dmul    = 0x39
	Idiv    = 0x3c
	Ddiv    = 0x3d
	Ineg    = 0x40
	Dneg    = 0x41
	Icmp    = 0x44
	Dcmp    = 0x45
	I2d     = 0x60
	D2i     = 0x61
	I2c     = 0x62
	Jmp     = 0x70
	Je      = 0x71
	Jne     = 0x72
	Jl      = 0x73
	Jge     = 0x74
	Jg      = 0x75
	Jle     = 0x76
	Call    = 0x80
	Ret     = 0x88
	Iret    = 0x89
	Dret    = 0x8a
	Aret    = 0x8b
	Iprint  = 0xa0
	Dprint  = 0xa1
	Cprint  = 0xa2
	Sprint  = 0xa3
	Printl  = 0xaf
	Iscan   = 0xb0
	Dscan   = 0xb1
	Cscan   = 0xb2
)

Variables

View Source
var Instructions = map[int]Instruction{
	Nop:     {Code: Nop, Representation: "nop", /* contains filtered or unexported fields */},
	Bipush:  {Code: Bipush, Representation: "bipush", Operands: []int{1}, /* contains filtered or unexported fields */},
	Ipush:   {Code: Ipush, Representation: "ipush", Operands: []int{4}, /* contains filtered or unexported fields */},
	Pop:     {Code: Pop, Representation: "pop", /* contains filtered or unexported fields */},
	Pop2:    {Code: Pop2, Representation: "pop2", /* contains filtered or unexported fields */},
	Popn:    {Code: Popn, Representation: "popn", Operands: []int{4}, /* contains filtered or unexported fields */},
	Dup:     {Code: Dup, Representation: "dup", /* contains filtered or unexported fields */},
	Dup2:    {Code: Dup2, Representation: "dup2", /* contains filtered or unexported fields */},
	Loadc:   {Code: Loadc, Representation: "loadc", Operands: []int{2}, /* contains filtered or unexported fields */},
	Loada:   {Code: Loada, Representation: "loada", Operands: []int{2, 4}, /* contains filtered or unexported fields */},
	New:     {Code: New, Representation: "new", /* contains filtered or unexported fields */},
	Snew:    {Code: Snew, Representation: "snew", Operands: []int{4}, /* contains filtered or unexported fields */},
	Iload:   {Code: Iload, Representation: "iload", /* contains filtered or unexported fields */},
	Dload:   {Code: Dload, Representation: "dload", /* contains filtered or unexported fields */},
	Aload:   {Code: Aload, Representation: "aload", /* contains filtered or unexported fields */},
	Iaload:  {Code: Iaload, Representation: "iaload", /* contains filtered or unexported fields */},
	Daload:  {Code: Daload, Representation: "daload", /* contains filtered or unexported fields */},
	Aaload:  {Code: Aaload, Representation: "aaload", /* contains filtered or unexported fields */},
	Istore:  {Code: Istore, Representation: "istore", /* contains filtered or unexported fields */},
	Dstore:  {Code: Dstore, Representation: "dstore", /* contains filtered or unexported fields */},
	Astore:  {Code: Astore, Representation: "astore", /* contains filtered or unexported fields */},
	Iastore: {Code: Iastore, Representation: "iastore", /* contains filtered or unexported fields */},
	Dastore: {Code: Dastore, Representation: "dastore", /* contains filtered or unexported fields */},
	Aastore: {Code: Aastore, Representation: "aastore", /* contains filtered or unexported fields */},
	Iadd:    {Code: Iadd, Representation: "iadd", /* contains filtered or unexported fields */},
	Dadd:    {Code: Dadd, Representation: "dadd", /* contains filtered or unexported fields */},
	Isub:    {Code: Isub, Representation: "isub", /* contains filtered or unexported fields */},
	Dsub:    {Code: Dsub, Representation: "dsub", /* contains filtered or unexported fields */},
	Imul:    {Code: Imul, Representation: "imul", /* contains filtered or unexported fields */},
	Dmul:    {Code: Dmul, Representation: "dmul", /* contains filtered or unexported fields */},
	Idiv:    {Code: Idiv, Representation: "idiv", /* contains filtered or unexported fields */},
	Ddiv:    {Code: Ddiv, Representation: "ddiv", /* contains filtered or unexported fields */},
	Ineg:    {Code: Ineg, Representation: "ineg", /* contains filtered or unexported fields */},
	Dneg:    {Code: Dneg, Representation: "dneg", /* contains filtered or unexported fields */},
	Icmp:    {Code: Icmp, Representation: "icmp", /* contains filtered or unexported fields */},
	Dcmp:    {Code: Dcmp, Representation: "dcmp", /* contains filtered or unexported fields */},
	I2d:     {Code: I2d, Representation: "i2d", /* contains filtered or unexported fields */},
	D2i:     {Code: D2i, Representation: "d2i", /* contains filtered or unexported fields */},
	I2c:     {Code: I2c, Representation: "i2c", /* contains filtered or unexported fields */},
	Jmp:     {Code: Jmp, Representation: "jmp", Operands: []int{2}, /* contains filtered or unexported fields */},
	Je:      {Code: Je, Representation: "je", Operands: []int{2}, /* contains filtered or unexported fields */},
	Jne:     {Code: Jne, Representation: "jne", Operands: []int{2}, /* contains filtered or unexported fields */},
	Jl:      {Code: Jl, Representation: "jl", Operands: []int{2}, /* contains filtered or unexported fields */},
	Jge:     {Code: Jge, Representation: "jge", Operands: []int{2}, /* contains filtered or unexported fields */},
	Jg:      {Code: Jg, Representation: "jg", Operands: []int{2}, /* contains filtered or unexported fields */},
	Jle:     {Code: Jle, Representation: "jle", Operands: []int{2}, /* contains filtered or unexported fields */},
	Call:    {Code: Call, Representation: "call", Operands: []int{2}, /* contains filtered or unexported fields */},
	Ret:     {Code: Ret, Representation: "ret", /* contains filtered or unexported fields */},
	Iret:    {Code: Iret, Representation: "iret", /* contains filtered or unexported fields */},
	Dret:    {Code: Dret, Representation: "dret", /* contains filtered or unexported fields */},
	Aret:    {Code: Aret, Representation: "aret", /* contains filtered or unexported fields */},
	Iprint:  {Code: Iprint, Representation: "iprint", /* contains filtered or unexported fields */},
	Dprint:  {Code: Dprint, Representation: "dprint", /* contains filtered or unexported fields */},
	Cprint:  {Code: Cprint, Representation: "cprint", /* contains filtered or unexported fields */},
	Sprint:  {Code: Sprint, Representation: "sprint", /* contains filtered or unexported fields */},
	Printl:  {Code: Printl, Representation: "printl", /* contains filtered or unexported fields */},
	Iscan:   {Code: Iscan, Representation: "iscan", /* contains filtered or unexported fields */},
	Dscan:   {Code: Dscan, Representation: "dscan", /* contains filtered or unexported fields */},
	Cscan:   {Code: Cscan, Representation: "cscan", /* contains filtered or unexported fields */},
}

Functions

This section is empty.

Types

type Constant

type Constant struct {
	Kind    int
	Value   interface{}
	Address int
}

type Error

type Error = cc0_error.Error

type Fn

type Fn struct {
	ReturnType int
	Parameters *[]string

	RelatedSymbolTable *SymbolTable
	// contains filtered or unexported fields
}

func InitFn

func InitFn(returnType int) (res *Fn)

func (*Fn) Append

func (f *Fn) Append(instruction int, operands ...int)

func (*Fn) ChangeInstructionTo

func (f *Fn) ChangeInstructionTo(offset, instruction int, operands ...int)

func (*Fn) GetAnEmptyConstantSlot

func (f *Fn) GetAnEmptyConstantSlot() (result int)

func (*Fn) GetCurrentConstantOffset

func (f *Fn) GetCurrentConstantOffset() int

func (*Fn) GetCurrentLine

func (f *Fn) GetCurrentLine() *Line

func (*Fn) GetCurrentOffset

func (f *Fn) GetCurrentOffset() int

func (*Fn) GetLines

func (f *Fn) GetLines() *[]Line

func (*Fn) GetPreviousLine

func (f *Fn) GetPreviousLine() *Line

func (*Fn) NextMemorySlot

func (f *Fn) NextMemorySlot(kind int) (slot int)

func (*Fn) PopStack

func (f *Fn) PopStack(reservedSize int)

func (*Fn) ReplaceNopAt

func (f *Fn) ReplaceNopAt(offset int, instruction int, operands ...int)

type FnInstructions

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

type Instruction

type Instruction struct {
	Code           int
	Representation string

	Operands []int
	// contains filtered or unexported fields
}

func GetCodeFrom

func GetCodeFrom(representation string) *Instruction

func GetInstruction

func GetInstruction(code int) Instruction

func (Instruction) IsValidInstruction

func (instruction Instruction) IsValidInstruction(operands ...int) bool

type Line

type Line struct {
	I        Instruction
	Operands *[]int
}

func (*Line) ChangeInstructionTo

func (l *Line) ChangeInstructionTo(instruction int, operands ...int)

func (*Line) SetFirstOperandTo

func (l *Line) SetFirstOperandTo(operand int)

type PriorityQueue

type PriorityQueue = common.PriorityQueue

type Symbol

type Symbol struct {
	Address    int
	FnInfo     *Fn
	IsCallable bool
	IsConstant bool
	Kind       int
	Name       string
}

type SymbolTable

type SymbolTable struct {
	Constants       *[]Constant
	Parent          *SymbolTable
	RelatedFunction *Fn
	Symbols         map[string]*Symbol
	// contains filtered or unexported fields
}

func InitSymbolTable

func InitSymbolTable(parent *SymbolTable, fi *Fn) *SymbolTable

func (SymbolTable) AddAConstant

func (st SymbolTable) AddAConstant(name string, kind int) *Error

func (*SymbolTable) AddAFunction

func (st *SymbolTable) AddAFunction(name string, returnType int, fn *Fn) *Error

Functions generated by this function would not have addresses. Their addresses should be reassigned by the assembler.

func (*SymbolTable) AddALiteral

func (st *SymbolTable) AddALiteral(kind int, value interface{}) (address int)

This is almost always only received by the global symbol table.

func (SymbolTable) AddAVariable

func (st SymbolTable) AddAVariable(name string, kind int) *Error

func (*SymbolTable) AppendChildSymbolTable

func (st *SymbolTable) AppendChildSymbolTable(relatedFunction *Fn) *SymbolTable

func (SymbolTable) GetAddressOf

func (st SymbolTable) GetAddressOf(symbol string) int

func (*SymbolTable) GetLevelDiff

func (st *SymbolTable) GetLevelDiff(name string) int

func (SymbolTable) GetSymbolNamed

func (st SymbolTable) GetSymbolNamed(name string) *Symbol

func (SymbolTable) HasDeclared

func (st SymbolTable) HasDeclared(name string) bool

func (SymbolTable) RemoveConstantNamed

func (st SymbolTable) RemoveConstantNamed(name string) *Error

Jump to

Keyboard shortcuts

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