module Language.Paraiso.Generator.Claris (
Program(..),
FileType(..),
Statement(..),
Preprocessing(..),
TypeRep(..), typeOf, toDyn,
Class(..), MemberDef(..), AccessModifier(..),
Function(..), function,
Qualifier(..),
Var(..),
Expr(..), Parenthesis(..)
) where
import qualified Algebra.Additive as Additive
import qualified Algebra.Ring as Ring
import qualified Algebra.IntegralDomain as IntegralDomain
import qualified Algebra.Field as Field
import qualified Data.Dynamic as Dyn
import Language.Paraiso.Name
import Language.Paraiso.Prelude
import NumericPrelude
data Program
= Program
{ progName :: Name,
topLevel :: [Statement]
}
deriving (Show)
instance Nameable Program where name = progName
data FileType
= HeaderFile
| SourceFile
deriving (Eq, Show)
data Statement
= StmtPrpr Preprocessing
| UsingNamespace Name
| ClassDef Class
| FuncDef Function
| VarDef Var
| VarDefCon Var [Expr]
| VarDefSub Var Expr
| StmtExpr Expr
| StmtWhile Expr [Statement]
| StmtFor Statement Expr Expr
[Statement]
| StmtReturn Expr
| Exclusive FileType Statement
| RawStatement Text
| Comment Text
deriving (Eq, Show)
data Preprocessing
= PrprInclude Parenthesis Text
| PrprPragma Text
deriving (Eq, Show)
data Class
= Class
{ className :: Name,
classMember :: [MemberDef]
}
deriving (Eq, Show)
instance Nameable Class where name = className
data MemberDef
= MemberFunc
{ memberAccess :: AccessModifier,
inlined :: Bool,
memberFunc :: Function
}
| MemberVar
{ memberAccess :: AccessModifier,
memberVar :: Var
}
deriving (Eq, Show)
data AccessModifier = Private | Protected | Public
deriving (Eq, Show)
data Function
= Function
{ funcName :: Name,
funcType :: TypeRep,
funcArgs :: [Var],
funcBody :: [Statement],
funcMemberInitializer :: [Expr]
}
deriving (Eq, Show)
instance Nameable Function where name = funcName
function :: TypeRep -> Name -> Function
function tr na = Function
{ funcName = na,
funcType = tr,
funcArgs = [],
funcBody = [],
funcMemberInitializer = []
}
data TypeRep
= UnitType Dyn.TypeRep
| PtrOf TypeRep
| RefOf TypeRep
| Const TypeRep
| TemplateType Text [TypeRep]
| QualifiedType [Qualifier] TypeRep
| ConstructorType
| UnknownType
deriving (Eq, Show)
data Qualifier
= CudaGlobal
| CudaDevice
| CudaHost
| CudaShared
| CudaConst
deriving (Eq, Show)
data Var = Var TypeRep Name deriving (Eq, Show)
instance Nameable Var where name (Var _ x) = x
data Expr
= Imm Dyn.Dynamic
| VarExpr Var
| FuncCallUsr Name [Expr]
| FuncCallStd Text [Expr]
| CudaFuncCallUsr Name Expr Expr [Expr]
| MemberAccess Expr Expr
| Op1Prefix Text Expr
| Op1Postfix Text Expr
| Op2Infix Text Expr Expr
| Op3Infix Text Text Expr Expr Expr
| ArrayAccess Expr Expr
| CommentExpr Text Expr
deriving (Show)
instance Eq Expr where
(==)_ _= error "cannot compare Expr."
instance Additive.C Expr where
zero = toDyn (0::Int)
(+) = Op2Infix "+"
() = Op2Infix "-"
negate = Op1Prefix "-"
instance Ring.C Expr where
one = toDyn (1::Int)
(*) = Op2Infix "*"
fromInteger = toDyn
instance Field.C Expr where
(/) = Op2Infix "/"
recip = Op1Prefix "1/"
fromRational' x = let
dx :: Double
dx = fromRational' x
in toDyn dx
instance IntegralDomain.C Expr where
div = Op2Infix "/"
mod = Op2Infix "%"
typeOf :: (Dyn.Typeable a) => a -> TypeRep
typeOf = UnitType . Dyn.typeOf
toDyn :: (Dyn.Typeable a) => a -> Expr
toDyn = Imm . Dyn.toDyn
data Parenthesis
= Paren
| Bracket
| Brace
| Chevron
| Chevron2
| Chevron3
| Quotation
| Quotation2
| SlashStar
deriving (Eq, Show)