aboutsummaryrefslogtreecommitdiff
path: root/src/Evaluator.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Evaluator.hs')
-rw-r--r--src/Evaluator.hs22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/Evaluator.hs b/src/Evaluator.hs
index f264ee0..28ee79b 100644
--- a/src/Evaluator.hs
+++ b/src/Evaluator.hs
@@ -2,21 +2,27 @@ module Evaluator (
2 eval 2 eval
3 ) where 3 ) where
4 4
5import Control.Monad.Except
6import Error (LispError (..), LispResult (..),
7 unwrap)
5import Operators 8import Operators
6import Parser 9import Parser
7import Text.ParserCombinators.Parsec 10import Text.ParserCombinators.Parsec
8 11
9apply :: String -> [Expr] -> Expr 12apply :: String -> [Expr] -> LispResult Expr
10apply fn args = 13apply fn args =
11 case lookup fn primitives of 14 case lookup fn primitives of
12 Just f -> f args 15 Just f -> f args
13 _ -> BoolLiteral False -- TODO: error out instead 16 _ -> throwError $ UnknownFunction fn
14 17
15eval :: Expr -> Expr 18eval :: Expr -> LispResult Expr
16eval v@(StringLiteral s) = v 19eval v@(StringLiteral s) = return v
17eval v@(IntLiteral i) = v 20eval v@(IntLiteral i) = return v
18eval v@(BoolLiteral b) = v 21eval v@(BoolLiteral b) = return v
19-- handle quotes as literals 22-- handle quotes as literals
20eval (List[Id "quote", val]) = val 23eval (List[Id "quote", val]) = return val
21eval (List (Id fn : args)) = apply fn $ map eval args 24eval (List (Id fn : args)) = mapM eval args >>= apply fn
25
26-- handle bad forms
27eval idk = throwError $ BadForm "lisk can't recognize this form" idk
22 28