From: Skgland Date: Sat, 6 Feb 2021 18:30:46 +0000 (+0100) Subject: remove use statements from main.rs that temporary replaced extern crate and fixed... X-Git-Tag: v0.9.0~150^2~65^2~6^2~10 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=8e5954f36f6d08be9422c8edfe3fb24df1eeb1d8;p=scryer-prolog.git remove use statements from main.rs that temporary replaced extern crate and fixed paths that previously used them --- diff --git a/src/allocator.rs b/src/allocator.rs index c0e46da0..8d447fb1 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -1,5 +1,5 @@ -use crate::prolog_parser_rebis::ast::*; -use crate::prolog_parser_rebis::temp_v; +use prolog_parser_rebis::ast::*; +use prolog_parser_rebis::temp_v; use crate::fixtures::*; use crate::forms::*; diff --git a/src/arithmetic.rs b/src/arithmetic.rs index c3492f31..68f9f483 100644 --- a/src/arithmetic.rs +++ b/src/arithmetic.rs @@ -1,5 +1,5 @@ -use crate::prolog_parser_rebis::ast::*; -use crate::prolog_parser_rebis::{atom, clause_name}; +use prolog_parser_rebis::ast::*; +use prolog_parser_rebis::{atom, clause_name}; use crate::clause_types::*; use crate::fixtures::*; @@ -11,9 +11,9 @@ use crate::machine::heap::*; use crate::machine::machine_errors::*; use crate::machine::machine_indices::*; -use crate::ordered_float::*; use crate::rug::ops::PowAssign; use crate::rug::{Assign, Integer, Rational}; +use ordered_float::*; use std::cell::Cell; use std::cmp::{max, min, Ordering}; diff --git a/src/clause_types.rs b/src/clause_types.rs index 335e24f8..5096ffad 100644 --- a/src/clause_types.rs +++ b/src/clause_types.rs @@ -1,11 +1,11 @@ -use crate::prolog_parser_rebis::ast::*; -use crate::prolog_parser_rebis::{clause_name, temp_v}; +use prolog_parser_rebis::ast::*; +use prolog_parser_rebis::{clause_name, temp_v}; use crate::forms::Number; use crate::machine::machine_indices::*; use crate::rug::rand::RandState; -use crate::ref_thread_local::{ref_thread_local, RefThreadLocal}; +use ref_thread_local::{ref_thread_local, RefThreadLocal}; use std::collections::BTreeMap; diff --git a/src/codegen.rs b/src/codegen.rs index 46e2ea82..41bd72c6 100644 --- a/src/codegen.rs +++ b/src/codegen.rs @@ -1,7 +1,7 @@ /// Code generation to WAM-like instructions. -use crate::prolog_parser_rebis::ast::*; -use crate::prolog_parser_rebis::tabled_rc::TabledData; -use crate::prolog_parser_rebis::{perm_v, temp_v}; +use prolog_parser_rebis::ast::*; +use prolog_parser_rebis::tabled_rc::TabledData; +use prolog_parser_rebis::{perm_v, temp_v}; use crate::allocator::*; use crate::arithmetic::*; @@ -15,7 +15,7 @@ use crate::targets::*; use crate::machine::machine_errors::*; -use crate::indexmap::{IndexMap, IndexSet}; +use indexmap::{IndexMap, IndexSet}; use std::cell::Cell; use std::collections::VecDeque; diff --git a/src/debray_allocator.rs b/src/debray_allocator.rs index 39b5a886..ed0b9704 100644 --- a/src/debray_allocator.rs +++ b/src/debray_allocator.rs @@ -1,7 +1,7 @@ -use crate::indexmap::IndexMap; +use indexmap::IndexMap; -use crate::prolog_parser_rebis::ast::*; -use crate::prolog_parser_rebis::temp_v; +use prolog_parser_rebis::ast::*; +use prolog_parser_rebis::temp_v; use crate::allocator::*; use crate::fixtures::*; diff --git a/src/fixtures.rs b/src/fixtures.rs index d9034562..002774de 100644 --- a/src/fixtures.rs +++ b/src/fixtures.rs @@ -1,10 +1,10 @@ -use crate::prolog_parser_rebis::ast::*; +use prolog_parser_rebis::ast::*; use crate::forms::*; use crate::instructions::*; use crate::iterators::*; -use crate::indexmap::{IndexMap, IndexSet}; +use indexmap::{IndexMap, IndexSet}; use std::cell::Cell; use std::collections::BTreeSet; @@ -83,18 +83,17 @@ impl TempVarData { type VariableFixture<'a> = (VarStatus, Vec<&'a Cell>); #[derive(Debug)] -pub struct VariableFixtures<'a>{ +pub struct VariableFixtures<'a> { perm_vars: IndexMap, VariableFixture<'a>>, - last_chunk_temp_vars: IndexSet> + last_chunk_temp_vars: IndexSet>, } impl<'a> VariableFixtures<'a> { pub fn new() -> Self { VariableFixtures { perm_vars: IndexMap::new(), - last_chunk_temp_vars: IndexSet::new() + last_chunk_temp_vars: IndexSet::new(), } - } pub fn insert(&mut self, var: Rc, vs: VariableFixture<'a>) { @@ -262,34 +261,32 @@ impl UnsafeVarMarker { pub fn new() -> Self { UnsafeVarMarker { unsafe_vars: IndexMap::new(), - safe_vars: IndexSet::new() + safe_vars: IndexSet::new(), } } pub fn from_safe_vars(safe_vars: IndexSet) -> Self { UnsafeVarMarker { unsafe_vars: IndexMap::new(), - safe_vars + safe_vars, } } pub fn mark_safe_vars(&mut self, query_instr: &QueryInstruction) -> bool { match query_instr { &QueryInstruction::PutVariable(r @ RegType::Temp(_), _) - | &QueryInstruction::SetVariable(r) => { + | &QueryInstruction::SetVariable(r) => { self.safe_vars.insert(r); true } - _ => { - false - } + _ => false, } } pub fn mark_phase(&mut self, query_instr: &QueryInstruction, phase: usize) { match query_instr { &QueryInstruction::PutValue(r @ RegType::Perm(_), _) - | &QueryInstruction::SetValue(r) => { + | &QueryInstruction::SetValue(r) => { let p = self.unsafe_vars.entry(r).or_insert(0); *p = phase; } diff --git a/src/forms.rs b/src/forms.rs index f71df86c..5dfc680d 100644 --- a/src/forms.rs +++ b/src/forms.rs @@ -1,14 +1,14 @@ -use crate::prolog_parser_rebis::ast::*; -use crate::prolog_parser_rebis::parser::OpDesc; -use crate::prolog_parser_rebis::{clause_name, is_infix, is_postfix}; +use prolog_parser_rebis::ast::*; +use prolog_parser_rebis::parser::OpDesc; +use prolog_parser_rebis::{clause_name, is_infix, is_postfix}; use crate::clause_types::*; use crate::machine::machine_errors::*; use crate::machine::machine_indices::*; -use crate::ordered_float::OrderedFloat; use crate::rug::{Integer, Rational}; +use ordered_float::OrderedFloat; -use crate::indexmap::{IndexMap, IndexSet}; +use indexmap::{IndexMap, IndexSet}; use slice_deque::*; diff --git a/src/heap_iter.rs b/src/heap_iter.rs index 44541237..a6d2e5fa 100644 --- a/src/heap_iter.rs +++ b/src/heap_iter.rs @@ -1,7 +1,7 @@ use crate::machine::machine_indices::*; use crate::machine::machine_state::*; -use crate::indexmap::IndexSet; +use indexmap::IndexSet; use std::cmp::Ordering; use std::ops::Deref; @@ -29,31 +29,21 @@ impl<'a> HCPreOrderIterator<'a> { fn follow_heap(&mut self, h: usize) -> Addr { match &self.machine_st.heap[h] { &HeapCellValue::NamedStr(arity, _, _) => { - for idx in (1 .. arity + 1).rev() { + for idx in (1..arity + 1).rev() { self.state_stack.push(Addr::HeapCell(h + idx)); } Addr::Str(h) } - &HeapCellValue::Addr(a) => { - self.follow(a) - } - HeapCellValue::PartialString(..) => { - self.follow(Addr::PStrLocation(h, 0)) - } - HeapCellValue::Atom(..) | HeapCellValue::DBRef(_) - | HeapCellValue::Integer(_) | HeapCellValue::Rational(_) => { - Addr::Con(h) - } - HeapCellValue::LoadStatePayload(_) => { - Addr::LoadStatePayload(h) - } - HeapCellValue::Stream(_) => { - Addr::Stream(h) - } - HeapCellValue::TcpListener(_) => { - Addr::TcpListener(h) - } + &HeapCellValue::Addr(a) => self.follow(a), + HeapCellValue::PartialString(..) => self.follow(Addr::PStrLocation(h, 0)), + HeapCellValue::Atom(..) + | HeapCellValue::DBRef(_) + | HeapCellValue::Integer(_) + | HeapCellValue::Rational(_) => Addr::Con(h), + HeapCellValue::LoadStatePayload(_) => Addr::LoadStatePayload(h), + HeapCellValue::Stream(_) => Addr::Stream(h), + HeapCellValue::TcpListener(_) => Addr::TcpListener(h), } } @@ -71,10 +61,12 @@ impl<'a> HCPreOrderIterator<'a> { da } Addr::PStrLocation(h, n) => { - if let &HeapCellValue::PartialString(ref pstr, has_tail) = &self.machine_st.heap[h] { - if let Some(c) = pstr.range_from(n ..).next() { + if let &HeapCellValue::PartialString(ref pstr, has_tail) = &self.machine_st.heap[h] + { + if let Some(c) = pstr.range_from(n..).next() { if !pstr.at_end(n + c.len_utf8()) { - self.state_stack.push(Addr::PStrLocation(h, n + c.len_utf8())); + self.state_stack + .push(Addr::PStrLocation(h, n + c.len_utf8())); } else if has_tail { self.state_stack.push(Addr::HeapCell(h + 1)); } else { @@ -95,8 +87,9 @@ impl<'a> HCPreOrderIterator<'a> { self.follow_heap(s) // record terms of structure. } Addr::Con(h) => { - if let &HeapCellValue::PartialString(ref pstr, has_tail) = &self.machine_st.heap[h] { - if let Some(c) = pstr.range_from(0 ..).next() { + if let &HeapCellValue::PartialString(ref pstr, has_tail) = &self.machine_st.heap[h] + { + if let Some(c) = pstr.range_from(0..).next() { self.state_stack.push(Addr::PStrLocation(h, c.len_utf8())); self.state_stack.push(Addr::Char(c)); @@ -110,9 +103,7 @@ impl<'a> HCPreOrderIterator<'a> { Addr::Con(h) } } - da => { - da - } + da => da, } } } @@ -125,7 +116,9 @@ impl<'a> Iterator for HCPreOrderIterator<'a> { } } -pub trait MutStackHCIterator<'b> where Self: Iterator +pub trait MutStackHCIterator<'b> +where + Self: Iterator, { type MutStack; @@ -178,7 +171,8 @@ impl<'a> Iterator for HCPostOrderIterator<'a> { } &HeapCellValue::Addr(Addr::PStrLocation(h, n)) => { match &self.machine_st.heap[h] { - &HeapCellValue::PartialString(..) => {// ref pstr, _) => { + &HeapCellValue::PartialString(..) => { + // ref pstr, _) => { /* let c = pstr.range_from(n ..).next().unwrap(); let next_n = n + c.len_utf8(); @@ -215,7 +209,7 @@ impl MachineState { HCPostOrderIterator::new(HCPreOrderIterator::new(self, a)) } - pub fn acyclic_pre_order_iter<'a>(&'a self, a: Addr,) -> HCAcyclicIterator<'a> { + pub fn acyclic_pre_order_iter<'a>(&'a self, a: Addr) -> HCAcyclicIterator<'a> { HCAcyclicIterator::new(HCPreOrderIterator::new(self, a)) } @@ -270,8 +264,7 @@ impl<'b, 'a: 'b> MutStackHCIterator<'b> for HCAcyclicIterator<'a> { } } -impl<'a> Iterator for HCAcyclicIterator<'a> -{ +impl<'a> Iterator for HCAcyclicIterator<'a> { type Item = Addr; fn next(&mut self) -> Option { @@ -315,8 +308,7 @@ impl<'a> HCZippedAcyclicIterator<'a> { } } -impl<'a> Iterator for HCZippedAcyclicIterator<'a> -{ +impl<'a> Iterator for HCZippedAcyclicIterator<'a> { type Item = (Addr, Addr); fn next(&mut self) -> Option { @@ -341,9 +333,7 @@ impl<'a> Iterator for HCZippedAcyclicIterator<'a> self.first_to_expire = Ordering::Less; None } - _ => { - None - } + _ => None, } } } diff --git a/src/heap_print.rs b/src/heap_print.rs index d4b9b09f..2bd5e3bf 100644 --- a/src/heap_print.rs +++ b/src/heap_print.rs @@ -1,5 +1,5 @@ -use crate::prolog_parser_rebis::ast::*; -use crate::prolog_parser_rebis::{ +use prolog_parser_rebis::ast::*; +use prolog_parser_rebis::{ alpha_char, alpha_numeric_char, backslash_char, capital_letter_char, char_class, clause_name, cut_char, decimal_digit_char, graphic_char, graphic_token_char, is_fx, is_infix, is_postfix, is_prefix, is_xf, is_xfx, is_xfy, is_yfx, semicolon_char, sign_char, single_quote_char, @@ -13,10 +13,10 @@ use crate::machine::heap::*; use crate::machine::machine_indices::*; use crate::machine::machine_state::*; use crate::machine::streams::*; -use crate::ordered_float::OrderedFloat; use crate::rug::{Integer, Rational}; +use ordered_float::OrderedFloat; -use crate::indexmap::{IndexMap, IndexSet}; +use indexmap::{IndexMap, IndexSet}; use std::cell::Cell; use std::convert::TryFrom; diff --git a/src/indexing.rs b/src/indexing.rs index 80bd4c17..1b14f301 100644 --- a/src/indexing.rs +++ b/src/indexing.rs @@ -1,12 +1,12 @@ -use crate::prolog_parser_rebis::ast::*; -use crate::prolog_parser_rebis::clause_name; -use crate::prolog_parser_rebis::tabled_rc::*; +use prolog_parser_rebis::ast::*; +use prolog_parser_rebis::clause_name; +use prolog_parser_rebis::tabled_rc::*; use crate::forms::*; use crate::instructions::*; -use crate::indexmap::IndexMap; use crate::rug::Integer; +use indexmap::IndexMap; use slice_deque::{sdeq, SliceDeque}; diff --git a/src/instructions.rs b/src/instructions.rs index 91982ea2..585cd2cb 100644 --- a/src/instructions.rs +++ b/src/instructions.rs @@ -1,5 +1,5 @@ -use crate::prolog_parser_rebis::ast::*; -use crate::prolog_parser_rebis::clause_name; +use prolog_parser_rebis::ast::*; +use prolog_parser_rebis::clause_name; use crate::clause_types::*; use crate::forms::*; @@ -9,7 +9,7 @@ use crate::machine::machine_errors::MachineStub; use crate::machine::machine_indices::*; use crate::rug::Integer; -use crate::indexmap::IndexMap; +use indexmap::IndexMap; use slice_deque::SliceDeque; diff --git a/src/iterators.rs b/src/iterators.rs index ce3733ec..beb81ca4 100644 --- a/src/iterators.rs +++ b/src/iterators.rs @@ -1,5 +1,5 @@ -use crate::prolog_parser_rebis::ast::*; -use crate::prolog_parser_rebis::rc_atom; +use prolog_parser_rebis::ast::*; +use prolog_parser_rebis::rc_atom; use crate::clause_types::*; use crate::forms::*; diff --git a/src/machine/arithmetic_ops.rs b/src/machine/arithmetic_ops.rs index aee346a2..b21cb7a9 100644 --- a/src/machine/arithmetic_ops.rs +++ b/src/machine/arithmetic_ops.rs @@ -1,7 +1,7 @@ -use crate::divrem::*; +use divrem::*; -use crate::prolog_parser_rebis::ast::*; -use crate::prolog_parser_rebis::clause_name; +use prolog_parser_rebis::ast::*; +use prolog_parser_rebis::clause_name; use crate::arithmetic::*; use crate::clause_types::*; @@ -9,8 +9,8 @@ use crate::forms::*; use crate::machine::machine_errors::*; use crate::machine::machine_indices::*; use crate::machine::machine_state::*; -use crate::ordered_float::*; use crate::rug::{Integer, Rational}; +use ordered_float::*; use std::cmp; use std::convert::TryFrom; diff --git a/src/machine/attributed_variables.rs b/src/machine/attributed_variables.rs index dff8e90e..4bc90fc4 100644 --- a/src/machine/attributed_variables.rs +++ b/src/machine/attributed_variables.rs @@ -1,8 +1,8 @@ use crate::heap_iter::*; use crate::machine::*; -use crate::prolog_parser_rebis::temp_v; +use prolog_parser_rebis::temp_v; -use crate::indexmap::IndexSet; +use indexmap::IndexSet; use std::cmp::Ordering; use std::vec::IntoIter; diff --git a/src/machine/compile.rs b/src/machine/compile.rs index 766c117a..1ab52a73 100644 --- a/src/machine/compile.rs +++ b/src/machine/compile.rs @@ -1,4 +1,4 @@ -use crate::prolog_parser_rebis::clause_name; +use prolog_parser_rebis::clause_name; use crate::codegen::*; use crate::debray_allocator::*; diff --git a/src/machine/heap.rs b/src/machine/heap.rs index 0d3a5cf6..c6115662 100644 --- a/src/machine/heap.rs +++ b/src/machine/heap.rs @@ -1,6 +1,6 @@ use core::marker::PhantomData; -use crate::prolog_parser_rebis::ast::Constant; +use prolog_parser_rebis::ast::Constant; use crate::machine::machine_indices::*; use crate::machine::partial_string::*; @@ -42,16 +42,17 @@ impl Drop for HeapTemplate { } #[derive(Debug)] -pub(crate) -struct HeapIntoIter { +pub(crate) struct HeapIntoIter { offset: usize, buf: RawBlock, } impl Drop for HeapIntoIter { fn drop(&mut self) { - let mut heap = - HeapTemplate { buf: self.buf.take(), _marker: PhantomData }; + let mut heap = HeapTemplate { + buf: self.buf.take(), + _marker: PhantomData, + }; heap.truncate(self.offset / mem::size_of::()); heap.buf.deallocate(); @@ -66,9 +67,7 @@ impl Iterator for HeapIntoIter { self.offset += mem::size_of::(); if ptr < self.buf.top as usize { - unsafe { - Some(ptr::read(ptr as *const HeapCellValue)) - } + unsafe { Some(ptr::read(ptr as *const HeapCellValue)) } } else { None } @@ -76,15 +75,13 @@ impl Iterator for HeapIntoIter { } #[derive(Debug)] -pub(crate) -struct HeapIter<'a, T: RawBlockTraits> { +pub(crate) struct HeapIter<'a, T: RawBlockTraits> { offset: usize, buf: &'a RawBlock, } impl<'a, T: RawBlockTraits> HeapIter<'a, T> { - pub(crate) - fn new(buf: &'a RawBlock, offset: usize) -> Self { + pub(crate) fn new(buf: &'a RawBlock, offset: usize) -> Self { HeapIter { buf, offset } } } @@ -97,9 +94,7 @@ impl<'a, T: RawBlockTraits> Iterator for HeapIter<'a, T> { self.offset += mem::size_of::(); if ptr < self.buf.top as usize { - unsafe { - Some(&*(ptr as *const _)) - } + unsafe { Some(&*(ptr as *const _)) } } else { None } @@ -107,23 +102,20 @@ impl<'a, T: RawBlockTraits> Iterator for HeapIter<'a, T> { } #[allow(dead_code)] -pub(crate) -fn print_heap_terms<'a, I: Iterator>(heap: I, h: usize) { +pub(crate) fn print_heap_terms<'a, I: Iterator>(heap: I, h: usize) { for (index, term) in heap.enumerate() { println!("{} : {}", h + index, term); } } #[derive(Debug)] -pub(crate) -struct HeapIterMut<'a, T: RawBlockTraits> { +pub(crate) struct HeapIterMut<'a, T: RawBlockTraits> { offset: usize, buf: &'a mut RawBlock, } impl<'a, T: RawBlockTraits> HeapIterMut<'a, T> { - pub(crate) - fn new(buf: &'a mut RawBlock, offset: usize) -> Self { + pub(crate) fn new(buf: &'a mut RawBlock, offset: usize) -> Self { HeapIterMut { buf, offset } } } @@ -136,9 +128,7 @@ impl<'a, T: RawBlockTraits> Iterator for HeapIterMut<'a, T> { self.offset += mem::size_of::(); if ptr < self.buf.top as usize { - unsafe { - Some(&mut *(ptr as *mut _)) - } + unsafe { Some(&mut *(ptr as *mut _)) } } else { None } @@ -147,51 +137,33 @@ impl<'a, T: RawBlockTraits> Iterator for HeapIterMut<'a, T> { impl HeapTemplate { #[inline] - pub(crate) - fn new() -> Self { - HeapTemplate { buf: RawBlock::new(), _marker: PhantomData } + pub(crate) fn new() -> Self { + HeapTemplate { + buf: RawBlock::new(), + _marker: PhantomData, + } } #[inline] - pub(crate) - fn clone(&self, h: usize) -> HeapCellValue { + pub(crate) fn clone(&self, h: usize) -> HeapCellValue { match &self[h] { - &HeapCellValue::Addr(addr) => { - HeapCellValue::Addr(addr) - } - &HeapCellValue::Atom(ref name, ref op) => { - HeapCellValue::Atom(name.clone(), op.clone()) - } - &HeapCellValue::DBRef(ref db_ref) => { - HeapCellValue::DBRef(db_ref.clone()) - } - &HeapCellValue::Integer(ref n) => { - HeapCellValue::Integer(n.clone()) - } - &HeapCellValue::LoadStatePayload(_) => { - HeapCellValue::Addr(Addr::LoadStatePayload(h)) - } + &HeapCellValue::Addr(addr) => HeapCellValue::Addr(addr), + &HeapCellValue::Atom(ref name, ref op) => HeapCellValue::Atom(name.clone(), op.clone()), + &HeapCellValue::DBRef(ref db_ref) => HeapCellValue::DBRef(db_ref.clone()), + &HeapCellValue::Integer(ref n) => HeapCellValue::Integer(n.clone()), + &HeapCellValue::LoadStatePayload(_) => HeapCellValue::Addr(Addr::LoadStatePayload(h)), &HeapCellValue::NamedStr(arity, ref name, ref op) => { HeapCellValue::NamedStr(arity, name.clone(), op.clone()) } - &HeapCellValue::PartialString(..) => { - HeapCellValue::Addr(Addr::PStrLocation(h, 0)) - } - &HeapCellValue::Rational(ref r) => { - HeapCellValue::Rational(r.clone()) - } - &HeapCellValue::Stream(_) => { - HeapCellValue::Addr(Addr::Stream(h)) - } - &HeapCellValue::TcpListener(_) => { - HeapCellValue::Addr(Addr::TcpListener(h)) - } + &HeapCellValue::PartialString(..) => HeapCellValue::Addr(Addr::PStrLocation(h, 0)), + &HeapCellValue::Rational(ref r) => HeapCellValue::Rational(r.clone()), + &HeapCellValue::Stream(_) => HeapCellValue::Addr(Addr::Stream(h)), + &HeapCellValue::TcpListener(_) => HeapCellValue::Addr(Addr::TcpListener(h)), } } #[inline] - pub(crate) - fn put_complete_string(&mut self, s: &str) -> Addr { + pub(crate) fn put_complete_string(&mut self, s: &str) -> Addr { if s.is_empty() { return Addr::EmptyList; } @@ -214,30 +186,15 @@ impl HeapTemplate { } #[inline] - pub(crate) - fn put_constant(&mut self, c: Constant) -> Addr { + pub(crate) fn put_constant(&mut self, c: Constant) -> Addr { match c { - Constant::Atom(name, op) => { - Addr::Con(self.push(HeapCellValue::Atom(name, op))) - } - Constant::Char(c) => { - Addr::Char(c) - } - Constant::EmptyList => { - Addr::EmptyList - } - Constant::Fixnum(n) => { - Addr::Fixnum(n) - } - Constant::Integer(n) => { - Addr::Con(self.push(HeapCellValue::Integer(n))) - } - Constant::Rational(r) => { - Addr::Con(self.push(HeapCellValue::Rational(r))) - } - Constant::Float(f) => { - Addr::Float(f) - } + Constant::Atom(name, op) => Addr::Con(self.push(HeapCellValue::Atom(name, op))), + Constant::Char(c) => Addr::Char(c), + Constant::EmptyList => Addr::EmptyList, + Constant::Fixnum(n) => Addr::Fixnum(n), + Constant::Integer(n) => Addr::Con(self.push(HeapCellValue::Integer(n))), + Constant::Rational(r) => Addr::Con(self.push(HeapCellValue::Rational(r))), + Constant::Float(f) => Addr::Float(f), Constant::String(s) => { if s.is_empty() { Addr::EmptyList @@ -245,15 +202,12 @@ impl HeapTemplate { self.put_complete_string(&s) } } - Constant::Usize(n) => { - Addr::Usize(n) - } + Constant::Usize(n) => Addr::Usize(n), } } #[inline] - pub(crate) - fn pop(&mut self) { + pub(crate) fn pop(&mut self) { let h = self.h(); if h > 0 { @@ -262,8 +216,7 @@ impl HeapTemplate { } #[inline] - pub(crate) - fn push(&mut self, val: HeapCellValue) -> usize { + pub(crate) fn push(&mut self, val: HeapCellValue) -> usize { let h = self.h(); unsafe { @@ -276,8 +229,7 @@ impl HeapTemplate { } #[inline] - pub(crate) - fn atom_at(&self, h: usize) -> bool { + pub(crate) fn atom_at(&self, h: usize) -> bool { if let HeapCellValue::Atom(..) = &self[h] { true } else { @@ -286,24 +238,15 @@ impl HeapTemplate { } #[inline] - pub(crate) - fn to_unifiable(&mut self, non_heap_value: HeapCellValue) -> Addr { + pub(crate) fn to_unifiable(&mut self, non_heap_value: HeapCellValue) -> Addr { match non_heap_value { - HeapCellValue::Addr(addr) => { - addr - } - val @ HeapCellValue::Atom(..) | - val @ HeapCellValue::Integer(_) | - val @ HeapCellValue::DBRef(_) | - val @ HeapCellValue::Rational(_) => { - Addr::Con(self.push(val)) - } - val @ HeapCellValue::LoadStatePayload(_) => { - Addr::LoadStatePayload(self.push(val)) - } - val @ HeapCellValue::NamedStr(..) => { - Addr::Str(self.push(val)) - } + HeapCellValue::Addr(addr) => addr, + val @ HeapCellValue::Atom(..) + | val @ HeapCellValue::Integer(_) + | val @ HeapCellValue::DBRef(_) + | val @ HeapCellValue::Rational(_) => Addr::Con(self.push(val)), + val @ HeapCellValue::LoadStatePayload(_) => Addr::LoadStatePayload(self.push(val)), + val @ HeapCellValue::NamedStr(..) => Addr::Str(self.push(val)), HeapCellValue::PartialString(pstr, has_tail) => { let h = self.push(HeapCellValue::PartialString(pstr, has_tail)); @@ -313,20 +256,14 @@ impl HeapTemplate { Addr::Con(h) } - val @ HeapCellValue::Stream(..) => { - Addr::Stream(self.push(val)) - } - val @ HeapCellValue::TcpListener(..) => { - Addr::TcpListener(self.push(val)) - } + val @ HeapCellValue::Stream(..) => Addr::Stream(self.push(val)), + val @ HeapCellValue::TcpListener(..) => Addr::TcpListener(self.push(val)), } } #[inline] - pub(crate) - fn allocate_pstr(&mut self, src: &str) -> Addr { - self.write_pstr(src) - .unwrap_or_else(|| Addr::EmptyList) + pub(crate) fn allocate_pstr(&mut self, src: &str) -> Addr { + self.write_pstr(src).unwrap_or_else(|| Addr::EmptyList) } #[inline] @@ -347,23 +284,20 @@ impl HeapTemplate { let h = self.h(); - let (pstr, rest_src) = - match PartialString::new(src) { - Some(tuple) => { - tuple + let (pstr, rest_src) = match PartialString::new(src) { + Some(tuple) => tuple, + None => { + if src.len() > '\u{0}'.len_utf8() { + src = &src['\u{0}'.len_utf8()..]; + continue; + } else if orig_h == h { + return None; + } else { + self[h - 1] = HeapCellValue::Addr(Addr::HeapCell(h - 1)); + return Some(Addr::PStrLocation(orig_h, 0)); } - None => { - if src.len() > '\u{0}'.len_utf8() { - src = &src['\u{0}'.len_utf8() ..]; - continue; - } else if orig_h == h { - return None; - } else { - self[h - 1] = HeapCellValue::Addr(Addr::HeapCell(h - 1)); - return Some(Addr::PStrLocation(orig_h, 0)); - } - } - }; + } + }; self.push(HeapCellValue::PartialString(pstr, true)); @@ -378,8 +312,7 @@ impl HeapTemplate { } #[inline] - pub(crate) - fn truncate(&mut self, h: usize) { + pub(crate) fn truncate(&mut self, h: usize) { let new_top = h * mem::size_of::() + self.buf.base as usize; let mut h = new_top; @@ -395,30 +328,27 @@ impl HeapTemplate { } #[inline] - pub(crate) - fn h(&self) -> usize { + pub(crate) fn h(&self) -> usize { (self.buf.top as usize - self.buf.base as usize) / mem::size_of::() } - pub(crate) - fn append(&mut self, vals: Vec) { + pub(crate) fn append(&mut self, vals: Vec) { for val in vals { self.push(val); } } - pub(crate) - fn clear(&mut self) { + pub(crate) fn clear(&mut self) { if !self.buf.base.is_null() { self.truncate(0); self.buf.top = self.buf.base; } } - pub(crate) - fn to_list(&mut self, values: Iter) -> usize - where Iter: Iterator, - SrcT: Into + pub(crate) fn to_list(&mut self, values: Iter) -> usize + where + Iter: Iterator, + SrcT: Into, { let head_addr = self.h(); let mut h = head_addr; @@ -436,35 +366,33 @@ impl HeapTemplate { } /* Create an iterator starting from the passed offset. */ - pub(crate) - fn iter_from<'a>(&'a self, offset: usize) -> HeapIter<'a, T> { + pub(crate) fn iter_from<'a>(&'a self, offset: usize) -> HeapIter<'a, T> { HeapIter::new(&self.buf, offset * mem::size_of::()) } - pub(crate) - fn iter_mut_from<'a>(&'a mut self, offset: usize) -> HeapIterMut<'a, T> { + pub(crate) fn iter_mut_from<'a>(&'a mut self, offset: usize) -> HeapIterMut<'a, T> { HeapIterMut::new(&mut self.buf, offset * mem::size_of::()) } - pub(crate) - fn into_iter(mut self) -> HeapIntoIter { - HeapIntoIter { buf: self.buf.take(), offset: 0 } + pub(crate) fn into_iter(mut self) -> HeapIntoIter { + HeapIntoIter { + buf: self.buf.take(), + offset: 0, + } } - pub(crate) - fn extend>(&mut self, iter: Iter) { + pub(crate) fn extend>(&mut self, iter: Iter) { for hcv in iter { self.push(hcv); } } - pub(crate) - fn to_local_code_ptr(&self, addr: &Addr) -> Option { + pub(crate) fn to_local_code_ptr(&self, addr: &Addr) -> Option { let extract_integer = |s: usize| -> Option { match &self[s] { &HeapCellValue::Addr(Addr::Fixnum(n)) => usize::try_from(n).ok(), &HeapCellValue::Integer(ref n) => n.to_usize(), - _ => None + _ => None, } }; @@ -473,9 +401,7 @@ impl HeapTemplate { match &self[*s] { HeapCellValue::NamedStr(arity, ref name, _) => { match (name.as_str(), *arity) { - ("dir_entry", 1) => { - extract_integer(s+1).map(LocalCodePtr::DirEntry) - } + ("dir_entry", 1) => extract_integer(s + 1).map(LocalCodePtr::DirEntry), /* ("top_level", 2) => { if let Some(chunk_num) = extract_integer(s+1) { @@ -487,15 +413,13 @@ impl HeapTemplate { None } */ - _ => { - None - } + _ => None, } } - _ => unreachable!() + _ => unreachable!(), } } - _ => None + _ => None, } } @@ -505,9 +429,7 @@ impl HeapTemplate { &Addr::Con(h) | &Addr::Str(h) | &Addr::Stream(h) | &Addr::TcpListener(h) => { RefOrOwned::Borrowed(&self[h]) } - addr => { - RefOrOwned::Owned(HeapCellValue::Addr(*addr)) - } + addr => RefOrOwned::Owned(HeapCellValue::Addr(*addr)), } } } diff --git a/src/machine/load_state.rs b/src/machine/load_state.rs index 466b2f99..5ddd2c9f 100644 --- a/src/machine/load_state.rs +++ b/src/machine/load_state.rs @@ -1,11 +1,11 @@ use crate::machine::machine_indices::*; use crate::machine::*; -use crate::prolog_parser_rebis::clause_name; +use prolog_parser_rebis::clause_name; use crate::machine::term_stream::*; use indexmap::IndexSet; -use crate::ref_thread_local::RefThreadLocal; +use ref_thread_local::RefThreadLocal; type ModuleOpExports = Vec<(OpDecl, Option<(usize, Specifier)>)>; diff --git a/src/machine/machine_errors.rs b/src/machine/machine_errors.rs index 1ca1861d..b1d60bb3 100644 --- a/src/machine/machine_errors.rs +++ b/src/machine/machine_errors.rs @@ -1,5 +1,5 @@ -use crate::prolog_parser_rebis::ast::*; -use crate::prolog_parser_rebis::{clause_name, temp_v}; +use prolog_parser_rebis::ast::*; +use prolog_parser_rebis::{clause_name, temp_v}; use crate::forms::{ModuleSource, Number}; //, PredicateKey}; use crate::machine::heap::*; diff --git a/src/machine/machine_indices.rs b/src/machine/machine_indices.rs index b4089147..918af24c 100644 --- a/src/machine/machine_indices.rs +++ b/src/machine/machine_indices.rs @@ -1,5 +1,5 @@ -use crate::prolog_parser_rebis::ast::*; -use crate::prolog_parser_rebis::clause_name; +use prolog_parser_rebis::ast::*; +use prolog_parser_rebis::clause_name; use crate::clause_types::*; use crate::fixtures::*; @@ -14,10 +14,10 @@ use crate::machine::streams::Stream; use crate::machine::term_stream::LoadStatePayload; use crate::machine::Ball; use crate::machine::CompilationTarget; -use crate::ordered_float::OrderedFloat; use crate::rug::{Integer, Rational}; +use ordered_float::OrderedFloat; -use crate::indexmap::IndexMap; +use indexmap::IndexMap; use std::cell::Cell; use std::cmp::Ordering; diff --git a/src/machine/machine_state.rs b/src/machine/machine_state.rs index c8338c94..f7160134 100644 --- a/src/machine/machine_state.rs +++ b/src/machine/machine_state.rs @@ -1,6 +1,6 @@ -use crate::prolog_parser_rebis::ast::*; -use crate::prolog_parser_rebis::tabled_rc::*; -use crate::prolog_parser_rebis::{clause_name, temp_v}; +use prolog_parser_rebis::ast::*; +use prolog_parser_rebis::tabled_rc::*; +use prolog_parser_rebis::{clause_name, temp_v}; use crate::clause_types::*; use crate::forms::*; @@ -15,11 +15,11 @@ use crate::machine::stack::*; use crate::machine::streams::*; use crate::rug::Integer; -use crate::downcast::{ +use downcast::{ downcast, downcast_methods, downcast_methods_core, downcast_methods_std, impl_downcast, Any, }; -use crate::indexmap::IndexMap; +use indexmap::IndexMap; use std::cmp::Ordering; use std::convert::TryFrom; diff --git a/src/machine/machine_state_impl.rs b/src/machine/machine_state_impl.rs index d0348f9f..141ec43f 100644 --- a/src/machine/machine_state_impl.rs +++ b/src/machine/machine_state_impl.rs @@ -1,6 +1,6 @@ -use crate::prolog_parser_rebis::ast::*; -use crate::prolog_parser_rebis::tabled_rc::*; -use crate::prolog_parser_rebis::{clause_name, perm_v, temp_v}; +use prolog_parser_rebis::ast::*; +use prolog_parser_rebis::tabled_rc::*; +use prolog_parser_rebis::{clause_name, perm_v, temp_v}; use crate::clause_types::*; use crate::forms::*; @@ -18,10 +18,10 @@ use crate::machine::partial_string::*; use crate::machine::stack::*; use crate::machine::streams::*; use crate::machine::INTERRUPT; -use crate::ordered_float::*; use crate::rug::Integer; +use ordered_float::*; -use crate::indexmap::{IndexMap, IndexSet}; +use indexmap::{IndexMap, IndexSet}; use std::cmp::Ordering; use std::convert::TryFrom; diff --git a/src/machine/mod.rs b/src/machine/mod.rs index eb9dd534..c0550c1e 100644 --- a/src/machine/mod.rs +++ b/src/machine/mod.rs @@ -1,8 +1,8 @@ -use crate::prolog_parser_rebis::ast::*; -use crate::prolog_parser_rebis::tabled_rc::*; -use crate::prolog_parser_rebis::{clause_name, temp_v}; +use prolog_parser_rebis::ast::*; +use prolog_parser_rebis::tabled_rc::*; +use prolog_parser_rebis::{clause_name, temp_v}; -use crate::lazy_static::lazy_static; +use lazy_static::lazy_static; use crate::clause_types::*; use crate::forms::*; @@ -45,7 +45,7 @@ use crate::machine::machine_indices::*; use crate::machine::machine_state::*; use crate::machine::streams::*; -use crate::indexmap::IndexMap; +use indexmap::IndexMap; //use std::convert::TryFrom; use prolog_parser_rebis::ast::ClauseName; @@ -304,7 +304,7 @@ impl Machine { } pub fn new(user_input: Stream, user_output: Stream) -> Self { - use crate::ref_thread_local::RefThreadLocal; + use ref_thread_local::RefThreadLocal; let mut wam = Machine { machine_st: MachineState::new(), diff --git a/src/machine/preprocessor.rs b/src/machine/preprocessor.rs index 34d47ebe..f0c7f8b5 100644 --- a/src/machine/preprocessor.rs +++ b/src/machine/preprocessor.rs @@ -1,6 +1,6 @@ -use crate::prolog_parser_rebis::ast::*; -use crate::prolog_parser_rebis::tabled_rc::*; -use crate::prolog_parser_rebis::{atom, clause_name, rc_atom}; +use prolog_parser_rebis::ast::*; +use prolog_parser_rebis::tabled_rc::*; +use prolog_parser_rebis::{atom, clause_name, rc_atom}; use crate::forms::*; use crate::iterators::*; @@ -8,7 +8,7 @@ use crate::machine::load_state::*; use crate::machine::machine_errors::*; use crate::machine::*; -use crate::indexmap::IndexSet; +use indexmap::IndexSet; use std::cell::Cell; use std::collections::VecDeque; diff --git a/src/machine/streams.rs b/src/machine/streams.rs index 531b47c4..dfa98eb3 100644 --- a/src/machine/streams.rs +++ b/src/machine/streams.rs @@ -1,5 +1,5 @@ -use crate::prolog_parser_rebis::ast::*; -use crate::prolog_parser_rebis::clause_name; +use prolog_parser_rebis::ast::*; +use prolog_parser_rebis::clause_name; use crate::machine::machine_errors::*; use crate::machine::machine_indices::*; @@ -20,7 +20,7 @@ use std::net::{Shutdown, TcpStream}; use std::ops::DerefMut; use std::rc::Rc; -use crate::native_tls::TlsStream; +use native_tls::TlsStream; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum StreamType { @@ -629,7 +629,7 @@ impl Stream { #[inline] pub(crate) fn peek_char(&mut self) -> std::io::Result { - use crate::unicode_reader::CodePoints; + use unicode_reader::CodePoints; match self.stream_inst.0.borrow_mut().1 { StreamInstance::InputFile(_, ref mut file) => { diff --git a/src/machine/system_calls.rs b/src/machine/system_calls.rs index 81bf2da5..cfad12af 100644 --- a/src/machine/system_calls.rs +++ b/src/machine/system_calls.rs @@ -1,14 +1,14 @@ -use crate::prolog_parser_rebis::ast::*; -use crate::prolog_parser_rebis::parser::*; -use crate::prolog_parser_rebis::tabled_rc::*; -use crate::prolog_parser_rebis::{ +use prolog_parser_rebis::ast::*; +use prolog_parser_rebis::parser::*; +use prolog_parser_rebis::tabled_rc::*; +use prolog_parser_rebis::{ alpha_char, alpha_numeric_char, backslash_char, binary_digit_char, char_class, clause_name, decimal_digit_char, exponent_char, graphic_char, graphic_token_char, hexadecimal_digit_char, layout_char, meta_char, new_line_char, octal_digit_char, prolog_char, sign_char, solo_char, symbolic_control_char, symbolic_hexadecimal_char, temp_v, }; -use crate::lazy_static::lazy_static; +use lazy_static::lazy_static; use crate::clause_types::*; use crate::forms::*; @@ -24,13 +24,13 @@ use crate::machine::machine_state::*; use crate::machine::preprocessor::to_op_decl; use crate::machine::streams::*; -use crate::ordered_float::OrderedFloat; use crate::read::readline; use crate::rug::Integer; +use ordered_float::OrderedFloat; -use crate::indexmap::IndexSet; +use indexmap::IndexSet; -use crate::ref_thread_local::RefThreadLocal; +use ref_thread_local::RefThreadLocal; use std::cmp; use std::collections::BTreeSet; @@ -44,29 +44,29 @@ use std::num::NonZeroU32; use std::ops::Sub; use std::rc::Rc; -use crate::chrono::{offset::Local, DateTime}; -use crate::cpu_time::ProcessTime; +use chrono::{offset::Local, DateTime}; +use cpu_time::ProcessTime; use std::time::{Duration, SystemTime}; -use crate::crossterm::event::{read, Event, KeyCode, KeyEvent, KeyModifiers}; -use crate::crossterm::terminal::{disable_raw_mode, enable_raw_mode}; +use crossterm::event::{read, Event, KeyCode, KeyEvent, KeyModifiers}; +use crossterm::terminal::{disable_raw_mode, enable_raw_mode}; -use crate::blake2::{Blake2b, Blake2s}; -use crate::ring::rand::{SecureRandom, SystemRandom}; -use crate::ring::{ +use blake2::{Blake2b, Blake2s}; +use ring::rand::{SecureRandom, SystemRandom}; +use ring::{ aead, digest, hkdf, pbkdf2, signature::{self, KeyPair}, }; -use crate::ripemd160::{Digest, Ripemd160}; -use crate::sha3::{Sha3_224, Sha3_256, Sha3_384, Sha3_512}; +use ripemd160::{Digest, Ripemd160}; +use sha3::{Sha3_224, Sha3_256, Sha3_384, Sha3_512}; -use crate::openssl::bn::{BigNum, BigNumContext}; -use crate::openssl::ec::{EcGroup, EcPoint}; -use crate::openssl::nid::Nid; +use openssl::bn::{BigNum, BigNumContext}; +use openssl::ec::{EcGroup, EcPoint}; +use openssl::nid::Nid; use sodiumoxide::crypto::scalarmult::curve25519::*; -use crate::native_tls::TlsConnector; +use native_tls::TlsConnector; extern crate select; @@ -4883,7 +4883,7 @@ impl MachineState { } } &SystemClauseType::ScryerPrologVersion => { - use crate::git_version::git_version; + use git_version::git_version; let version = self[temp_v!(1)]; let buffer = git_version!(cargo_prefix = "cargo:", fallback = "unknown"); let chars = buffer.chars().map(|c| Addr::Char(c)); diff --git a/src/machine/term_stream.rs b/src/machine/term_stream.rs index e408a6f1..1305ad65 100644 --- a/src/machine/term_stream.rs +++ b/src/machine/term_stream.rs @@ -1,16 +1,16 @@ -use crate::prolog_parser_rebis::ast::*; -use crate::prolog_parser_rebis::parser::*; +use prolog_parser_rebis::ast::*; +use prolog_parser_rebis::parser::*; -use crate::machine::*; use crate::machine::machine_errors::CompilationError; use crate::machine::preprocessor::*; +use crate::machine::*; use indexmap::IndexSet; use std::collections::VecDeque; use std::fmt; -pub(crate) trait TermStream : Sized { +pub(crate) trait TermStream: Sized { type Evacuable; fn next(&mut self, op_dir: &CompositeOpDir) -> Result; @@ -27,15 +27,17 @@ pub(super) struct BootstrappingTermStream<'a> { impl<'a> BootstrappingTermStream<'a> { #[inline] - pub(super) - fn from_prolog_stream( + pub(super) fn from_prolog_stream( stream: &'a mut PrologStream, atom_tbl: TabledData, flags: MachineFlags, listing_src: ListingSource, ) -> Self { let parser = Parser::new(stream, atom_tbl, flags); - Self { parser, listing_src } + Self { + parser, + listing_src, + } } } @@ -45,13 +47,14 @@ impl<'a> TermStream for BootstrappingTermStream<'a> { #[inline] fn next(&mut self, op_dir: &CompositeOpDir) -> Result { self.parser.reset(); - self.parser.read_term(op_dir) + self.parser + .read_term(op_dir) .map_err(CompilationError::from) } #[inline] fn eof(&mut self) -> Result { - self.parser.devour_whitespace()?; // eliminate dangling comments before checking for EOF. + self.parser.devour_whitespace()?; // eliminate dangling comments before checking for EOF. Ok(self.parser.eof()?) } @@ -65,9 +68,10 @@ impl<'a> TermStream for BootstrappingTermStream<'a> { loader.compile_and_submit()?; } - loader.load_state.retraction_info.reset( - loader.load_state.wam.code_repo.code.len(), - ); + loader + .load_state + .retraction_info + .reset(loader.load_state.wam.code_repo.code.len()); loader.load_state.remove_module_op_exports(); @@ -82,8 +86,7 @@ pub struct LiveTermStream { impl LiveTermStream { #[inline] - pub(super) - fn new(listing_src: ListingSource) -> Self { + pub(super) fn new(listing_src: ListingSource) -> Self { Self { term_queue: VecDeque::new(), listing_src, @@ -109,8 +112,7 @@ impl fmt::Debug for LoadStatePayload { } impl LoadStatePayload { - pub(super) - fn new(wam: &Machine) -> Self { + pub(super) fn new(wam: &Machine) -> Self { Self { term_stream: LiveTermStream::new(ListingSource::User), compilation_target: CompilationTarget::default(), diff --git a/src/main.rs b/src/main.rs index 82b89c95..a79563b6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,24 +1,3 @@ -use blake2; -use chrono; -use cpu_time; -use crossterm; -use divrem; -use downcast; -use git_version; -use indexmap; -use lazy_static; -use native_tls; -use nix::sys::signal; -use openssl; -use ordered_float; -use prolog_parser_rebis; -use ref_thread_local; -use ring; -use ripemd160; -use rustyline; -use sha3; -use unicode_reader; - #[cfg(feature = "num-rug-adapter")] use num_rug_adapter as rug; #[cfg(feature = "rug")] @@ -47,6 +26,7 @@ use machine::streams::*; use machine::*; use read::*; +use nix::sys::signal; use std::sync::atomic::Ordering; extern "C" fn handle_sigint(signal: libc::c_int) { diff --git a/src/read.rs b/src/read.rs index 4ed74fbf..ac2d3fa0 100644 --- a/src/read.rs +++ b/src/read.rs @@ -1,6 +1,6 @@ -use crate::prolog_parser_rebis::ast::*; -use crate::prolog_parser_rebis::parser::*; -use crate::prolog_parser_rebis::tabled_rc::TabledData; +use prolog_parser_rebis::ast::*; +use prolog_parser_rebis::parser::*; +use prolog_parser_rebis::tabled_rc::TabledData; use crate::forms::*; use crate::iterators::*; @@ -16,8 +16,8 @@ pub type PrologStream = ParsingStream; pub mod readline { use crate::machine::streams::Stream; - use crate::rustyline::error::ReadlineError; - use crate::rustyline::{Cmd, Config, Editor, KeyEvent}; + use rustyline::error::ReadlineError; + use rustyline::{Cmd, Config, Editor, KeyEvent}; use std::io::{Cursor, Error, ErrorKind, Read}; static mut PROMPT: bool = false; @@ -33,7 +33,11 @@ pub mod readline { #[inline] fn get_prompt() -> &'static str { unsafe { - if PROMPT { "?- " } else { "" } + if PROMPT { + "?- " + } else { + "" + } } } @@ -61,7 +65,10 @@ pub mod readline { } rl.bind_sequence(KeyEvent::from('\t'), Cmd::Insert(1, "\t".to_string())); - ReadlineStream { rl, pending_input: Cursor::new(pending_input) } + ReadlineStream { + rl, + pending_input: Cursor::new(pending_input), + } } #[inline] @@ -89,12 +96,8 @@ pub mod readline { self.pending_input.read(buf) } - Err(ReadlineError::Eof) => { - Ok(0) - } - Err(e) => { - Err(Error::new(ErrorKind::InvalidInput, e)) - } + Err(ReadlineError::Eof) => Ok(0), + Err(e) => Err(Error::new(ErrorKind::InvalidInput, e)), } } @@ -121,21 +124,15 @@ pub mod readline { Some(b) => { return Ok(b); } - None => { - match self.call_readline(&mut []) { - Err(e) => { - return Err(e); - } - Ok(0) => { - return Err(Error::new( - ErrorKind::UnexpectedEof, - "end of file", - )); - } - _ => { - } + None => match self.call_readline(&mut []) { + Err(e) => { + return Err(e); } - } + Ok(0) => { + return Err(Error::new(ErrorKind::UnexpectedEof, "end of file")); + } + _ => {} + }, } } } @@ -148,21 +145,15 @@ pub mod readline { Some(c) => { return Ok(c); } - None => { - match self.call_readline(&mut []) { - Err(e) => { - return Err(e); - } - Ok(0) => { - return Err(Error::new( - ErrorKind::UnexpectedEof, - "end of file", - )); - } - _ => { - } + None => match self.call_readline(&mut []) { + Err(e) => { + return Err(e); } - } + Ok(0) => { + return Err(Error::new(ErrorKind::UnexpectedEof, "end of file")); + } + _ => {} + }, } } } @@ -171,12 +162,8 @@ pub mod readline { impl Read for ReadlineStream { fn read(&mut self, buf: &mut [u8]) -> std::io::Result { match self.pending_input.read(buf) { - Ok(0) => { - self.call_readline(buf) - } - result => { - result - } + Ok(0) => self.call_readline(buf), + result => result, } } } @@ -214,8 +201,7 @@ impl MachineState { } #[inline] -pub(crate) -fn write_term_to_heap(term: &Term, machine_st: &mut MachineState) -> TermWriteResult { +pub(crate) fn write_term_to_heap(term: &Term, machine_st: &mut MachineState) -> TermWriteResult { let term_writer = TermWriter::new(machine_st); term_writer.write_term_to_heap(term) } @@ -246,8 +232,7 @@ impl<'a> TermWriter<'a> { #[inline] fn modify_head_of_queue(&mut self, term: &TermRef<'a>, h: usize) { if let Some((arity, site_h)) = self.queue.pop_front() { - self.machine_st.heap[site_h] = - HeapCellValue::Addr(self.term_as_addr(term, h)); + self.machine_st.heap[site_h] = HeapCellValue::Addr(self.term_as_addr(term, h)); if arity > 1 { self.queue.push_front((arity - 1, site_h + 1)); @@ -258,26 +243,18 @@ impl<'a> TermWriter<'a> { #[inline] fn push_stub_addr(&mut self) { let h = self.machine_st.heap.h(); - self.machine_st.heap.push(HeapCellValue::Addr(Addr::HeapCell(h))); + self.machine_st + .heap + .push(HeapCellValue::Addr(Addr::HeapCell(h))); } fn term_as_addr(&mut self, term: &TermRef<'a>, h: usize) -> Addr { match term { - &TermRef::AnonVar(_) | &TermRef::Var(..) => { - Addr::HeapCell(h) - } - &TermRef::Cons(..) => { - Addr::HeapCell(h) - } - &TermRef::Constant(_, _, c) => { - self.machine_st.heap.put_constant(c.clone()) - } - &TermRef::Clause(..) => { - Addr::Str(h) - } - &TermRef::PartialString(..) => { - Addr::PStrLocation(h, 0) - } + &TermRef::AnonVar(_) | &TermRef::Var(..) => Addr::HeapCell(h), + &TermRef::Cons(..) => Addr::HeapCell(h), + &TermRef::Constant(_, _, c) => self.machine_st.heap.put_constant(c.clone()), + &TermRef::Clause(..) => Addr::Str(h), + &TermRef::PartialString(..) => Addr::PStrLocation(h, 0), } } @@ -290,7 +267,9 @@ impl<'a> TermWriter<'a> { match &term { &TermRef::Cons(lvl, ..) => { self.queue.push_back((2, h + 1)); - self.machine_st.heap.push(HeapCellValue::Addr(Addr::Lis(h + 1))); + self.machine_st + .heap + .push(HeapCellValue::Addr(Addr::Lis(h + 1))); self.push_stub_addr(); self.push_stub_addr(); @@ -359,13 +338,15 @@ impl<'a> TermWriter<'a> { continue; } - _ => { - } + _ => {} }; self.modify_head_of_queue(&term, h); } - TermWriteResult { heap_loc, var_dict: self.var_dict } + TermWriteResult { + heap_loc, + var_dict: self.var_dict, + } } } diff --git a/src/targets.rs b/src/targets.rs index a75d3f79..c59fe47f 100644 --- a/src/targets.rs +++ b/src/targets.rs @@ -1,4 +1,4 @@ -use crate::prolog_parser_rebis::ast::*; +use prolog_parser_rebis::ast::*; use crate::clause_types::*; use crate::forms::*;