1
0
Fork 0

Kill impl StackPointer.

That was a silly idea for a silly abstraction, and it brought no
improvement, only confusion. So, revert it.
This commit is contained in:
whitequark 2016-07-17 05:55:03 +00:00 committed by edef
parent 244db8490b
commit 40fbfdde0c
2 changed files with 19 additions and 31 deletions

View File

@ -17,17 +17,6 @@ use stack::Stack;
#[derive(Debug)] #[derive(Debug)]
pub struct StackPointer(*mut usize); pub struct StackPointer(*mut usize);
impl StackPointer {
unsafe fn new(stack: &Stack) -> StackPointer {
StackPointer(stack.top() as *mut usize)
}
unsafe fn push(&mut self, val: usize) {
self.0 = self.0.offset(-1);
*self.0 = val
}
}
pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackPointer { pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackPointer {
#[naked] #[naked]
unsafe extern "C" fn trampoline() -> ! { unsafe extern "C" fn trampoline() -> ! {
@ -43,12 +32,17 @@ pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackP
::core::intrinsics::unreachable() ::core::intrinsics::unreachable()
} }
let mut sp = StackPointer::new(stack); unsafe fn push(sp: &mut StackPointer, val: usize) {
sp.push(0); // alignment sp.0 = sp.0.offset(-1);
sp.push(0); // alignment *sp.0 = val
sp.push(0); // alignment }
sp.push(f as usize); // function
sp.push(trampoline as usize); let mut sp = StackPointer(stack.top() as *mut usize);
push(&mut sp, 0); // alignment
push(&mut sp, 0); // alignment
push(&mut sp, 0); // alignment
push(&mut sp, f as usize); // function
push(&mut sp, trampoline as usize);
sp sp
} }

View File

@ -22,21 +22,15 @@ use stack::Stack;
#[derive(Debug)] #[derive(Debug)]
pub struct StackPointer(*mut usize); pub struct StackPointer(*mut usize);
impl StackPointer {
unsafe fn new(stack: &Stack) -> StackPointer {
StackPointer(stack.top() as *mut usize)
}
unsafe fn push(&mut self, val: usize) {
self.0 = self.0.offset(-1);
*self.0 = val
}
}
pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackPointer { pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackPointer {
let mut sp = StackPointer::new(stack); unsafe fn push(sp: &mut StackPointer, val: usize) {
sp.push(0); // alignment sp.0 = sp.0.offset(-1);
sp.push(f as usize); *sp.0 = val
}
let mut sp = StackPointer(stack.top() as *mut usize);
push(&mut sp, 0); // alignment
push(&mut sp, f as usize);
sp sp
} }