aboutsummaryrefslogtreecommitdiff
path: root/src/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lisp')
-rw-r--r--src/lisp/prelude.rs23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/lisp/prelude.rs b/src/lisp/prelude.rs
index 4a6a4ed..372bb00 100644
--- a/src/lisp/prelude.rs
+++ b/src/lisp/prelude.rs
@@ -27,6 +27,13 @@ macro_rules! primitive {
27} 27}
28 28
29#[macro_export] 29#[macro_export]
30macro_rules! define {
31 ($env:expr, $name:expr, $value:expr) => {
32 let _ = $env.insert($name.to_string(), $value);
33 };
34}
35
36#[macro_export]
30macro_rules! type_match { 37macro_rules! type_match {
31 ($args:expr, $($range:literal => $kind:pat),+) => { 38 ($args:expr, $($range:literal => $kind:pat),+) => {
32 { 39 {
@@ -54,6 +61,8 @@ macro_rules! type_match {
54pub fn new_env() -> Result<Environment, LispError> { 61pub fn new_env() -> Result<Environment, LispError> {
55 let mut env = Environment::new(); 62 let mut env = Environment::new();
56 63
64 define!(env, "else", LispExpr::BoolLit(true));
65
57 primitive!(env, Arity::Atleast(2), "+", |args, _| { 66 primitive!(env, Arity::Atleast(2), "+", |args, _| {
58 let nums = args 67 let nums = args
59 .into_iter() 68 .into_iter()
@@ -98,11 +107,6 @@ pub fn new_env() -> Result<Environment, LispError> {
98 Ok(LispExpr::Number(acc)) 107 Ok(LispExpr::Number(acc))
99 }); 108 });
100 109
101 primitive!(env, Arity::Exact(0), "toggle-grid", |_, app| {
102 app.toggle_grid();
103 Ok(LispExpr::Unit)
104 });
105
106 primitive!(env, Arity::Atleast(2), "and", |args, _| { 110 primitive!(env, Arity::Atleast(2), "and", |args, _| {
107 if args 111 if args
108 .iter() 112 .iter()
@@ -252,6 +256,15 @@ pub fn new_env() -> Result<Environment, LispError> {
252 } 256 }
253 }); 257 });
254 258
259 primitive!(env, Arity::Exact(0), "grid-enabled?", |_, app| {
260 Ok(LispExpr::BoolLit(app.grid.enabled))
261 });
262
263 primitive!(env, Arity::Exact(1), "set-grid!", |args, app| {
264 app.grid.enabled = args[0].cast_bool();
265 Ok(LispExpr::Unit)
266 });
267
255 primitive!(env, Arity::Exact(0), "brush-fill", |_, app| { 268 primitive!(env, Arity::Exact(0), "brush-fill", |_, app| {
256 app.brush = Brush::Fill; 269 app.brush = Brush::Fill;
257 return Ok(LispExpr::Unit); 270 return Ok(LispExpr::Unit);