bytecode

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2018 License: MIT Imports: 4 Imported by: 12

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

instruction actions

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

These constants are enums that represent argument's types

Variables

This section is empty.

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) FindIndex added in v0.1.6

func (as *ArgSet) FindIndex(name string) int

func (*ArgSet) Names added in v0.1.6

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

Names are the getter method of *ArgSet's names attribute

func (*ArgSet) Types added in v0.1.6

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

Types are the getter method of *ArgSet's types attribute

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

	ArgSet *ArgSet
	// 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() *ArgSet

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) Type added in v0.1.6

func (is *InstructionSet) Type() string

SetType returns instruction's type

Jump to

Keyboard shortcuts

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