aboutsummaryrefslogtreecommitdiff
path: root/src/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lisp')
-rw-r--r--src/lisp/error.rs2
-rw-r--r--src/lisp/eval.rs1
-rw-r--r--src/lisp/expr.rs1
-rw-r--r--src/lisp/prelude.rs21
4 files changed, 24 insertions, 1 deletions
diff --git a/src/lisp/error.rs b/src/lisp/error.rs
index b90e211..a360eb2 100644
--- a/src/lisp/error.rs
+++ b/src/lisp/error.rs
@@ -90,6 +90,7 @@ pub enum EvalError {
90 DivByZero, 90 DivByZero,
91 TypeMismatch, 91 TypeMismatch,
92 NoFileName, 92 NoFileName,
93 CustomInternal(&'static str),
93} 94}
94 95
95impl fmt::Display for EvalError { 96impl fmt::Display for EvalError {
@@ -112,6 +113,7 @@ impl fmt::Display for EvalError {
112 Self::TypeMismatch => write!(f, "mismatched types"), 113 Self::TypeMismatch => write!(f, "mismatched types"),
113 Self::DivByZero => write!(f, "attempt to divide by zero"), 114 Self::DivByZero => write!(f, "attempt to divide by zero"),
114 Self::NoFileName => write!(f, "no file name specified"), 115 Self::NoFileName => write!(f, "no file name specified"),
116 Self::CustomInternal(s) => write!(f, "{}", s),
115 } 117 }
116 } 118 }
117} 119}
diff --git a/src/lisp/eval.rs b/src/lisp/eval.rs
index 370b624..6ffff23 100644
--- a/src/lisp/eval.rs
+++ b/src/lisp/eval.rs
@@ -20,6 +20,7 @@ pub fn eval(expr: &LispExpr, app: &mut AppState) -> Result<LispExpr, LispError>
20 LispExpr::Number(_) => Ok(expr.clone()), 20 LispExpr::Number(_) => Ok(expr.clone()),
21 LispExpr::BoolLit(_) => Ok(expr.clone()), 21 LispExpr::BoolLit(_) => Ok(expr.clone()),
22 LispExpr::Ident(ref id) => lookup_extended(&app.lisp_env, id), 22 LispExpr::Ident(ref id) => lookup_extended(&app.lisp_env, id),
23 LispExpr::Quote(_, _) => Ok(expr.clone()),
23 LispExpr::List(li) => { 24 LispExpr::List(li) => {
24 let func_expr = &li[0]; 25 let func_expr = &li[0];
25 match func_expr { 26 match func_expr {
diff --git a/src/lisp/expr.rs b/src/lisp/expr.rs
index 40420a1..9ef9f65 100644
--- a/src/lisp/expr.rs
+++ b/src/lisp/expr.rs
@@ -222,6 +222,7 @@ impl AsRef<str> for LispExpr {
222 fn as_ref(&self) -> &str { 222 fn as_ref(&self) -> &str {
223 match self { 223 match self {
224 LispExpr::StringLit(i) => &i, 224 LispExpr::StringLit(i) => &i,
225 LispExpr::Ident(i) => &i,
225 _ => panic!("invalid downcast!"), 226 _ => panic!("invalid downcast!"),
226 } 227 }
227 } 228 }
diff --git a/src/lisp/prelude.rs b/src/lisp/prelude.rs
index 6153e4f..d2a6ae6 100644
--- a/src/lisp/prelude.rs
+++ b/src/lisp/prelude.rs
@@ -1,7 +1,8 @@
1use crate::{ 1use crate::{
2 brush::Brush,
2 lisp::{ 3 lisp::{
3 error::{EvalError, LispError}, 4 error::{EvalError, LispError},
4 expr::{Arity, LispExpr}, 5 expr::{is_ident, Arity, LispExpr},
5 number::LispNumber, 6 number::LispNumber,
6 Environment, 7 Environment,
7 }, 8 },
@@ -193,5 +194,23 @@ pub fn new_env() -> Environment {
193 return Ok(LispExpr::Unit); 194 return Ok(LispExpr::Unit);
194 }); 195 });
195 196
197 primitive!(env, Arity::Atmost(1), "brush", |args, app| {
198 info!("brush {}", &args[0]);
199 if let [LispExpr::Quote(kind, _)] = args {
200 if is_ident(kind) {
201 match (&**kind).as_ref() {
202 "fill" => app.brush = Brush::Fill,
203 "circle" => app.brush = Brush::new(),
204 "line" => app.brush = Brush::line(0, false),
205 "line-extend" => app.brush = Brush::line(0, true),
206 _ => return Err(EvalError::CustomInternal("unknown brush type").into()),
207 }
208 }
209 } else {
210 return Err(EvalError::TypeMismatch.into());
211 }
212 return Ok(LispExpr::Unit);
213 });
214
196 env 215 env
197} 216}