diff options
Diffstat (limited to 'Sil')
-rw-r--r-- | Sil/Compile.icl | 2 | ||||
-rw-r--r-- | Sil/Parse.dcl | 2 | ||||
-rw-r--r-- | Sil/Parse.icl | 4 | ||||
-rw-r--r-- | Sil/Syntax.dcl | 10 | ||||
-rw-r--r-- | Sil/Syntax.icl | 52 | ||||
-rw-r--r-- | Sil/Util/Parser.dcl (renamed from Sil/Parse/Parser.dcl) | 2 | ||||
-rw-r--r-- | Sil/Util/Parser.icl (renamed from Sil/Parse/Parser.icl) | 2 | ||||
-rw-r--r-- | Sil/Util/Printer.dcl (renamed from Sil/Util.dcl) | 8 | ||||
-rw-r--r-- | Sil/Util/Printer.icl (renamed from Sil/Util.icl) | 48 |
9 files changed, 71 insertions, 59 deletions
diff --git a/Sil/Compile.icl b/Sil/Compile.icl index 4c0d02d..42fa162 100644 --- a/Sil/Compile.icl +++ b/Sil/Compile.icl @@ -19,7 +19,7 @@ from Text import <+ import qualified ABC.Assembler as ABC import Sil.Syntax -import Sil.Util +import Sil.Util.Printer instance toString CompileError where diff --git a/Sil/Parse.dcl b/Sil/Parse.dcl index 0d00969..73f9ad3 100644 --- a/Sil/Parse.dcl +++ b/Sil/Parse.dcl @@ -4,8 +4,8 @@ from StdOverloaded import class ==, class toString from Data.Error import :: MaybeError -from Sil.Parse.Parser import class name from Sil.Syntax import :: Program, :: Literal +from Sil.Util.Parser import class name :: Token = TParenOpen //* ( diff --git a/Sil/Parse.icl b/Sil/Parse.icl index 092d3da..3a11622 100644 --- a/Sil/Parse.icl +++ b/Sil/Parse.icl @@ -20,9 +20,9 @@ from Text import <+, class Text, instance Text String import GenEq -import Sil.Parse.Parser import Sil.Syntax -import Sil.Util +import Sil.Util.Parser +import Sil.Util.Printer derive gEq Token, Literal instance == Token where == a b = gEq{|*|} a b diff --git a/Sil/Syntax.dcl b/Sil/Syntax.dcl index 6df64a3..5c91dc6 100644 --- a/Sil/Syntax.dcl +++ b/Sil/Syntax.dcl @@ -1,5 +1,7 @@ definition module Sil.Syntax +from StdOverloaded import class toString + from Data.Maybe import :: Maybe :: Program = @@ -66,3 +68,11 @@ from Data.Maybe import :: Maybe | ILit Int :: Name :== String + +instance toString Statement +instance toString Type +instance toString Arg +instance toString Application +instance toString Op1 +instance toString Op2 +instance toString Literal 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 diff --git a/Sil/Parse/Parser.dcl b/Sil/Util/Parser.dcl index cdeaf49..361fa83 100644 --- a/Sil/Parse/Parser.dcl +++ b/Sil/Util/Parser.dcl @@ -1,4 +1,4 @@ -definition module Sil.Parse.Parser +definition module Sil.Util.Parser from StdOverloaded import class == diff --git a/Sil/Parse/Parser.icl b/Sil/Util/Parser.icl index 52956a3..f0895fe 100644 --- a/Sil/Parse/Parser.icl +++ b/Sil/Util/Parser.icl @@ -1,4 +1,4 @@ -implementation module Sil.Parse.Parser +implementation module Sil.Util.Parser import StdList import StdOverloaded diff --git a/Sil/Util.dcl b/Sil/Util/Printer.dcl index 54617ce..1d8fc5c 100644 --- a/Sil/Util.dcl +++ b/Sil/Util/Printer.dcl @@ -1,4 +1,4 @@ -definition module Sil.Util +definition module Sil.Util.Printer from StdOverloaded import class toString, class zero @@ -14,14 +14,10 @@ class PrettyPrinter t where print :: PrintState t -> String instance PrettyPrinter [Token] - instance PrettyPrinter Program instance PrettyPrinter Function instance PrettyPrinter CodeBlock instance PrettyPrinter Initialisation instance PrettyPrinter Statement -instance toString Statement -instance toString Type -instance toString Application -instance toString Literal +printersperse :: a [b] -> String | toString a & toString b diff --git a/Sil/Util.icl b/Sil/Util/Printer.icl index 35b8522..2252ee4 100644 --- a/Sil/Util.icl +++ b/Sil/Util/Printer.icl @@ -1,4 +1,4 @@ -implementation module Sil.Util +implementation module Sil.Util.Printer import _SystemArray import StdEnum @@ -99,52 +99,6 @@ where 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 (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 - printersperse :: a [b] -> String | toString a & toString b printersperse _ [] = "" printersperse _ [x] = toString x |