bytecode

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2020 License: MIT Imports: 3 Imported by: 12

Documentation

Index

Constants

View Source
const (
	MethodDef = "Def"
	ClassDef  = "DefClass"
	Block     = "Block"
	Program   = "ProgramStart"
)

instruction set types

View Source
const (
	GetLocal uint8 = iota
	GetConstant
	GetInstanceVariable
	SetLocal
	SetConstant
	SetInstanceVariable
	PutBoolean
	PutString
	PutFloat
	PutSelf
	PutObject
	PutNull
	NewArray
	ExpandArray
	SplatArray
	NewHash
	NewRange
	BranchUnless
	BranchIf
	Jump
	Break
	DefMethod
	DefSingletonMethod
	DefClass
	Send
	InvokeBlock
	GetBlock
	Pop
	Dup
	Leave
	InstructionCount
)

instruction actions

View Source
const (
	NormalArg uint8 = iota
	OptionedArg
	SplatArg
	RequiredKeywordArg
	OptionalKeywordArg
)

These constants are enums that represent argument's types

Variables

View Source
var InstructionNameTable = []string{
	GetLocal:            "getlocal",
	GetConstant:         "getconstant",
	GetInstanceVariable: "getinstancevariable",
	SetLocal:            "setlocal",
	SetConstant:         "setconstant",
	SetInstanceVariable: "setinstancevariable",
	PutBoolean:          "putboolean",
	PutString:           "putstring",
	PutFloat:            "putfloat",
	PutSelf:             "putself",
	PutObject:           "putobject",
	PutNull:             "putnil",
	NewArray:            "newarray",
	ExpandArray:         "expand_array",
	SplatArray:          "splat_array",
	NewHash:             "newhash",
	NewRange:            "newrange",
	BranchUnless:        "branchunless",
	BranchIf:            "branchif",
	Jump:                "jump",
	Break:               "break",
	DefMethod:           "def_method",
	DefSingletonMethod:  "def_singleton_method",
	DefClass:            "def_class",
	Send:                "send",
	InvokeBlock:         "invokeblock",
	GetBlock:            "getblock",
	Pop:                 "pop",
	Dup:                 "dup",
	Leave:               "leave",
}

InstructionNameTable is the table the maps instruction's op code with its readable name

Functions

This section is empty.

Types

type ArgSet added in v0.1.6

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

ArgSet stores the metadata of a method definition's parameters.

func (*ArgSet) Names added in v0.1.6

func (as *ArgSet) Names() []string

Names are the getter method of *ArgSet's names attribute TODO: needs to change the func to simple public variable

func (*ArgSet) Types added in v0.1.6

func (as *ArgSet) Types() []uint8

Types are the getter method of *ArgSet's types attribute TODO: needs to change the func to simple public variable

type Generator

type Generator struct {
	REPL bool
	// contains filtered or unexported fields
}

Generator contains program's AST and will store generated instruction sets

func NewGenerator

func NewGenerator() *Generator

NewGenerator initializes new Generator with complete AST tree.

func (*Generator) GenerateInstructions

func (g *Generator) GenerateInstructions(stmts []ast.Statement) []*InstructionSet

GenerateInstructions returns compiled instructions

func (*Generator) InitTopLevelScope

func (g *Generator) InitTopLevelScope(program *ast.Program)

InitTopLevelScope sets generator's scope with program node, which means it's the top level scope

func (*Generator) ResetInstructionSets

func (g *Generator) ResetInstructionSets()

ResetInstructionSets clears generator's instruction sets

type Instruction

type Instruction struct {
	Opcode uint8
	Params []interface{}
	// contains filtered or unexported fields
}

Instruction represents compiled bytecode instruction

func (*Instruction) ActionName added in v0.1.11

func (i *Instruction) ActionName() string

ActionName returns the human readable name of the instruction

func (*Instruction) AnchorLine

func (i *Instruction) AnchorLine() int

AnchorLine returns instruction anchor's line number if it has an anchor

func (*Instruction) Inspect added in v0.1.11

func (i *Instruction) Inspect() string

Inspect is for inspecting the instruction's content

func (*Instruction) Line

func (i *Instruction) Line() int

Line returns instruction's line number

func (*Instruction) SourceLine added in v0.1.0

func (i *Instruction) SourceLine() int

SourceLine returns instruction's source line number TODO: needs to change the func to simple public variable

type InstructionSet

type InstructionSet struct {
	Instructions []*Instruction
	// contains filtered or unexported fields
}

InstructionSet contains a set of Instructions and some metadata

func (*InstructionSet) ArgTypes

func (is *InstructionSet) ArgTypes() *ArgSet

ArgTypes returns enums that represents each argument's type TODO: needs to change the func to simple public variable

func (*InstructionSet) Name

func (is *InstructionSet) Name() string

Name returns instruction set's name TODO: needs to change the func to simple public variable

func (*InstructionSet) Type added in v0.1.6

func (is *InstructionSet) Type() string

Type returns instruction's type TODO: needs to change the func to simple public variable

Jump to

Keyboard shortcuts

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