bytecode

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2017 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

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

instruction set types

View Source
const (
	GetLocal            = "getlocal"
	GetConstant         = "getconstant"
	GetInstanceVariable = "getinstancevariable"
	SetLocal            = "setlocal"
	SetConstant         = "setconstant"
	SetInstanceVariable = "setinstancevariable"
	PutString           = "putstring"
	PutSelf             = "putself"
	PutObject           = "putobject"
	PutNull             = "putnil"
	NewArray            = "newarray"
	ExpandArray         = "expand_array"
	SplatArray          = "splat_array"
	NewHash             = "newhash"
	NewRange            = "newrange"
	BranchUnless        = "branchunless"
	BranchIf            = "branchif"
	Jump                = "jump"
	DefMethod           = "def_method"
	DefSingletonMethod  = "def_singleton_method"
	DefClass            = "def_class"
	Send                = "send"
	InvokeBlock         = "invokeblock"
	Pop                 = "pop"
	Dup                 = "dup"
	Leave               = "leave"
)

instruction actions

View Source
const (
	NormalArg int = iota
	OptionedArg
	SplatArg
)

These constants are enums that represent argument's types

Variables

This section is empty.

Functions

This section is empty.

Types

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) GenerateByteCode

func (g *Generator) GenerateByteCode(stmts []ast.Statement) string

GenerateByteCode returns compiled instructions in string format

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 {
	Action string
	Params []string
	// contains filtered or unexported fields
}

Instruction represents compiled bytecode instruction

func (*Instruction) AnchorLine

func (i *Instruction) AnchorLine() (int, error)

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

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

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() []int

ArgTypes returns enums that represents each argument's type

func (*InstructionSet) Name

func (is *InstructionSet) Name() string

Name returns instruction set's name

func (*InstructionSet) SetType

func (is *InstructionSet) SetType() string

SetType returns instruction's type

Jump to

Keyboard shortcuts

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