blob: 10e5e584a27bc245f52935687cfffb3ecd96840e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
module Evaluator (
eval
) where
import Control.Monad.Except
import Error (LispError (..), LispResult (..),
unwrap)
import Operators
import Parser
import Text.ParserCombinators.Parsec
apply :: String -> [Expr] -> LispResult Expr
apply fn args = maybe
(throwError $ UnknownFunction fn)
($ args)
(lookup fn primitives)
eval :: Expr -> LispResult Expr
eval v@(StringLiteral s) = return v
eval v@(IntLiteral i) = return v
eval v@(BoolLiteral b) = return v
eval v@(FloatLiteral f) = return v
-- handle quotes as literals
eval (List[Id "quote", val]) = return val
eval (List[Id "quasiquote", val]) = undefined
eval (List[Id "unquote", val]) = undefined
eval (List (Id fn : args)) = mapM eval args >>= apply fn
-- handle bad forms
eval invalidForm = throwError $ BadForm "lisk can't recognize this form" invalidForm
|