In order to translate C macros to Haskell code, hs-bindgen needs to
imbue C macros with a semantics. This project c-expr provides one such
semantics.
-
The semantics of expressions is based on C arithmetic expressions, implementing the integral-promotion and arithmetic-conversion rules of the C standard.
-
The semantics of types is based on
typedefs.
This project c-expr is the main macro language used by hs-bindgen, but
can be used independently.
See Section 5.2 c-expr: a DSL for C Expressions in Cardwell, Derbyshire & de
Vries, and Schrempf (2025) Automatic C Bindings Generation for Haskell
(DOI,
PDF).
-
c-expr-dsl: a library that provides a DSL for the expression and type language implemented inc-expr: a Parsec-based parser turninglibclangmacro tokens into a syntax tree, and a typechecker. -
c-expr-runtime: a library that provides runtime support for this DSL. It is the semantic core: a type-level universe of C types and a class-per-operator hierarchy whose associated type families encode C's conversion rules. For example, addition is defined with the following type class, where the result typeAddResis computed according to the C standard's arithmetic-conversion rules:infixl 2 + type Add :: Type -> Type -> Constraint class Add a b where type family AddRes a b :: Type (+) :: a -> b -> AddRes a b
Platform-specific instances (e.g.,
AddRes CInt CFloat = CDouble) are generated via Template Haskell.
Our thanks go to those who have contributed to this project with development,
bug reports, feature requests, blog posts, etc. We list
contributors
in the hs-bindgen README.