Documentation ¶
Index ¶
Constants ¶
const ( MethodDef = "Def" ClassDef = "DefClass" Block = "Block" Program = "ProgramStart" )
instruction set types
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
const ( NormalArg uint8 = iota OptionedArg SplatArg RequiredKeywordArg OptionalKeywordArg )
These constants are enums that represent argument's types
Variables ¶
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.
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 ¶
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) 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