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);
}
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;
}
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;
}
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);
}
}
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();
}
Aggregations