aboutsummaryrefslogtreecommitdiff
path: root/ast/CC
diff options
context:
space:
mode:
Diffstat (limited to 'ast/CC')
-rw-r--r--ast/CC/AST/Source.hs5
-rw-r--r--ast/CC/AST/Typed.hs70
-rw-r--r--ast/CC/Context.hs2
3 files changed, 40 insertions, 37 deletions
diff --git a/ast/CC/AST/Source.hs b/ast/CC/AST/Source.hs
index 3d7d5ea..11b7bc6 100644
--- a/ast/CC/AST/Source.hs
+++ b/ast/CC/AST/Source.hs
@@ -1,4 +1,7 @@
-module CC.AST.Source(module CC.AST.Source, module CC.Types) where
+module CC.AST.Source(
+ module CC.AST.Source,
+ module CC.Types
+) where
import Data.List
diff --git a/ast/CC/AST/Typed.hs b/ast/CC/AST/Typed.hs
index 537c7a4..26f7b5c 100644
--- a/ast/CC/AST/Typed.hs
+++ b/ast/CC/AST/Typed.hs
@@ -9,68 +9,68 @@ import CC.Pretty
import CC.Types
-data ProgramT = ProgramT [DefT]
+data Program = Program [Def]
deriving (Show, Read)
-data DefT = DefT Name ExprT
+data Def = Def Name Expr
deriving (Show, Read)
-data TypeT = TFunT TypeT TypeT
- | TIntT
- | TTupT [TypeT]
- | TyVar Int
+data Type = TFun Type Type
+ | TInt
+ | TTup [Type]
+ | TyVar Int
deriving (Show, Read)
-data TypeSchemeT = TypeSchemeT [Int] TypeT
+data TypeScheme = TypeScheme [Int] Type
deriving (Show, Read)
-data ExprT = LamT TypeT Occ ExprT
- | CallT TypeT ExprT ExprT
- | IntT Int
- | TupT [ExprT]
- | VarT Occ
+data Expr = Lam Type Occ Expr
+ | Call Type Expr Expr
+ | Int Int
+ | Tup [Expr]
+ | Var Occ
deriving (Show, Read)
-data Occ = Occ Name TypeT
+data Occ = Occ Name Type
deriving (Show, Read)
-exprType :: ExprT -> TypeT
-exprType (LamT typ _ _) = typ
-exprType (CallT typ _ _) = typ
-exprType (IntT _) = TIntT
-exprType (TupT es) = TTupT (map exprType es)
-exprType (VarT (Occ _ typ)) = typ
+exprType :: Expr -> Type
+exprType (Lam typ _ _) = typ
+exprType (Call typ _ _) = typ
+exprType (Int _) = TInt
+exprType (Tup es) = TTup (map exprType es)
+exprType (Var (Occ _ typ)) = typ
-instance Pretty TypeT where
- prettyPrec _ TIntT = "Int"
- prettyPrec p (TFunT a b) =
+instance Pretty Type where
+ prettyPrec _ TInt = "Int"
+ prettyPrec p (TFun a b) =
precParens p 2 (prettyPrec 3 a ++ " -> " ++ prettyPrec 2 b)
- prettyPrec _ (TTupT ts) =
+ prettyPrec _ (TTup ts) =
"(" ++ intercalate ", " (map pretty ts) ++ ")"
prettyPrec _ (TyVar i) = 't' : show i
-instance Pretty TypeSchemeT where
- prettyPrec p (TypeSchemeT bnds ty) =
+instance Pretty TypeScheme where
+ prettyPrec p (TypeScheme bnds ty) =
precParens p 2
("forall " ++ intercalate " " (map (pretty . TyVar) bnds) ++ ". " ++
prettyPrec 2 ty)
-instance Pretty ExprT where
- prettyPrec p (LamT ty (Occ n t) e) =
+instance Pretty Expr where
+ prettyPrec p (Lam ty (Occ n t) e) =
precParens p 2 $
"(\\(" ++ n ++ " :: " ++ pretty t ++ ") -> "
++ prettyPrec 2 e ++ ") :: " ++ pretty ty
- prettyPrec p (CallT ty e1 e2) =
+ prettyPrec p (Call ty e1 e2) =
precParens p 2 $
prettyPrec 3 e1 ++ " " ++ prettyPrec 3 e2 ++ " :: " ++ pretty ty
- prettyPrec _ (IntT i) = show i
- prettyPrec _ (TupT es) = "(" ++ intercalate ", " (map pretty es) ++ ")"
- prettyPrec p (VarT (Occ n t)) =
+ prettyPrec _ (Int i) = show i
+ prettyPrec _ (Tup es) = "(" ++ intercalate ", " (map pretty es) ++ ")"
+ prettyPrec p (Var (Occ n t)) =
precParens p 2 $
show n ++ " :: " ++ pretty t
-instance Pretty DefT where
- pretty (DefT n e) = n ++ " = " ++ pretty e
+instance Pretty Def where
+ pretty (Def n e) = n ++ " = " ++ pretty e
-instance Pretty ProgramT where
- pretty (ProgramT defs) = concatMap ((++ "\n") . pretty) defs
+instance Pretty Program where
+ pretty (Program defs) = concatMap ((++ "\n") . pretty) defs
diff --git a/ast/CC/Context.hs b/ast/CC/Context.hs
index 0a54392..b86685d 100644
--- a/ast/CC/Context.hs
+++ b/ast/CC/Context.hs
@@ -7,4 +7,4 @@ import CC.AST.Typed
data Context = Context FilePath Builtins
-- | Information about builtins supported by the enabled backend
-data Builtins = Builtins [(Name, TypeT)]
+data Builtins = Builtins [(Name, Type)]