Class: SketchGen

Sketch. SketchGen

Creates an instance of the SketchGen module. SketchGen takes a JSON tree output by the default Jison generated parser and outputs MVM bytecode used to drive computations and canvas operations.

new SketchGen()

Author:
  • FelixMcFelix (Kyle S.)
Source:

Classes

Label
ScopeStackFrame

Members

<static, constant> SketchGenInstr

Table of unbound functions used in code generation. These correspond to keys in Sketch.SketchGenNodes, and MUST be bound to an instance of Sketch.SketchGen to function.
Author:
  • FelixMcFelix (Kyle S.)
Source:

Methods

beginFunction(type)

Tell the generator that we are beginning a function definition, so that we can ensure that returns have the right type.
Parameters:
Name Type Description
type string the return type of the function we are working on.
Source:
Returns:
void

cleanSlate()

Reset the internal object state to allow onject reuse when compiling a new program.
Source:
Returns:
void

currentFunctionType() → {string}

Request the type of the current function definition.
Source:
Returns:
Type
string

emit(code) → {number}

Write a value to the next available code word.
Parameters:
Name Type Description
code * the code word or data value to be written into the next slot.
Source:
Returns:
- the address which was just written to.
Type
number

endFunction()

Tell the generator that we are ending a function definition.
Source:
Returns:
void

interpret(program)

Compile a Sketch program.
Parameters:
Name Type Description
program Object an AST object generated by the Jison parser.
Source:
Returns:
number[] - an array of opcodes and literals to be parsed by MVM.

interpretNode(node, opt) → {Object}

Interpret an AST node using the current code generator.
Parameters:
Name Type Description
node Object the AST node to be processed in the production of the current code store.
opt * an optional parameter to be passed to the individual node handler function.
Source:
Returns:
Type
Object

patch(addr, code)

Replace a code value at a given address.
Parameters:
Name Type Description
addr number the code address to be replaced.
code * the value to write to the code store.
Source:
Returns:
void

pc() → {number}

Return the current program counter value.
Source:
Returns:
- the current program counter value.
Type
number

scopeLookup(label) → {Object}

Search for a reference to a label (a variable) within the program scope.
Parameters:
Name Type Description
label string the variable name to lookup.
Source:
Returns:
- an object detailing the height of the referenced label, its address and its type as well as any extra data.
Type
Object

scopePop(noEmit)

Pop off the current program scope frame.
Parameters:
Name Type Argument Default Description
noEmit boolean <optional>
false specifies whether push and pop commands should not be written to the program as a side effect. This should be true for function definitions.
Source:
Returns:
void

scopePush(noEmit)

Push a new program scope frame.
Parameters:
Name Type Argument Default Description
noEmit boolean <optional>
false specifies whether push and pop commands should not be written to the program as a side effect. This should be true for function definitions.
Source:
Returns:
void

scopeRegister(label, type, extra)

Register a label in the current scope frame.
Parameters:
Name Type Argument Description
label string the variable name to register.
type string the data type that the variable will be declared with.
extra object <optional>
any extra data that could be required when handling this label (for example, function definitions).
Source:
Returns:
void