Search in sources :

Example 11 with Instruction

use of org.wso2.ballerinalang.programfile.Instruction in project ballerina by ballerina-lang.

the class CodeGenerator method visit.

public void visit(BLangWhile whileNode) {
    Instruction gotoTopJumpInstr = InstructionFactory.get(InstructionCodes.GOTO, getOperand(this.nextIP()));
    this.genNode(whileNode.expr, this.env);
    Operand exitLoopJumpAddr = getOperand(-1);
    Instruction exitLoopJumpInstr = InstructionFactory.get(InstructionCodes.GOTO, exitLoopJumpAddr);
    emit(InstructionCodes.BR_FALSE, whileNode.expr.regIndex, exitLoopJumpAddr);
    this.loopResetInstructionStack.push(gotoTopJumpInstr);
    this.loopExitInstructionStack.push(exitLoopJumpInstr);
    this.genNode(whileNode.body, this.env);
    this.loopResetInstructionStack.pop();
    this.loopExitInstructionStack.pop();
    this.emit(gotoTopJumpInstr);
    exitLoopJumpAddr.value = nextIP();
}
Also used : Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) Instruction(org.wso2.ballerinalang.programfile.Instruction)

Aggregations

Operand (org.wso2.ballerinalang.programfile.Instruction.Operand)11 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)7 Instruction (org.wso2.ballerinalang.programfile.Instruction)5 RegIndex (org.wso2.ballerinalang.programfile.Instruction.RegIndex)4 ErrorTableEntry (org.wso2.ballerinalang.programfile.ErrorTableEntry)3 ErrorTableAttributeInfo (org.wso2.ballerinalang.programfile.attributes.ErrorTableAttributeInfo)3 StructureRefCPEntry (org.wso2.ballerinalang.programfile.cpentries.StructureRefCPEntry)3 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)2 BLangLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 ArrayList (java.util.ArrayList)1 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)1 BPackageSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol)1 BStructSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol)1 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)1 BTypeSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol)1 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)1 BLangRecordKey (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangRecordKey)1 BLangRecordKeyValue (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangRecordKeyValue)1