use of org.wso2.ballerinalang.programfile.Instruction.Operand in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
public void visit(BLangActionInvocation aIExpr) {
BInvokableSymbol actionSymbol = (BInvokableSymbol) aIExpr.symbol;
int pkgRefCPIndex = addPackageRefCPEntry(currentPkgInfo, actionSymbol.pkgID);
int actionNameCPIndex = addUTF8CPEntry(currentPkgInfo, actionSymbol.name.value);
ActionRefCPEntry actionRefCPEntry = new ActionRefCPEntry(pkgRefCPIndex, actionNameCPIndex);
int actionRefCPIndex = currentPkgInfo.addCPEntry(actionRefCPEntry);
Operand[] operands = getFuncOperands(aIExpr, actionRefCPIndex);
emit(InstructionCodes.ACALL, operands);
}
use of org.wso2.ballerinalang.programfile.Instruction.Operand in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
@Override
public void visit(BLangPackageXMLNS xmlnsNode) {
BLangExpression nsURIExpr = xmlnsNode.namespaceURI;
Operand pvIndex = getPVIndex(TypeTags.STRING);
BXMLNSSymbol nsSymbol = (BXMLNSSymbol) xmlnsNode.symbol;
genNode(nsURIExpr, env);
nsSymbol.nsURIIndex = pvIndex;
emit(InstructionCodes.SGSTORE, nsURIExpr.regIndex, pvIndex);
}
use of org.wso2.ballerinalang.programfile.Instruction.Operand in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
@Override
public void visit(BLangFieldVarRef fieldVarRef) {
RegIndex fieldIndex = fieldVarRef.symbol.varIndex;
// This is a connector field.
// the connector reference must be stored in the current reference register index.
Operand varRegIndex = getOperand(0);
if (varAssignment) {
int opcode = getOpcode(fieldVarRef.type.tag, InstructionCodes.IFIELDSTORE);
emit(opcode, varRegIndex, fieldIndex, fieldVarRef.regIndex);
return;
}
int opcode = getOpcode(fieldVarRef.type.tag, InstructionCodes.IFIELDLOAD);
RegIndex exprRegIndex = calcAndGetExprRegIndex(fieldVarRef);
emit(opcode, varRegIndex, fieldIndex, exprRegIndex);
}
use of org.wso2.ballerinalang.programfile.Instruction.Operand 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.Operand 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;
}
}
Aggregations