Passing all tests i guess

This commit is contained in:
2017-06-06 14:19:35 +02:00
commit 1b3c582ee2
13 changed files with 699 additions and 0 deletions

40
src/ijvm/stack.rs Normal file
View File

@@ -0,0 +1,40 @@
use ijvm::Result;
#[derive(Debug)]
pub struct Stack {
pub data: Vec<i32>
}
impl Stack {
pub fn new() -> Stack {
Stack {
data: Vec::new()
}
}
// pub fn len(&self) -> usize {
// return self.data.len();
// }
pub fn top(&self) -> Result<i32> {
Ok(match self.data.last() {
Some(a) => *a,
None => return Err("Stack empty"),
})
}
pub fn pop(&mut self) -> Result<i32> {
Ok(match self.data.pop() {
Some(a) => a,
None => return Err("Stack empty"),
})
}
pub fn push(&mut self, val: i32) {
self.data.push(val);
}
pub fn len(&self) -> usize {
self.data.len()
}
}