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 | Let SourceRange (Name, SourceRange) Expr 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 (Let sr _ _ _) = sr range (Call sr _ _) = sr range (Int sr _) = sr range (Tup sr _) = sr range (Var sr _) = sr range (Annot sr _ _) = sr