remove use statements from main.rs that temporary replaced extern crate and fixed paths that previously used them

This commit is contained in:
Skgland
2021-02-06 19:30:46 +01:00
parent b53ef148a0
commit 8e5954f36f
29 changed files with 302 additions and 430 deletions

View File

@@ -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<Stream>;
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<usize> {
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,
}
}
}