libfringe/src/context.rs

30 lines
557 B
Rust
Raw Normal View History

use core::prelude::*;
use arch::Registers;
2015-04-16 04:26:51 +08:00
use stack;
2014-12-24 13:12:39 +08:00
2015-04-16 04:26:51 +08:00
pub struct Context<Stack: stack::Stack> {
2014-12-23 11:24:40 +08:00
regs: Registers,
2015-04-16 09:54:56 +08:00
stack: Stack
2014-12-23 11:24:40 +08:00
}
2015-04-16 04:26:51 +08:00
impl<Stack> Context<Stack> where Stack: stack::Stack {
#[inline]
2015-04-16 04:26:51 +08:00
pub unsafe fn new<F>(mut stack: Stack, f: F) -> Context<Stack>
where F: FnOnce() + Send + 'static {
let regs = Registers::new(&mut stack, f);
2014-12-23 11:24:40 +08:00
Context {
regs: regs,
2015-04-16 09:54:56 +08:00
stack: stack
2014-12-23 11:24:40 +08:00
}
}
#[inline(always)]
pub unsafe fn swap(&mut self) {
self.regs.swap()
2014-12-23 11:24:40 +08:00
}
2015-04-16 09:54:56 +08:00
pub unsafe fn destroy(self) -> Stack {
self.stack
}
2014-12-23 11:24:40 +08:00
}