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
- data Sym sig where
- Lit :: String -> a -> Sym (Full a)
- Const :: String -> a -> Sym (Full a)
- Fun :: Signature sig => 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)
- WithCode :: SupportCode -> Sym (a :-> Full a)
- type SupportCode = forall m. MonadC m => m ()
- 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 :: forall t. () => forall a. (CType (DenResult (Full t)), (~#) * * (Full t) (Full a)) => a -> CExp t
- pattern LitP' :: forall t. () => forall a. (CType (DenResult t), (~#) * * t (Full a)) => a -> AST T t
- pattern NonLitP :: forall a. CExp a
- pattern NonLitP' :: forall a. ASTF T a
- pattern OpP :: forall t. () => forall a a1 a2 b c. (CType (DenResult ((:->) a1 ((:->) a (Full t)))), (~#) * * ((:->) a1 ((:->) a (Full t))) ((:->) a2 ((:->) b (Full c)))) => Binary (a2 -> b -> c) -> AST T (Full a1) -> AST T (Full a) -> CExp t
- pattern OpP' :: forall t. () => forall a a1 a2 b c. (CType (DenResult ((:->) a1 ((:->) a t))), (~#) * * ((:->) a1 ((:->) a t)) ((:->) a2 ((:->) b (Full c)))) => Binary (a2 -> b -> c) -> AST T (Full a1) -> AST T (Full a) -> AST T t
- pattern UOpP :: forall t. () => forall a a1 b. (CType (DenResult ((:->) a (Full t))), (~#) * * ((:->) a (Full t)) ((:->) a1 (Full b))) => Unary (a1 -> b) -> AST T (Full a) -> CExp t
- pattern UOpP' :: forall t. () => forall a a1 b. (CType (DenResult ((:->) a t)), (~#) * * ((:->) a t) ((:->) a1 (Full b))) => Unary (a1 -> 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 => String -> a -> CExp a
- variable :: CType a => VarId -> CExp a
- withCode :: CType a => (forall m. MonadC m => m ()) -> CExp 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
- 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 #
Syntactic symbols for C
Lit :: String -> a -> Sym (Full a) | |
Const :: String -> a -> Sym (Full a) | |
Fun :: Signature sig => 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) | |
WithCode :: SupportCode -> Sym (a :-> Full a) |
type SupportCode = forall m. MonadC m => m () Source #
C expression
EvalExp CExp Source # | |
FreeExp CExp Source # | |
CompExp CExp Source # | |
Eq (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 FreePred CExp Source # | |
type Internal (CExp a) Source # | |
type Domain (CExp a) 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 LitP :: forall t. () => forall a. (CType (DenResult (Full t)), (~#) * * (Full t) (Full a)) => a -> CExp t Source #
pattern LitP' :: forall t. () => forall a. (CType (DenResult t), (~#) * * t (Full a)) => a -> AST T t Source #
pattern OpP :: forall t. () => forall a a1 a2 b c. (CType (DenResult ((:->) a1 ((:->) a (Full t)))), (~#) * * ((:->) a1 ((:->) a (Full t))) ((:->) a2 ((:->) b (Full c)))) => Binary (a2 -> b -> c) -> AST T (Full a1) -> AST T (Full a) -> CExp t Source #
pattern OpP' :: forall t. () => forall a a1 a2 b c. (CType (DenResult ((:->) a1 ((:->) a t))), (~#) * * ((:->) a1 ((:->) a t)) ((:->) a2 ((:->) b (Full c)))) => Binary (a2 -> b -> c) -> AST T (Full a1) -> AST T (Full a) -> AST T t Source #
pattern UOpP :: forall t. () => forall a a1 b. (CType (DenResult ((:->) a (Full t))), (~#) * * ((:->) a (Full t)) ((:->) a1 (Full b))) => Unary (a1 -> b) -> AST T (Full a) -> CExp t Source #
pattern UOpP' :: forall t. () => forall a a1 b. (CType (DenResult ((:->) a t)), (~#) * * ((:->) a t) ((:->) a1 (Full b))) => Unary (a1 -> 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
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