struct CatspeakIRBuilder
function CatspeakIRBuilder() constructor {
// 5 fields omitted
}
๐ฌ This is an experimental feature. It may change at any moment.
Intended to be a stable inferface for generating code for Catspeak IR programs. The preferred method of creating correctly formed, and optimised Catspeak IR.
ยง allocArg
static allocArg = function(
name : String,
location? : Real,
) -> Struct
Allocates a new named function argument with the supplied name. Returns a term to get or set the value of this argument.
โ ๏ธ WarningAll parameter names must be allocated before allocating any local variables.
Arguments
name
The name of the local variable to allocate.
location
(optional)The source location of this local variable.
Returns Struct
ยง allocLocal
static allocLocal = function(
name : String,
location? : Real,
) -> Struct
Allocates a new local variable with the supplied name in the current scope. Returns a term to get or set the value of this local variable.
Arguments
name
The name of the local variable to allocate.
location
(optional)The source location of this local variable.
Returns Struct
ยง allocLocalOrReuse
static allocLocalOrReuse = function(
name : String,
location? : Real,
) -> Struct
Reuses a local variable with the supplied name, if one exists in the
current scope. Otherwise, behaves identically to allocLocal
.
Arguments
name
The name of the local variable to allocate.
location
(optional)The source location of this local variable.
Returns Struct
ยง createAccessor
static createAccessor = function(
collection : Struct,
key : Struct,
location? : Real,
) -> Struct
Creates an accessor expression.
Arguments
collection
The term containing the collection to access.
key
The term containing the key to access the collection with.
location
(optional)The source location of this term.
Returns Struct
ยง createAnd
static createAnd = function(
eager : Struct,
lazy : Struct,
location? : Real,
) -> Struct
Emits the instruction for a short-circuiting logical AND expression.
Arguments
eager
The term which evaluates immediately.
lazy
The term which evaluates if the first term is true.
location
(optional)The source location of this value term.
Returns Struct
ยง createArray
static createArray = function(
values : Array,
location? : Real,
) -> Struct
Emits the instruction to create a new array literal.
Arguments
values
The values to populate the array with.
location
(optional)The source location of this value term.
Returns Struct
ยง createAssign
static createAssign = function(
type : Enum.CatspeakAssign,
lhs : Struct,
rhs : Struct,
location? : Real,
) -> Struct
Attempts to assign a right-hand-side value to a left-hand-side target.
๐ NoteEither terms A or B could be optimised or modified, therefore you should always treat both terms as being invalid after calling this method. Always use the result returned by this method as the new source of truth.
Arguments
type
The assignment type to use.
lhs
The assignment target to use. Typically this is a local/global variable get expression.
rhs
The assignment target to use. Typically this is a local/global variable get expression.
location
(optional)The source location of this assignment.
Returns Struct
ยง createBinary
static createBinary = function(
operator : Enum.CatspeakOperator,
lhs : String,
rhs : String,
location? : Real,
) -> Struct
Creates a binary operator.
Arguments
operator
The operator type to use.
lhs
The left-hand side operand.
rhs
The right-hand side operand.
location
(optional)The source location of this term.
Returns Struct
ยง createBreak
static createBreak = function(
value : Struct,
location? : Real,
) -> Struct
Emits the instruction to break from the current loop with a specified value.
Arguments
value
The instruction for the value to break with.
location
(optional)The source location of this value term.
Returns Struct
ยง createCall
static createCall = function(
callee : Struct,
args : Struct,
location? : Real,
) -> Struct
Emits the instruction to call a function with a set of arguments.
Arguments
callee
The instruction containing the function to call.
args
The the arguments to pass into the function call.
location
(optional)The source location of this value term.
Returns Struct
ยง createCallNew
static createCallNew = function(
callee : Struct,
args : Struct,
location? : Real,
) -> Struct
Emits the instruction to call a constructor function with a set of arguments.
Arguments
callee
The instruction containing the function to call.
args
The the arguments to pass into the function call.
location
(optional)The source location of this value term.
Returns Struct
ยง createContinue
static createContinue = function(
location? : Real,
) -> Struct
Emits the instruction to continue to the next iteration of the current loop.
Arguments
location
(optional)The source location of this value term.
Returns Struct
ยง createGet
static createGet = function(
name : String,
location? : Real,
) -> Struct
Searches a for a variable with the supplied name and emits a get instruction for it.
Arguments
name
The name of the variable to search for.
location
(optional)The source location of this term.
Returns Struct
ยง createIf
static createIf = function(
condition : Struct,
ifTrue : Struct,
ifFalse : Struct,
location? : Real,
) -> Struct
Emits the instruction for an if statement.
Arguments
condition
The term which evaluates to the condition of the if statement.
ifTrue
The term which evaluates if the condition of the if statement is true.
ifFalse
The term which evaluates if the condition of the if statement is false.
location
(optional)The source location of this value term.
Returns Struct
ยง createLoop
static createLoop = function(
preCondition : Struct,
postCondition : Struct,
step : Struct,
body : Struct,
location? : Real,
) -> Struct
Emits the instruction for a generic loop. GML style while
,
for
, and do
loops can be implemented in terms of this function.
Arguments
preCondition
The term which evaluates to the condition of a
while
loop. Can beundefined
.postCondition
The term which evaluates to the condition of a
do
loop. Can beundefined
.step
The term which evaluates to the step of a
for
loop. Can beundefined
.body
The body of the while loop.
location
(optional)The source location of this value term.
Returns Struct
ยง createMatch
static createMatch = function(
value : Struct,
arms : Array,
location? : Real,
)
Emits the instruction for a match expression.
Arguments
value
The term to evaluate and compare against.
arms
A list of pairs where the first term is compared against
value
and the second term is returned if both match.location
(optional)The source location of this match term.
ยง createOr
static createOr = function(
eager : Struct,
lazy : Struct,
location? : Real,
) -> Struct
Emits the instruction for a short-circuiting logical OR expression.
Arguments
eager
The term which evaluates immediately.
lazy
The term which evaluates if the first term is false.
location
(optional)The source location of this value term.
Returns Struct
ยง createProperty
static createProperty = function(
property : Struct,
location? : Real,
) -> Struct
Creates a property expression.
Arguments
property
The term containing the property to access.
location
(optional)The source location of this term.
Returns Struct
ยง createReturn
static createReturn = function(
value : Struct,
location? : Real,
) -> Struct
Emits the instruction to return a value from the current function.
Arguments
value
The instruction for the value to return.
location
(optional)The source location of this value term.
Returns Struct
ยง createSelf
static createSelf = function(
location? : Real,
) -> Struct
Creates an instruction for accessing the caller self
.
Arguments
location
(optional)The source location of this term.
Returns Struct
ยง createStatement
static createStatement = function(
term : Struct,
)
Adds an existing node to the current block's statement list.
Arguments
term
The term to register to the current block.
ยง createStruct
static createStruct = function(
values : Array,
location? : Real,
) -> Struct
Emits the instruction to create a new struct literal.
Arguments
values
The key-value pairs to populate the struct with.
location
(optional)The source location of this value term.
Returns Struct
ยง createUnary
static createUnary = function(
operator : Enum.CatspeakOperator,
value : String,
location? : Real,
) -> Struct
Creates a binary operator.
Arguments
operator
The operator type to use.
value
The value to apply the operator to.
location
(optional)The source location of this term.
Returns Struct
ยง createValue
static createValue = function(
value : Any,
location? : Real,
) -> Struct
Emits the instruction to return a new constant value.
Arguments
value
The value this term should resolve to.
location
(optional)The source location of this value term.
Returns Struct
ยง createWith
static createWith = function(
scope : Struct,
body : Struct,
location? : Real,
) -> Struct
Emits the instruction for a GML style with
loop.
Arguments
scope
The term which evaluates to the self scope of the
with
loop.body
The body of the while loop.
location
(optional)The source location of this value term.
Returns Struct
ยง get
static get = function()
-> Struct
Returns the underlying representation of this builder.
Returns Struct
ยง popBlock
static popBlock = function(
location? : Real,
) -> Struct
Clears the most recent local scope and frees any allocated local variables.
Arguments
location
(optional)The source location of this block.
Returns Struct
ยง popFunction
static popFunction = function(
location? : Real,
) -> Struct
Finalises a Catspeak function and inserts it into the list of known functionScopes and returns its term.
Arguments
location
(optional)The source location of this function definition.
Returns Struct
ยง pushBlock
static pushBlock = function(
inherit? : Bool,
)
Starts a new local variable block scope. Any local variables allocated in this scope will be cleared after [popBlock] is called.
Arguments
inherit
(optional)Whether to write terms to the parent block or not. Defaults to
false
, which will always create a new block term per local scope.
ยง pushFunction
static pushFunction = function()
Begins a new Catspeak function scope.
ยง createWhile
static createWhile = function(
condition : Struct,
body : Struct,
location? : Real,
) -> Struct
๐ DeprecatedUse
createLoop
instead.
Emits the instruction for a GML style while
loop.
Arguments
condition
The term which evaluates to the condition of the
while
loop.body
The body of the while loop.
location
(optional)The source location of this value term.
Returns Struct