summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs44
1 files changed, 36 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs
index dbc60fb..62a3562 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3,33 +3,61 @@ use macroquad::prelude::*;
use std::{cell::RefCell, rc::Rc};
use rust_lisp::default_env;
+use rust_lisp::lisp;
use rust_lisp::parser::parse;
use rust_lisp::interpreter::eval;
+use rust_lisp::model::{Symbol, Value};
+mod extended_environment;
#[macroquad::main("BasicShapes")]
async fn main() {
// create a base environment
let env = Rc::new(RefCell::new(default_env()));
+ // define new methods
+ extended_environment::extend_environment(&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();
+ // 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();
+ // let evaluation_result = eval(env.clone(), &first_expression).unwrap();
+ // let mut ast_iter = parse("(test_draw)");
+ // let first_expression = ast_iter.next().unwrap().unwrap();
+
+ // let first_expression = lisp! {(test_draw)};
+
+ // let mut inc = parse("(begin (set a 0) (+ a 1))");
+ // let mut inc = parse("(begin (define a 0) (set a (+ a 1)))");
+ // let inc_exp = inc.next().unwrap().unwrap();
+
+ // let inc_exp = lisp! {
+ // (begin (define a 0) (set a (+ a 1)))
+ // };
+ // eval(env.clone(), &inc_exp).unwrap();
- // use result
- println!("{}", &evaluation_result);
+ // let inc_exp = lisp! {
+ // (set a (+ a 1))
+ // };
+
+ let gol_exp = parse(include_str!("../scripts/main.el"));
+ for exp in gol_exp {
+ eval(env.clone(), &exp.unwrap()).unwrap();
+ }
+
+ // let mut inc = parse("(set a (+ a 1))");
+ // let inc_exp = inc.next().unwrap().unwrap();
loop {
clear_background(RED);
draw_line(40.0, 40.0, 100.0, 200.0, 15.0, BLUE);
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(&format!("IT WORKS! {}!", &evaluation_result), 20.0, 20.0, 30.0, DARKGRAY);
+ eval(env.clone(), &first_expression).unwrap();
+ let inc_eval = eval(env.clone(), &inc_exp).unwrap();
+ draw_text(&format!("IT WORKS! {}!", &inc_eval), 20.0, 20.0, 30.0, DARKGRAY);
next_frame().await
}