issue singleton variable warnings from loader.pl (#812)
This commit is contained in:
@@ -1947,6 +1947,18 @@ impl Machine {
|
||||
self.restore_load_state_payload(result, evacuable_h);
|
||||
}
|
||||
|
||||
pub(crate) fn add_non_counted_backtracking(&mut self) {
|
||||
let key = self
|
||||
.machine_st
|
||||
.read_predicate_key(self.machine_st[temp_v!(1)], self.machine_st[temp_v!(2)]);
|
||||
|
||||
let (mut loader, evacuable_h) = self.loader_from_heap_evacuable(temp_v!(3));
|
||||
loader.non_counted_bt_preds.insert(key);
|
||||
|
||||
let result = LiveTermStream::evacuate(loader);
|
||||
self.restore_load_state_payload(result, evacuable_h);
|
||||
}
|
||||
|
||||
pub(crate) fn meta_predicate_property(&mut self) {
|
||||
let module_name = atom_from!(
|
||||
self.machine_st,
|
||||
|
||||
@@ -449,6 +449,7 @@ pub enum REPLCodePtr {
|
||||
IsConsistentWithTermQueue,
|
||||
FlushTermQueue,
|
||||
RemoveModuleExports,
|
||||
AddNonCountedBacktracking,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
|
||||
@@ -27,6 +27,7 @@ use std::fmt;
|
||||
use std::io::Write;
|
||||
use std::mem;
|
||||
use std::ops::{Index, IndexMut};
|
||||
use std::rc::Rc;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Ball {
|
||||
@@ -299,6 +300,30 @@ pub struct MachineState {
|
||||
|
||||
impl MachineState {
|
||||
pub(crate) fn read_term(&mut self, mut stream: Stream, indices: &mut IndexStore) -> CallResult {
|
||||
fn push_var_eq_functors<'a>(
|
||||
heap: &mut Heap,
|
||||
iter: impl Iterator<Item=(&'a Rc<Var>, &'a Addr)>,
|
||||
op_dir: &OpDir,
|
||||
atom_tbl: TabledData<Atom>,
|
||||
) -> Vec<Addr> {
|
||||
let mut list_of_var_eqs = vec![];
|
||||
|
||||
for (var, binding) in iter {
|
||||
let var_atom = clause_name!(var.to_string(), atom_tbl);
|
||||
|
||||
let h = heap.h();
|
||||
let spec = fetch_atom_op_spec(clause_name!("="), None, op_dir);
|
||||
|
||||
heap.push(HeapCellValue::NamedStr(2, clause_name!("="), spec));
|
||||
heap.push(HeapCellValue::Atom(var_atom, None));
|
||||
heap.push(HeapCellValue::Addr(*binding));
|
||||
|
||||
list_of_var_eqs.push(Addr::Str(h));
|
||||
}
|
||||
|
||||
list_of_var_eqs
|
||||
}
|
||||
|
||||
self.check_stream_properties(
|
||||
&mut stream,
|
||||
StreamType::Text,
|
||||
@@ -327,47 +352,40 @@ impl MachineState {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut list_of_var_eqs = vec![];
|
||||
|
||||
for (var, binding) in term_write_result.var_dict.into_iter() {
|
||||
let var_atom = clause_name!(var.to_string(), self.atom_tbl);
|
||||
|
||||
let h = self.heap.h();
|
||||
let spec = fetch_atom_op_spec(clause_name!("="), None, &indices.op_dir);
|
||||
|
||||
self.heap
|
||||
.push(HeapCellValue::NamedStr(2, clause_name!("="), spec));
|
||||
self.heap.push(HeapCellValue::Atom(var_atom, None));
|
||||
self.heap.push(HeapCellValue::Addr(binding));
|
||||
|
||||
list_of_var_eqs.push(Addr::Str(h));
|
||||
}
|
||||
|
||||
let mut var_set: IndexMap<Ref, bool> = IndexMap::new();
|
||||
|
||||
for addr in self.acyclic_pre_order_iter(term) {
|
||||
if let Some(var) = addr.as_var() {
|
||||
if !var_set.contains_key(&var) {
|
||||
var_set.insert(var, true);
|
||||
} else {
|
||||
var_set.insert(var, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
let list_of_var_eqs = push_var_eq_functors(
|
||||
&mut self.heap,
|
||||
term_write_result.var_dict.iter(),
|
||||
&indices.op_dir,
|
||||
self.atom_tbl.clone(),
|
||||
);
|
||||
|
||||
let mut singleton_var_set: IndexMap<Ref, bool> = IndexMap::new();
|
||||
let mut var_list = vec![];
|
||||
let mut singleton_var_list = vec![];
|
||||
|
||||
for addr in self.acyclic_pre_order_iter(term) {
|
||||
if let Some(var) = addr.as_var() {
|
||||
if var_set.get(&var) == Some(&true) {
|
||||
singleton_var_list.push(var.as_addr());
|
||||
if !singleton_var_set.contains_key(&var) {
|
||||
singleton_var_set.insert(var, true);
|
||||
var_list.push(addr);
|
||||
} else {
|
||||
singleton_var_set.insert(var, false);
|
||||
}
|
||||
|
||||
var_list.push(var.as_addr());
|
||||
}
|
||||
}
|
||||
|
||||
let singleton_var_list = push_var_eq_functors(
|
||||
&mut self.heap,
|
||||
term_write_result.var_dict.iter().filter(|(_, binding)| {
|
||||
if let Some(r) = binding.as_var() {
|
||||
*singleton_var_set.get(&r).unwrap_or(&false)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}),
|
||||
&indices.op_dir,
|
||||
self.atom_tbl.clone(),
|
||||
);
|
||||
|
||||
let singleton_addr = self[temp_v!(3)];
|
||||
let singletons_offset =
|
||||
Addr::HeapCell(self.heap.to_list(singleton_var_list.into_iter()));
|
||||
|
||||
@@ -513,6 +513,9 @@ impl Machine {
|
||||
REPLCodePtr::RemoveModuleExports => {
|
||||
self.remove_module_exports();
|
||||
}
|
||||
REPLCodePtr::AddNonCountedBacktracking => {
|
||||
self.add_non_counted_backtracking();
|
||||
}
|
||||
}
|
||||
|
||||
self.machine_st.p = CodePtr::Local(p);
|
||||
|
||||
@@ -202,6 +202,7 @@ struct InnerStream {
|
||||
options: StreamOptions,
|
||||
stream_inst: StreamInstance,
|
||||
past_end_of_stream: bool,
|
||||
lines_read: usize,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -214,7 +215,9 @@ impl WrappedStreamInstance {
|
||||
InnerStream {
|
||||
options: StreamOptions::default(),
|
||||
stream_inst,
|
||||
past_end_of_stream }
|
||||
past_end_of_stream,
|
||||
lines_read: 0,
|
||||
}
|
||||
)))
|
||||
}
|
||||
}
|
||||
@@ -363,6 +366,11 @@ impl Stream {
|
||||
ptr as *const u8
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn add_lines_read(&mut self, incr_num_lines_read: usize) {
|
||||
self.stream_inst.0.borrow_mut().lines_read += incr_num_lines_read;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn options(&self) -> std::cell::Ref<'_, StreamOptions> {
|
||||
std::cell::Ref::map(
|
||||
@@ -380,11 +388,18 @@ impl Stream {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn position(&mut self) -> Option<u64> {
|
||||
match self.stream_inst.0.borrow_mut().stream_inst {
|
||||
pub(crate) fn position(&mut self) -> Option<(u64, usize)> { // returns lines_read, position.
|
||||
let result = match self.stream_inst.0.borrow_mut().stream_inst {
|
||||
StreamInstance::InputFile(_, ref mut file) => file.seek(SeekFrom::Current(0)).ok(),
|
||||
StreamInstance::TcpStream(..) |
|
||||
StreamInstance::TlsStream(..) |
|
||||
StreamInstance::ReadlineStream(..) |
|
||||
StreamInstance::StaticStr(..) |
|
||||
StreamInstance::Bytes(..) => Some(0),
|
||||
_ => None,
|
||||
}
|
||||
};
|
||||
|
||||
result.map(|position| (position, self.stream_inst.0.borrow().lines_read))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -588,6 +603,7 @@ impl Stream {
|
||||
// returns true on success.
|
||||
#[inline]
|
||||
pub(super) fn reset(&mut self) -> bool {
|
||||
self.stream_inst.0.borrow_mut().lines_read = 0;
|
||||
self.stream_inst.0.borrow_mut().past_end_of_stream = false;
|
||||
|
||||
loop {
|
||||
|
||||
@@ -4534,8 +4534,17 @@ impl MachineState {
|
||||
}
|
||||
}
|
||||
"position" => {
|
||||
if let Some(position) = stream.position() {
|
||||
HeapCellValue::Addr(Addr::Usize(position as usize))
|
||||
if let Some((position, lines_read)) = stream.position() {
|
||||
let h = self.heap.h();
|
||||
|
||||
let position_term = functor!(
|
||||
"position_and_lines_read",
|
||||
[integer(position), integer(lines_read)]
|
||||
);
|
||||
|
||||
self.heap.extend(position_term.into_iter());
|
||||
|
||||
HeapCellValue::Addr(Addr::HeapCell(h))
|
||||
} else {
|
||||
self.fail = true;
|
||||
return Ok(());
|
||||
@@ -4543,7 +4552,6 @@ impl MachineState {
|
||||
}
|
||||
"end_of_stream" => {
|
||||
let end_of_stream_pos = stream.position_relative_to_end();
|
||||
|
||||
HeapCellValue::Atom(clause_name!(end_of_stream_pos.as_str()), None)
|
||||
}
|
||||
"eof_action" => HeapCellValue::Atom(
|
||||
|
||||
Reference in New Issue
Block a user