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 {
0 => NOP,
1 => ACONST_NULL,
2 => ICONST_M1,
3 => ICONST_0,
4 => ICONST_1,
5 => ICONST_2,
6 => ICONST_3,
7 => ICONST_4,
8 => ICONST_5,
9 => LCONST_0,
10 => LCONST_1,
11 => FCONST_0,
12 => FCONST_1,
13 => FCONST_2,
14 => DCONST_0,
15 => DCONST_1,
2 => ICONST(-1),
3 => ICONST(0),
4 => ICONST(1),
5 => ICONST(2),
6 => ICONST(3),
7 => ICONST(4),
8 => ICONST(5),
9 => LCONST(0),
10 => LCONST(1),
11 => FCONST(0),
12 => FCONST(1),
13 => FCONST(2),
14 => DCONST(0),
15 => DCONST(1),
16 => BIPUSH(read_u8(opcodes, c)),
17 => SIPUSH(read_u16(opcodes, c)),
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)),
57 => DSTORE(read_u8(opcodes, c)),
58 => ASTORE(read_u8(opcodes, c)),
59 => ISTORE_0,
60 => ISTORE_1,
61 => ISTORE_2,
62 => ISTORE_3,
63 => LSTORE_0,
64 => LSTORE_1,
65 => LSTORE_2,
66 => LSTORE_3,
67 => FSTORE_0,
68 => FSTORE_1,
69 => FSTORE_2,
70 => FSTORE_3,
71 => DSTORE_0,
72 => DSTORE_1,
73 => DSTORE_2,
74 => DSTORE_3,
75 => ASTORE_0,
76 => ASTORE_1,
77 => ASTORE_2,
78 => ASTORE_3,
59 => ISTORE(0),
60 => ISTORE(1),
61 => ISTORE(2),
62 => ISTORE(3),
63 => LSTORE(0),
64 => LSTORE(1),
65 => LSTORE(2),
66 => LSTORE(3),
67 => FSTORE(0),
68 => FSTORE(1),
69 => FSTORE(2),
70 => FSTORE(3),
71 => DSTORE(0),
72 => DSTORE(1),
73 => DSTORE(2),
74 => DSTORE(3),
75 => ASTORE(0),
76 => ASTORE(1),
77 => ASTORE(2),
78 => ASTORE(3),
79 => IASTORE,
80 => LASTORE,
81 => FASTORE,

View file

@ -5,20 +5,10 @@ use crate::classloader::io::{Lookupswitch, Tableswitch};
pub(crate) enum Opcode {
NOP,
ACONST_NULL,
ICONST_M1,
ICONST_0,
ICONST_1,
ICONST_2,
ICONST_3,
ICONST_4,
ICONST_5,
LCONST_0,
LCONST_1,
FCONST_0,
FCONST_1,
FCONST_2,
DCONST_0,
DCONST_1,
ICONST(i16),
LCONST(u8),
FCONST(u8),
DCONST(u8),
BIPUSH(u8),
SIPUSH(u16),
LDC(u16),
@ -52,26 +42,6 @@ pub(crate) enum Opcode {
WIDE_DSTORE(u16),
ASTORE(u8),
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,
LASTORE,
FASTORE,

View file

@ -98,47 +98,17 @@ impl Stackframe {
ACONST_NULL => {
self.push(Null);
}
ICONST_M1 => {
self.push(I32(-1));
ICONST(v) => {
self.push(I32(*v as i32));
}
ICONST_0 => {
self.push(I32(0));
LCONST(v) => {
self.push(I64(*v as i64));
}
ICONST_1 => {
self.push(I32(1));
FCONST(v) => {
self.push(F32(*v as f32));
}
ICONST_2 => {
self.push(I32(2));
}
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));
DCONST(v) => {
self.push(F64(*v as f64));
}
SIPUSH(si) => {
self.push(I32(*si as i32));
@ -191,18 +161,6 @@ impl Stackframe {
// omitting the type checks so far
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 => {
let index = self.pop();
let arrayref = self.pop();
@ -211,19 +169,6 @@ impl Stackframe {
ISTORE(c) | LSTORE(c) | FSTORE(c) | DSTORE(c) | ASTORE(c) => {
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) => {
if let Some(invocation) =
get_signature_for_invoke(&constant_pool, *c)