provisional changes to module insertion
This commit is contained in:
35
src/main.rs
35
src/main.rs
@@ -11,22 +11,11 @@ use prolog::machine::*;
|
||||
use prolog::read::*;
|
||||
use prolog::write::*;
|
||||
|
||||
use std::io::{Write, stdout};
|
||||
use std::io::{Write, stdin, stdout};
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
fn parse_and_compile_line(wam: &mut Machine, buffer: &str)
|
||||
{
|
||||
match parse_code(wam, buffer) {
|
||||
Ok(packet) => {
|
||||
let result = compile_packet(wam, packet);
|
||||
print(wam, result);
|
||||
},
|
||||
Err(e) => print(wam, EvalSession::from(e))
|
||||
}
|
||||
}
|
||||
|
||||
fn prolog_repl() {
|
||||
let mut wam = Machine::new();
|
||||
|
||||
@@ -35,17 +24,14 @@ fn prolog_repl() {
|
||||
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))
|
||||
},
|
||||
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());
|
||||
Ok(Input::Term(term)) => {
|
||||
let result = compile_term(&mut wam, term);
|
||||
print(&mut wam, result)
|
||||
},
|
||||
Ok(Input::Batch) => {
|
||||
let stdin = stdin();
|
||||
let result = compile_user_module(&mut wam, stdin.lock());
|
||||
|
||||
print(&mut wam, result);
|
||||
},
|
||||
Ok(Input::Quit) => break,
|
||||
@@ -53,7 +39,8 @@ fn prolog_repl() {
|
||||
wam.clear();
|
||||
continue;
|
||||
},
|
||||
Err(e) => print(&mut wam, EvalSession::from(e))
|
||||
Err(e) =>
|
||||
print(&mut wam, EvalSession::from(e))
|
||||
};
|
||||
|
||||
wam.reset();
|
||||
|
||||
Reference in New Issue
Block a user