diff options
Diffstat (limited to 'src/Evaluator.hs')
-rw-r--r-- | src/Evaluator.hs | 22 |
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 | ||
5 | import Control.Monad.Except | ||
6 | import Error (LispError (..), LispResult (..), | ||
7 | unwrap) | ||
5 | import Operators | 8 | import Operators |
6 | import Parser | 9 | import Parser |
7 | import Text.ParserCombinators.Parsec | 10 | import Text.ParserCombinators.Parsec |
8 | 11 | ||
9 | apply :: String -> [Expr] -> Expr | 12 | apply :: String -> [Expr] -> LispResult Expr |
10 | apply fn args = | 13 | apply 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 | ||
15 | eval :: Expr -> Expr | 18 | eval :: Expr -> LispResult Expr |
16 | eval v@(StringLiteral s) = v | 19 | eval v@(StringLiteral s) = return v |
17 | eval v@(IntLiteral i) = v | 20 | eval v@(IntLiteral i) = return v |
18 | eval v@(BoolLiteral b) = v | 21 | eval v@(BoolLiteral b) = return v |
19 | -- handle quotes as literals | 22 | -- handle quotes as literals |
20 | eval (List[Id "quote", val]) = val | 23 | eval (List[Id "quote", val]) = return val |
21 | eval (List (Id fn : args)) = apply fn $ map eval args | 24 | eval (List (Id fn : args)) = mapM eval args >>= apply fn |
25 | |||
26 | -- handle bad forms | ||
27 | eval idk = throwError $ BadForm "lisk can't recognize this form" idk | ||
22 | 28 | ||