Safe Haskell | None |
---|---|
Language | Haskell2010 |
Typed deep embedding of simple C expressions
This is a subset of C expressions that only have simple non-compound and non-pointed types, and that don't contain any control structures.
(Of course, nothing stops one from translating CExp
to something other than
C, but its constructors and set of supported types is inspired by C.)
- data Unary a where
- evalUnary :: Unary a -> a
- unaryOp :: Unary a -> UnOp
- data Binary a where
- BiAdd :: Num a => Binary (a -> a -> a)
- BiSub :: Num a => Binary (a -> a -> a)
- BiMul :: Num a => Binary (a -> a -> a)
- BiDiv :: Fractional a => Binary (a -> a -> a)
- BiQuot :: Integral a => Binary (a -> a -> a)
- BiRem :: Integral a => Binary (a -> a -> a)
- BiAnd :: Binary (Bool -> Bool -> Bool)
- BiOr :: Binary (Bool -> Bool -> Bool)
- BiEq :: CType a => Binary (a -> a -> Bool)
- BiNEq :: CType a => Binary (a -> a -> Bool)
- BiLt :: (Ord a, CType a) => Binary (a -> a -> Bool)
- BiGt :: (Ord a, CType a) => Binary (a -> a -> Bool)
- BiLe :: (Ord a, CType a) => Binary (a -> a -> Bool)
- BiGe :: (Ord a, CType a) => Binary (a -> a -> Bool)
- evalBinary :: Binary a -> a
- binaryOp :: Binary a -> BinOp
- type SupportCode = forall m. MonadC m => m ()
- data Sym sig where
- Lit :: String -> a -> Sym (Full a)
- Const :: SupportCode -> String -> a -> Sym (Full a)
- Fun :: Signature sig => SupportCode -> String -> Denotation sig -> Sym sig
- UOp :: Unary (a -> b) -> Sym (a :-> Full b)
- Op :: Binary (a -> b -> c) -> Sym (a :-> (b :-> Full c))
- Cast :: (a -> b) -> Sym (a :-> Full b)
- Cond :: Sym (Bool :-> (a :-> (a :-> Full a)))
- Var :: VarId -> Sym (Full a)
- ArrIx :: (Integral i, Ix i) => IArr i a -> Sym (i :-> Full a)
- data T sig where
- newtype CExp a = CExp {}
- evalSym :: Sym sig -> Denotation sig
- evalCExp :: CExp a -> a
- compCExp :: forall m a. MonadC m => CExp a -> m Exp
- constFold :: CExp a -> CExp a
- castAST :: forall a b. Typeable b => ASTF T a -> Maybe (ASTF T b)
- viewLit :: CExp a -> Maybe a
- pattern LitP :: (CType (DenResult (Full t)), (~) * (Full t) (Full a)) => a -> CExp t
- pattern LitP' :: (CType (DenResult t), (~) * t (Full a)) => a -> AST T t
- pattern NonLitP :: CExp a
- pattern NonLitP' :: ASTF T a
- pattern OpP :: (CType (DenResult ((:->) a ((:->) a (Full t)))), (~) * ((:->) a ((:->) a (Full t))) ((:->) a ((:->) b (Full c)))) => Binary (a -> b -> c) -> AST T (Full a) -> AST T (Full a) -> CExp t
- pattern OpP' :: (CType (DenResult ((:->) a ((:->) a t))), (~) * ((:->) a ((:->) a t)) ((:->) a ((:->) b (Full c)))) => Binary (a -> b -> c) -> AST T (Full a) -> AST T (Full a) -> AST T t
- pattern UOpP :: (CType (DenResult ((:->) a (Full t))), (~) * ((:->) a (Full t)) ((:->) a (Full b))) => Unary (a -> b) -> AST T (Full a) -> CExp t
- pattern UOpP' :: (CType (DenResult ((:->) a t)), (~) * ((:->) a t) ((:->) a (Full b))) => Unary (a -> b) -> AST T (Full a) -> AST T t
- isFloat :: forall a. CType a => CExp a -> Bool
- isExact :: CType a => CExp a -> Bool
- isExact' :: CType a => ASTF T a -> Bool
- value :: CType a => a -> CExp a
- constant :: CType a => SupportCode -> String -> a -> CExp a
- variable :: CType a => VarId -> CExp a
- true :: CExp Bool
- false :: CExp Bool
- quot_ :: (Integral a, CType a) => CExp a -> CExp a -> CExp a
- (#%) :: (Integral a, CType a) => CExp a -> CExp a -> CExp a
- round_ :: (RealFrac a, Integral b, CType b) => CExp a -> CExp b
- i2n :: (Integral a, Num b, CType b) => CExp a -> CExp b
- i2b :: Integral a => CExp a -> CExp Bool
- b2i :: (Integral a, CType a) => CExp Bool -> CExp a
- not_ :: CExp Bool -> CExp Bool
- (#&&) :: CExp Bool -> CExp Bool -> CExp Bool
- (#||) :: CExp Bool -> CExp Bool -> CExp Bool
- (#==) :: (Eq a, CType a) => CExp a -> CExp a -> CExp Bool
- (#!=) :: (Eq a, CType a) => CExp a -> CExp a -> CExp Bool
- (#<) :: (Ord a, CType a) => CExp a -> CExp a -> CExp Bool
- (#>) :: (Ord a, CType a) => CExp a -> CExp a -> CExp Bool
- (#<=) :: (Ord a, CType a) => CExp a -> CExp a -> CExp Bool
- (#>=) :: (Ord a, CType a) => CExp a -> CExp a -> CExp Bool
- cond :: CType a => CExp Bool -> CExp a -> CExp a -> CExp a
- (?) :: CType a => CExp Bool -> CExp a -> CExp a -> CExp a
- (#!) :: (CType a, Integral i, Ix i) => IArr i a -> CExp i -> CExp a
Expressions
BiAdd :: Num a => Binary (a -> a -> a) | |
BiSub :: Num a => Binary (a -> a -> a) | |
BiMul :: Num a => Binary (a -> a -> a) | |
BiDiv :: Fractional a => Binary (a -> a -> a) | |
BiQuot :: Integral a => Binary (a -> a -> a) | |
BiRem :: Integral a => Binary (a -> a -> a) | |
BiAnd :: Binary (Bool -> Bool -> Bool) | |
BiOr :: Binary (Bool -> Bool -> Bool) | |
BiEq :: CType a => Binary (a -> a -> Bool) | |
BiNEq :: CType a => Binary (a -> a -> Bool) | |
BiLt :: (Ord a, CType a) => Binary (a -> a -> Bool) | |
BiGt :: (Ord a, CType a) => Binary (a -> a -> Bool) | |
BiLe :: (Ord a, CType a) => Binary (a -> a -> Bool) | |
BiGe :: (Ord a, CType a) => Binary (a -> a -> Bool) |
evalBinary :: Binary a -> a Source
type SupportCode = forall m. MonadC m => m () Source
Syntactic symbols for C
Lit :: String -> a -> Sym (Full a) | |
Const :: SupportCode -> String -> a -> Sym (Full a) | |
Fun :: Signature sig => SupportCode -> String -> Denotation sig -> Sym sig | |
UOp :: Unary (a -> b) -> Sym (a :-> Full b) | |
Op :: Binary (a -> b -> c) -> Sym (a :-> (b :-> Full c)) | |
Cast :: (a -> b) -> Sym (a :-> Full b) | |
Cond :: Sym (Bool :-> (a :-> (a :-> Full a))) | |
Var :: VarId -> Sym (Full a) | |
ArrIx :: (Integral i, Ix i) => IArr i a -> Sym (i :-> Full a) |
C expression
EvalExp CExp Source | |
FreeExp CExp Source | |
CompExp CExp Source | |
Eq (CExp a) Source | |
(Floating a, Ord a, CType a) => Floating (CExp a) Source | |
(Fractional a, Ord a, CType a) => Fractional (CExp a) Source | |
(Num a, Ord a, CType a) => Num (CExp a) Source | |
Syntactic (CExp a) Source | |
type VarPred CExp = CType Source | |
type Internal (CExp a) = a Source | |
type Domain (CExp a) = T Source |
evalSym :: Sym sig -> Denotation sig Source
constFold :: CExp a -> CExp a Source
One-level constant folding: if all immediate sub-expressions are literals, the expression is reduced to a single literal
pattern OpP :: (CType (DenResult ((:->) a ((:->) a (Full t)))), (~) * ((:->) a ((:->) a (Full t))) ((:->) a ((:->) b (Full c)))) => Binary (a -> b -> c) -> AST T (Full a) -> AST T (Full a) -> CExp t Source
pattern OpP' :: (CType (DenResult ((:->) a ((:->) a t))), (~) * ((:->) a ((:->) a t)) ((:->) a ((:->) b (Full c)))) => Binary (a -> b -> c) -> AST T (Full a) -> AST T (Full a) -> AST T t Source
pattern UOpP :: (CType (DenResult ((:->) a (Full t))), (~) * ((:->) a (Full t)) ((:->) a (Full b))) => Unary (a -> b) -> AST T (Full a) -> CExp t Source
pattern UOpP' :: (CType (DenResult ((:->) a t)), (~) * ((:->) a t) ((:->) a (Full b))) => Unary (a -> b) -> AST T (Full a) -> AST T t Source
isFloat :: forall a. CType a => CExp a -> Bool Source
Return whether the type of the expression is a floating-point numeric type
isExact :: CType a => CExp a -> Bool Source
Return whether the type of the expression is a non-floating-point type
isExact' :: CType a => ASTF T a -> Bool Source
Return whether the type of the expression is a non-floating-point type
User interface
:: CType a | |
=> SupportCode | Supporting C code |
-> String | Name of constant |
-> a | Value of constant |
-> CExp a |
Predefined constant
quot_ :: (Integral a, CType a) => CExp a -> CExp a -> CExp a Source
Integer division truncated toward zero
(#%) :: (Integral a, CType a) => CExp a -> CExp a -> CExp a Source
Integer remainder satisfying
(x `quot_` y)*y + (x #% y) == x
Conditional expression
Condition operator; use as follows:
cond1 ? a $ cond2 ? b $ cond3 ? c $ default