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,
) -> StructAllocates a new named function argument with the supplied name. Returns a term to get or set the value of this argument.
Arguments
nameThe 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,
) -> StructAllocates 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
nameThe 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,
) -> StructCreates an accessor expression.
Arguments
collectionThe term containing the collection to access.
keyThe 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,
) -> StructEmits the instruction for a short-circuiting logical AND expression.
Arguments
eagerThe term which evaluates immediately.
lazyThe 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,
) -> StructEmits the instruction to create a new array literal.
Arguments
valuesThe 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,
) -> StructAttempts 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
typeThe assignment type to use.
lhsThe assignment target to use. Typically this is a local/global variable get expression.
rhsThe 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,
) -> StructCreates a binary operator.
Arguments
operatorThe operator type to use.
lhsThe left-hand side operand.
rhsThe right-hand side operand.
location(optional)The source location of this term.
Returns Struct
ยง createBreak
static createBreak = function(
value : Struct,
location? : Real,
) -> StructEmits the instruction to break from the current loop with a specified value.
Arguments
valueThe 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,
) -> StructEmits the instruction to call a function with a set of arguments.
Arguments
calleeThe instruction containing the function to call.
argsThe 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,
) -> StructEmits the instruction to call a constructor function with a set of arguments.
Arguments
calleeThe instruction containing the function to call.
argsThe 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,
) -> StructEmits 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,
) -> StructSearches a for a variable with the supplied name and emits a get instruction for it.
Arguments
nameThe 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,
) -> StructEmits the instruction for an if statement.
Arguments
conditionThe term which evaluates to the condition of the if statement.
ifTrueThe term which evaluates if the condition of the if statement is true.
ifFalseThe term which evaluates if the condition of the if statement is false.
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
valueThe term to evaluate and compare against.
armsA list of pairs where the first term is compared against
valueand 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,
) -> StructEmits the instruction for a short-circuiting logical OR expression.
Arguments
eagerThe term which evaluates immediately.
lazyThe 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,
) -> StructCreates a property expression.
Arguments
propertyThe term containing the property to access.
location(optional)The source location of this term.
Returns Struct
ยง createReturn
static createReturn = function(
value : Struct,
location? : Real,
) -> StructEmits the instruction to return a value from the current function.
Arguments
valueThe instruction for the value to return.
location(optional)The source location of this value term.
Returns Struct
ยง createSelf
static createSelf = function(
location? : Real,
) -> StructCreates 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
termThe term to register to the current block.
ยง createStruct
static createStruct = function(
values : Array,
location? : Real,
) -> StructEmits the instruction to create a new struct literal.
Arguments
valuesThe 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,
) -> StructCreates a binary operator.
Arguments
operatorThe operator type to use.
valueThe value to apply the operator to.
location(optional)The source location of this term.
Returns Struct
ยง createUse
static createUse = function(
condition : Struct,
body : Struct,
location? : Real,
) -> StructEmits the instruction for a context managed use block.
Arguments
conditionThe term which evaluates to the condition of the context block.
bodyThe body of the block.
location(optional)The source location of this value term.
Returns Struct
ยง createValue
static createValue = function(
value : Any,
location? : Real,
) -> StructEmits the instruction to return a new constant value.
Arguments
valueThe value this term should resolve to.
location(optional)The source location of this value term.
Returns Struct
ยง createWhile
static createWhile = function(
condition : Struct,
body : Struct,
location? : Real,
) -> StructEmits the instruction for a while loop.
Arguments
conditionThe term which evaluates to the condition of the while loop.
bodyThe body of the while loop.
location(optional)The source location of this value term.
Returns Struct
ยง get
static get = function()
-> StructReturns the underlying representation of this builder.
Returns Struct
ยง popBlock
static popBlock = function(
location? : Real,
) -> StructClears 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,
) -> StructFinalises 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.