Search in sources :

Example 11 with UTF8CPEntry

use of org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry in project ballerina by ballerina-lang.

the class CodeGenerator method addWorkerInfoEntries.

private void addWorkerInfoEntries(CallableUnitInfo callableUnitInfo, List<BLangWorker> workers) {
    UTF8CPEntry workerNameCPEntry = new UTF8CPEntry("default");
    int workerNameCPIndex = this.currentPkgInfo.addCPEntry(workerNameCPEntry);
    WorkerInfo defaultWorkerInfo = new WorkerInfo(workerNameCPIndex, "default");
    callableUnitInfo.defaultWorkerInfo = defaultWorkerInfo;
    for (BLangWorker worker : workers) {
        workerNameCPEntry = new UTF8CPEntry(worker.name.value);
        workerNameCPIndex = currentPkgInfo.addCPEntry(workerNameCPEntry);
        WorkerInfo workerInfo = new WorkerInfo(workerNameCPIndex, worker.getName().value);
        callableUnitInfo.addWorkerInfo(worker.getName().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 12 with UTF8CPEntry

use of org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry 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 13 with UTF8CPEntry

use of org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry in project ballerina by ballerina-lang.

the class CodeGenerator method getDefaultValue.

private DefaultValue getDefaultValue(BLangLiteral literalExpr) {
    String desc = literalExpr.type.getDesc();
    int typeDescCPIndex = addUTF8CPEntry(currentPkgInfo, desc);
    DefaultValue defaultValue = new DefaultValue(typeDescCPIndex, desc);
    int typeTag = literalExpr.type.tag;
    switch(typeTag) {
        case TypeTags.INT:
            defaultValue.intValue = (Long) literalExpr.value;
            defaultValue.valueCPIndex = currentPkgInfo.addCPEntry(new IntegerCPEntry(defaultValue.intValue));
            break;
        case TypeTags.FLOAT:
            defaultValue.floatValue = (Double) literalExpr.value;
            defaultValue.valueCPIndex = currentPkgInfo.addCPEntry(new FloatCPEntry(defaultValue.floatValue));
            break;
        case TypeTags.STRING:
            defaultValue.stringValue = (String) literalExpr.value;
            defaultValue.valueCPIndex = currentPkgInfo.addCPEntry(new UTF8CPEntry(defaultValue.stringValue));
            break;
        case TypeTags.BOOLEAN:
            defaultValue.booleanValue = (Boolean) literalExpr.value;
            break;
        default:
            defaultValue = null;
    }
    return defaultValue;
}
Also used : DefaultValue(org.wso2.ballerinalang.programfile.DefaultValue) UTF8CPEntry(org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry) BLangXMLQuotedString(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString) IntegerCPEntry(org.wso2.ballerinalang.programfile.cpentries.IntegerCPEntry) FloatCPEntry(org.wso2.ballerinalang.programfile.cpentries.FloatCPEntry) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 14 with UTF8CPEntry

use of org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry 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

UTF8CPEntry (org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry)14 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)13 RegIndex (org.wso2.ballerinalang.programfile.Instruction.RegIndex)4 BLangWorker (org.wso2.ballerinalang.compiler.tree.BLangWorker)3 BLangXMLQuotedString (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString)3 Operand (org.wso2.ballerinalang.programfile.Instruction.Operand)3 WorkerDataChannelInfo (org.wso2.ballerinalang.programfile.WorkerDataChannelInfo)3 WorkerInfo (org.wso2.ballerinalang.programfile.WorkerInfo)3 WorkerDataChannelRefCPEntry (org.wso2.ballerinalang.programfile.cpentries.WorkerDataChannelRefCPEntry)3 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)2 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)2 DefaultValue (org.wso2.ballerinalang.programfile.DefaultValue)2 FloatCPEntry (org.wso2.ballerinalang.programfile.cpentries.FloatCPEntry)2 ForkJoinCPEntry (org.wso2.ballerinalang.programfile.cpentries.ForkJoinCPEntry)2 IntegerCPEntry (org.wso2.ballerinalang.programfile.cpentries.IntegerCPEntry)2 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)1 BLangIdentifier (org.wso2.ballerinalang.compiler.tree.BLangIdentifier)1 BLangLocalVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef.BLangLocalVarRef)1 ForkjoinInfo (org.wso2.ballerinalang.programfile.ForkjoinInfo)1 LineNumberInfo (org.wso2.ballerinalang.programfile.LineNumberInfo)1