summaryrefslogtreecommitdiff
path: root/assignment-13/C.dcl
diff options
context:
space:
mode:
authorCamil Staps2018-01-02 22:28:13 +0100
committerCamil Staps2018-01-02 22:28:13 +0100
commit82b4d838ee16fea80bfc0da630603273f7cba6c2 (patch)
tree1762a3ae13ae7b9758325606e301176ee1c61a67 /assignment-13/C.dcl
parentRemove value from cashModel; add further explanation to gastje (diff)
Start with assignment 13
Diffstat (limited to 'assignment-13/C.dcl')
-rw-r--r--assignment-13/C.dcl71
1 files changed, 71 insertions, 0 deletions
diff --git a/assignment-13/C.dcl b/assignment-13/C.dcl
new file mode 100644
index 0000000..88b048f
--- /dev/null
+++ b/assignment-13/C.dcl
@@ -0,0 +1,71 @@
+definition module C
+
+from Data.Maybe import :: Maybe
+
+from Arduino import :: Button
+from Util import class print
+
+:: Signedness = Sig | Unsig
+
+:: CType
+ = CTChar Signedness
+ | CTBool
+ | CTInt Signedness
+ | CTLong Signedness
+ | CTVoid
+ | CTArray CType
+ | CTStruct String
+
+:: CExpr
+ = CEButton Button
+ | CEGlobal String
+ | CEInfix String CExpr CExpr
+ | CEApp String [CExpr]
+ | CEBool Bool
+ | CEInt Int
+ | CEChar Char
+ | CEBArray Int [Bool]
+ | CEIArray Int [Int]
+ | CEIf CExpr CExpr CExpr
+ | CERef CExpr
+ | CEDeref CExpr
+
+:: CBody
+ = CBReturn (Maybe CExpr)
+ | CBIf CExpr CBody CBody
+ | CBWhile CExpr CBody
+ | CBAssign String CExpr
+ | CBSeq CBody CBody
+ | CBEmpty
+ | CBExpr CExpr
+
+(`seq`) infix 0 :: CBody CBody -> CBody
+
+:: CVar =
+ { name :: String
+ , type :: CType
+ , value :: CExpr
+ }
+
+:: CFun =
+ { params :: [(Int, CType)]
+ , body :: CBody
+ , fresh :: Int
+ , type :: CType
+ , name :: String
+ }
+
+:: CG t p = CG (CFun -> (t, CFun))
+
+unCG :: (CG t p) -> CFun -> (t, CFun)
+cg :: (CG t p) -> CFun
+
+(>>-) infixl 1 :: (CG a p) (a -> CG b q) -> CG b q
+return :: (a -> CG a p)
+
+instance print Signedness
+instance print CType
+instance print CExpr
+instance print CBody
+instance print CVar
+instance print CFun