Add base pointer to frame class. Has no real use outside of webijvm

This commit is contained in:
2019-04-18 00:38:17 +02:00
parent 932abd0cb2
commit 73a03ddbb0
3 changed files with 11 additions and 9 deletions

View File

@@ -1,18 +1,20 @@
use Result;
use stack::Stack;
use Result;
#[derive(Debug)]
pub struct Frame {
pub base: usize,
pub stack: Stack,
pub locals: Vec<i32>,
}
impl Frame {
pub fn new(num_locals: usize) -> Frame {
if cfg!(feature="debug:frame") {
println!("Initializing frame of len {}", num_locals);
pub fn new(num_locals: usize, base: usize) -> Frame {
if cfg!(feature = "debug:frame") {
println!("Initializing frame of len {}", num_locals);
}
Frame {
base,
stack: Stack::new(),
locals: vec![0; num_locals],
}
@@ -40,4 +42,4 @@ impl Frame {
self.locals[offset] = val;
Ok(())
}
}
}

View File

@@ -41,7 +41,7 @@ impl Machine {
halted: false,
pool,
block,
frame: vec![Frame::new(ANTI_BS_SIZE)],
frame: vec![Frame::new(ANTI_BS_SIZE, 0)],
stream_in: Box::new(::std::io::stdin()),
stream_out: Arc::new(Mutex::new(::std::io::stdout())),

View File

@@ -235,13 +235,13 @@ fn iinc(machine: &mut Machine) -> Result<()> {
fn invokevirtual(machine: &mut Machine) -> Result<()> {
let method_index = machine.block.read_u16()?;
let invoke_addr = machine.pool.get(method_index as usize)?;
let invoke_addr = machine.pool.get(method_index as usize)? as usize;
let return_addr = machine.get_program_counter();
machine.block.seek(invoke_addr as usize)?;
machine.block.seek(invoke_addr)?;
let arg_count = machine.block.read_u16()?;
let var_count = machine.block.read_u16()?;
let mut newframe = Frame::new((arg_count + var_count) as usize);
let mut newframe = Frame::new((arg_count + var_count) as usize, invoke_addr);
// Lifetime for cur_stack
{