Search in sources :

Example 1 with BLangWorkerSend

use of org.wso2.ballerinalang.compiler.tree.statements.BLangWorkerSend in project ballerina by ballerina-lang.

the class BLangPackageBuilder method addWorkerSendStmt.

public void addWorkerSendStmt(DiagnosticPos pos, Set<Whitespace> ws, String workerName, boolean isForkJoinSend) {
    BLangWorkerSend workerSendNode = (BLangWorkerSend) TreeBuilder.createWorkerSendNode();
    workerSendNode.setWorkerName(this.createIdentifier(workerName));
    exprNodeListStack.pop().forEach(expr -> workerSendNode.exprs.add((BLangExpression) expr));
    workerSendNode.addWS(commaWsStack.pop());
    workerSendNode.isForkJoinSend = isForkJoinSend;
    workerSendNode.pos = pos;
    workerSendNode.addWS(ws);
    addStmtToCurrentBlock(workerSendNode);
}
Also used : BLangWorkerSend(org.wso2.ballerinalang.compiler.tree.statements.BLangWorkerSend) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Example 2 with BLangWorkerSend

use of org.wso2.ballerinalang.compiler.tree.statements.BLangWorkerSend in project ballerina by ballerina-lang.

the class CodeAnalyzer method validateWorkerInteractions.

private void validateWorkerInteractions(WorkerActionSystem workerActionSystem) {
    BLangStatement currentAction;
    WorkerActionStateMachine currentSM;
    String currentWorkerId;
    boolean systemRunning;
    do {
        systemRunning = false;
        for (Map.Entry<String, WorkerActionStateMachine> entry : workerActionSystem.entrySet()) {
            currentWorkerId = entry.getKey();
            currentSM = entry.getValue();
            if (currentSM.done()) {
                continue;
            }
            currentAction = currentSM.currentAction();
            if (isWorkerSend(currentAction)) {
                if (isWorkerForkSend(currentAction)) {
                    currentSM.next();
                    systemRunning = true;
                } else {
                    WorkerActionStateMachine otherSM = workerActionSystem.get(this.extractWorkerId(currentAction));
                    if (otherSM.currentIsReceive(currentWorkerId)) {
                        this.validateWorkerActionParameters((BLangWorkerSend) currentAction, (BLangWorkerReceive) otherSM.currentAction());
                        otherSM.next();
                        currentSM.next();
                        systemRunning = true;
                    }
                }
            }
        }
    } while (systemRunning);
    if (!workerActionSystem.everyoneDone()) {
        this.reportInvalidWorkerInteractionDiagnostics(workerActionSystem);
    }
}
Also used : BLangStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangStatement) BLangXMLQuotedString(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with BLangWorkerSend

use of org.wso2.ballerinalang.compiler.tree.statements.BLangWorkerSend in project ballerina by ballerina-lang.

the class CodeGenerator method visit.

public void visit(BLangWorkerSend workerSendStmt) {
    WorkerDataChannelInfo workerDataChannelInfo = this.getWorkerDataChannelInfo(this.currentCallableUnitInfo, this.currentWorkerInfo.getWorkerName(), workerSendStmt.workerIdentifier.value);
    WorkerDataChannelRefCPEntry wrkrInvRefCPEntry = new WorkerDataChannelRefCPEntry(workerDataChannelInfo.getUniqueNameCPIndex(), workerDataChannelInfo.getUniqueName());
    wrkrInvRefCPEntry.setWorkerDataChannelInfo(workerDataChannelInfo);
    Operand wrkrInvRefCPIndex = getOperand(currentPkgInfo.addCPEntry(wrkrInvRefCPEntry));
    if (workerSendStmt.isForkJoinSend) {
        this.currentWorkerInfo.setWrkrDtChnlRefCPIndex(wrkrInvRefCPIndex.value);
        this.currentWorkerInfo.setWorkerDataChannelInfoForForkJoin(workerDataChannelInfo);
    }
    workerDataChannelInfo.setDataChannelRefIndex(wrkrInvRefCPIndex.value);
    int nArgExprs = workerSendStmt.exprs.size();
    RegIndex[] argRegs = new RegIndex[nArgExprs];
    BType[] bTypes = new BType[nArgExprs];
    for (int i = 0; i < nArgExprs; i++) {
        BLangExpression argExpr = workerSendStmt.exprs.get(i);
        genNode(argExpr, this.env);
        argRegs[i] = argExpr.regIndex;
        bTypes[i] = argExpr.type;
    }
    UTF8CPEntry sigCPEntry = new UTF8CPEntry(this.generateSig(bTypes));
    Operand sigCPIndex = getOperand(this.currentPkgInfo.addCPEntry(sigCPEntry));
    // WRKSEND wrkrInvRefCPIndex typesCPIndex nRegIndexes, regIndexes[nRegIndexes]
    Operand[] wrkSendArgRegs = new Operand[nArgExprs + 3];
    wrkSendArgRegs[0] = wrkrInvRefCPIndex;
    wrkSendArgRegs[1] = sigCPIndex;
    wrkSendArgRegs[2] = getOperand(nArgExprs);
    System.arraycopy(argRegs, 0, wrkSendArgRegs, 3, argRegs.length);
    this.emit(InstructionCodes.WRKSEND, wrkSendArgRegs);
}
Also used : UTF8CPEntry(org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry) Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) WorkerDataChannelRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.WorkerDataChannelRefCPEntry) WorkerDataChannelInfo(org.wso2.ballerinalang.programfile.WorkerDataChannelInfo) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Aggregations

BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)2 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)1 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)1 BLangXMLQuotedString (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString)1 BLangStatement (org.wso2.ballerinalang.compiler.tree.statements.BLangStatement)1 BLangWorkerSend (org.wso2.ballerinalang.compiler.tree.statements.BLangWorkerSend)1 Operand (org.wso2.ballerinalang.programfile.Instruction.Operand)1 RegIndex (org.wso2.ballerinalang.programfile.Instruction.RegIndex)1 WorkerDataChannelInfo (org.wso2.ballerinalang.programfile.WorkerDataChannelInfo)1 UTF8CPEntry (org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry)1 WorkerDataChannelRefCPEntry (org.wso2.ballerinalang.programfile.cpentries.WorkerDataChannelRefCPEntry)1