use of org.wso2.ballerinalang.programfile.Instruction.Operand in project ballerina by ballerina-lang.
the class CodeGenerator method getOperands.
private Operand[] getOperands(BLangLock lockNode) {
Operand[] operands = new Operand[(lockNode.lockVariables.size() * 2) + 1];
int i = 0;
operands[i++] = new Operand(lockNode.lockVariables.size());
for (BVarSymbol varSymbol : lockNode.lockVariables) {
int typeSigCPIndex = addUTF8CPEntry(currentPkgInfo, varSymbol.getType().getDesc());
TypeRefCPEntry typeRefCPEntry = new TypeRefCPEntry(typeSigCPIndex);
operands[i++] = getOperand(currentPkgInfo.addCPEntry(typeRefCPEntry));
operands[i++] = varSymbol.varIndex;
}
return operands;
}
use of org.wso2.ballerinalang.programfile.Instruction.Operand in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
@Override
public void visit(BLangPackageVarRef packageVarRef) {
Operand gvIndex = packageVarRef.symbol.varIndex;
if (varAssignment) {
int opcode = getOpcode(packageVarRef.type.tag, InstructionCodes.IGSTORE);
emit(opcode, packageVarRef.regIndex, gvIndex);
return;
}
int opcode = getOpcode(packageVarRef.type.tag, InstructionCodes.IGLOAD);
packageVarRef.regIndex = calcAndGetExprRegIndex(packageVarRef);
emit(opcode, gvIndex, packageVarRef.regIndex);
}
use of org.wso2.ballerinalang.programfile.Instruction.Operand in project ballerina by ballerina-lang.
the class CodeGenerator method generateFinallyInstructions.
private void generateFinallyInstructions(BLangStatement statement, NodeKind... expectedParentKinds) {
BLangStatement current = statement;
while (current != null && current.statementLink.parent != null) {
BLangStatement parent = current.statementLink.parent.statement;
for (NodeKind expected : expectedParentKinds) {
if (expected == parent.getKind()) {
return;
}
}
if (NodeKind.TRY == parent.getKind()) {
BLangTryCatchFinally tryCatchFinally = (BLangTryCatchFinally) parent;
if (tryCatchFinally.finallyBody != null && current != tryCatchFinally.finallyBody) {
genNode(tryCatchFinally.finallyBody, env);
}
} else if (NodeKind.LOCK == parent.getKind()) {
BLangLock lockNode = (BLangLock) parent;
if (!lockNode.lockVariables.isEmpty()) {
Operand[] operands = getOperands(lockNode);
emit((InstructionCodes.UNLOCK), operands);
}
}
current = parent;
}
}
use of org.wso2.ballerinalang.programfile.Instruction.Operand in project ballerina by ballerina-lang.
the class CodeGenerator method processJoinBlock.
/* generate code for Join block */
private void processJoinBlock(BLangForkJoin forkJoin, ForkjoinInfo forkjoinInfo, SymbolEnv forkJoinEnv, RegIndex joinVarRegIndex, Operand joinBlockAddr) {
UTF8CPEntry joinType = new UTF8CPEntry(forkJoin.joinType.name());
int joinTypeCPIndex = this.currentPkgInfo.addCPEntry(joinType);
forkjoinInfo.setJoinType(forkJoin.joinType.name());
forkjoinInfo.setJoinTypeCPIndex(joinTypeCPIndex);
joinBlockAddr.value = nextIP();
if (forkJoin.joinResultVar != null) {
visitForkJoinParameterDefs(forkJoin.joinResultVar, forkJoinEnv);
joinVarRegIndex.value = forkJoin.joinResultVar.symbol.varIndex.value;
}
if (forkJoin.joinedBody != null) {
this.genNode(forkJoin.joinedBody, forkJoinEnv);
}
}
use of org.wso2.ballerinalang.programfile.Instruction.Operand in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
public void visit(BLangIf ifNode) {
addLineNumberInfo(ifNode.pos);
// Generate code for the if condition evaluation
genNode(ifNode.expr, this.env);
Operand ifCondJumpAddr = getOperand(-1);
emit(InstructionCodes.BR_FALSE, ifNode.expr.regIndex, ifCondJumpAddr);
// Generate code for the then body
genNode(ifNode.body, this.env);
Operand endJumpAddr = getOperand(-1);
emit(InstructionCodes.GOTO, endJumpAddr);
ifCondJumpAddr.value = nextIP();
// Visit else statement if any
if (ifNode.elseStmt != null) {
genNode(ifNode.elseStmt, this.env);
}
endJumpAddr.value = nextIP();
}
Aggregations