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