From dc902a1cd718770bffcecfa4fffa8142db37a7e6 Mon Sep 17 00:00:00 2001 From: Akshay Date: Fri, 2 Apr 2021 10:16:42 +0530 Subject: add rylander dithering, `define` macro, begin work on guides. --- src/lisp/prelude.rs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'src/lisp') 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 @@ -26,6 +26,13 @@ macro_rules! primitive { }; } +#[macro_export] +macro_rules! define { + ($env:expr, $name:expr, $value:expr) => { + let _ = $env.insert($name.to_string(), $value); + }; +} + #[macro_export] macro_rules! type_match { ($args:expr, $($range:literal => $kind:pat),+) => { @@ -54,6 +61,8 @@ macro_rules! type_match { pub fn new_env() -> Result { let mut env = Environment::new(); + define!(env, "else", LispExpr::BoolLit(true)); + primitive!(env, Arity::Atleast(2), "+", |args, _| { let nums = args .into_iter() @@ -98,11 +107,6 @@ pub fn new_env() -> Result { Ok(LispExpr::Number(acc)) }); - primitive!(env, Arity::Exact(0), "toggle-grid", |_, app| { - app.toggle_grid(); - Ok(LispExpr::Unit) - }); - primitive!(env, Arity::Atleast(2), "and", |args, _| { if args .iter() @@ -252,6 +256,15 @@ pub fn new_env() -> Result { } }); + primitive!(env, Arity::Exact(0), "grid-enabled?", |_, app| { + Ok(LispExpr::BoolLit(app.grid.enabled)) + }); + + primitive!(env, Arity::Exact(1), "set-grid!", |args, app| { + app.grid.enabled = args[0].cast_bool(); + Ok(LispExpr::Unit) + }); + primitive!(env, Arity::Exact(0), "brush-fill", |_, app| { app.brush = Brush::Fill; return Ok(LispExpr::Unit); -- cgit v1.2.3