Working up until registerNatives()

This commit is contained in:
vegowotenks 2024-09-06 23:51:35 +02:00
parent 5bc0d813e5
commit 3282694b32
4 changed files with 268 additions and 58 deletions

View file

@ -25,6 +25,7 @@ impl Bytecode {
0x10 => (Instruction::LoadByteImmediate(self.bytes[offset+1]), 2),
0x11 => (Instruction::LoadShortImmediate((self.bytes[offset+1] as u16) << 8 | self.bytes[offset+2] as u16), 3),
0x12 => (Instruction::LoadConstant(self.bytes[offset+1]), 2),
0x13 => (Instruction::LoadWideConstant((self.bytes[offset+1] as u16) << 8 | self.bytes[offset+2] as u16), 3),
0x14 => (Instruction::LoadConstant64((self.bytes[offset+1] as u16) << 8 | self.bytes[offset+2] as u16), 3),
0x1A => (Instruction::LoadLocalInt0(), 1),
@ -41,6 +42,7 @@ impl Bytecode {
0x2D => (Instruction::LoadLocalReference3(), 1),
0x32 => (Instruction::ArrayElement(), 1),
0x36 => (Instruction::StoreLocalInt(self.bytes[offset+1]), 2),
0x3B => (Instruction::StoreLocalInt0(), 1),
0x3C => (Instruction::StoreLocalInt1(), 1),
0x3D => (Instruction::StoreLocalInt2(), 1),
@ -50,6 +52,9 @@ impl Bytecode {
0x4D => (Instruction::StoreReference2(), 1),
0x4E => (Instruction::StoreReference3(), 1),
0x53 => (Instruction::StoreIntoRArray(), 1),
0x54 => (Instruction::StoreIntoBArray(), 1),
0x57 => (Instruction::Pop(), 1),
0x59 => (Instruction::Duplicate(), 1),
@ -85,6 +90,31 @@ impl Bytecode {
(Instruction::BranchNonNegative(i16::from_be_bytes(bytes)), 3)
}
0x9F => {
let bytes = [self.bytes[offset+1], self.bytes[offset+2]];
(Instruction::BranchIntEquality(i16::from_be_bytes(bytes)), 3)
}
0xA0 => {
let bytes = [self.bytes[offset+1], self.bytes[offset+2]];
(Instruction::BranchIntInequality(i16::from_be_bytes(bytes)), 3)
}
0xA1 => {
let bytes = [self.bytes[offset+1], self.bytes[offset+2]];
(Instruction::BranchIntLessThan(i16::from_be_bytes(bytes)), 3)
}
0xA2 => {
let bytes = [self.bytes[offset+1], self.bytes[offset+2]];
(Instruction::BranchIntGreaterEquals(i16::from_be_bytes(bytes)), 3)
}
0xA3 => {
let bytes = [self.bytes[offset+1], self.bytes[offset+2]];
(Instruction::BranchIntGreaterThan(i16::from_be_bytes(bytes)), 3)
}
0xA4 => {
let bytes = [self.bytes[offset+1], self.bytes[offset+2]];
(Instruction::BranchIntLessEquals(i16::from_be_bytes(bytes)), 3)
}
0xAC => (Instruction::ReturnInt(), 1),
0xA7 => {
let bytes = [self.bytes[offset+1], self.bytes[offset+2]];
@ -102,6 +132,7 @@ impl Bytecode {
0xB8 => (Instruction::InvokeStatic((self.bytes[offset+1] as u16) << 8 | self.bytes[offset+2] as u16), 3),
0xBA => (Instruction::InvokeDynamic((self.bytes[offset+1] as u16) << 8 | self.bytes[offset+2] as u16, (self.bytes[offset+3] as u16) << 8 | self.bytes[offset+4] as u16), 5),
0xBB => (Instruction::NewObject((self.bytes[offset+1] as u16) << 8 | self.bytes[offset+2] as u16), 3),
0xBC => (Instruction::NewPrimitiveArray(self.bytes[offset+1]), 2),
0xBD => (Instruction::NewArray((self.bytes[offset+1] as u16) << 8 | self.bytes[offset+2] as u16), 3),
0xBE => (Instruction::ArrayLength(), 1),
_ => (Instruction::Unknown(opcode), 1)
@ -150,6 +181,8 @@ pub enum Instruction {
LoadByteImmediate(u8) = 0x10, // push immediate short
LoadShortImmediate(u16) = 0x11, // push immediate short
LoadConstant(u8) = 0x12, // Push from constant pool
LoadWideConstant(u16) = 0x13, // Push from constant pool with wide index, don't load
// double or long or whatever
LoadConstant64(u16) = 0x14, // Push Long or Double from constant pool
LoadLocalInt0() = 0x1A, // Load int from local variable
LoadLocalInt1() = 0x1B, // Load int from local variable
@ -166,6 +199,7 @@ pub enum Instruction {
LoadLocalReference3() = 0x2D, // Load local reference variable reference onto stack
ArrayElement() = 0x32, // load element from array
StoreLocalInt(u8) = 0x36, // store into indexed local variable
StoreLocalInt0() = 0x3B, // store int into local variable
StoreLocalInt1() = 0x3C, // store int into local variable
StoreLocalInt2() = 0x3D, // store int into local variable
@ -175,6 +209,8 @@ pub enum Instruction {
StoreReference2() = 0x4D, // store reference into local variable
StoreReference3() = 0x4E, // store reference into local variable
StoreIntoRArray() = 0x53, // store value into reference array
StoreIntoBArray() = 0x54, // store value into byte or boolean array
Pop() = 0x57, // Pop top stack value
Duplicate() = 0x59, // duplicate top stack value
@ -197,6 +233,7 @@ pub enum Instruction {
BranchIntLessThan(i16) = 0xA1,
BranchIntGreaterEquals(i16) = 0xA2,
BranchIntGreaterThan(i16) = 0xA3,
BranchIntLessEquals(i16) = 0xA4,
BranchAlways(i16) = 0xA7, // branch if true
ReturnInt() = 0xAC, // return integer from function
@ -212,6 +249,7 @@ pub enum Instruction {
InvokeStatic(u16) = 0xB8, // invoke static function
InvokeDynamic(u16, u16) = 0xBA, // invoke dynamic function
NewObject(u16) = 0xBB, // Create a new object from a constant-pool class reference
NewPrimitiveArray(u8) = 0xBC, // make a primitive array
NewArray(u16) = 0xBD, // Create a new array from a constant-pool component class reference
ArrayLength() = 0xBE, // Get length from array reference
Unknown(u8),