remove pstr_vec
This commit is contained in:
@@ -37,7 +37,7 @@ pub(super) enum MachineMode {
|
||||
pub(super) enum HeapPtr {
|
||||
HeapCell(usize),
|
||||
PStr(usize), // Char(usize),
|
||||
// PStrLocation(usize),
|
||||
// PStrLocation(usize),
|
||||
}
|
||||
|
||||
impl Default for HeapPtr {
|
||||
@@ -215,7 +215,8 @@ fn push_var_eq_functors(
|
||||
let mut writer = heap.reserve(1 + 5 * size)?;
|
||||
|
||||
writer.write_with(|section| {
|
||||
for (var_loc, var) in iter { // (var, binding) in iter {
|
||||
for (var_loc, var) in iter {
|
||||
// (var, binding) in iter {
|
||||
let var_atom = AtomTable::build_with(atom_tbl, &var.to_string());
|
||||
let binding = heap_loc_as_cell!(var_loc);
|
||||
|
||||
@@ -224,7 +225,7 @@ fn push_var_eq_functors(
|
||||
section.push_cell(binding);
|
||||
}
|
||||
|
||||
for idx in 0 .. size {
|
||||
for idx in 0..size {
|
||||
section.push_cell(list_loc_as_cell!(section.cell_len() + 1));
|
||||
section.push_cell(str_loc_as_cell!(src_h + 3 * idx));
|
||||
}
|
||||
@@ -252,6 +253,7 @@ pub(crate) fn copy_and_align_iter<Iter: Iterator<Item = HeapCellValue>>(
|
||||
#[derive(Debug)]
|
||||
pub struct Ball {
|
||||
pub(super) boundary: usize,
|
||||
pub(super) pstr_boundary: usize,
|
||||
pub(super) stub: Heap,
|
||||
}
|
||||
|
||||
@@ -259,12 +261,14 @@ impl Ball {
|
||||
pub(super) fn new() -> Self {
|
||||
Ball {
|
||||
boundary: 0,
|
||||
pstr_boundary: 0,
|
||||
stub: Heap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn reset(&mut self) {
|
||||
self.boundary = 0;
|
||||
self.pstr_boundary = 0;
|
||||
self.stub.clear();
|
||||
}
|
||||
|
||||
@@ -272,10 +276,23 @@ impl Ball {
|
||||
let h = dest.cell_len();
|
||||
let diff = self.boundary as i64 - h as i64;
|
||||
|
||||
dest.append(self.stub.splice(..))?;
|
||||
let mut dest_writer = dest.reserve(self.stub.cell_len())?;
|
||||
|
||||
for cell in &mut dest.splice_mut(h ..) {
|
||||
*cell = *cell - diff;
|
||||
dest_writer.write_with(|section| {
|
||||
for idx in 0..self.pstr_boundary {
|
||||
section.push_cell(self.stub[idx] - diff);
|
||||
}
|
||||
});
|
||||
|
||||
let mut pstr_threshold = heap_index!(self.pstr_boundary);
|
||||
|
||||
while pstr_threshold < heap_index!(self.stub.cell_len()) {
|
||||
let HeapStringScan { string, tail_idx } = self.stub.scan_slice_to_str(pstr_threshold);
|
||||
|
||||
pstr_threshold += dest_writer.write_with(|section| {
|
||||
section.push_pstr(string).unwrap();
|
||||
section.push_cell(self.stub[tail_idx] - diff);
|
||||
});
|
||||
}
|
||||
|
||||
Ok(h)
|
||||
@@ -335,32 +352,16 @@ impl<'a> CopierTarget for CopyTerm<'a> {
|
||||
self.state.heap.cell_len()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn as_slice_from<'b>(&'b self, from: usize) -> Box<dyn Iterator<Item = u8> + 'b> {
|
||||
Box::new(self.state.heap.as_slice()[from..].iter().cloned())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn copy_pstr_to_threshold(&mut self, pstr_loc: usize) -> Result<usize, usize> {
|
||||
self.state.heap.copy_pstr_within(pstr_loc)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn pstr_head_cell_index(&self, pstr_loc: usize) -> usize {
|
||||
self.state.heap.pstr_vec()[0 .. cell_index!(pstr_loc)]
|
||||
.last_zero()
|
||||
.map(|idx| idx + 1)
|
||||
.unwrap_or(0)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn pstr_at(&self, loc: usize) -> bool {
|
||||
self.state.heap.pstr_vec()[loc]
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn next_non_pstr_cell_index(&self, loc: usize) -> usize {
|
||||
// unwrap is safe here because a partial string is always
|
||||
// followed by a tail cell, i.e. a non-pstr cell, supposing
|
||||
// self.state.heap[loc] is a pstr cell
|
||||
self.state.heap.pstr_vec()[loc ..].first_zero().unwrap()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn reserve(&mut self, num_cells: usize) -> Result<HeapWriter, usize> {
|
||||
self.state.heap.reserve(num_cells)
|
||||
@@ -469,9 +470,22 @@ impl<'a> CopierTarget for CopyBallTerm<'a> {
|
||||
fn copy_pstr_to_threshold(&mut self, pstr_loc: usize) -> Result<usize, usize> {
|
||||
debug_assert!(pstr_loc < self.heap.byte_len());
|
||||
|
||||
let (string, tail_loc) = self.heap.scan_slice_to_str(pstr_loc);
|
||||
let HeapStringScan { string, tail_idx } = self.heap.scan_slice_to_str(pstr_loc);
|
||||
self.stub.allocate_pstr(string)?;
|
||||
Ok(tail_loc)
|
||||
Ok(tail_idx)
|
||||
}
|
||||
|
||||
fn as_slice_from<'b>(&'b self, from: usize) -> Box<dyn Iterator<Item = u8> + 'b> {
|
||||
if from < self.heap.byte_len() {
|
||||
Box::new(
|
||||
self.heap.as_slice()[from..]
|
||||
.iter()
|
||||
.cloned()
|
||||
.chain(self.stub.as_slice().iter().cloned()),
|
||||
)
|
||||
} else {
|
||||
Box::new(self.stub.as_slice()[from..].iter().cloned())
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -479,41 +493,6 @@ impl<'a> CopierTarget for CopyBallTerm<'a> {
|
||||
self.stub.reserve(num_cells)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn pstr_head_cell_index(&self, pstr_loc: usize) -> usize {
|
||||
if pstr_loc >= self.heap.byte_len() {
|
||||
self.stub.pstr_vec()[0 .. cell_index!(pstr_loc - self.heap.byte_len())]
|
||||
.last_zero()
|
||||
.map(|idx| idx + 1)
|
||||
.unwrap_or(0)
|
||||
} else {
|
||||
self.heap.pstr_vec()[0 .. cell_index!(pstr_loc)]
|
||||
.last_zero()
|
||||
.map(|idx| idx + 1)
|
||||
.unwrap_or(0)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn pstr_at(&self, loc: usize) -> bool {
|
||||
if loc >= self.heap.cell_len() {
|
||||
self.stub.pstr_vec()[loc - self.heap.cell_len()]
|
||||
} else {
|
||||
self.heap.pstr_vec()[loc]
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn next_non_pstr_cell_index(&self, loc: usize) -> usize {
|
||||
let zero_from_loc = if loc >= self.heap.cell_len() {
|
||||
self.stub.pstr_vec()[loc - self.heap.cell_len() ..].first_zero().unwrap()
|
||||
} else {
|
||||
self.heap.pstr_vec()[loc ..].first_zero().unwrap()
|
||||
};
|
||||
|
||||
zero_from_loc + loc
|
||||
}
|
||||
|
||||
fn copy_slice_to_end(&mut self, bounds: Range<usize>) -> Result<(), usize> {
|
||||
let len = bounds.end - bounds.start;
|
||||
let mut stub_writer = self.stub.reserve(len)?;
|
||||
@@ -699,9 +678,9 @@ impl MachineState {
|
||||
push_var_eq_functors(
|
||||
&mut self.heap,
|
||||
var_list.len(),
|
||||
var_list.iter().map(|(var_name, var, _)| {
|
||||
(var.get_value() as usize, var_name.clone())
|
||||
}),
|
||||
var_list
|
||||
.iter()
|
||||
.map(|(var_name, var, _)| { (var.get_value() as usize, var_name.clone()) }),
|
||||
&self.atom_tbl,
|
||||
)
|
||||
);
|
||||
@@ -737,7 +716,9 @@ impl MachineState {
|
||||
|
||||
let mut singleton_var_set: IndexMap<Ref, bool> = IndexMap::new();
|
||||
|
||||
for cell in stackful_preorder_iter::<NonListElider>(&mut self.heap, &mut self.stack, term.focus) {
|
||||
for cell in
|
||||
stackful_preorder_iter::<NonListElider>(&mut self.heap, &mut self.stack, term.focus)
|
||||
{
|
||||
let cell = unmark_cell_bits!(cell);
|
||||
|
||||
if let Some(var) = cell.as_var() {
|
||||
@@ -756,9 +737,10 @@ impl MachineState {
|
||||
singleton_var_set
|
||||
.iter()
|
||||
.filter(|(var, is_singleton)| {
|
||||
**is_singleton && term.inverse_var_locs.contains_key(
|
||||
&(var.get_value() as usize)
|
||||
)
|
||||
**is_singleton
|
||||
&& term
|
||||
.inverse_var_locs
|
||||
.contains_key(&(var.get_value() as usize))
|
||||
})
|
||||
.count(),
|
||||
term.inverse_var_locs
|
||||
@@ -873,7 +855,8 @@ impl MachineState {
|
||||
CompilationError::ParserError(e) if e.is_unexpected_eof() => {
|
||||
match eof_handler(self, stream)? {
|
||||
OnEOF::Return => {
|
||||
return self.write_read_term_options(vec![], empty_list_as_cell!());
|
||||
return self
|
||||
.write_read_term_options(vec![], empty_list_as_cell!());
|
||||
}
|
||||
OnEOF::Continue => continue,
|
||||
}
|
||||
@@ -1012,11 +995,9 @@ impl MachineState {
|
||||
|
||||
let term_loc = self.heap.cell_len();
|
||||
|
||||
step_or_resource_error!(
|
||||
self,
|
||||
self.heap.push_cell(term_to_be_printed),
|
||||
{ return Ok(None); }
|
||||
);
|
||||
step_or_resource_error!(self, self.heap.push_cell(term_to_be_printed), {
|
||||
return Ok(None);
|
||||
});
|
||||
|
||||
let mut printer = HCPrinter::new(
|
||||
&mut self.heap,
|
||||
|
||||
Reference in New Issue
Block a user