aboutsummaryrefslogtreecommitdiff
path: root/Sil/Util.icl
diff options
context:
space:
mode:
Diffstat (limited to 'Sil/Util.icl')
-rw-r--r--Sil/Util.icl49
1 files changed, 41 insertions, 8 deletions
diff --git a/Sil/Util.icl b/Sil/Util.icl
index ad7cfac..35b8522 100644
--- a/Sil/Util.icl
+++ b/Sil/Util.icl
@@ -22,6 +22,12 @@ import Sil.Syntax
instance zero PrintState where zero = {indent=0}
+incIndent :: PrintState -> PrintState
+incIndent ps = {ps & indent=inc ps.indent}
+
+decIndent :: PrintState -> PrintState
+decIndent ps = {ps & indent=dec ps.indent}
+
instance toString PrintState where toString st = {'\t' \\ _ <- [1..st.indent]}
instance PrettyPrinter [Token]
@@ -83,14 +89,24 @@ instance PrettyPrinter Initialisation
where
print st init = st <+ init.init_type <+ " " <+ init.init_name <+ ";"
-instance PrettyPrinter Statement where print st stm = st <+ stm <+ ";"
+instance PrettyPrinter Statement
+where
+ print st (If c t Nothing) = st <+ "if (" <+ c <+ ") {\r\n" <+
+ print (incIndent st) t <+ "\r\n" <+ st <+ "}"
+ print st (If c t (Just e)) = st <+ "if (" <+ c <+ ") {\r\n" <+
+ print st` t <+ "\r\n" <+ st <+ "} else {\r\n" <+
+ print st` e <+ "\r\n" <+ st <+ "}"
+ where st` = incIndent st
+ print st stm = st <+ stm
instance toString Statement
where
- toString (Declaration n a) = n <+ " " <+ TAssign <+ " " <+ a
- toString (Application app) = toString app
- toString (Return Nothing) = "return"
- toString (Return (Just a)) = "return " <+ a <+ ""
+ toString (Declaration n a) = n <+ " " <+ TAssign <+ " " <+ a <+ ";"
+ toString (Application app) = toString app <+ ";"
+ toString (Return Nothing) = "return;"
+ toString (Return (Just a)) = "return " <+ a <+ ";"
+ toString (If c t e) = "if (" <+ c <+ ") ..."
+ toString (MachineStm s) = "|~" <+ s
toString _ = "<<unimplemented Statement>>"
instance toString Type
@@ -103,9 +119,26 @@ instance toString Arg where toString arg = arg.arg_type <+ " " <+ arg.arg_name
instance toString Application
where
- toString (Name n) = n
- toString (Literal lit) = toString lit
- toString (App n args) = n <+ "(" <+ printersperse ", " args <+ ")"
+ toString (Name n) = n
+ toString (Literal lit) = toString lit
+ toString (App n args) = n <+ "(" <+ printersperse ", " args <+ ")"
+ toString (BuiltinApp op e) = op <+ "(" <+ e <+ ")"
+ toString (BuiltinApp2 e1 op e2) = "(" <+ e1 <+ ") " <+ op <+ " (" <+ e2 <+ ")"
+
+instance toString Op1
+where
+ toString Neg = "~"
+
+instance toString Op2
+where
+ toString Add = "+"
+ toString Sub = "-"
+ toString Mul = "*"
+ toString Div = "/"
+ toString Rem = "%"
+ toString Equals = "=="
+ toString LogOr = "||"
+ toString LogAnd = "&&"
instance toString Literal
where