use of org.wso2.ballerinalang.compiler.tree.statements.BLangForkJoin in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addJoinCause.
public void addJoinCause(Set<Whitespace> ws, String identifier) {
BLangForkJoin forkJoin = (BLangForkJoin) this.forkJoinNodesStack.peek();
forkJoin.joinedBody = (BLangBlockStmt) this.blockNodeStack.pop();
Set<Whitespace> varWS = removeNthFromLast(ws, 3);
forkJoin.addWS(ws);
forkJoin.joinResultVar = (BLangVariable) this.generateBasicVarNode((DiagnosticPos) this.typeNodeStack.peek().getPosition(), varWS, identifier, false);
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangForkJoin in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addWorker.
public void addWorker(DiagnosticPos pos, Set<Whitespace> ws, String workerName) {
BLangWorker worker = (BLangWorker) this.invokableNodeStack.pop();
worker.setName(createIdentifier(workerName));
worker.pos = pos;
worker.addWS(ws);
worker.setBody(this.blockNodeStack.pop());
if (this.forkJoinNodesStack.empty()) {
InvokableNode invokableNode = this.invokableNodeStack.peek();
invokableNode.getParameters().forEach(worker::addParameter);
invokableNode.getReturnParameters().forEach(worker::addReturnParameter);
invokableNode.addWorker(worker);
invokableNode.addFlag(Flag.PARALLEL);
} else {
((BLangForkJoin) this.forkJoinNodesStack.peek()).workers.add(worker);
}
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangForkJoin in project ballerina by ballerina-lang.
the class TreeVisitor method visit.
@Override
public void visit(BLangForkJoin forkJoin) {
SymbolEnv folkJoinEnv = SymbolEnv.createFolkJoinEnv(forkJoin, this.symbolEnv);
// TODO: check the symbolEnter.defineNode
forkJoin.workers.forEach(e -> this.symbolEnter.defineNode(e, folkJoinEnv));
forkJoin.workers.forEach(e -> this.acceptNode(e, folkJoinEnv));
// if (!this.isJoinResultType(forkJoin.joinResultVar)) {
// this.dlog.error(forkJoin.joinResultVar.pos, DiagnosticCode.INVALID_WORKER_JOIN_RESULT_TYPE);
// }
/* create code black and environment for join result section, i.e. (map results) */
BLangBlockStmt joinResultsBlock = this.generateCodeBlock(this.createVarDef(forkJoin.joinResultVar));
SymbolEnv joinResultsEnv = SymbolEnv.createBlockEnv(joinResultsBlock, this.symbolEnv);
this.acceptNode(joinResultsBlock, joinResultsEnv);
/* create an environment for the join body, making the enclosing environment the earlier
* join result's environment */
SymbolEnv joinBodyEnv = SymbolEnv.createBlockEnv(forkJoin.joinedBody, joinResultsEnv);
this.acceptNode(forkJoin.joinedBody, joinBodyEnv);
if (forkJoin.timeoutExpression != null) {
/* create code black and environment for timeout section */
BLangBlockStmt timeoutVarBlock = this.generateCodeBlock(this.createVarDef(forkJoin.timeoutVariable));
SymbolEnv timeoutVarEnv = SymbolEnv.createBlockEnv(timeoutVarBlock, this.symbolEnv);
this.acceptNode(timeoutVarBlock, timeoutVarEnv);
/* create an environment for the timeout body, making the enclosing environment the earlier
* timeout var's environment */
SymbolEnv timeoutBodyEnv = SymbolEnv.createBlockEnv(forkJoin.timeoutBody, timeoutVarEnv);
this.acceptNode(forkJoin.timeoutBody, timeoutBodyEnv);
}
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangForkJoin in project ballerina by ballerina-lang.
the class CodeGenerator method populateForkJoinWorkerInfo.
private void populateForkJoinWorkerInfo(BLangForkJoin forkJoin, ForkjoinInfo forkjoinInfo) {
for (BLangWorker worker : forkJoin.workers) {
UTF8CPEntry workerNameCPEntry = new UTF8CPEntry(worker.name.value);
int workerNameCPIndex = this.currentPkgInfo.addCPEntry(workerNameCPEntry);
WorkerInfo workerInfo = new WorkerInfo(workerNameCPIndex, worker.name.value);
forkjoinInfo.addWorkerInfo(worker.name.value, workerInfo);
}
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangForkJoin in project ballerina by ballerina-lang.
the class CodeGenerator method processJoinWorkers.
/* visit the workers within fork-join block */
private void processJoinWorkers(BLangForkJoin forkJoin, ForkjoinInfo forkjoinInfo, SymbolEnv forkJoinEnv) {
UTF8CPEntry codeUTF8CPEntry = new UTF8CPEntry(AttributeInfo.Kind.CODE_ATTRIBUTE.toString());
int codeAttribNameIndex = this.currentPkgInfo.addCPEntry(codeUTF8CPEntry);
for (BLangWorker worker : forkJoin.workers) {
VariableIndex lvIndexesCopy = copyVarIndex(this.lvIndexes);
this.regIndexes = new VariableIndex(REG);
VariableIndex regIndexesCopy = this.regIndexes;
this.regIndexes = new VariableIndex(REG);
VariableIndex maxRegIndexesCopy = this.maxRegIndexes;
this.maxRegIndexes = new VariableIndex(REG);
List<RegIndex> regIndexListCopy = this.regIndexList;
this.regIndexList = new ArrayList<>();
WorkerInfo workerInfo = forkjoinInfo.getWorkerInfo(worker.name.value);
workerInfo.codeAttributeInfo.attributeNameIndex = codeAttribNameIndex;
workerInfo.codeAttributeInfo.codeAddrs = this.nextIP();
this.currentWorkerInfo = workerInfo;
this.genNode(worker.body, forkJoinEnv);
this.endWorkerInfoUnit(workerInfo.codeAttributeInfo);
this.emit(InstructionCodes.HALT);
this.lvIndexes = lvIndexesCopy;
this.regIndexes = regIndexesCopy;
this.maxRegIndexes = maxRegIndexesCopy;
this.regIndexList = regIndexListCopy;
}
}
Aggregations