diff options
Diffstat (limited to 'Sil/Syntax.icl')
-rw-r--r-- | Sil/Syntax.icl | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/Sil/Syntax.icl b/Sil/Syntax.icl index 522412b..934a300 100644 --- a/Sil/Syntax.icl +++ b/Sil/Syntax.icl @@ -1,3 +1,55 @@ implementation module Sil.Syntax +import StdOverloaded +import StdString +import Data.Maybe +import Text + +import Sil.Util.Printer + +instance toString Statement +where + toString (Declaration n a) = n <+ " := " <+ 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 +where + toString TBool = "Bool" + toString TInt = "Int" + toString TVoid = "Void" + +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 (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 + toString (BLit b) = toString b + toString (ILit i) = toString i |