Extend frame a bit

This commit is contained in:
2018-05-24 14:39:01 +02:00
parent 1384971d4e
commit 58bbaddc21

View File

@@ -4,7 +4,7 @@ use stack::Stack;
#[derive(Debug)] #[derive(Debug)]
pub struct Frame { pub struct Frame {
pub stack: Stack, pub stack: Stack,
locals: Vec<i32>, pub locals: Vec<i32>,
} }
impl Frame { impl Frame {
@@ -18,6 +18,14 @@ impl Frame {
} }
} }
pub fn len(&self) -> usize {
self.locals.len()
}
pub fn is_empty(&self) -> bool {
self.locals.is_empty()
}
pub fn get(&self, offset: usize) -> Result<i32> { pub fn get(&self, offset: usize) -> Result<i32> {
if offset >= self.locals.len() { if offset >= self.locals.len() {
return Err("Local variable out of range"); return Err("Local variable out of range");