From 9181292651a8b48b84c200679bb1fb2c5d3e005c Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Sun, 1 Nov 2020 20:15:07 +0000 Subject: [PATCH] Print debug data of reader and evaluator on the rep --- Makefile | 12 ++++++++++++ bootstrap/src/core.rs | 15 +++++++++++---- bootstrap/src/errors.rs | 1 + bootstrap/src/main.rs | 8 -------- bootstrap/src/repl.rs | 5 +++-- 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 0e91481..cbecf97 100644 --- a/Makefile +++ b/Makefile @@ -10,3 +10,15 @@ test-bootstrap: .PHONY: test test: test-bootstrap + + +.PHONY: clean-bootstrap +clean-bootstrap: + cd $(THIS_DIR)/bootstrap && cargo clean + +.PHONY: bootstrap-repl +bootstrap-repl: + cd $(THIS_DIR)/bootstrap && cargo run repl + +.PHONY: clean +clean: clean-bootstrap diff --git a/bootstrap/src/core.rs b/bootstrap/src/core.rs index 64a3d88..4934358 100644 --- a/bootstrap/src/core.rs +++ b/bootstrap/src/core.rs @@ -24,18 +24,25 @@ fn eval_expr(rt: &RT, scope: &Scope, expr: Expr) -> PossibleExpr { Ok(expr) } -pub fn eval(rt: &RT, scope: &Scope, exprs: Vec) -> PossibleExpr { +pub fn eval(rt: &RT, exprs: Vec) -> PossibleExpr { match exprs.last() { Some(e) => Ok(e.clone()), _ => Err(err("NotImplemented".to_string())), } } -pub fn rep(rt: &RT, scope: &Scope, input: &str) { +pub fn read_eval_print(rt: &RT, input: &str) { match read_string(input) { Ok(exprs) => { - let result_expr = eval(rt, scope, exprs); - println!("<<"); + if rt.is_debug() { + println!("Read Result: \n{:?}\n", exprs); + } + + let result_expr = eval(rt, exprs); + + if rt.is_debug() { + println!("Eval Result: \n{:?}\n", result_expr); + } } Err(e) => println!("Error: {}", e), } diff --git a/bootstrap/src/errors.rs b/bootstrap/src/errors.rs index 5a00447..5387b0a 100644 --- a/bootstrap/src/errors.rs +++ b/bootstrap/src/errors.rs @@ -19,6 +19,7 @@ pub trait IError { fn message(&self) -> &str; } +#[derive(Debug)] pub struct Error { msg: String, } diff --git a/bootstrap/src/main.rs b/bootstrap/src/main.rs index 86763d8..d27058a 100644 --- a/bootstrap/src/main.rs +++ b/bootstrap/src/main.rs @@ -15,10 +15,7 @@ * along with this program. If not, see . */ use clap::{load_yaml, App, ArgMatches}; -use std::fs::File; use std::io; -use std::io::prelude::*; -use std::string::String; pub mod ast; pub mod builtins; @@ -50,11 +47,6 @@ fn main() -> io::Result<()> { let yaml = load_yaml!("cli.yml"); let app = App::from(yaml); - // let rt = runtime::RT::new(); - - // rt.create_ns("user".to_string(), None); - // rt.set_current_ns("user".to_string()); - match app.get_matches().subcommand() { Some(("repl", args)) => repl(args.clone()), Some(("run", args)) => println!("repl, {:?}", args), diff --git a/bootstrap/src/repl.rs b/bootstrap/src/repl.rs index 3dc1fe5..9b447b1 100644 --- a/bootstrap/src/repl.rs +++ b/bootstrap/src/repl.rs @@ -13,7 +13,8 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . -*/ + */ +use crate::core::read_eval_print; use crate::runtime::RT; use rustyline::error::ReadlineError; use rustyline::Editor; @@ -32,7 +33,7 @@ pub fn repl(rt: RT) { match readline { Ok(line) => { rl.add_history_entry(line.as_str()); - println!("Line: {}", line); + read_eval_print(&rt, &line); } Err(ReadlineError::Interrupted) => { println!("CTRL-C");