Search in sources :

Example 1 with Operand

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

the class PackageInfoWriter method writeInstructions.

private static byte[] writeInstructions(Instruction[] instructions) throws IOException {
    ByteArrayOutputStream byteAOS = new ByteArrayOutputStream();
    DataOutputStream dataOutStream = new DataOutputStream(byteAOS);
    for (Instruction instruction : instructions) {
        dataOutStream.write(instruction.opcode);
        for (Operand operand : instruction.ops) {
            dataOutStream.writeInt(operand.value);
        }
    }
    return byteAOS.toByteArray();
}
Also used : DataOutputStream(java.io.DataOutputStream) Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 2 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(BLangArrayAccessExpr arrayIndexAccessExpr) {
    boolean variableStore = this.varAssignment;
    this.varAssignment = false;
    genNode(arrayIndexAccessExpr.expr, this.env);
    Operand varRefRegIndex = arrayIndexAccessExpr.expr.regIndex;
    genNode(arrayIndexAccessExpr.indexExpr, this.env);
    Operand indexRegIndex = arrayIndexAccessExpr.indexExpr.regIndex;
    BArrayType arrayType = (BArrayType) arrayIndexAccessExpr.expr.type;
    if (variableStore) {
        int opcode = getOpcode(arrayType.eType.tag, InstructionCodes.IASTORE);
        emit(opcode, varRefRegIndex, indexRegIndex, arrayIndexAccessExpr.regIndex);
    } else {
        int opcode = getOpcode(arrayType.eType.tag, InstructionCodes.IALOAD);
        emit(opcode, varRefRegIndex, indexRegIndex, calcAndGetExprRegIndex(arrayIndexAccessExpr));
    }
    this.varAssignment = variableStore;
}
Also used : BArrayType(org.wso2.ballerinalang.compiler.semantics.model.types.BArrayType) Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 3 with Operand

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

the class CodeGenerator method visit.

public void visit(BLangTypeofExpr accessExpr) {
    Operand typeCPIndex = getTypeCPIndex(accessExpr.resolvedType);
    emit(InstructionCodes.TYPELOAD, typeCPIndex, calcAndGetExprRegIndex(accessExpr));
}
Also used : Operand(org.wso2.ballerinalang.programfile.Instruction.Operand)

Example 4 with Operand

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

the class CodeGenerator method processTimeoutBlock.

/* generate code for timeout block */
private void processTimeoutBlock(BLangForkJoin forkJoin, SymbolEnv forkJoinEnv, RegIndex timeoutVarRegIndex, Operand timeoutBlockAddr) {
    /* emit a GOTO instruction to jump out of the timeout block */
    Operand gotoAddr = getOperand(-1);
    this.emit(InstructionCodes.GOTO, gotoAddr);
    timeoutBlockAddr.value = nextIP();
    if (forkJoin.timeoutVariable != null) {
        visitForkJoinParameterDefs(forkJoin.timeoutVariable, forkJoinEnv);
        timeoutVarRegIndex.value = forkJoin.timeoutVariable.symbol.varIndex.value;
    }
    if (forkJoin.timeoutBody != null) {
        this.genNode(forkJoin.timeoutBody, forkJoinEnv);
    }
    gotoAddr.value = nextIP();
}
Also used : Operand(org.wso2.ballerinalang.programfile.Instruction.Operand)

Example 5 with Operand

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

the class CodeGenerator method visit.

public void visit(BLangLock lockNode) {
    if (lockNode.lockVariables.isEmpty()) {
        this.genNode(lockNode.body, this.env);
        return;
    }
    Operand gotoLockEndAddr = getOperand(-1);
    Instruction instructGotoLockEnd = InstructionFactory.get(InstructionCodes.GOTO, gotoLockEndAddr);
    Operand[] operands = getOperands(lockNode);
    ErrorTableAttributeInfo errorTable = createErrorTableIfAbsent(currentPkgInfo);
    int fromIP = nextIP();
    emit((InstructionCodes.LOCK), operands);
    this.genNode(lockNode.body, this.env);
    int toIP = nextIP() - 1;
    emit((InstructionCodes.UNLOCK), operands);
    emit(instructGotoLockEnd);
    ErrorTableEntry errorTableEntry = new ErrorTableEntry(fromIP, toIP, nextIP(), 0, -1);
    errorTable.addErrorTableEntry(errorTableEntry);
    emit((InstructionCodes.UNLOCK), operands);
    emit(InstructionFactory.get(InstructionCodes.THROW, getOperand(-1)));
    gotoLockEndAddr.value = nextIP();
}
Also used : Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) ErrorTableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.ErrorTableAttributeInfo) Instruction(org.wso2.ballerinalang.programfile.Instruction) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) ErrorTableEntry(org.wso2.ballerinalang.programfile.ErrorTableEntry)

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