Search in sources :

Example 6 with BLangForkJoin

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);
}
Also used : BLangForkJoin(org.wso2.ballerinalang.compiler.tree.statements.BLangForkJoin) Whitespace(org.ballerinalang.model.Whitespace)

Example 7 with BLangForkJoin

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);
    }
}
Also used : BLangWorker(org.wso2.ballerinalang.compiler.tree.BLangWorker) InvokableNode(org.ballerinalang.model.tree.InvokableNode)

Example 8 with BLangForkJoin

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);
    }
}
Also used : BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 9 with BLangForkJoin

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);
    }
}
Also used : UTF8CPEntry(org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry) BLangWorker(org.wso2.ballerinalang.compiler.tree.BLangWorker) WorkerInfo(org.wso2.ballerinalang.programfile.WorkerInfo) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 10 with BLangForkJoin

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;
    }
}
Also used : UTF8CPEntry(org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry) BLangWorker(org.wso2.ballerinalang.compiler.tree.BLangWorker) WorkerInfo(org.wso2.ballerinalang.programfile.WorkerInfo) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Aggregations

BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)4 BLangForkJoin (org.wso2.ballerinalang.compiler.tree.statements.BLangForkJoin)4 UTF8CPEntry (org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry)4 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)3 BLangWorker (org.wso2.ballerinalang.compiler.tree.BLangWorker)3 Whitespace (org.ballerinalang.model.Whitespace)2 BLangIdentifier (org.wso2.ballerinalang.compiler.tree.BLangIdentifier)2 BLangBlockStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt)2 Operand (org.wso2.ballerinalang.programfile.Instruction.Operand)2 RegIndex (org.wso2.ballerinalang.programfile.Instruction.RegIndex)2 WorkerInfo (org.wso2.ballerinalang.programfile.WorkerInfo)2 InvokableNode (org.ballerinalang.model.tree.InvokableNode)1 BLangXMLQuotedString (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString)1 ForkjoinInfo (org.wso2.ballerinalang.programfile.ForkjoinInfo)1 ForkJoinCPEntry (org.wso2.ballerinalang.programfile.cpentries.ForkJoinCPEntry)1