Search in sources :

Example 1 with RegIndex

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

the class CodeGenerator method visitFunctionPointerLoad.

private void visitFunctionPointerLoad(BLangExpression fpExpr, BInvokableSymbol funcSymbol) {
    int pkgRefCPIndex = addPackageRefCPEntry(currentPkgInfo, funcSymbol.pkgID);
    int funcNameCPIndex = addUTF8CPEntry(currentPkgInfo, funcSymbol.name.value);
    FunctionRefCPEntry funcRefCPEntry = new FunctionRefCPEntry(pkgRefCPIndex, funcNameCPIndex);
    int funcRefCPIndex = currentPkgInfo.addCPEntry(funcRefCPEntry);
    RegIndex nextIndex = calcAndGetExprRegIndex(fpExpr);
    emit(InstructionCodes.FPLOAD, getOperand(funcRefCPIndex), nextIndex);
}
Also used : FunctionRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.FunctionRefCPEntry) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Example 2 with RegIndex

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

the class CodeGenerator method getNamespaceURIIndex.

private RegIndex getNamespaceURIIndex(BXMLNSSymbol namespaceSymbol, SymbolEnv env) {
    if (namespaceSymbol == null && env.node.getKind() == NodeKind.XML_ATTRIBUTE) {
        return createStringLiteral(XMLConstants.NULL_NS_URI, null, env);
    }
    if (namespaceSymbol == null) {
        return createStringLiteral(null, null, env);
    }
    // Otherwise get the URI index in the global var registry.
    if ((namespaceSymbol.owner.tag & SymTag.INVOKABLE) == SymTag.INVOKABLE) {
        return (RegIndex) namespaceSymbol.nsURIIndex;
    }
    RegIndex index = getRegIndex(TypeTags.STRING);
    emit(InstructionCodes.SGLOAD, namespaceSymbol.nsURIIndex, index);
    return index;
}
Also used : RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Example 3 with RegIndex

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

the class CodeGenerator method visitXMLTagName.

/**
 * Visit XML tag name and return the index of the tag name in the reference registry.
 *
 * @param tagName           Tag name expression
 * @param xmlElementEnv     Environment of the XML element of the tag
 * @param xmlElementLiteral XML element literal to which the tag name belongs to
 * @return Index of the tag name, in the reference registry
 */
private RegIndex visitXMLTagName(BLangExpression tagName, SymbolEnv xmlElementEnv, BLangXMLElementLiteral xmlElementLiteral) {
    genNode(tagName, xmlElementEnv);
    RegIndex startTagNameRegIndex = tagName.regIndex;
    // If this is a string representation of element name, generate the namespace lookup instructions
    if (tagName.getKind() != NodeKind.XML_QNAME) {
        RegIndex localNameRegIndex = getRegIndex(TypeTags.STRING);
        RegIndex uriRegIndex = getRegIndex(TypeTags.STRING);
        emit(InstructionCodes.S2QNAME, startTagNameRegIndex, localNameRegIndex, uriRegIndex);
        startTagNameRegIndex = getRegIndex(TypeTags.XML);
        generateURILookupInstructions(xmlElementLiteral.namespacesInScope, localNameRegIndex, uriRegIndex, startTagNameRegIndex, xmlElementLiteral.pos, xmlElementEnv);
        tagName.regIndex = startTagNameRegIndex;
    }
    return startTagNameRegIndex;
}
Also used : RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Example 4 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(BLangBinaryExpr binaryExpr) {
    if (OperatorKind.AND.equals(binaryExpr.opKind)) {
        visitAndExpression(binaryExpr);
    } else if (OperatorKind.OR.equals(binaryExpr.opKind)) {
        visitOrExpression(binaryExpr);
    } else if (binaryExpr.opSymbol.opcode == InstructionCodes.REQ_NULL || binaryExpr.opSymbol.opcode == InstructionCodes.RNE_NULL || binaryExpr.opSymbol.opcode == InstructionCodes.SEQ_NULL || binaryExpr.opSymbol.opcode == InstructionCodes.SNE_NULL) {
        BLangExpression expr = (binaryExpr.lhsExpr.type.tag == TypeTags.NULL) ? binaryExpr.rhsExpr : binaryExpr.lhsExpr;
        genNode(expr, this.env);
        emit(binaryExpr.opSymbol.opcode, expr.regIndex, calcAndGetExprRegIndex(binaryExpr));
    } else {
        genNode(binaryExpr.lhsExpr, this.env);
        genNode(binaryExpr.rhsExpr, this.env);
        RegIndex regIndex = calcAndGetExprRegIndex(binaryExpr);
        emit(binaryExpr.opSymbol.opcode, binaryExpr.lhsExpr.regIndex, binaryExpr.rhsExpr.regIndex, regIndex);
    }
}
Also used : BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Example 5 with RegIndex

use of org.wso2.ballerinalang.programfile.Instruction.RegIndex 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();
}
Also used : Operand(org.wso2.ballerinalang.programfile.Instruction.Operand)

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