2014-12-24 13:12:39 +08:00
|
|
|
use platform;
|
2014-12-24 14:28:21 +08:00
|
|
|
use core::ptr;
|
2014-12-23 11:24:40 +08:00
|
|
|
|
|
|
|
pub enum Stack {
|
|
|
|
Native {
|
|
|
|
sp_limit: *const u8
|
|
|
|
},
|
2014-12-24 14:07:25 +08:00
|
|
|
Managed(platform::Stack)
|
2014-12-23 11:24:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Stack {
|
|
|
|
pub fn new(size: uint) -> Stack {
|
2014-12-24 14:07:25 +08:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-24 13:51:46 +08:00
|
|
|
pub fn top(&mut self) -> *mut u8 {
|
2014-12-24 14:07:25 +08:00
|
|
|
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 {
|
2014-12-24 14:07:25 +08:00
|
|
|
Stack::Native { sp_limit, .. } => sp_limit,
|
|
|
|
Stack::Managed(ref stack) => stack.limit()
|
2014-12-23 11:24:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|