split into lib and bin

* makes most pub things in src/ pub(crate) as not to expose things accidentally
  * only those things needed by src/bin/scryer-prolog.rs and tests/scryer.rs
    should be pub
* split src/main.rs into src/lib.rs and src/bin/scryer-prolog.rs
* add tests folder and run most of the files in src/tests with cargo test
  added bytes method to Stream in src/machine/streams.rs to check if stdout is as expected
This commit is contained in:
Skgland
2021-02-25 23:24:20 +01:00
parent f935060b2b
commit 2f428b7261
35 changed files with 981 additions and 964 deletions

View File

@@ -12,7 +12,7 @@ use std::collections::VecDeque;
type SubtermDeque = VecDeque<(usize, usize)>;
pub type PrologStream = ParsingStream<Stream>;
pub(crate) type PrologStream = ParsingStream<Stream>;
pub mod readline {
use crate::machine::streams::Stream;
@@ -24,7 +24,7 @@ pub mod readline {
const HISTORY_FILE: &'static str = ".scryer_history";
pub fn set_prompt(value: bool) {
pub(crate) fn set_prompt(value: bool) {
unsafe {
PROMPT = value;
}
@@ -49,10 +49,8 @@ pub mod readline {
impl ReadlineStream {
#[inline]
pub fn new(pending_input: String) -> Self {
let config = Config::builder()
.check_cursor_position(true)
.build();
pub(crate) fn new(pending_input: String) -> Self {
let config = Config::builder().check_cursor_position(true).build();
let mut rl = Editor::<()>::with_config(config); //Editor::<()>::new();
if let Some(mut path) = dirs_next::home_dir() {
@@ -72,7 +70,7 @@ pub mod readline {
}
#[inline]
pub fn input_stream(pending_input: String) -> Stream {
pub(crate) fn input_stream(pending_input: String) -> Stream {
Stream::from(Self::new(pending_input))
}
@@ -116,7 +114,7 @@ pub mod readline {
}
}
pub fn peek_byte(&mut self) -> std::io::Result<u8> {
pub(crate) fn peek_byte(&mut self) -> std::io::Result<u8> {
set_prompt(false);
loop {
@@ -137,7 +135,7 @@ pub mod readline {
}
}
pub fn peek_char(&mut self) -> std::io::Result<char> {
pub(crate) fn peek_char(&mut self) -> std::io::Result<char> {
set_prompt(false);
loop {
@@ -176,7 +174,7 @@ pub mod readline {
}
impl MachineState {
pub fn devour_whitespace(
pub(crate) fn devour_whitespace(
&mut self,
mut inner: Stream,
atom_tbl: TabledData<Atom>,
@@ -196,7 +194,7 @@ impl MachineState {
result
}
pub fn read(
pub(crate) fn read(
&mut self,
mut inner: Stream,
atom_tbl: TabledData<Atom>,
@@ -241,7 +239,7 @@ struct TermWriter<'a> {
}
#[derive(Debug)]
pub struct TermWriteResult {
pub(crate) struct TermWriteResult {
pub(crate) heap_loc: usize,
pub(crate) var_dict: HeapVarDict,
}