Search in sources :

Example 36 with Operand

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

the class CodeGenerator method visit.

public void visit(BLangActionInvocation aIExpr) {
    BInvokableSymbol actionSymbol = (BInvokableSymbol) aIExpr.symbol;
    int pkgRefCPIndex = addPackageRefCPEntry(currentPkgInfo, actionSymbol.pkgID);
    int actionNameCPIndex = addUTF8CPEntry(currentPkgInfo, actionSymbol.name.value);
    ActionRefCPEntry actionRefCPEntry = new ActionRefCPEntry(pkgRefCPIndex, actionNameCPIndex);
    int actionRefCPIndex = currentPkgInfo.addCPEntry(actionRefCPEntry);
    Operand[] operands = getFuncOperands(aIExpr, actionRefCPIndex);
    emit(InstructionCodes.ACALL, operands);
}
Also used : Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) ActionRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.ActionRefCPEntry) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 37 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(BLangPackageXMLNS xmlnsNode) {
    BLangExpression nsURIExpr = xmlnsNode.namespaceURI;
    Operand pvIndex = getPVIndex(TypeTags.STRING);
    BXMLNSSymbol nsSymbol = (BXMLNSSymbol) xmlnsNode.symbol;
    genNode(nsURIExpr, env);
    nsSymbol.nsURIIndex = pvIndex;
    emit(InstructionCodes.SGSTORE, nsURIExpr.regIndex, pvIndex);
}
Also used : BXMLNSSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol) Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Example 38 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(BLangFieldVarRef fieldVarRef) {
    RegIndex fieldIndex = fieldVarRef.symbol.varIndex;
    // This is a connector field.
    // the connector reference must be stored in the current reference register index.
    Operand varRegIndex = getOperand(0);
    if (varAssignment) {
        int opcode = getOpcode(fieldVarRef.type.tag, InstructionCodes.IFIELDSTORE);
        emit(opcode, varRegIndex, fieldIndex, fieldVarRef.regIndex);
        return;
    }
    int opcode = getOpcode(fieldVarRef.type.tag, InstructionCodes.IFIELDLOAD);
    RegIndex exprRegIndex = calcAndGetExprRegIndex(fieldVarRef);
    emit(opcode, varRegIndex, fieldIndex, exprRegIndex);
}
Also used : Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Example 39 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(BLangBracedOrTupleExpr bracedOrTupleExpr) {
    // Emit create array instruction
    RegIndex exprRegIndex = calcAndGetExprRegIndex(bracedOrTupleExpr);
    Operand typeCPIndex = getTypeCPIndex(bracedOrTupleExpr.type);
    emit(InstructionCodes.RNEWARRAY, exprRegIndex, typeCPIndex);
    // Emit instructions populate initial array values;
    for (int i = 0; i < bracedOrTupleExpr.expressions.size(); i++) {
        BLangExpression argExpr = bracedOrTupleExpr.expressions.get(i);
        genNode(argExpr, this.env);
        BLangLiteral indexLiteral = new BLangLiteral();
        indexLiteral.pos = argExpr.pos;
        indexLiteral.value = (long) i;
        indexLiteral.type = symTable.intType;
        genNode(indexLiteral, this.env);
        emit(InstructionCodes.RASTORE, exprRegIndex, indexLiteral.regIndex, argExpr.regIndex);
    }
}
Also used : BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral) Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Example 40 with Operand

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

the class CodeGenerator method visit.

public void visit(BLangWorkerReceive workerReceiveStmt) {
    WorkerDataChannelInfo workerDataChannelInfo = this.getWorkerDataChannelInfo(this.currentCallableUnitInfo, workerReceiveStmt.workerIdentifier.value, this.currentWorkerInfo.getWorkerName());
    WorkerDataChannelRefCPEntry wrkrChnlRefCPEntry = new WorkerDataChannelRefCPEntry(workerDataChannelInfo.getUniqueNameCPIndex(), workerDataChannelInfo.getUniqueName());
    wrkrChnlRefCPEntry.setWorkerDataChannelInfo(workerDataChannelInfo);
    Operand wrkrRplyRefCPIndex = getOperand(currentPkgInfo.addCPEntry(wrkrChnlRefCPEntry));
    workerDataChannelInfo.setDataChannelRefIndex(wrkrRplyRefCPIndex.value);
    List<BLangExpression> lhsExprs = workerReceiveStmt.exprs;
    int nLHSExprs = lhsExprs.size();
    RegIndex[] regIndexes = new RegIndex[nLHSExprs];
    BType[] bTypes = new BType[nLHSExprs];
    for (int i = 0; i < nLHSExprs; i++) {
        BLangExpression lExpr = lhsExprs.get(i);
        if (lExpr.getKind() == NodeKind.SIMPLE_VARIABLE_REF && lExpr instanceof BLangLocalVarRef) {
            lExpr.regIndex = ((BLangLocalVarRef) lExpr).symbol.varIndex;
            regIndexes[i] = lExpr.regIndex;
        } else {
            lExpr.regIndex = getRegIndex(lExpr.type.tag);
            lExpr.regIndex.isLHSIndex = true;
            regIndexes[i] = lExpr.regIndex;
        }
        bTypes[i] = lExpr.type;
    }
    UTF8CPEntry sigCPEntry = new UTF8CPEntry(this.generateSig(bTypes));
    Operand sigCPIndex = getOperand(currentPkgInfo.addCPEntry(sigCPEntry));
    // WRKRECEIVE wrkrRplyRefCPIndex typesCPIndex nRegIndexes, regIndexes[nRegIndexes]
    Operand[] wrkReceiveArgRegs = new Operand[nLHSExprs + 3];
    wrkReceiveArgRegs[0] = wrkrRplyRefCPIndex;
    wrkReceiveArgRegs[1] = sigCPIndex;
    wrkReceiveArgRegs[2] = getOperand(nLHSExprs);
    System.arraycopy(regIndexes, 0, wrkReceiveArgRegs, 3, regIndexes.length);
    emit(InstructionCodes.WRKRECEIVE, wrkReceiveArgRegs);
    for (BLangExpression lExpr : lhsExprs) {
        if (lExpr.getKind() == NodeKind.SIMPLE_VARIABLE_REF && lExpr instanceof BLangLocalVarRef) {
            continue;
        }
        this.varAssignment = true;
        this.genNode(lExpr, this.env);
        this.varAssignment = false;
    }
}
Also used : BLangLocalVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef.BLangLocalVarRef) Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) WorkerDataChannelRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.WorkerDataChannelRefCPEntry) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex) UTF8CPEntry(org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) WorkerDataChannelInfo(org.wso2.ballerinalang.programfile.WorkerDataChannelInfo) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

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