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.)
- class (Show a, Eq a, Typeable a) => CType a where
- pCType :: Proxy CType
- isFloat :: forall a. CType a => CExp a -> Bool
- isExact :: CType a => CExp a -> Bool
- data Sym sig where
- 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
- viewLit :: CExp a -> Maybe a
- castAST :: forall a b. Typeable b => ASTF T a -> Maybe (ASTF T b)
- variable :: CType a => String -> CExp a
- value :: CType a => a -> 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
- i2n :: (Integral a, Num b, CType b) => CExp a -> CExp b
- not_ :: 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
Types
class (Show a, Eq a, Typeable a) => CType a where Source
Types supported by C
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
Expressions
Syntactic symbols for C
C expression
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
User interface
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