diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs index 6b82d49..dbc60fb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,27 @@ use macroquad::prelude::*; +use std::{cell::RefCell, rc::Rc}; + +use rust_lisp::default_env; +use rust_lisp::parser::parse; +use rust_lisp::interpreter::eval; + #[macroquad::main("BasicShapes")] async fn main() { + // create a base environment + let env = Rc::new(RefCell::new(default_env())); + + // parse into an iterator of syntax trees (one for each root) + let mut ast_iter = parse("(+ \"Hello \" \"world!\")"); + let first_expression = ast_iter.next().unwrap().unwrap(); + + // evaluate + let evaluation_result = eval(env.clone(), &first_expression).unwrap(); + + // use result + println!("{}", &evaluation_result); + loop { clear_background(RED); @@ -10,7 +29,7 @@ async fn main() { draw_rectangle(screen_width() / 2.0 - 60.0, 100.0, 120.0, 60.0, GREEN); draw_circle(screen_width() - 30.0, screen_height() - 30.0, 15.0, YELLOW); - draw_text("IT WORKS!", 20.0, 20.0, 30.0, DARKGRAY); + draw_text(&format!("IT WORKS! {}!", &evaluation_result), 20.0, 20.0, 30.0, DARKGRAY); next_frame().await } |