summaryrefslogtreecommitdiff
path: root/ast.hs
diff options
context:
space:
mode:
Diffstat (limited to 'ast.hs')
-rw-r--r--ast.hs9
1 files changed, 7 insertions, 2 deletions
diff --git a/ast.hs b/ast.hs
index e3db600..f566335 100644
--- a/ast.hs
+++ b/ast.hs
@@ -31,6 +31,8 @@ data Type = TypeInt Int
| TypeDouble
| TypePtr Type
| TypeName Name
+ | TypeFunc Type [Type]
+ | TypeVoid
deriving (Show, Eq)
data Literal = LitInt Integer
@@ -63,7 +65,7 @@ data Statement
| StAssignment Name Expression
| StIf Expression Statement Statement
| StWhile Expression Statement
- | StReturn Expression
+ | StReturn (Maybe Expression)
deriving (Show)
@@ -116,6 +118,8 @@ instance PShow Type where
pshow TypeDouble = "double"
pshow (TypePtr t) = concat ["ptr(", pshow t, ")"]
pshow (TypeName n) = n
+ pshow TypeVoid = "void"
+ pshow (TypeFunc ret args) = concat ["func ", pshow ret, "("] ++ intercalate "," (map pshow args) ++ ")"
instance PShow Literal where
pshow (LitInt i) = pshow i
@@ -164,4 +168,5 @@ instance PShow Statement where
pshow (StIf c t@(StBlock _) e) = concat ["if (", pshow c, ") ", pshow t, " else ", pshow e]
pshow (StIf c t e) = concat ["if (", pshow c, ") ", pshow t, "\nelse ", pshow e]
pshow (StWhile c s) = concat ["while (", pshow c, ") ", pshow s]
- pshow (StReturn e) = concat ["return ", pshow e, ";"]
+ pshow (StReturn Nothing) = "return;"
+ pshow (StReturn (Just e)) = concat ["return ", pshow e, ";"]