use of org.ballerinalang.model.types.BEnumType in project ballerina by ballerina-lang.
the class CPU method execLoadOpcodes.
@SuppressWarnings({ "rawtypes", "unchecked" })
private static void execLoadOpcodes(WorkerExecutionContext ctx, WorkerData sf, int opcode, int[] operands) {
int i;
int j;
int k;
// Index of the local variable
int lvIndex;
int fieldIndex;
BIntArray bIntArray;
BFloatArray bFloatArray;
BStringArray bStringArray;
BBooleanArray bBooleanArray;
BBlobArray bBlobArray;
BRefValueArray bArray;
StructureType structureType;
BMap<String, BRefType> bMap;
BJSON jsonVal;
switch(opcode) {
case InstructionCodes.IMOVE:
lvIndex = operands[0];
i = operands[1];
sf.longRegs[i] = sf.longRegs[lvIndex];
break;
case InstructionCodes.FMOVE:
lvIndex = operands[0];
i = operands[1];
sf.doubleRegs[i] = sf.doubleRegs[lvIndex];
break;
case InstructionCodes.SMOVE:
lvIndex = operands[0];
i = operands[1];
sf.stringRegs[i] = sf.stringRegs[lvIndex];
break;
case InstructionCodes.BMOVE:
lvIndex = operands[0];
i = operands[1];
sf.intRegs[i] = sf.intRegs[lvIndex];
break;
case InstructionCodes.LMOVE:
lvIndex = operands[0];
i = operands[1];
sf.byteRegs[i] = sf.byteRegs[lvIndex];
break;
case InstructionCodes.RMOVE:
lvIndex = operands[0];
i = operands[1];
sf.refRegs[i] = sf.refRegs[lvIndex];
break;
case InstructionCodes.IALOAD:
i = operands[0];
j = operands[1];
k = operands[2];
bIntArray = (BIntArray) sf.refRegs[i];
if (bIntArray == null) {
handleNullRefError(ctx);
break;
}
try {
sf.longRegs[k] = bIntArray.get(sf.longRegs[j]);
} catch (Exception e) {
ctx.setError(BLangVMErrors.createError(ctx, e.getMessage()));
handleError(ctx);
}
break;
case InstructionCodes.FALOAD:
i = operands[0];
j = operands[1];
k = operands[2];
bFloatArray = (BFloatArray) sf.refRegs[i];
if (bFloatArray == null) {
handleNullRefError(ctx);
break;
}
try {
sf.doubleRegs[k] = bFloatArray.get(sf.longRegs[j]);
} catch (Exception e) {
ctx.setError(BLangVMErrors.createError(ctx, e.getMessage()));
handleError(ctx);
}
break;
case InstructionCodes.SALOAD:
i = operands[0];
j = operands[1];
k = operands[2];
bStringArray = (BStringArray) sf.refRegs[i];
if (bStringArray == null) {
handleNullRefError(ctx);
break;
}
try {
sf.stringRegs[k] = bStringArray.get(sf.longRegs[j]);
} catch (Exception e) {
ctx.setError(BLangVMErrors.createError(ctx, e.getMessage()));
handleError(ctx);
}
break;
case InstructionCodes.BALOAD:
i = operands[0];
j = operands[1];
k = operands[2];
bBooleanArray = (BBooleanArray) sf.refRegs[i];
if (bBooleanArray == null) {
handleNullRefError(ctx);
break;
}
try {
sf.intRegs[k] = bBooleanArray.get(sf.longRegs[j]);
} catch (Exception e) {
ctx.setError(BLangVMErrors.createError(ctx, e.getMessage()));
handleError(ctx);
}
break;
case InstructionCodes.LALOAD:
i = operands[0];
j = operands[1];
k = operands[2];
bBlobArray = (BBlobArray) sf.refRegs[i];
if (bBlobArray == null) {
handleNullRefError(ctx);
break;
}
try {
sf.byteRegs[k] = bBlobArray.get(sf.longRegs[j]);
} catch (Exception e) {
ctx.setError(BLangVMErrors.createError(ctx, e.getMessage()));
handleError(ctx);
}
break;
case InstructionCodes.RALOAD:
i = operands[0];
j = operands[1];
k = operands[2];
bArray = (BRefValueArray) sf.refRegs[i];
if (bArray == null) {
handleNullRefError(ctx);
break;
}
try {
sf.refRegs[k] = bArray.get(sf.longRegs[j]);
} catch (Exception e) {
ctx.setError(BLangVMErrors.createError(ctx, e.getMessage()));
handleError(ctx);
}
break;
case InstructionCodes.JSONALOAD:
i = operands[0];
j = operands[1];
k = operands[2];
jsonVal = (BJSON) sf.refRegs[i];
if (jsonVal == null) {
handleNullRefError(ctx);
break;
}
try {
sf.refRegs[k] = JSONUtils.getArrayElement(jsonVal, sf.longRegs[j]);
} catch (Exception e) {
ctx.setError(BLangVMErrors.createError(ctx, e.getMessage()));
handleError(ctx);
}
break;
case InstructionCodes.IGLOAD:
// Global variable index
i = operands[0];
// Stack registry index
j = operands[1];
sf.longRegs[j] = ctx.programFile.getGlobalMemoryBlock().getIntField(i);
break;
case InstructionCodes.FGLOAD:
i = operands[0];
j = operands[1];
sf.doubleRegs[j] = ctx.programFile.getGlobalMemoryBlock().getFloatField(i);
break;
case InstructionCodes.SGLOAD:
i = operands[0];
j = operands[1];
sf.stringRegs[j] = ctx.programFile.getGlobalMemoryBlock().getStringField(i);
break;
case InstructionCodes.BGLOAD:
i = operands[0];
j = operands[1];
sf.intRegs[j] = ctx.programFile.getGlobalMemoryBlock().getBooleanField(i);
break;
case InstructionCodes.LGLOAD:
i = operands[0];
j = operands[1];
sf.byteRegs[j] = ctx.programFile.getGlobalMemoryBlock().getBlobField(i);
break;
case InstructionCodes.RGLOAD:
i = operands[0];
j = operands[1];
sf.refRegs[j] = ctx.programFile.getGlobalMemoryBlock().getRefField(i);
break;
case InstructionCodes.IFIELDLOAD:
i = operands[0];
fieldIndex = operands[1];
j = operands[2];
structureType = (StructureType) sf.refRegs[i];
if (structureType == null) {
handleNullRefError(ctx);
break;
}
sf.longRegs[j] = structureType.getIntField(fieldIndex);
break;
case InstructionCodes.FFIELDLOAD:
i = operands[0];
fieldIndex = operands[1];
j = operands[2];
structureType = (StructureType) sf.refRegs[i];
if (structureType == null) {
handleNullRefError(ctx);
break;
}
sf.doubleRegs[j] = structureType.getFloatField(fieldIndex);
break;
case InstructionCodes.SFIELDLOAD:
i = operands[0];
fieldIndex = operands[1];
j = operands[2];
structureType = (StructureType) sf.refRegs[i];
if (structureType == null) {
handleNullRefError(ctx);
break;
}
sf.stringRegs[j] = structureType.getStringField(fieldIndex);
break;
case InstructionCodes.BFIELDLOAD:
i = operands[0];
fieldIndex = operands[1];
j = operands[2];
structureType = (StructureType) sf.refRegs[i];
if (structureType == null) {
handleNullRefError(ctx);
break;
}
sf.intRegs[j] = structureType.getBooleanField(fieldIndex);
break;
case InstructionCodes.LFIELDLOAD:
i = operands[0];
fieldIndex = operands[1];
j = operands[2];
structureType = (StructureType) sf.refRegs[i];
if (structureType == null) {
handleNullRefError(ctx);
break;
}
sf.byteRegs[j] = structureType.getBlobField(fieldIndex);
break;
case InstructionCodes.RFIELDLOAD:
i = operands[0];
fieldIndex = operands[1];
j = operands[2];
structureType = (StructureType) sf.refRegs[i];
if (structureType == null) {
handleNullRefError(ctx);
break;
}
sf.refRegs[j] = structureType.getRefField(fieldIndex);
break;
case InstructionCodes.MAPLOAD:
i = operands[0];
j = operands[1];
k = operands[2];
bMap = (BMap<String, BRefType>) sf.refRegs[i];
if (bMap == null) {
handleNullRefError(ctx);
break;
}
sf.refRegs[k] = bMap.get(sf.stringRegs[j]);
break;
case InstructionCodes.JSONLOAD:
i = operands[0];
j = operands[1];
k = operands[2];
jsonVal = (BJSON) sf.refRegs[i];
if (jsonVal == null) {
handleNullRefError(ctx);
break;
}
sf.refRegs[k] = JSONUtils.getElement(jsonVal, sf.stringRegs[j]);
break;
case InstructionCodes.ENUMERATORLOAD:
i = operands[0];
j = operands[1];
k = operands[2];
TypeRefCPEntry typeRefCPEntry = (TypeRefCPEntry) ctx.constPool[i];
BEnumType enumType = (BEnumType) typeRefCPEntry.getType();
sf.refRegs[k] = enumType.getEnumerator(j);
break;
default:
throw new UnsupportedOperationException();
}
}
use of org.ballerinalang.model.types.BEnumType in project ballerina by ballerina-lang.
the class ProgramFileReader method readEnumInfoEntries.
private void readEnumInfoEntries(DataInputStream dataInStream, PackageInfo packageInfo) throws IOException {
int enumCount = dataInStream.readShort();
for (int i = 0; i < enumCount; i++) {
// Create enum info entry
int enumNameCPIndex = dataInStream.readInt();
int flags = dataInStream.readInt();
UTF8CPEntry enumNameUTF8Entry = (UTF8CPEntry) packageInfo.getCPEntry(enumNameCPIndex);
String enumName = enumNameUTF8Entry.getValue();
EnumInfo enumInfo = new EnumInfo(packageInfo.getPkgNameCPIndex(), packageInfo.getPkgPath(), enumNameCPIndex, enumName, flags);
packageInfo.addEnumInfo(enumName, enumInfo);
// Set enum type
BEnumType enumType = new BEnumType(enumName, packageInfo.getPkgPath());
enumInfo.setType(enumType);
int enumeratorCount = dataInStream.readShort();
BEnumerator[] enumerators = new BEnumerator[enumeratorCount];
for (int j = 0; j < enumeratorCount; j++) {
int enumeratorNameCPIndex = dataInStream.readInt();
UTF8CPEntry enumeratorNameUTF8Entry = (UTF8CPEntry) packageInfo.getCPEntry(enumeratorNameCPIndex);
String enumeratorName = enumeratorNameUTF8Entry.getValue();
BEnumerator enumerator = new BEnumerator(enumeratorName, enumType);
enumerators[j] = enumerator;
}
enumType.setEnumerators(enumerators);
// Read attributes of the struct info
readAttributeInfoEntries(dataInStream, packageInfo, enumInfo);
}
}
Aggregations