aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-10-23 13:34:27 +0100
committerAkshay <[email protected]>2020-10-23 13:34:27 +0100
commitfbdd64d7e0888dd106abe8da7a7c46ec032db1ea (patch)
treee237a9a151583ccf2daf1f116572d737f1259455
parent494078074e5f620f11f72e48d0fc44cff73faaf2 (diff)
add Base module
-rw-r--r--src/Base.hs42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/Base.hs b/src/Base.hs
new file mode 100644
index 0000000..08131e8
--- /dev/null
+++ b/src/Base.hs
@@ -0,0 +1,42 @@
1module Base (Expr (..)
2 , Env (..)
3 , Function (..)
4 ) where
5
6import Data.IORef
7
8-- TODO: use LispNumber (src/Operators.hs) here instead of IntLiteral and FloatLiteral
9-- TODO: add character literals: \#a \#b \#c \#space \#newline
10-- TODO: add support for complex numbers, oct and hex numbers
11data Expr = List [Expr]
12 | Vector [Expr]
13 | DottedList [Expr] Expr
14 | StringLiteral String
15 | IntLiteral Integer
16 | FloatLiteral Double
17 | BoolLiteral Bool
18 | Id String
19 deriving (Eq)
20
21data Function =
22 Function {
23 params :: [String]
24 , body :: Expr
25 , environment :: Env
26 }
27
28type Env = IORef [(String, IORef Expr)]
29
30showLispList :: [Expr] -> String
31showLispList = unwords . map show
32
33instance Show Expr where
34 show (DottedList xs x) = "(" ++ showLispList xs ++ " . " ++ show x ++ ")"
35 show (List xs) = "(" ++ showLispList xs ++ ")"
36 show (Vector xs) = "#(" ++ showLispList xs ++ ")"
37 show (StringLiteral s) = "\"" ++ s ++ "\""
38 show (IntLiteral n) = show n
39 show (FloatLiteral n) = show n
40 show (BoolLiteral True) = "#t"
41 show (BoolLiteral False) = "#f"
42 show (Id i) = i