summaryrefslogtreecommitdiff
path: root/assignment-13/uFPL/C.dcl
diff options
context:
space:
mode:
authorCamil Staps2018-01-03 09:24:21 +0100
committerCamil Staps2018-01-03 09:24:21 +0100
commit33db1946d2a09898761b7d397fe4028725f2215b (patch)
tree1f68cb8b276b7a20f42f325c76e6d4853ea8e68f /assignment-13/uFPL/C.dcl
parentCleanup (diff)
Rename & restructure
Diffstat (limited to 'assignment-13/uFPL/C.dcl')
-rw-r--r--assignment-13/uFPL/C.dcl73
1 files changed, 73 insertions, 0 deletions
diff --git a/assignment-13/uFPL/C.dcl b/assignment-13/uFPL/C.dcl
new file mode 100644
index 0000000..f9d3595
--- /dev/null
+++ b/assignment-13/uFPL/C.dcl
@@ -0,0 +1,73 @@
+definition module uFPL.C
+
+from Data.Maybe import :: Maybe
+
+from uFPL.Arduino import :: Button
+from uFPL.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
+ | CEStruct [(String, 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
+ }
+
+:: CProg =
+ { bootstrap :: String
+ , globals :: [CVar]
+ , funs :: [CFun]
+ }
+
+instance print Signedness
+instance print CType
+instance print CExpr
+instance print CBody
+instance print CVar
+instance print CFun
+instance print CProg
+
+combinePrograms :: CProg CProg -> CProg