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);
}
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);
}
}
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);
}
Aggregations