Documentation ¶
Index ¶
- Constants
- Variables
- type ArgSet
- type Generator
- type InstructionSet
- func (is *InstructionSet) GetBool(index int) bool
- func (is *InstructionSet) GetFloat(index int) float64
- func (is *InstructionSet) GetObject(index int) interface{}
- func (is *InstructionSet) GetString(index int) string
- func (is *InstructionSet) Inspect() string
- func (is *InstructionSet) SetConstant(o interface{}) int
Constants ¶
const ( Method = "Method" Class = "Class" Block = "Block" Program = "Program" )
instruction set types
const ( NoOp int = iota GetLocal GetConstant GetConstantNamespace GetInstanceVariable SetLocal SetOptional SetConstant SetInstanceVariable PutTrue PutFalse PutString PutFloat PutSelf PutSuper PutInt PutObject PutNull NewArray ExpandArray SplatArray SplatBlock NewHash NewRange NewRangeExcl BranchUnless BranchIf Jump Break DefMethod DefMetaMethod DefClass Send BinaryOperator Add Subtract Greater Less GreaterEqual LessEqual InvokeBlock GetBlock HasBlock Pop Dup Defer Leave InstructionCount )
instruction actions
const ( NormalArg uint8 = iota OptionedArg SplatArg RequiredKeywordArg OptionalKeywordArg )
These constants are enums that represent argument's types
const (
NoSuperClass = "__none__"
)
NoSuperClass represents a class without a superclass. Using this will result in the superclass being Object.
Variables ¶
var Instructions = [...]instruction{ NoOp: {"no_op", 0, nil}, GetLocal: {"getlocal", 2, []bool{false, false}}, GetConstant: {"getconstant", 1, []bool{true}}, GetConstantNamespace: {"getconstantnamespace", 1, []bool{true}}, GetInstanceVariable: {"getinstancevariable", 1, []bool{true}}, SetLocal: {"setlocal", 2, []bool{false, false}}, SetOptional: {"setoptional", 2, []bool{false, false}}, SetConstant: {"setconstant", 1, []bool{true}}, SetInstanceVariable: {"setinstancevariable", 1, []bool{true}}, PutTrue: {"puttrue", 0, nil}, PutFalse: {"putfalse", 0, nil}, PutString: {"putstring", 1, []bool{true}}, PutFloat: {"putfloat", 1, []bool{true}}, PutSelf: {"putself", 0, nil}, PutSuper: {"putsuper", 0, nil}, PutInt: {"putint", 1, []bool{false}}, PutObject: {"putobject", 1, []bool{true}}, PutNull: {"putnil", 0, nil}, NewArray: {"newarray", 1, []bool{false}}, ExpandArray: {"expand_array", 1, []bool{false}}, SplatArray: {"splat_array", 0, nil}, SplatBlock: {"splat_block", 0, nil}, NewHash: {"newhash", 1, []bool{false}}, NewRange: {"newrange", 0, nil}, NewRangeExcl: {"newrangeexcl", 0, nil}, BranchUnless: {"branchunless", 1, []bool{false}}, BranchIf: {"branchif", 1, []bool{false}}, Jump: {"jump", 1, []bool{false}}, Break: {"break", 0, nil}, DefMethod: {"def_method", 3, []bool{false, true, true}}, DefMetaMethod: {"def_meta_method", 3, []bool{false, true, true}}, DefClass: {"def_class", 4, []bool{true, true, true, true}}, Send: {"send", 4, []bool{true, false, true, true}}, BinaryOperator: {"bin_op", 1, []bool{true}}, Add: {"add", 1, []bool{true}}, Subtract: {"subtract", 1, []bool{true}}, Greater: {"greater", 1, []bool{true}}, Less: {"less", 1, []bool{true}}, GreaterEqual: {"greater_equal", 1, []bool{true}}, LessEqual: {"less_equal", 1, []bool{true}}, InvokeBlock: {"invokeblock", 1, []bool{false}}, GetBlock: {"getblock", 0, nil}, HasBlock: {"hasblock", 0, nil}, Pop: {"pop", 0, nil}, Dup: {"dup", 0, nil}, Defer: {"defer", 2, []bool{true, true}}, Leave: {"leave", 0, nil}, InstructionCount: {"instruction_count", 0, nil}, }
Instructions is the table that maps instruction's opcode with its readable name
Functions ¶
This section is empty.
Types ¶
type ArgSet ¶
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 initialises 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) ResetMethodInstructionSets ¶
func (g *Generator) ResetMethodInstructionSets()
ResetMethodInstructionSets clears generator's method instruction sets
type InstructionSet ¶
type InstructionSet struct { Name string Filename string Type string Instructions []int Constants []interface{} SourceMap []int Count int ArgTypes ArgSet }
InstructionSet contains a set of Instructions and some metadata
func (*InstructionSet) GetBool ¶
func (is *InstructionSet) GetBool(index int) bool
GetBool returns a bool value from the constant pool
func (*InstructionSet) GetFloat ¶
func (is *InstructionSet) GetFloat(index int) float64
GetFloat returns the int value from the constant pool
func (*InstructionSet) GetObject ¶
func (is *InstructionSet) GetObject(index int) interface{}
GetObject returns an interface{} object
func (*InstructionSet) GetString ¶
func (is *InstructionSet) GetString(index int) string
GetString returns the value of the string from the constant table
func (*InstructionSet) Inspect ¶
func (is *InstructionSet) Inspect() string
Inspect returns a string representation of the InstructionSet
func (*InstructionSet) SetConstant ¶
func (is *InstructionSet) SetConstant(o interface{}) int
SetConstant adds a constant to the constant pool