Readonly
instructionsThe actual list of instructions.
Private
_getAppends an instruction at the end of this expression.
The type of instruction to append.
Rest
...args: TThe arguments of this instruction. Changes depending upon the opcode.
Emits a block
instruction with a new expression as the body.
Optional
lambda: ((block) => any)A function invoked before this method returns which emits instructions to the expression inside the block.
Optional
blocktype: SpiderValueTypeThe type of value left on the stack after the emitted block has executed. Leave undefined for blocks which leave no value on the stack.
The expression executed inside this block. This is the same expression passed to the lambda function.
func.body.emitBlock(SpiderNumberType.f64, expr => {
expr.emitConstant(SpiderNumberType.f64, 1);
expr.emitConstant(SpiderNumberType.f64, 2);
expr.emit(SpiderNumberType.f64_add);
});
Emits one of i32_const
, i64_const
, f32_const
or f64_const
with the value
depending on the type argument.
The type of const instruction to be emitted.
The argument of the const instruction to be emitted.
Emits an if
instruction with a new expression as the body, without an else expression.
Optional
lambda: ((block) => any)A function invoked before this method returns which emits instructions to the expression which executes if the condition is true.
Optional
blocktype: SpiderValueTypeThe type of value left on the stack if the condition is true. Leave undefined for expressions which leave no value on the stack.
The expression executed inside the if statement. This is the same expression passed to the lambda function.
An if statement which makes sure that 1 + 1 = 2.
const loopCounter = func.addLocalVariable(SpiderNumberType.i32);
func.body.emitConstant(SpiderNumberType.i32, 1);
func.body.emitConstant(SpiderNumberType.i32, 1);
func.body.emit(SpiderNumberType.i32_add); // 1 + 1
func.body.emitConstant(SpiderNumberType.i32, 2);
func.body.emit(SpiderNumberType.i32_eq); // 1 + 1 === 2
func.body.emitIf(expr => {
expr.emit(SpiderOpcodes.call, mathIsntBrokenYay);
});
Emits an if
instruction with an else block using two new expressions as the bodys.
Optional
lambdaTrue: ((block) => any)A function invoked before this method returns which emits instructions to the expression which executes if the condition is true.
Optional
lambdaFalse: ((block) => any)A function invoked before this method returns which emits instructions to the expression which executes if the condition is false.
Optional
blocktype: SpiderValueTypeThe type of value left on the stack after the emitted if or else expressions have executed. Leave undefined for expressions which leave no value on the stack.
The two expressions the could be executed.
The expression executed if the condition is false.
The expression executed if the condition is true.
An if-else statement which makes sure that 1 + 1 = 2.
const loopCounter = func.addLocalVariable(SpiderNumberType.i32);
func.body.emitConstant(SpiderNumberType.i32, 1);
func.body.emitConstant(SpiderNumberType.i32, 1);
func.body.emit(SpiderNumberType.i32_add); // 1 + 1
func.body.emitConstant(SpiderNumberType.i32, 2);
func.body.emit(SpiderNumberType.i32_eq); // 1 + 1 === 2
func.body.emitIfElse(expr => { // if
expr.emit(SpiderOpcodes.call, mathIsntBrokenYay);
}, expr => { // else
expr.emit(SpiderOpcodes.call, mathIsBrokenOmfg);
});
Emits a loop
instruction with a new expression as the body.
Optional
lambda: ((block) => any)A function invoked before this method returns which emits instructions to the expression inside the loop.
Optional
blocktype: SpiderValueTypeThe type of value left on the stack after the emitted loop has executed. Leave undefined for blocks which leave no value on the stack.
The expression executed inside this block. This is the same expression passed to the lambda function.
A loop which runs 10 times.
const loopCounter = func.addLocalVariable(SpiderNumberType.i32);
func.body.emitConstant(SpiderNumberType.i32, 0);
func.body.emit(SpiderOpcodes.local_set, loopCounter);
func.body.emitLoop(expr => {
expr.emit(SpiderOpcodes.local_get, loopCounter);
expr.emitConstant(SpiderNumberType.i32, 1);
expr.emit(SpiderOpcodes.i32_add)
expr.emit(SpiderOpcodes.local_tee, loopCounter);
expr.emitConstant(SpiderNumberType.i32, 10);
expr.emit(SpiderOpcodes.i32_ne);
expr.emit(SpiderOpcodes.br_if, 0);
});
If this expression has one instruction which pushes a funcref onto the stack, returns the function referred to by the constant funcref or null if the constant funcref is null.
If this expression doesn't have exactly one instruction, or that one instruction's opcode
isn't global_get
.
If this expression has one instruction which pushes the value of a global onto the stack, returns that global.
If this expression doesn't have exactly one instruction, or that one instruction's opcode
isn't global_get
.
If this expression has one instruction which pushes a constant number onto the stack, returns that number.
Gets the number the global is being set to on module initialization.
const globalValue = global.value.getAsConstNumber();
If this expression doesn't have exactly one instruction, or that one instruction's opcode isn't a constant number.
Clears this expression and emits the instruction to push a constant with the specified type and value onto the stack.
global.value.setToConst(SpiderNumberType.i64, 69420);
TypeError if type and value are incompatible.
Clears this expression and emits the instruction to push a reference to the function or a null function reference onto the stack.
Clears this expression and emits the instruction to push the value of a global onto the stack.
Clears this expression and emits the instruction to push a number with the specified type and value onto the stack.
Static
createCreates a constant expression with the specified type and value.
TypeError if type and value are incompatible.
Generated using TypeDoc
A series of instructions which can be executed at runtime.