From 9168867ab73b15e4783cadf1f9cc89a6633c017a Mon Sep 17 00:00:00 2001 From: Sander Hautvast Date: Fri, 29 Sep 2023 18:04:06 +0200 Subject: [PATCH] some thoughts --- src/opcodes.rs | 3 ++- src/vm.rs | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/opcodes.rs b/src/opcodes.rs index c978320..cc5ecd3 100644 --- a/src/opcodes.rs +++ b/src/opcodes.rs @@ -4,7 +4,8 @@ // pub const fconst_2: u8 = 13; // (0xd) Push float 2 // pub const dconst_0:u8 = 14; // (0xe) push double 0 // pub const dconst_1:u8 = 15; // (0xf) push double 1 -pub const BIPUSH:u8 = 16; // (0x10) Push byte +// TODO turn all into references +pub const BIPUSH: &u8 = &16; // (0x10) Push byte pub const LDC: u8 = 18; // (0x12) Push item from run-time pub constant pool pub const LDC_W: u8 = 19; // (0x13) Push item from run-time constant pool (wide index) pub const LDC2_W: u8 = 20; // (0x14) Push long or double from run-time constant pool (wide index) diff --git a/src/vm.rs b/src/vm.rs index aa7b01e..5c8c582 100644 --- a/src/vm.rs +++ b/src/vm.rs @@ -86,7 +86,7 @@ impl Vm { pc += 1; println!("{}", opcode); match opcode { - &opcodes::BIPUSH => { + opcodes::BIPUSH => { let c = code.opcodes[pc] as i32; stack.push(Arc::new(Value::I32(c))); pc += 1; @@ -151,10 +151,10 @@ impl Vm { &opcodes::GETFIELD => { let cp_index = read_u16(&code.opcodes, pc); if let CpEntry::Fieldref(class_index, name_and_type_index) = method.constant_pool.get(&cp_index).unwrap() { - if let Value::Ref(inst) = &*stack.pop()? { + if let Value::Ref(inst) = &*stack.pop()? { //TODO smell? if let CpEntry::NameAndType(name, _) = method.constant_pool.get(name_and_type_index).unwrap() { let value = inst.data.get(&name).unwrap(); - println!("{:?}", value); + // println!("{:?}", value); stack.push(value.clone()); } }