summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--assignment-13/C.dcl1
-rw-r--r--assignment-13/C.icl9
-rw-r--r--assignment-13/Util.dcl2
-rw-r--r--assignment-13/Util.icl4
-rw-r--r--assignment-13/ufpl.icl6
5 files changed, 16 insertions, 6 deletions
diff --git a/assignment-13/C.dcl b/assignment-13/C.dcl
index 88b048f..1ec912a 100644
--- a/assignment-13/C.dcl
+++ b/assignment-13/C.dcl
@@ -29,6 +29,7 @@ from Util import class print
| CEIf CExpr CExpr CExpr
| CERef CExpr
| CEDeref CExpr
+ | CEStruct [(String, CExpr)]
:: CBody
= CBReturn (Maybe CExpr)
diff --git a/assignment-13/C.icl b/assignment-13/C.icl
index 328802f..5091def 100644
--- a/assignment-13/C.icl
+++ b/assignment-13/C.icl
@@ -1,6 +1,7 @@
implementation module C
from StdFunc import id, o
+import StdList
import StdString
import StdTuple
@@ -60,13 +61,17 @@ where
print (CEButton b) = print b
print (CEGlobal g) = print g
print (CEInfix op a b) = print "(" o print a o print ") " o print op o print " (" o print b o print ")"
- print (CEApp f ps) = print f o print "(" o prsperse ", " ps o print ")"
+ print (CEApp f ps) = print f o print "(" o prsperse (print ", ") ps o print ")"
print (CEBool b) = print (if b "true" "false")
print (CEInt i) = print i
print (CEChar c) = print "'" o print (toString c) o print "'"
print (CEIf b t e) = print "(" o print b o print " ? " o print t o print " : " o print e o print ")"
print (CERef e) = print "&(" o print e o print ")"
print (CEDeref e) = print "*(" o print e o print ")"
+ print (CEStruct m) = print "{" o indent o nl o prsperse (print "," o nl) (map pr m) o unindent o nl o print "}"
+ where
+ pr :: (String, CExpr) -> String
+ pr (s, e) = "." +++ s +++ " = " +++ printToString e
instance print CBody
where
@@ -89,5 +94,5 @@ where
instance print CFun
where
print cf = print cf.CFun.type o print " " o print cf.CFun.name
- o print "(" o prsperse ", " cf.params o print ") {" o indent o nl
+ o print "(" o prsperse (print ", ") cf.params o print ") {" o indent o nl
o print cf.body o unindent o nl o print "}"
diff --git a/assignment-13/Util.dcl b/assignment-13/Util.dcl
index 11ad93e..baef165 100644
--- a/assignment-13/Util.dcl
+++ b/assignment-13/Util.dcl
@@ -16,4 +16,4 @@ nl :: PrState -> PrState
indent :: PrState -> PrState
unindent :: PrState -> PrState
-prsperse :: a [b] -> PrState -> PrState | print a & print b
+prsperse :: (PrState -> PrState) [a] -> PrState -> PrState | print a
diff --git a/assignment-13/Util.icl b/assignment-13/Util.icl
index 7775601..ba7de9f 100644
--- a/assignment-13/Util.icl
+++ b/assignment-13/Util.icl
@@ -31,7 +31,7 @@ indent st = {st & indent=max 0 (st.indent - 1)}
unindent :: PrState -> PrState
unindent st = {st & indent=st.indent + 1}
-prsperse :: a [b] -> PrState -> PrState | print a & print b
+prsperse :: (PrState -> PrState) [a] -> PrState -> PrState | print a
prsperse _ [] = id
prsperse _ [x] = print x
-prsperse g [x:xs] = print x o print g o prsperse g xs
+prsperse g [x:xs] = print x o g o prsperse g xs
diff --git a/assignment-13/ufpl.icl b/assignment-13/ufpl.icl
index 73d1ff0..2f6de7e 100644
--- a/assignment-13/ufpl.icl
+++ b/assignment-13/ufpl.icl
@@ -163,7 +163,11 @@ where
gen shr =
{ name = "s" +++ shr.sname
, type = CTStruct (typedfun shr.stype "share")
- , value = shr.srepr.map_to shr.sinit
+ , value = CEStruct
+ [ ("val", shr.srepr.map_to shr.sinit)
+ , ("dirty", CEInt 0)
+ , ("subscriptions", CEInt 0)
+ ]
}
instance gen [NamedRule] String