use std::mem;
use std::ptr;
-pub(crate) trait RawVecTraits {
+pub(crate) trait RawBlockTraits {
fn init_size() -> usize;
fn align() -> usize;
fn base_offset(base: *const u8) -> *const u8;
}
-pub(crate) struct RawVec<T: RawVecTraits> {
+pub(crate) struct RawBlock<T: RawBlockTraits> {
pub(crate) size: usize,
pub(crate) base: *const u8,
pub(crate) top: *const u8,
_marker: PhantomData<T>,
}
-impl<T: RawVecTraits> RawVec<T> {
+impl<T: RawBlockTraits> RawBlock<T> {
pub(crate)
fn new() -> Self {
- let mut vec = RawVec { size: 0,
- base: ptr::null(),
- top: ptr::null(),
- _marker: PhantomData };
+ let mut block = RawBlock { size: 0,
+ base: ptr::null(),
+ top: ptr::null(),
+ _marker: PhantomData };
unsafe {
- vec.grow();
+ block.grow();
}
- vec
+ block
}
pub(crate)
}
}
- fn empty_vec() -> Self {
- RawVec { size: 0,
+ fn empty_block() -> Self {
+ RawBlock { size: 0,
base: ptr::null(),
top: ptr::null(),
_marker: PhantomData }
#[inline]
pub(crate)
fn take(&mut self) -> Self {
- mem::replace(self, Self::empty_vec())
+ mem::replace(self, Self::empty_block())
}
use crate::prolog::machine::machine_indices::*;
-use crate::prolog::machine::raw_vec::*;
+use crate::prolog::machine::raw_block::*;
use core::marker::PhantomData;
struct StackTraits {}
-impl RawVecTraits for StackTraits {
+impl RawBlockTraits for StackTraits {
#[inline]
fn init_size() -> usize {
10 * 1024 * 1024
}
pub struct Stack {
- buf: RawVec<StackTraits>,
+ buf: RawBlock<StackTraits>,
_marker: PhantomData<Addr>,
}
impl Stack {
pub fn new() -> Self {
- Stack { buf: RawVec::new(), _marker: PhantomData }
+ Stack { buf: RawBlock::new(), _marker: PhantomData }
}
pub fn allocate_and_frame(&mut self, num_cells: usize) -> usize {
let e = self.buf.top as usize - self.buf.base as usize;
self.buf.top = new_top;
-
+
e
}
}