use of org.wso2.ballerinalang.programfile.Instruction.RegIndex in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
@Override
public void visit(BLangBracedOrTupleExpr bracedOrTupleExpr) {
// Emit create array instruction
RegIndex exprRegIndex = calcAndGetExprRegIndex(bracedOrTupleExpr);
Operand typeCPIndex = getTypeCPIndex(bracedOrTupleExpr.type);
emit(InstructionCodes.RNEWARRAY, exprRegIndex, typeCPIndex);
// Emit instructions populate initial array values;
for (int i = 0; i < bracedOrTupleExpr.expressions.size(); i++) {
BLangExpression argExpr = bracedOrTupleExpr.expressions.get(i);
genNode(argExpr, this.env);
BLangLiteral indexLiteral = new BLangLiteral();
indexLiteral.pos = argExpr.pos;
indexLiteral.value = (long) i;
indexLiteral.type = symTable.intType;
genNode(indexLiteral, this.env);
emit(InstructionCodes.RASTORE, exprRegIndex, indexLiteral.regIndex, argExpr.regIndex);
}
}
use of org.wso2.ballerinalang.programfile.Instruction.RegIndex in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
public void visit(BLangWorkerReceive workerReceiveStmt) {
WorkerDataChannelInfo workerDataChannelInfo = this.getWorkerDataChannelInfo(this.currentCallableUnitInfo, workerReceiveStmt.workerIdentifier.value, this.currentWorkerInfo.getWorkerName());
WorkerDataChannelRefCPEntry wrkrChnlRefCPEntry = new WorkerDataChannelRefCPEntry(workerDataChannelInfo.getUniqueNameCPIndex(), workerDataChannelInfo.getUniqueName());
wrkrChnlRefCPEntry.setWorkerDataChannelInfo(workerDataChannelInfo);
Operand wrkrRplyRefCPIndex = getOperand(currentPkgInfo.addCPEntry(wrkrChnlRefCPEntry));
workerDataChannelInfo.setDataChannelRefIndex(wrkrRplyRefCPIndex.value);
List<BLangExpression> lhsExprs = workerReceiveStmt.exprs;
int nLHSExprs = lhsExprs.size();
RegIndex[] regIndexes = new RegIndex[nLHSExprs];
BType[] bTypes = new BType[nLHSExprs];
for (int i = 0; i < nLHSExprs; i++) {
BLangExpression lExpr = lhsExprs.get(i);
if (lExpr.getKind() == NodeKind.SIMPLE_VARIABLE_REF && lExpr instanceof BLangLocalVarRef) {
lExpr.regIndex = ((BLangLocalVarRef) lExpr).symbol.varIndex;
regIndexes[i] = lExpr.regIndex;
} else {
lExpr.regIndex = getRegIndex(lExpr.type.tag);
lExpr.regIndex.isLHSIndex = true;
regIndexes[i] = lExpr.regIndex;
}
bTypes[i] = lExpr.type;
}
UTF8CPEntry sigCPEntry = new UTF8CPEntry(this.generateSig(bTypes));
Operand sigCPIndex = getOperand(currentPkgInfo.addCPEntry(sigCPEntry));
// WRKRECEIVE wrkrRplyRefCPIndex typesCPIndex nRegIndexes, regIndexes[nRegIndexes]
Operand[] wrkReceiveArgRegs = new Operand[nLHSExprs + 3];
wrkReceiveArgRegs[0] = wrkrRplyRefCPIndex;
wrkReceiveArgRegs[1] = sigCPIndex;
wrkReceiveArgRegs[2] = getOperand(nLHSExprs);
System.arraycopy(regIndexes, 0, wrkReceiveArgRegs, 3, regIndexes.length);
emit(InstructionCodes.WRKRECEIVE, wrkReceiveArgRegs);
for (BLangExpression lExpr : lhsExprs) {
if (lExpr.getKind() == NodeKind.SIMPLE_VARIABLE_REF && lExpr instanceof BLangLocalVarRef) {
continue;
}
this.varAssignment = true;
this.genNode(lExpr, this.env);
this.varAssignment = false;
}
}
use of org.wso2.ballerinalang.programfile.Instruction.RegIndex in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
@Override
public void visit(BLangMapAccessExpr mapKeyAccessExpr) {
boolean variableStore = this.varAssignment;
this.varAssignment = false;
genNode(mapKeyAccessExpr.expr, this.env);
Operand varRefRegIndex = mapKeyAccessExpr.expr.regIndex;
genNode(mapKeyAccessExpr.indexExpr, this.env);
Operand keyRegIndex = mapKeyAccessExpr.indexExpr.regIndex;
BMapType mapType = (BMapType) mapKeyAccessExpr.expr.type;
if (variableStore) {
int opcode = getValueToRefTypeCastOpcode(mapType.constraint.tag);
if (opcode == InstructionCodes.NOP) {
emit(InstructionCodes.MAPSTORE, varRefRegIndex, keyRegIndex, mapKeyAccessExpr.regIndex);
} else {
RegIndex refRegMapValue = getRegIndex(TypeTags.ANY);
emit(opcode, mapKeyAccessExpr.regIndex, refRegMapValue);
emit(InstructionCodes.MAPSTORE, varRefRegIndex, keyRegIndex, refRegMapValue);
}
} else {
int opcode = getRefToValueTypeCastOpcode(mapType.constraint.tag);
if (opcode == InstructionCodes.NOP) {
emit(InstructionCodes.MAPLOAD, varRefRegIndex, keyRegIndex, calcAndGetExprRegIndex(mapKeyAccessExpr));
} else {
RegIndex refRegMapValue = getRegIndex(TypeTags.ANY);
emit(InstructionCodes.MAPLOAD, varRefRegIndex, keyRegIndex, refRegMapValue);
emit(opcode, refRegMapValue, calcAndGetExprRegIndex(mapKeyAccessExpr));
}
}
this.varAssignment = variableStore;
}
use of org.wso2.ballerinalang.programfile.Instruction.RegIndex in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
@Override
public void visit(BLangXMLAttributeAccess xmlAttributeAccessExpr) {
boolean variableStore = this.varAssignment;
this.varAssignment = false;
genNode(xmlAttributeAccessExpr.expr, this.env);
RegIndex varRefRegIndex = xmlAttributeAccessExpr.expr.regIndex;
if (xmlAttributeAccessExpr.indexExpr == null) {
RegIndex xmlValueRegIndex = calcAndGetExprRegIndex(xmlAttributeAccessExpr);
emit(InstructionCodes.XML2XMLATTRS, varRefRegIndex, xmlValueRegIndex);
return;
}
BLangExpression indexExpr = xmlAttributeAccessExpr.indexExpr;
genNode(xmlAttributeAccessExpr.indexExpr, this.env);
RegIndex qnameRegIndex = xmlAttributeAccessExpr.indexExpr.regIndex;
// If this is a string representation of qname
if (indexExpr.getKind() != NodeKind.XML_QNAME) {
RegIndex localNameRegIndex = getRegIndex(TypeTags.STRING);
RegIndex uriRegIndex = getRegIndex(TypeTags.STRING);
emit(InstructionCodes.S2QNAME, qnameRegIndex, localNameRegIndex, uriRegIndex);
qnameRegIndex = getRegIndex(TypeTags.XML);
generateURILookupInstructions(xmlAttributeAccessExpr.namespaces, localNameRegIndex, uriRegIndex, qnameRegIndex, indexExpr.pos, env);
}
if (variableStore) {
emit(InstructionCodes.XMLATTRSTORE, varRefRegIndex, qnameRegIndex, xmlAttributeAccessExpr.regIndex);
} else {
RegIndex xmlValueRegIndex = calcAndGetExprRegIndex(xmlAttributeAccessExpr);
emit(InstructionCodes.XMLATTRLOAD, varRefRegIndex, qnameRegIndex, xmlValueRegIndex);
}
}
use of org.wso2.ballerinalang.programfile.Instruction.RegIndex in project ballerina by ballerina-lang.
the class CodeGenerator method generateNamedArgs.
private int generateNamedArgs(BLangInvocation iExpr, Operand[] operands, int currentIndex) {
if (iExpr.namedArgs.isEmpty()) {
return currentIndex;
}
PackageInfo pkgInfo = programFile.packageInfoMap.get(iExpr.symbol.pkgID.bvmAlias());
CallableUnitInfo callableUnitInfo;
if (iExpr.symbol.kind == SymbolKind.FUNCTION) {
callableUnitInfo = pkgInfo.functionInfoMap.get(iExpr.symbol.name.value);
} else if (iExpr.symbol.kind == SymbolKind.ACTION) {
ConnectorInfo connectorInfo = pkgInfo.connectorInfoMap.get(iExpr.symbol.owner.name.value);
callableUnitInfo = connectorInfo.actionInfoMap.get(iExpr.symbol.name.value);
} else {
throw new IllegalStateException("Unsupported callable unit");
}
ParamDefaultValueAttributeInfo defaultValAttrInfo = (ParamDefaultValueAttributeInfo) callableUnitInfo.getAttributeInfo(AttributeInfo.Kind.PARAMETER_DEFAULTS_ATTRIBUTE);
for (int i = 0; i < iExpr.namedArgs.size(); i++) {
BLangExpression argExpr = iExpr.namedArgs.get(i);
// at this point. If so, get the default value for that parameter from the function info.
if (argExpr == null) {
DefaultValue defaultVal = defaultValAttrInfo.getDefaultValueInfo()[i];
argExpr = getDefaultValExpr(defaultVal);
}
operands[currentIndex++] = genNode(argExpr, this.env).regIndex;
}
return currentIndex;
}
Aggregations