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 stack::Stack;
use Result;
#[derive(Debug)] #[derive(Debug)]
pub struct Frame { pub struct Frame {
pub base: usize,
pub stack: Stack, pub stack: Stack,
pub locals: Vec<i32>, pub locals: Vec<i32>,
} }
impl Frame { impl Frame {
pub fn new(num_locals: usize) -> Frame { pub fn new(num_locals: usize, base: usize) -> Frame {
if cfg!(feature="debug:frame") { if cfg!(feature = "debug:frame") {
println!("Initializing frame of len {}", num_locals); println!("Initializing frame of len {}", num_locals);
} }
Frame { Frame {
base,
stack: Stack::new(), stack: Stack::new(),
locals: vec![0; num_locals], locals: vec![0; num_locals],
} }

View File

@@ -41,7 +41,7 @@ impl Machine {
halted: false, halted: false,
pool, pool,
block, block,
frame: vec![Frame::new(ANTI_BS_SIZE)], frame: vec![Frame::new(ANTI_BS_SIZE, 0)],
stream_in: Box::new(::std::io::stdin()), stream_in: Box::new(::std::io::stdin()),
stream_out: Arc::new(Mutex::new(::std::io::stdout())), 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<()> { fn invokevirtual(machine: &mut Machine) -> Result<()> {
let method_index = machine.block.read_u16()?; 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(); 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 arg_count = machine.block.read_u16()?;
let var_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 // Lifetime for cur_stack
{ {