Merge pull request #191 from dingelish/master

Fix some old Rust codes
This commit is contained in:
Mark Thom
2019-10-14 00:59:03 -03:00
committed by GitHub
8 changed files with 26 additions and 26 deletions

View File

@@ -147,7 +147,7 @@ fn char_to_string(c: char) -> String {
'\u{0c}' => "\\f".to_string(), // UTF-8 form feed '\u{0c}' => "\\f".to_string(), // UTF-8 form feed
'\u{08}' => "\\b".to_string(), // UTF-8 backspace '\u{08}' => "\\b".to_string(), // UTF-8 backspace
'\u{07}' => "\\a".to_string(), // UTF-8 alert '\u{07}' => "\\a".to_string(), // UTF-8 alert
'\x20'...'\x7e' => c.to_string(), '\x20'..='\x7e' => c.to_string(),
_ => format!("\\x{:x}\\", c as u32), _ => format!("\\x{:x}\\", c as u32),
} }
} }

View File

@@ -342,7 +342,7 @@ fn contains_cut_var<'a, Iter: Iterator<Item = &'a Term>>(terms: Iter) -> bool {
pub struct ChunkedIterator<'a> { pub struct ChunkedIterator<'a> {
pub chunk_num: usize, pub chunk_num: usize,
iter: Box<Iterator<Item = ChunkedTerm<'a>> + 'a>, iter: Box<dyn Iterator<Item = ChunkedTerm<'a>> + 'a>,
deep_cut_encountered: bool, deep_cut_encountered: bool,
cut_var_in_head: bool, cut_var_in_head: bool,
} }
@@ -351,7 +351,7 @@ type ChunkedIteratorItem<'a> = (usize, usize, Vec<ChunkedTerm<'a>>);
type RuleBodyIteratorItem<'a> = (usize, usize, Vec<&'a QueryTerm>); type RuleBodyIteratorItem<'a> = (usize, usize, Vec<&'a QueryTerm>);
impl<'a> ChunkedIterator<'a> { impl<'a> ChunkedIterator<'a> {
pub fn rule_body_iter(self) -> Box<Iterator<Item = RuleBodyIteratorItem<'a>> + 'a> { pub fn rule_body_iter(self) -> Box<dyn Iterator<Item = RuleBodyIteratorItem<'a>> + 'a> {
Box::new(self.filter_map(|(cn, lt_arity, terms)| { Box::new(self.filter_map(|(cn, lt_arity, terms)| {
let filtered_terms: Vec<_> = terms let filtered_terms: Vec<_> = terms
.into_iter() .into_iter()

View File

@@ -250,7 +250,7 @@ impl MachineError {
} }
} }
fn into_iter(self, offset: usize) -> Box<Iterator<Item = HeapCellValue>> { fn into_iter(self, offset: usize) -> Box<dyn Iterator<Item = HeapCellValue>> {
match self.from { match self.from {
ErrorProvenance::Constructed => { ErrorProvenance::Constructed => {
Box::new(self.stub.into_iter().map(move |hcv| match hcv { Box::new(self.stub.into_iter().map(move |hcv| match hcv {

View File

@@ -943,22 +943,22 @@ impl CallPolicy for CWILCallPolicy {
} }
} }
downcast!(CallPolicy); downcast!(dyn CallPolicy);
pub(crate) struct DefaultCallPolicy {} pub(crate) struct DefaultCallPolicy {}
impl CallPolicy for DefaultCallPolicy {} impl CallPolicy for DefaultCallPolicy {}
pub(crate) struct CWILCallPolicy { pub(crate) struct CWILCallPolicy {
pub(crate) prev_policy: Box<CallPolicy>, pub(crate) prev_policy: Box<dyn CallPolicy>,
count: Integer, count: Integer,
limits: Vec<(Integer, usize)>, limits: Vec<(Integer, usize)>,
inference_limit_exceeded: bool, inference_limit_exceeded: bool,
} }
impl CWILCallPolicy { impl CWILCallPolicy {
pub(crate) fn new_in_place(policy: &mut Box<CallPolicy>) { pub(crate) fn new_in_place(policy: &mut Box<dyn CallPolicy>) {
let mut prev_policy: Box<CallPolicy> = Box::new(DefaultCallPolicy {}); let mut prev_policy: Box<dyn CallPolicy> = Box::new(DefaultCallPolicy {});
mem::swap(&mut prev_policy, policy); mem::swap(&mut prev_policy, policy);
let new_policy = CWILCallPolicy { let new_policy = CWILCallPolicy {
@@ -1016,8 +1016,8 @@ impl CWILCallPolicy {
self.limits.is_empty() self.limits.is_empty()
} }
pub(crate) fn into_inner(&mut self) -> Box<CallPolicy> { pub(crate) fn into_inner(&mut self) -> Box<dyn CallPolicy> {
let mut new_inner: Box<CallPolicy> = Box::new(DefaultCallPolicy {}); let mut new_inner: Box<dyn CallPolicy> = Box::new(DefaultCallPolicy {});
mem::swap(&mut self.prev_policy, &mut new_inner); mem::swap(&mut self.prev_policy, &mut new_inner);
new_inner new_inner
} }
@@ -1028,7 +1028,7 @@ pub(crate) trait CutPolicy: Any {
fn cut(&mut self, &mut MachineState, RegType) -> bool; fn cut(&mut self, &mut MachineState, RegType) -> bool;
} }
downcast!(CutPolicy); downcast!(dyn CutPolicy);
fn cut_body(machine_st: &mut MachineState, addr: Addr) -> bool { fn cut_body(machine_st: &mut MachineState, addr: Addr) -> bool {
let b = machine_st.b; let b = machine_st.b;

View File

@@ -3151,8 +3151,8 @@ impl MachineState {
&mut self, &mut self,
indices: &mut IndexStore, indices: &mut IndexStore,
code_repo: &CodeRepo, code_repo: &CodeRepo,
call_policy: &mut Box<CallPolicy>, call_policy: &mut Box<dyn CallPolicy>,
cut_policy: &mut Box<CutPolicy>, cut_policy: &mut Box<dyn CutPolicy>,
parsing_stream: &mut PrologStream, parsing_stream: &mut PrologStream,
ct: &ClauseType, ct: &ClauseType,
arity: usize, arity: usize,
@@ -3167,7 +3167,7 @@ impl MachineState {
return; return;
} }
let mut default_call_policy: Box<CallPolicy> = Box::new(DefaultCallPolicy {}); let mut default_call_policy: Box<dyn CallPolicy> = Box::new(DefaultCallPolicy {});
let call_policy = if use_default_cp { let call_policy = if use_default_cp {
&mut default_call_policy &mut default_call_policy
} else { } else {
@@ -3217,8 +3217,8 @@ impl MachineState {
&mut self, &mut self,
indices: &mut IndexStore, indices: &mut IndexStore,
code_repo: &CodeRepo, code_repo: &CodeRepo,
call_policy: &mut Box<CallPolicy>, call_policy: &mut Box<dyn CallPolicy>,
cut_policy: &mut Box<CutPolicy>, cut_policy: &mut Box<dyn CutPolicy>,
parsing_stream: &mut PrologStream, parsing_stream: &mut PrologStream,
instr: &ControlInstruction, instr: &ControlInstruction,
) { ) {
@@ -3253,7 +3253,7 @@ impl MachineState {
pub(super) fn execute_indexed_choice_instr( pub(super) fn execute_indexed_choice_instr(
&mut self, &mut self,
instr: &IndexedChoiceInstruction, instr: &IndexedChoiceInstruction,
call_policy: &mut Box<CallPolicy>, call_policy: &mut Box<dyn CallPolicy>,
) { ) {
match instr { match instr {
&IndexedChoiceInstruction::Try(l) => { &IndexedChoiceInstruction::Try(l) => {
@@ -3292,7 +3292,7 @@ impl MachineState {
pub(super) fn execute_choice_instr( pub(super) fn execute_choice_instr(
&mut self, &mut self,
instr: &ChoiceInstruction, instr: &ChoiceInstruction,
call_policy: &mut Box<CallPolicy>, call_policy: &mut Box<dyn CallPolicy>,
) { ) {
match instr { match instr {
&ChoiceInstruction::TryMeElse(offset) => { &ChoiceInstruction::TryMeElse(offset) => {
@@ -3341,7 +3341,7 @@ impl MachineState {
pub(super) fn execute_cut_instr( pub(super) fn execute_cut_instr(
&mut self, &mut self,
instr: &CutInstruction, instr: &CutInstruction,
cut_policy: &mut Box<CutPolicy>, cut_policy: &mut Box<dyn CutPolicy>,
) { ) {
match instr { match instr {
&CutInstruction::NeckCut => { &CutInstruction::NeckCut => {

View File

@@ -51,8 +51,8 @@ use std::sync::atomic::AtomicBool;
use termion::raw::IntoRawMode; use termion::raw::IntoRawMode;
pub struct MachinePolicies { pub struct MachinePolicies {
call_policy: Box<CallPolicy>, call_policy: Box<dyn CallPolicy>,
cut_policy: Box<CutPolicy>, cut_policy: Box<dyn CutPolicy>,
} }
lazy_static! { lazy_static! {
@@ -75,7 +75,7 @@ pub struct Machine {
pub(super) indices: IndexStore, pub(super) indices: IndexStore,
pub(super) code_repo: CodeRepo, pub(super) code_repo: CodeRepo,
pub(super) toplevel_idx: usize, pub(super) toplevel_idx: usize,
pub(super) prolog_stream: ParsingStream<Box<Read>>, pub(super) prolog_stream: ParsingStream<Box<dyn Read>>,
} }
impl Index<LocalCodePtr> for CodeRepo { impl Index<LocalCodePtr> for CodeRepo {

View File

@@ -550,8 +550,8 @@ impl MachineState {
ct: &SystemClauseType, ct: &SystemClauseType,
code_repo: &CodeRepo, code_repo: &CodeRepo,
indices: &mut IndexStore, indices: &mut IndexStore,
call_policy: &mut Box<CallPolicy>, call_policy: &mut Box<dyn CallPolicy>,
cut_policy: &mut Box<CutPolicy>, cut_policy: &mut Box<dyn CutPolicy>,
current_input_stream: &mut PrologStream, current_input_stream: &mut PrologStream,
) -> CallResult { ) -> CallResult {
match ct { match ct {

View File

@@ -23,7 +23,7 @@ impl<'a> TermRef<'a> {
} }
} }
pub type PrologStream = ParsingStream<Box<Read>>; pub type PrologStream = ParsingStream<Box<dyn Read>>;
pub mod readline { pub mod readline {
use prolog_parser::ast::*; use prolog_parser::ast::*;
@@ -116,7 +116,7 @@ pub mod readline {
#[inline] #[inline]
pub fn input_stream() -> ::PrologStream { pub fn input_stream() -> ::PrologStream {
let reader: Box<Read> = Box::new(ReadlineStream::input_stream(String::from(""))); let reader: Box<dyn Read> = Box::new(ReadlineStream::input_stream(String::from("")));
parsing_stream(reader) parsing_stream(reader)
} }
} }