From fbdd64d7e0888dd106abe8da7a7c46ec032db1ea Mon Sep 17 00:00:00 2001 From: Akshay Date: Fri, 23 Oct 2020 18:04:27 +0530 Subject: add Base module --- src/Base.hs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/Base.hs 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 @@ +module Base (Expr (..) + , Env (..) + , Function (..) + ) where + +import Data.IORef + +-- TODO: use LispNumber (src/Operators.hs) here instead of IntLiteral and FloatLiteral +-- TODO: add character literals: \#a \#b \#c \#space \#newline +-- TODO: add support for complex numbers, oct and hex numbers +data Expr = List [Expr] + | Vector [Expr] + | DottedList [Expr] Expr + | StringLiteral String + | IntLiteral Integer + | FloatLiteral Double + | BoolLiteral Bool + | Id String + deriving (Eq) + +data Function = + Function { + params :: [String] + , body :: Expr + , environment :: Env + } + +type Env = IORef [(String, IORef Expr)] + +showLispList :: [Expr] -> String +showLispList = unwords . map show + +instance Show Expr where + show (DottedList xs x) = "(" ++ showLispList xs ++ " . " ++ show x ++ ")" + show (List xs) = "(" ++ showLispList xs ++ ")" + show (Vector xs) = "#(" ++ showLispList xs ++ ")" + show (StringLiteral s) = "\"" ++ s ++ "\"" + show (IntLiteral n) = show n + show (FloatLiteral n) = show n + show (BoolLiteral True) = "#t" + show (BoolLiteral False) = "#f" + show (Id i) = i -- cgit v1.2.3