Implemented Exception Throwing fith specific catchers

This commit is contained in:
vegowotenks 2024-11-13 12:14:42 +01:00
parent 796e52241d
commit fc0d11c1e1
8 changed files with 351 additions and 12 deletions

View file

@ -39,6 +39,7 @@ impl Bytecode {
0x15 => (Instruction::LoadLocalInt(self.bytes[offset+1]), 2),
0x16 => (Instruction::LoadLocalLong(self.bytes[offset+1]), 2),
0x17 => (Instruction::LoadLocalFloat(self.bytes[offset+1]), 2),
0x18 => (Instruction::LoadLocalDouble(self.bytes[offset+1]), 2),
0x19 => (Instruction::LoadLocalReference(self.bytes[offset+1]), 2),
0x1A => (Instruction::LoadLocalInt0(), 1),
0x1B => (Instruction::LoadLocalInt1(), 1),
@ -66,6 +67,7 @@ impl Bytecode {
0x36 => (Instruction::StoreLocalInt(self.bytes[offset+1]), 2),
0x37 => (Instruction::StoreLocalLong(self.bytes[offset+1]), 2),
0x38 => (Instruction::StoreLocalFloat(self.bytes[offset+1]), 2),
0x39 => (Instruction::StoreLocalDouble(self.bytes[offset+1]), 2),
0x3A => (Instruction::StoreLocalReference(self.bytes[offset+1]), 2),
0x3B => (Instruction::StoreLocalInt0(), 1),
0x3C => (Instruction::StoreLocalInt1(), 1),
@ -101,6 +103,7 @@ impl Bytecode {
0x6C => (Instruction::DivideInt(), 1),
0x6D => (Instruction::DivideLong(), 1),
0x6E => (Instruction::DivideFloat(), 1),
0x6F => (Instruction::DivideDouble(), 1),
0x70 => (Instruction::ModuloInt(), 1),
0x74 => (Instruction::NegateInt(), 1),
@ -110,6 +113,7 @@ impl Bytecode {
0x7A => (Instruction::ArithmeticShiftIntRight(), 1),
0x7B => (Instruction::ArithmeticShiftLongRight(), 1),
0x7C => (Instruction::LogicalShiftIntRight(), 1),
0x7D => (Instruction::LogicalShiftLongRight(), 1),
0x7E => (Instruction::AndInt(), 1),
0x7F => (Instruction::AndLong(), 1),
@ -119,16 +123,20 @@ impl Bytecode {
0x85 => (Instruction::ConvertIntToLong(), 1),
0x86 => (Instruction::ConvertIntToFloat(), 1),
0x87 => (Instruction::ConvertIntToDouble(), 1),
0x88 => (Instruction::ConvertLongToInt(), 1),
0x89 => (Instruction::ConvertLongToFloat(), 1),
0x8B => (Instruction::ConvertFloatToInt(), 1),
0x8D => (Instruction::ConvertFloatToDouble(), 1),
0x8E => (Instruction::ConvertDoubleToInt(), 1),
0x8F => (Instruction::ConvertDoubleToLong(), 1),
0x91 => (Instruction::ConvertIntToByte(), 1),
0x92 => (Instruction::ConvertIntToChar(), 1),
0x94 => (Instruction::CompareLong(), 1),
0x95 => (Instruction::CompareFloatL(), 1),
0x96 => (Instruction::CompareFloatG(), 1),
0x97 => (Instruction::CompareDoubleL(), 1),
0x98 => (Instruction::CompareDoubleG(), 1),
0x99 => {
let bytes = [self.bytes[offset+1], self.bytes[offset+2]];
(Instruction::BranchZero(i16::from_be_bytes(bytes)), 3)
@ -238,6 +246,7 @@ impl Bytecode {
}
0xAC => (Instruction::ReturnInt(), 1),
0xAD => (Instruction::ReturnLong(), 1),
0xAF => (Instruction::ReturnDouble(), 1),
0xB0 => (Instruction::ReturnReference(), 1),
0xB1 => (Instruction::ReturnVoid(), 1),
@ -326,6 +335,7 @@ pub enum Instruction {
LoadLocalInt(u8) = 0x15, // Load int from indexed local variable
LoadLocalLong(u8) = 0x16, // Load long from indexed local variable
LoadLocalFloat(u8) = 0x17, // Load float from indexed local variable
LoadLocalDouble(u8) = 0x18, // Load double from indexed local variable
LoadLocalReference(u8) = 0x19, // Load reference from indexed local variable
LoadLocalInt0() = 0x1A, // Load int from local variable
LoadLocalInt1() = 0x1B, // Load int from local variable
@ -354,6 +364,7 @@ pub enum Instruction {
StoreLocalInt(u8) = 0x36, // store into indexed local variable
StoreLocalLong(u8) = 0x37, // store into indexed local variable
StoreLocalFloat(u8) = 0x38, // store into indexed local variable
StoreLocalDouble(u8) = 0x39, // store into indexed local variable
StoreLocalReference(u8) = 0x3A, // store into indexed local variable
StoreLocalInt0() = 0x3B, // store int into local variable
StoreLocalInt1() = 0x3C, // store int into local variable
@ -388,6 +399,7 @@ pub enum Instruction {
DivideInt() = 0x6C, // integer division, round toward zero and more rules
DivideLong() = 0x6D, // long division
DivideFloat() = 0x6E, // float division
DivideDouble() = 0x6F, // double division
ModuloInt() = 0x70, // modulo
NegateInt() = 0x74, // arithmetic negation
@ -397,6 +409,7 @@ pub enum Instruction {
ArithmeticShiftIntRight() = 0x7A, // shift int right, preserve sign
ArithmeticShiftLongRight() = 0x7B, // shift long right, preserve sign
LogicalShiftIntRight() = 0x7C, // shift int right with zero extension
LogicalShiftLongRight() = 0x7D, // shift long right with zero extension
AndInt() = 0x7E, // bitwise and
AndLong() = 0x7F, // bitwise and
@ -406,16 +419,20 @@ pub enum Instruction {
ConvertIntToLong() = 0x85, // convert int on stack to long
ConvertIntToFloat() = 0x86, // change data type
ConvertIntToDouble() = 0x87, // change data type
ConvertLongToInt() = 0x88, // change data type
ConvertLongToFloat() = 0x89, // change data type
ConvertFloatToInt() = 0x8B, // change data type
ConvertFloatToDouble() = 0x8D, // change data type
ConvertDoubleToInt() = 0x8E, // change data type
ConvertDoubleToLong() = 0x8F, // change data type
ConvertIntToByte() = 0x91, // truncate int to 8 bits
ConvertIntToChar() = 0x92, // truncate int to 16 bits
CompareLong() = 0x94, // compare long
CompareFloatL() = 0x95, // compare float, push -1 if one is NaN
CompareFloatG() = 0x96, // compare float, push 1 if one is NaN
CompareDoubleL() = 0x97, // compare float, push -1 if one is NaN
CompareDoubleG() = 0x98, // compare float, push 1 if one is NaN
BranchZero(i16) = 0x99, // branch if value == 0
BranchNonZero(i16) = 0x9A, // branch if value != 0
BranchNegative(i16) = 0x9B, // branch if value < 0
@ -437,6 +454,7 @@ pub enum Instruction {
LookupSwitch(i32, Box<[(i32, i32)]>) = 0xAB, // jump based on switch value
ReturnInt() = 0xAC, // return integer from function
ReturnLong() = 0xAD, // return long from function
ReturnDouble() = 0xAF, // return double from function
ReturnReference() = 0xB0, // return top-ref from current function
ReturnVoid() = 0xB1, // return void from function