Search in sources :

Example 36 with RegIndex

use of org.wso2.ballerinalang.programfile.Instruction.RegIndex in project ballerina by ballerina-lang.

the class CodeGenerator method visit.

@Override
public void visit(BLangIntRangeExpression rangeExpr) {
    BLangExpression startExpr = rangeExpr.startExpr;
    BLangExpression endExpr = rangeExpr.endExpr;
    genNode(startExpr, env);
    genNode(endExpr, env);
    rangeExpr.regIndex = calcAndGetExprRegIndex(rangeExpr);
    if (!rangeExpr.includeStart || !rangeExpr.includeEnd) {
        RegIndex const1RegIndex = getRegIndex(TypeTags.INT);
        emit(InstructionCodes.ICONST_1, const1RegIndex);
        if (!rangeExpr.includeStart) {
            emit(InstructionCodes.IADD, startExpr.regIndex, const1RegIndex, startExpr.regIndex);
        }
        if (!rangeExpr.includeEnd) {
            emit(InstructionCodes.ISUB, endExpr.regIndex, const1RegIndex, endExpr.regIndex);
        }
    }
    emit(InstructionCodes.NEW_INT_RANGE, startExpr.regIndex, endExpr.regIndex, rangeExpr.regIndex);
}
Also used : BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Example 37 with RegIndex

use of org.wso2.ballerinalang.programfile.Instruction.RegIndex 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)

Example 38 with RegIndex

use of org.wso2.ballerinalang.programfile.Instruction.RegIndex in project ballerina by ballerina-lang.

the class CodeGenerator method visit.

@Override
public void visit(BLangXMLQName xmlQName) {
    // If the QName is use outside of XML, treat it as string.
    if (!xmlQName.isUsedInXML) {
        xmlQName.regIndex = calcAndGetExprRegIndex(xmlQName);
        String qName = xmlQName.namespaceURI == null ? xmlQName.localname.value : ("{" + xmlQName.namespaceURI + "}" + xmlQName.localname);
        xmlQName.regIndex = createStringLiteral(qName, xmlQName.regIndex, env);
        return;
    }
    // Else, treat it as QName
    RegIndex nsURIIndex = getNamespaceURIIndex(xmlQName.nsSymbol, env);
    RegIndex localnameIndex = createStringLiteral(xmlQName.localname.value, null, env);
    RegIndex prefixIndex = createStringLiteral(xmlQName.prefix.value, null, env);
    xmlQName.regIndex = calcAndGetExprRegIndex(xmlQName.regIndex, TypeTags.XML);
    emit(InstructionCodes.NEWQNAME, localnameIndex, nsURIIndex, prefixIndex, xmlQName.regIndex);
}
Also used : BLangXMLQuotedString(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Example 39 with RegIndex

use of org.wso2.ballerinalang.programfile.Instruction.RegIndex in project ballerina by ballerina-lang.

the class CodeGenerator method createStringLiteral.

/**
 * Creates a string literal expression, generate the code and returns the registry index.
 *
 * @param value    String value to generate the string literal
 * @param regIndex String literal expression's reg index
 * @param env      Environment
 * @return String registry index of the generated string
 */
private RegIndex createStringLiteral(String value, RegIndex regIndex, SymbolEnv env) {
    BLangLiteral prefixLiteral = (BLangLiteral) TreeBuilder.createLiteralExpression();
    prefixLiteral.value = value;
    prefixLiteral.typeTag = TypeTags.STRING;
    prefixLiteral.type = symTable.stringType;
    prefixLiteral.regIndex = regIndex;
    genNode(prefixLiteral, env);
    return prefixLiteral.regIndex;
}
Also used : BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral)

Example 40 with RegIndex

use of org.wso2.ballerinalang.programfile.Instruction.RegIndex in project ballerina by ballerina-lang.

the class CodeGenerator method visit.

@Override
public void visit(BLangXMLElementLiteral xmlElementLiteral) {
    SymbolEnv xmlElementEnv = SymbolEnv.getXMLElementEnv(xmlElementLiteral, env);
    xmlElementLiteral.regIndex = calcAndGetExprRegIndex(xmlElementLiteral);
    // Visit in-line namespace declarations. These needs to be visited first before visiting the
    // attributes, start and end tag names of the element.
    xmlElementLiteral.inlineNamespaces.forEach(xmlns -> {
        genNode(xmlns, xmlElementEnv);
    });
    // Create start tag name
    BLangExpression startTagName = (BLangExpression) xmlElementLiteral.getStartTagName();
    RegIndex startTagNameRegIndex = visitXMLTagName(startTagName, xmlElementEnv, xmlElementLiteral);
    // Create end tag name. If there is no endtag name (empty XML tag),
    // then consider start tag name as the end tag name too.
    BLangExpression endTagName = (BLangExpression) xmlElementLiteral.getEndTagName();
    RegIndex endTagNameRegIndex = endTagName == null ? startTagNameRegIndex : visitXMLTagName(endTagName, xmlElementEnv, xmlElementLiteral);
    // Create an XML with the given QName
    RegIndex defaultNsURIIndex = getNamespaceURIIndex(xmlElementLiteral.defaultNsSymbol, xmlElementEnv);
    emit(InstructionCodes.NEWXMLELEMENT, xmlElementLiteral.regIndex, startTagNameRegIndex, endTagNameRegIndex, defaultNsURIIndex);
    // Add namespaces decelerations visible to this element.
    xmlElementLiteral.namespacesInScope.forEach((name, symbol) -> {
        BLangXMLQName nsQName = new BLangXMLQName(name.getValue(), XMLConstants.XMLNS_ATTRIBUTE);
        genNode(nsQName, xmlElementEnv);
        RegIndex uriIndex = getNamespaceURIIndex(symbol, xmlElementEnv);
        emit(InstructionCodes.XMLATTRSTORE, xmlElementLiteral.regIndex, nsQName.regIndex, uriIndex);
    });
    // Add attributes
    xmlElementLiteral.attributes.forEach(attribute -> {
        genNode(attribute, xmlElementEnv);
        emit(InstructionCodes.XMLATTRSTORE, xmlElementLiteral.regIndex, attribute.name.regIndex, attribute.value.regIndex);
    });
    // Add children
    xmlElementLiteral.modifiedChildren.forEach(child -> {
        genNode(child, xmlElementEnv);
        emit(InstructionCodes.XMLSEQSTORE, xmlElementLiteral.regIndex, child.regIndex);
    });
}
Also used : BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Aggregations

RegIndex (org.wso2.ballerinalang.programfile.Instruction.RegIndex)37 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)22 Operand (org.wso2.ballerinalang.programfile.Instruction.Operand)20 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)13 UTF8CPEntry (org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry)6 BLangXMLQuotedString (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString)5 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)4 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)4 BXMLNSSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol)3 BLangXMLQName (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName)3 Stack (java.util.Stack)2 Name (org.ballerinalang.model.Name)2 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)2 BTypeSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol)2 BMapType (org.wso2.ballerinalang.compiler.semantics.model.types.BMapType)2 BLangEnumerator (org.wso2.ballerinalang.compiler.tree.BLangEnum.BLangEnumerator)2 BLangIdentifier (org.wso2.ballerinalang.compiler.tree.BLangIdentifier)2 BLangLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral)2 BLangRecordKeyValue (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangRecordKeyValue)2 EnumInfo (org.wso2.ballerinalang.programfile.EnumInfo)2