make use of read_term in the repl
This commit is contained in:
36
src/main.rs
36
src/main.rs
@@ -7,8 +7,11 @@ use prolog::instructions::*;
|
||||
mod prolog;
|
||||
|
||||
use prolog::compile::*;
|
||||
use prolog::io::*;
|
||||
use prolog::machine::*;
|
||||
use prolog::read::*;
|
||||
use prolog::write::*;
|
||||
|
||||
use std::io::{Write, stdout};
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
@@ -20,7 +23,7 @@ fn parse_and_compile_line(wam: &mut Machine, buffer: &str)
|
||||
let result = compile_packet(wam, packet);
|
||||
print(wam, result);
|
||||
},
|
||||
Err(s) => println!("{:?}", s)
|
||||
Err(e) => print(wam, EvalSession::from(e))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,19 +32,28 @@ fn prolog_repl() {
|
||||
|
||||
loop {
|
||||
print!("prolog> ");
|
||||
|
||||
match read() {
|
||||
Input::Line(line) => parse_and_compile_line(&mut wam, line.as_str()),
|
||||
Input::Batch(batch) =>
|
||||
match compile_user_module(&mut wam, batch.as_str()) {
|
||||
EvalSession::Error(e) => println!("{}", e),
|
||||
_ => {}
|
||||
stdout().flush().unwrap();
|
||||
|
||||
match read_toplevel(&mut wam) {
|
||||
Ok(Input::Term(term)) =>
|
||||
match compile_term(&mut wam, term) {
|
||||
Ok(packet) => {
|
||||
let result = compile_packet(&mut wam, packet);
|
||||
print(&mut wam, result);
|
||||
},
|
||||
Err(e) => print(&mut wam, EvalSession::from(e))
|
||||
},
|
||||
Input::Quit => break,
|
||||
Input::Clear => {
|
||||
Ok(Input::Line(line)) => parse_and_compile_line(&mut wam, line.as_str()),
|
||||
Ok(Input::Batch(batch)) => {
|
||||
let result = compile_user_module(&mut wam, batch.as_bytes());
|
||||
print(&mut wam, result);
|
||||
},
|
||||
Ok(Input::Quit) => break,
|
||||
Ok(Input::Clear) => {
|
||||
wam.clear();
|
||||
continue;
|
||||
}
|
||||
},
|
||||
Err(e) => print(&mut wam, EvalSession::from(e))
|
||||
};
|
||||
|
||||
wam.reset();
|
||||
|
||||
Reference in New Issue
Block a user