Documentation
¶
Index ¶
Constants ¶
const ( MethodDef = "Def" ClassDef = "DefClass" Block = "Block" Program = "ProgramStart" )
instruction set types
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
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.
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 ¶
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 ¶
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) 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