1
0
Fork 0
libfringe/src/stack.rs

36 lines
654 B
Rust
Raw Normal View History

2014-12-24 13:12:39 +08:00
use platform;
use core::ptr;
2014-12-23 11:24:40 +08:00
pub enum Stack {
Native {
sp_limit: *const u8
},
Managed(platform::Stack)
2014-12-23 11:24:40 +08:00
}
impl Stack {
2015-01-13 15:38:52 +08:00
pub fn new(size: usize) -> Stack {
Stack::Managed(platform::Stack::new(size))
2014-12-23 11:24:40 +08:00
}
pub unsafe fn native(limit: *const u8) -> Stack {
Stack::Native {
sp_limit: limit
}
}
pub fn top(&mut self) -> *mut u8 {
match *self {
Stack::Native { .. } => ptr::null_mut(),
Stack::Managed(ref mut stack) => stack.top()
2014-12-23 11:24:40 +08:00
}
}
pub fn limit(&self) -> *const u8 {
match *self {
Stack::Native { sp_limit, .. } => sp_limit,
Stack::Managed(ref stack) => stack.limit()
2014-12-23 11:24:40 +08:00
}
}
}