slightly smarter again

This commit is contained in:
Shautvast 2023-11-24 23:12:51 +01:00
parent 0e6fce058f
commit 98300a1532
3 changed files with 46 additions and 131 deletions

View file

@ -42,20 +42,20 @@ fn get_opcode(opcodes: &[u8], c: &mut usize) -> Opcode {
let opcode = match opcode_u8 { let opcode = match opcode_u8 {
0 => NOP, 0 => NOP,
1 => ACONST_NULL, 1 => ACONST_NULL,
2 => ICONST_M1, 2 => ICONST(-1),
3 => ICONST_0, 3 => ICONST(0),
4 => ICONST_1, 4 => ICONST(1),
5 => ICONST_2, 5 => ICONST(2),
6 => ICONST_3, 6 => ICONST(3),
7 => ICONST_4, 7 => ICONST(4),
8 => ICONST_5, 8 => ICONST(5),
9 => LCONST_0, 9 => LCONST(0),
10 => LCONST_1, 10 => LCONST(1),
11 => FCONST_0, 11 => FCONST(0),
12 => FCONST_1, 12 => FCONST(1),
13 => FCONST_2, 13 => FCONST(2),
14 => DCONST_0, 14 => DCONST(0),
15 => DCONST_1, 15 => DCONST(1),
16 => BIPUSH(read_u8(opcodes, c)), 16 => BIPUSH(read_u8(opcodes, c)),
17 => SIPUSH(read_u16(opcodes, c)), 17 => SIPUSH(read_u16(opcodes, c)),
18 => LDC(read_u8(opcodes, c) as u16), 18 => LDC(read_u8(opcodes, c) as u16),
@ -99,26 +99,26 @@ fn get_opcode(opcodes: &[u8], c: &mut usize) -> Opcode {
56 => FSTORE(read_u8(opcodes, c)), 56 => FSTORE(read_u8(opcodes, c)),
57 => DSTORE(read_u8(opcodes, c)), 57 => DSTORE(read_u8(opcodes, c)),
58 => ASTORE(read_u8(opcodes, c)), 58 => ASTORE(read_u8(opcodes, c)),
59 => ISTORE_0, 59 => ISTORE(0),
60 => ISTORE_1, 60 => ISTORE(1),
61 => ISTORE_2, 61 => ISTORE(2),
62 => ISTORE_3, 62 => ISTORE(3),
63 => LSTORE_0, 63 => LSTORE(0),
64 => LSTORE_1, 64 => LSTORE(1),
65 => LSTORE_2, 65 => LSTORE(2),
66 => LSTORE_3, 66 => LSTORE(3),
67 => FSTORE_0, 67 => FSTORE(0),
68 => FSTORE_1, 68 => FSTORE(1),
69 => FSTORE_2, 69 => FSTORE(2),
70 => FSTORE_3, 70 => FSTORE(3),
71 => DSTORE_0, 71 => DSTORE(0),
72 => DSTORE_1, 72 => DSTORE(1),
73 => DSTORE_2, 73 => DSTORE(2),
74 => DSTORE_3, 74 => DSTORE(3),
75 => ASTORE_0, 75 => ASTORE(0),
76 => ASTORE_1, 76 => ASTORE(1),
77 => ASTORE_2, 77 => ASTORE(2),
78 => ASTORE_3, 78 => ASTORE(3),
79 => IASTORE, 79 => IASTORE,
80 => LASTORE, 80 => LASTORE,
81 => FASTORE, 81 => FASTORE,

View file

@ -5,20 +5,10 @@ use crate::classloader::io::{Lookupswitch, Tableswitch};
pub(crate) enum Opcode { pub(crate) enum Opcode {
NOP, NOP,
ACONST_NULL, ACONST_NULL,
ICONST_M1, ICONST(i16),
ICONST_0, LCONST(u8),
ICONST_1, FCONST(u8),
ICONST_2, DCONST(u8),
ICONST_3,
ICONST_4,
ICONST_5,
LCONST_0,
LCONST_1,
FCONST_0,
FCONST_1,
FCONST_2,
DCONST_0,
DCONST_1,
BIPUSH(u8), BIPUSH(u8),
SIPUSH(u16), SIPUSH(u16),
LDC(u16), LDC(u16),
@ -52,26 +42,6 @@ pub(crate) enum Opcode {
WIDE_DSTORE(u16), WIDE_DSTORE(u16),
ASTORE(u8), ASTORE(u8),
WIDE_ASTORE(u16), WIDE_ASTORE(u16),
ISTORE_0,
ISTORE_1,
ISTORE_2,
ISTORE_3,
LSTORE_0,
LSTORE_1,
LSTORE_2,
LSTORE_3,
FSTORE_0,
FSTORE_1,
FSTORE_2,
FSTORE_3,
DSTORE_0,
DSTORE_1,
DSTORE_2,
DSTORE_3,
ASTORE_0,
ASTORE_1,
ASTORE_2,
ASTORE_3,
IASTORE, IASTORE,
LASTORE, LASTORE,
FASTORE, FASTORE,

View file

@ -98,47 +98,17 @@ impl Stackframe {
ACONST_NULL => { ACONST_NULL => {
self.push(Null); self.push(Null);
} }
ICONST_M1 => { ICONST(v) => {
self.push(I32(-1)); self.push(I32(*v as i32));
} }
ICONST_0 => { LCONST(v) => {
self.push(I32(0)); self.push(I64(*v as i64));
} }
ICONST_1 => { FCONST(v) => {
self.push(I32(1)); self.push(F32(*v as f32));
} }
ICONST_2 => { DCONST(v) => {
self.push(I32(2)); self.push(F64(*v as f64));
}
ICONST_3 => {
self.push(I32(3));
}
ICONST_4 => {
self.push(I32(4));
}
ICONST_5 => {
self.push(I32(5));
}
LCONST_0 => {
self.push(I64(0));
}
LCONST_1 => {
self.push(I64(1));
}
FCONST_0 => {
self.push(F32(0.0));
}
FCONST_1 => {
self.push(F32(1.0));
}
FCONST_2 => {
self.push(F32(2.0));
}
DCONST_0 => {
self.push(F64(0.0));
}
DCONST_1 => {
self.push(F64(1.0));
} }
SIPUSH(si) => { SIPUSH(si) => {
self.push(I32(*si as i32)); self.push(I32(*si as i32));
@ -191,18 +161,6 @@ impl Stackframe {
// omitting the type checks so far // omitting the type checks so far
self.push(self.locals[*n as usize].clone()); self.push(self.locals[*n as usize].clone());
} }
ILOAD_0 | LLOAD_0 | FLOAD_0 | DLOAD_0 | ALOAD_0 => {
self.push(self.locals[0].clone());
}
ILOAD_1 | LLOAD_1 | FLOAD_1 | DLOAD_1 | ALOAD_1 => {
self.push(self.locals[1].clone());
}
ILOAD_2 | LLOAD_2 | FLOAD_2 | DLOAD_2 | ALOAD_2 => {
self.push(self.locals[2].clone());
}
ILOAD_3 | LLOAD_3 | FLOAD_3 | DLOAD_3 | ALOAD_3 => {
self.push(self.locals[3].clone());
}
IALOAD | LALOAD | FALOAD | DALOAD | AALOAD | BALOAD | CALOAD | SALOAD => { IALOAD | LALOAD | FALOAD | DALOAD | AALOAD | BALOAD | CALOAD | SALOAD => {
let index = self.pop(); let index = self.pop();
let arrayref = self.pop(); let arrayref = self.pop();
@ -211,19 +169,6 @@ impl Stackframe {
ISTORE(c) | LSTORE(c) | FSTORE(c) | DSTORE(c) | ASTORE(c) => { ISTORE(c) | LSTORE(c) | FSTORE(c) | DSTORE(c) | ASTORE(c) => {
self.store(*c).unwrap(); self.store(*c).unwrap();
} }
ISTORE_0 | LSTORE_0 | DSTORE_0 | ASTORE_0 | FSTORE_0 => {
self.store(0).unwrap();
}
ISTORE_1 | LSTORE_1 | DSTORE_1 | ASTORE_1 | FSTORE_1 => {
self.store(1).unwrap();
}
ISTORE_2 | LSTORE_2 | DSTORE_2 | ASTORE_2 | FSTORE_2 => {
self.store(2).unwrap();
}
ISTORE_3 | LSTORE_3 | DSTORE_3 | ASTORE_3 | FSTORE_3 => {
self.store(3).unwrap();
}
INVOKEVIRTUAL(c) => { INVOKEVIRTUAL(c) => {
if let Some(invocation) = if let Some(invocation) =
get_signature_for_invoke(&constant_pool, *c) get_signature_for_invoke(&constant_pool, *c)