use of org.wso2.ballerinalang.programfile.Instruction.Operand in project ballerina by ballerina-lang.
the class PackageInfoWriter method writeInstructions.
private static byte[] writeInstructions(Instruction[] instructions) throws IOException {
ByteArrayOutputStream byteAOS = new ByteArrayOutputStream();
DataOutputStream dataOutStream = new DataOutputStream(byteAOS);
for (Instruction instruction : instructions) {
dataOutStream.write(instruction.opcode);
for (Operand operand : instruction.ops) {
dataOutStream.writeInt(operand.value);
}
}
return byteAOS.toByteArray();
}
use of org.wso2.ballerinalang.programfile.Instruction.Operand in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
@Override
public void visit(BLangArrayAccessExpr arrayIndexAccessExpr) {
boolean variableStore = this.varAssignment;
this.varAssignment = false;
genNode(arrayIndexAccessExpr.expr, this.env);
Operand varRefRegIndex = arrayIndexAccessExpr.expr.regIndex;
genNode(arrayIndexAccessExpr.indexExpr, this.env);
Operand indexRegIndex = arrayIndexAccessExpr.indexExpr.regIndex;
BArrayType arrayType = (BArrayType) arrayIndexAccessExpr.expr.type;
if (variableStore) {
int opcode = getOpcode(arrayType.eType.tag, InstructionCodes.IASTORE);
emit(opcode, varRefRegIndex, indexRegIndex, arrayIndexAccessExpr.regIndex);
} else {
int opcode = getOpcode(arrayType.eType.tag, InstructionCodes.IALOAD);
emit(opcode, varRefRegIndex, indexRegIndex, calcAndGetExprRegIndex(arrayIndexAccessExpr));
}
this.varAssignment = variableStore;
}
use of org.wso2.ballerinalang.programfile.Instruction.Operand in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
public void visit(BLangTypeofExpr accessExpr) {
Operand typeCPIndex = getTypeCPIndex(accessExpr.resolvedType);
emit(InstructionCodes.TYPELOAD, typeCPIndex, calcAndGetExprRegIndex(accessExpr));
}
use of org.wso2.ballerinalang.programfile.Instruction.Operand 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();
}
use of org.wso2.ballerinalang.programfile.Instruction.Operand in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
public void visit(BLangLock lockNode) {
if (lockNode.lockVariables.isEmpty()) {
this.genNode(lockNode.body, this.env);
return;
}
Operand gotoLockEndAddr = getOperand(-1);
Instruction instructGotoLockEnd = InstructionFactory.get(InstructionCodes.GOTO, gotoLockEndAddr);
Operand[] operands = getOperands(lockNode);
ErrorTableAttributeInfo errorTable = createErrorTableIfAbsent(currentPkgInfo);
int fromIP = nextIP();
emit((InstructionCodes.LOCK), operands);
this.genNode(lockNode.body, this.env);
int toIP = nextIP() - 1;
emit((InstructionCodes.UNLOCK), operands);
emit(instructGotoLockEnd);
ErrorTableEntry errorTableEntry = new ErrorTableEntry(fromIP, toIP, nextIP(), 0, -1);
errorTable.addErrorTableEntry(errorTableEntry);
emit((InstructionCodes.UNLOCK), operands);
emit(InstructionFactory.get(InstructionCodes.THROW, getOperand(-1)));
gotoLockEndAddr.value = nextIP();
}
Aggregations