use of org.wso2.ballerinalang.programfile.Instruction.RegIndex in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
public void visit(BLangCatch bLangCatch) {
// Define local variable index for Error.
BLangVariable variable = bLangCatch.param;
RegIndex lvIndex = getLVIndex(variable.symbol.type.tag);
variable.symbol.varIndex = lvIndex;
emit(InstructionFactory.get(InstructionCodes.ERRSTORE, lvIndex));
// Visit Catch Block.
genNode(bLangCatch.body, env);
}
use of org.wso2.ballerinalang.programfile.Instruction.RegIndex in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
// Expressions
@Override
public void visit(BLangLiteral literalExpr) {
int opcode;
Operand regIndex = calcAndGetExprRegIndex(literalExpr);
int typeTag = literalExpr.type.tag;
switch(typeTag) {
case TypeTags.INT:
long longVal = (Long) literalExpr.value;
if (longVal >= 0 && longVal <= 5) {
opcode = InstructionCodes.ICONST_0 + (int) longVal;
emit(opcode, regIndex);
} else {
int intCPEntryIndex = currentPkgInfo.addCPEntry(new IntegerCPEntry(longVal));
emit(InstructionCodes.ICONST, getOperand(intCPEntryIndex), regIndex);
}
break;
case TypeTags.FLOAT:
double doubleVal = (Double) literalExpr.value;
if (doubleVal == 0 || doubleVal == 1 || doubleVal == 2 || doubleVal == 3 || doubleVal == 4 || doubleVal == 5) {
opcode = InstructionCodes.FCONST_0 + (int) doubleVal;
emit(opcode, regIndex);
} else {
int floatCPEntryIndex = currentPkgInfo.addCPEntry(new FloatCPEntry(doubleVal));
emit(InstructionCodes.FCONST, getOperand(floatCPEntryIndex), regIndex);
}
break;
case TypeTags.STRING:
String strValue = (String) literalExpr.value;
StringCPEntry stringCPEntry = new StringCPEntry(addUTF8CPEntry(currentPkgInfo, strValue), strValue);
int strCPIndex = currentPkgInfo.addCPEntry(stringCPEntry);
emit(InstructionCodes.SCONST, getOperand(strCPIndex), regIndex);
break;
case TypeTags.BOOLEAN:
boolean booleanVal = (Boolean) literalExpr.value;
if (!booleanVal) {
opcode = InstructionCodes.BCONST_0;
} else {
opcode = InstructionCodes.BCONST_1;
}
emit(opcode, regIndex);
break;
case TypeTags.NULL:
emit(InstructionCodes.RCONST_NULL, regIndex);
}
}
Aggregations