summaryrefslogtreecommitdiff
path: root/assignment-13/ufpl.icl
diff options
context:
space:
mode:
Diffstat (limited to 'assignment-13/ufpl.icl')
-rw-r--r--assignment-13/ufpl.icl42
1 files changed, 28 insertions, 14 deletions
diff --git a/assignment-13/ufpl.icl b/assignment-13/ufpl.icl
index 2f6de7e..bfd8a8a 100644
--- a/assignment-13/ufpl.icl
+++ b/assignment-13/ufpl.icl
@@ -128,6 +128,18 @@ where
gen (EOr _ a b) = CEInfix "||" (gen a) (gen b)
gen (EIf b t e) = CEIf (gen b) (gen t) (gen e)
+instance gen (Shared t rw) CVar
+where
+ gen shr =
+ { name = "s" +++ shr.sname
+ , type = CTStruct (typedfun shr.stype "share")
+ , value = CEStruct
+ [ ("val", shr.srepr.map_to shr.sinit)
+ , ("dirty", CEInt 0)
+ , ("subscriptions", CEInt 0)
+ ]
+ }
+
instance gen Trigger CExpr
where
gen (Change (EShared shr)) = CEApp (typedfun shr.stype "dirty") [CERef (CEGlobal ("s" +++ shr.sname))]
@@ -158,18 +170,6 @@ where
, name = "t" +++ name
}
-instance gen (Shared t rw) CVar
-where
- gen shr =
- { name = "s" +++ shr.sname
- , type = CTStruct (typedfun shr.stype "share")
- , value = CEStruct
- [ ("val", shr.srepr.map_to shr.sinit)
- , ("dirty", CEInt 0)
- , ("subscriptions", CEInt 0)
- ]
- }
-
instance gen [NamedRule] String
where
gen rs = foldl1 (+++) $
@@ -183,8 +183,22 @@ where
genv :: ((Shared t rw) -> CVar)
genv = gen
-Start :: String
-Start = gen example_score
+instance gen NamedRule CProg
+where
+ gen r = combinePrograms zero
+ { bootstrap = ""
+ , globals = sharesMap gen (allShares r)
+ , funs = [gen r]
+ }
+
+instance gen [NamedRule] CProg
+where
+ gen rs = foldr (combinePrograms o gen) zero rs
+
+Start = printToString (genp example_score)
+where
+ genp :: (a -> CProg) | gen a CProg
+ genp = gen
example_score :: [NamedRule]
example_score =