From d951a11b1141b9f4c1ee50c7f89b68c552883c16 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Fri, 24 Jul 2020 22:24:44 +0200 Subject: Move CC.{Source,Typed} to CC.AST.* --- ast/CC/AST/Source.hs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 ast/CC/AST/Source.hs (limited to 'ast/CC/AST/Source.hs') diff --git a/ast/CC/AST/Source.hs b/ast/CC/AST/Source.hs new file mode 100644 index 0000000..3d7d5ea --- /dev/null +++ b/ast/CC/AST/Source.hs @@ -0,0 +1,47 @@ +module CC.AST.Source(module CC.AST.Source, module CC.Types) where + +import Data.List + +import CC.Pretty +import CC.Types + + +data Program = Program [Decl] + deriving (Show, Read) + +data Decl = Def Def -- import? + deriving (Show, Read) + +data Def = Function (Maybe Type) + (Name, SourceRange) + [(Name, SourceRange)] + Expr + deriving (Show, Read) + +data Type = TFun Type Type + | TInt + | TTup [Type] + deriving (Show, Read) + +data Expr = Lam SourceRange [(Name, SourceRange)] Expr + | Call SourceRange Expr Expr + | Int SourceRange Int + | Tup SourceRange [Expr] + | Var SourceRange Name + | Annot SourceRange Expr Type + deriving (Show, Read) + +instance Pretty Type where + prettyPrec _ TInt = "Int" + prettyPrec p (TFun a b) = + precParens p 2 (prettyPrec 3 a ++ " -> " ++ prettyPrec 2 b) + prettyPrec _ (TTup ts) = + "(" ++ intercalate ", " (map pretty ts) ++ ")" + +instance HasRange Expr where + range (Lam sr _ _) = sr + range (Call sr _ _) = sr + range (Int sr _) = sr + range (Tup sr _) = sr + range (Var sr _) = sr + range (Annot sr _ _) = sr -- cgit v1.2.3-54-g00ecf