Basic usage

Compiler

Instance of this class are used to compile a yarn AST output by the YarnParser

new Compiler(config: CompilerConfig)
Parameters
config (CompilerConfig) the configuration for this compiler
Instance Members
process(yarnParser)
assemble()
writeBytecode(logicStream, dialogueStream, sourceMapStream, debugStream)
writeBuffers(includeSourceMap, includeDebug)
reset()

CompilerConfig

Compiler configuration

new CompilerConfig()
Static Members
errorIfNodeUndefined

Commands

ByName

Command types by name (constant is the opcode in octal)

ByName
Static Members
Noop
ShowText
RunCommand
ShowDialogBlock
DialogBlockEnd
NodeEntry
Jump
JumpIfTrue
JumpIfFalse
VariableLoad
VariableSet
StaticNull
StaticTrue
StaticFalse
StaticString
StaticFloat
StaticInteger
Add
Subtract
Multiply
Divide
Modulus
Equal
Not
And
Or
Xor
GreaterThan
LessThan
FunctionReturn
FunctionNoReturn
PushOption
RunOptions
ClearArguments
ClearOptionStack
StopExecution

ByOpcode

Command types by name (constant is the opcode in octal)

ByOpcode

Internal API documentation

SetupPrivates

Create a new private field store

new SetupPrivates(defaults: Object<string, any>, attrs: Object<string, any>): Object<string, any>
Parameters
defaults (Object<string, any>) The defaults that this class instance has
attrs (Object<string, any>) Object containing values that override the defaults
Returns
Object<string, any>: an object that is the private variables with new instances of any non-overridden values

BufferObj

Buffer return object

new BufferObj()
Instance Members
BufferObj.dialogue
BufferObj.debug
BufferObj.logic
BufferObj.sourceMap

Pass1

This Handles pass 1 compiling which just unrolls all the nested statements into a continous list of commands. Jump instructions are either referencing command indexes or node names function, variable and string references are still referencing the names. This is desiggned to run on one node at a time.

new Pass1(node: any)
Parameters
node (any)

add

This Handles pass 2 compiling which concatenates all the nodes into one long list and builds the start of the node table (for the logic file) and dialog table (for the dialog file)

add(state: any, pass1Output: any)
Parameters
state (any)
pass1Output (any)

Pass4

This pass converts all the commands into bytecode. It includes the lengths of all non-jump instructions Jump instructions lengths are set at the maximum possible size of the instructions

new Pass4(state: any)
Parameters
state (any)

Pass5

Calculate size of jump addresses now we know the rough locations of everything

new Pass5(state: any)
Parameters
state (any)