Search in sources :

Example 16 with Operand

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

the class CodeGenerator method getOperands.

private Operand[] getOperands(BLangLock lockNode) {
    Operand[] operands = new Operand[(lockNode.lockVariables.size() * 2) + 1];
    int i = 0;
    operands[i++] = new Operand(lockNode.lockVariables.size());
    for (BVarSymbol varSymbol : lockNode.lockVariables) {
        int typeSigCPIndex = addUTF8CPEntry(currentPkgInfo, varSymbol.getType().getDesc());
        TypeRefCPEntry typeRefCPEntry = new TypeRefCPEntry(typeSigCPIndex);
        operands[i++] = getOperand(currentPkgInfo.addCPEntry(typeRefCPEntry));
        operands[i++] = varSymbol.varIndex;
    }
    return operands;
}
Also used : Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) TypeRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.TypeRefCPEntry) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)

Example 17 with Operand

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

the class CodeGenerator method visit.

@Override
public void visit(BLangPackageVarRef packageVarRef) {
    Operand gvIndex = packageVarRef.symbol.varIndex;
    if (varAssignment) {
        int opcode = getOpcode(packageVarRef.type.tag, InstructionCodes.IGSTORE);
        emit(opcode, packageVarRef.regIndex, gvIndex);
        return;
    }
    int opcode = getOpcode(packageVarRef.type.tag, InstructionCodes.IGLOAD);
    packageVarRef.regIndex = calcAndGetExprRegIndex(packageVarRef);
    emit(opcode, gvIndex, packageVarRef.regIndex);
}
Also used : Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 18 with Operand

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

the class CodeGenerator method generateFinallyInstructions.

private void generateFinallyInstructions(BLangStatement statement, NodeKind... expectedParentKinds) {
    BLangStatement current = statement;
    while (current != null && current.statementLink.parent != null) {
        BLangStatement parent = current.statementLink.parent.statement;
        for (NodeKind expected : expectedParentKinds) {
            if (expected == parent.getKind()) {
                return;
            }
        }
        if (NodeKind.TRY == parent.getKind()) {
            BLangTryCatchFinally tryCatchFinally = (BLangTryCatchFinally) parent;
            if (tryCatchFinally.finallyBody != null && current != tryCatchFinally.finallyBody) {
                genNode(tryCatchFinally.finallyBody, env);
            }
        } else if (NodeKind.LOCK == parent.getKind()) {
            BLangLock lockNode = (BLangLock) parent;
            if (!lockNode.lockVariables.isEmpty()) {
                Operand[] operands = getOperands(lockNode);
                emit((InstructionCodes.UNLOCK), operands);
            }
        }
        current = parent;
    }
}
Also used : NodeKind(org.ballerinalang.model.tree.NodeKind) BLangStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangStatement) BLangLock(org.wso2.ballerinalang.compiler.tree.statements.BLangLock) BLangTryCatchFinally(org.wso2.ballerinalang.compiler.tree.statements.BLangTryCatchFinally)

Example 19 with Operand

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

the class CodeGenerator method processJoinBlock.

/* generate code for Join block */
private void processJoinBlock(BLangForkJoin forkJoin, ForkjoinInfo forkjoinInfo, SymbolEnv forkJoinEnv, RegIndex joinVarRegIndex, Operand joinBlockAddr) {
    UTF8CPEntry joinType = new UTF8CPEntry(forkJoin.joinType.name());
    int joinTypeCPIndex = this.currentPkgInfo.addCPEntry(joinType);
    forkjoinInfo.setJoinType(forkJoin.joinType.name());
    forkjoinInfo.setJoinTypeCPIndex(joinTypeCPIndex);
    joinBlockAddr.value = nextIP();
    if (forkJoin.joinResultVar != null) {
        visitForkJoinParameterDefs(forkJoin.joinResultVar, forkJoinEnv);
        joinVarRegIndex.value = forkJoin.joinResultVar.symbol.varIndex.value;
    }
    if (forkJoin.joinedBody != null) {
        this.genNode(forkJoin.joinedBody, forkJoinEnv);
    }
}
Also used : UTF8CPEntry(org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 20 with Operand

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

the class CodeGenerator method visit.

public void visit(BLangIf ifNode) {
    addLineNumberInfo(ifNode.pos);
    // Generate code for the if condition evaluation
    genNode(ifNode.expr, this.env);
    Operand ifCondJumpAddr = getOperand(-1);
    emit(InstructionCodes.BR_FALSE, ifNode.expr.regIndex, ifCondJumpAddr);
    // Generate code for the then body
    genNode(ifNode.body, this.env);
    Operand endJumpAddr = getOperand(-1);
    emit(InstructionCodes.GOTO, endJumpAddr);
    ifCondJumpAddr.value = nextIP();
    // Visit else statement if any
    if (ifNode.elseStmt != null) {
        genNode(ifNode.elseStmt, this.env);
    }
    endJumpAddr.value = nextIP();
}
Also used : Operand(org.wso2.ballerinalang.programfile.Instruction.Operand)

Aggregations

Operand (org.wso2.ballerinalang.programfile.Instruction.Operand)42 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)28 RegIndex (org.wso2.ballerinalang.programfile.Instruction.RegIndex)18 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)10 Instruction (org.wso2.ballerinalang.programfile.Instruction)6 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)5 UTF8CPEntry (org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry)5 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)4 BLangRecordKeyValue (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangRecordKeyValue)4 BLangXMLQuotedString (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString)4 StructureRefCPEntry (org.wso2.ballerinalang.programfile.cpentries.StructureRefCPEntry)4 BXMLNSSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol)3 BMapType (org.wso2.ballerinalang.compiler.semantics.model.types.BMapType)3 BLangLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral)3 ErrorTableEntry (org.wso2.ballerinalang.programfile.ErrorTableEntry)3 WorkerDataChannelInfo (org.wso2.ballerinalang.programfile.WorkerDataChannelInfo)3 ErrorTableAttributeInfo (org.wso2.ballerinalang.programfile.attributes.ErrorTableAttributeInfo)3 StringCPEntry (org.wso2.ballerinalang.programfile.cpentries.StringCPEntry)3 TypeRefCPEntry (org.wso2.ballerinalang.programfile.cpentries.TypeRefCPEntry)3 WorkerDataChannelRefCPEntry (org.wso2.ballerinalang.programfile.cpentries.WorkerDataChannelRefCPEntry)3