2023-09-12 11:21:51 +00:00
|
|
|
use std::io::{self, Write};
|
|
|
|
|
2023-09-19 14:15:40 +00:00
|
|
|
mod evaluator;
|
2024-05-04 19:23:06 +00:00
|
|
|
mod node;
|
2023-09-13 12:47:24 +00:00
|
|
|
mod parser;
|
|
|
|
|
2023-09-12 11:21:51 +00:00
|
|
|
fn main() {
|
2023-09-19 14:15:40 +00:00
|
|
|
let env = evaluator::core_environment();
|
2023-09-12 11:21:51 +00:00
|
|
|
let mut input = String::new();
|
|
|
|
|
2024-03-09 12:55:17 +00:00
|
|
|
println!("Mute -- REPL");
|
2023-09-12 11:21:51 +00:00
|
|
|
|
|
|
|
loop {
|
|
|
|
print!("> ");
|
|
|
|
io::stdout().flush().expect("failed to write to stdout");
|
|
|
|
|
|
|
|
let bytes_read = io::stdin()
|
|
|
|
.read_line(&mut input)
|
|
|
|
.expect("failed to read from stdin");
|
|
|
|
|
|
|
|
if bytes_read == 0 {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-05-04 17:13:34 +00:00
|
|
|
let ast = parser::parse_str(&input).unwrap();
|
2024-02-17 11:52:14 +00:00
|
|
|
let res = evaluator::eval(env.clone(), ast);
|
2023-09-12 11:21:51 +00:00
|
|
|
|
2024-02-17 11:52:14 +00:00
|
|
|
match res {
|
|
|
|
Ok(expressions) => expressions.into_iter().for_each(|expr| println!("{expr}")),
|
|
|
|
Err(err) => println!("{}", err.to_string()),
|
2023-09-19 12:17:13 +00:00
|
|
|
}
|
2023-09-12 11:21:51 +00:00
|
|
|
|
|
|
|
input.clear();
|
|
|
|
}
|
|
|
|
}
|