use of org.wso2.ballerinalang.compiler.tree.statements.BLangForkJoin in project ballerina by ballerina-lang.
the class SemanticAnalyzer method visit.
@Override
public void visit(BLangForkJoin forkJoin) {
SymbolEnv forkJoinEnv = SymbolEnv.createFolkJoinEnv(forkJoin, this.env);
forkJoin.workers.forEach(e -> this.symbolEnter.defineNode(e, forkJoinEnv));
forkJoin.workers.forEach(e -> this.analyzeDef(e, forkJoinEnv));
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.env);
this.analyzeNode(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.analyzeNode(forkJoin.joinedBody, joinBodyEnv);
if (forkJoin.timeoutExpression != null) {
if (!this.isJoinResultType(forkJoin.timeoutVariable)) {
this.dlog.error(forkJoin.timeoutVariable.pos, DiagnosticCode.INVALID_WORKER_TIMEOUT_RESULT_TYPE);
}
/* create code black and environment for timeout section */
BLangBlockStmt timeoutVarBlock = this.generateCodeBlock(this.createVarDef(forkJoin.timeoutVariable));
SymbolEnv timeoutVarEnv = SymbolEnv.createBlockEnv(timeoutVarBlock, this.env);
this.typeChecker.checkExpr(forkJoin.timeoutExpression, timeoutVarEnv, Arrays.asList(symTable.intType));
this.analyzeNode(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.analyzeNode(forkJoin.timeoutBody, timeoutBodyEnv);
}
this.validateJoinWorkerList(forkJoin, forkJoinEnv);
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangForkJoin 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();
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangForkJoin in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
public void visit(BLangForkJoin forkJoin) {
SymbolEnv forkJoinEnv = SymbolEnv.createForkJoinSymbolEnv(forkJoin, this.env);
ForkjoinInfo forkjoinInfo = new ForkjoinInfo(this.lvIndexes.toArray());
this.populateForkJoinWorkerInfo(forkJoin, forkjoinInfo);
int forkJoinInfoIndex = this.forkJoinCount++;
/* was I already inside a fork/join */
if (this.env.forkJoin != null) {
this.currentWorkerInfo.addForkJoinInfo(forkjoinInfo);
} else {
this.currentCallableUnitInfo.defaultWorkerInfo.addForkJoinInfo(forkjoinInfo);
}
ForkJoinCPEntry forkJoinCPEntry = new ForkJoinCPEntry(forkJoinInfoIndex);
Operand forkJoinCPIndex = getOperand(this.currentPkgInfo.addCPEntry(forkJoinCPEntry));
forkjoinInfo.setIndexCPIndex(forkJoinCPIndex.value);
RegIndex timeoutRegIndex = new RegIndex(-1, TypeTags.INT);
addToRegIndexList(timeoutRegIndex);
if (forkJoin.timeoutExpression != null) {
forkjoinInfo.setTimeoutAvailable(true);
this.genNode(forkJoin.timeoutExpression, forkJoinEnv);
timeoutRegIndex.value = forkJoin.timeoutExpression.regIndex.value;
}
// FORKJOIN forkJoinCPIndex timeoutRegIndex joinVarRegIndex joinBlockAddr timeoutVarRegIndex timeoutBlockAddr
RegIndex joinVarRegIndex = new RegIndex(-1, TypeTags.MAP);
Operand joinBlockAddr = getOperand(-1);
RegIndex timeoutVarRegIndex = new RegIndex(-1, TypeTags.MAP);
Operand timeoutBlockAddr = getOperand(-1);
this.emit(InstructionCodes.FORKJOIN, forkJoinCPIndex, timeoutRegIndex, joinVarRegIndex, joinBlockAddr, timeoutVarRegIndex, timeoutBlockAddr);
this.processJoinWorkers(forkJoin, forkjoinInfo, forkJoinEnv);
int i = 0;
int[] joinWrkrNameCPIndexes = new int[forkJoin.joinedWorkers.size()];
String[] joinWrkrNames = new String[joinWrkrNameCPIndexes.length];
for (BLangIdentifier workerName : forkJoin.joinedWorkers) {
UTF8CPEntry workerNameCPEntry = new UTF8CPEntry(workerName.value);
int workerNameCPIndex = this.currentPkgInfo.addCPEntry(workerNameCPEntry);
joinWrkrNameCPIndexes[i] = workerNameCPIndex;
joinWrkrNames[i] = workerName.value;
i++;
}
forkjoinInfo.setJoinWrkrNameIndexes(joinWrkrNameCPIndexes);
forkjoinInfo.setJoinWorkerNames(joinWrkrNames);
forkjoinInfo.setWorkerCount(forkJoin.joinedWorkerCount);
this.processJoinBlock(forkJoin, forkjoinInfo, forkJoinEnv, joinVarRegIndex, joinBlockAddr);
this.processTimeoutBlock(forkJoin, forkJoinEnv, timeoutVarRegIndex, timeoutBlockAddr);
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangForkJoin in project ballerina by ballerina-lang.
the class CodeGenerator method processJoinBlock.
/* generate code for Join block */
private void processJoinBlock(BLangForkJoin forkJoin, ForkjoinInfo forkjoinInfo, SymbolEnv forkJoinEnv, RegIndex joinVarRegIndex, Operand joinBlockAddr) {
UTF8CPEntry joinType = new UTF8CPEntry(forkJoin.joinType.name());
int joinTypeCPIndex = this.currentPkgInfo.addCPEntry(joinType);
forkjoinInfo.setJoinType(forkJoin.joinType.name());
forkjoinInfo.setJoinTypeCPIndex(joinTypeCPIndex);
joinBlockAddr.value = nextIP();
if (forkJoin.joinResultVar != null) {
visitForkJoinParameterDefs(forkJoin.joinResultVar, forkJoinEnv);
joinVarRegIndex.value = forkJoin.joinResultVar.symbol.varIndex.value;
}
if (forkJoin.joinedBody != null) {
this.genNode(forkJoin.joinedBody, forkJoinEnv);
}
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangForkJoin in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addForkJoinStmt.
public void addForkJoinStmt(DiagnosticPos pos, Set<Whitespace> ws) {
BLangForkJoin forkJoin = (BLangForkJoin) this.forkJoinNodesStack.pop();
forkJoin.pos = pos;
forkJoin.addWS(ws);
this.addStmtToCurrentBlock(forkJoin);
}
Aggregations