Safe Haskell | None |
---|---|
Language | Haskell98 |
Core Public API (provisional, to be refactored)
Intended for constructing basic Core Programs. Use the binary serialization from Binary
to produce a core file, which can be compiled by UHC.
Restrictions:
- Extendable data types are not supported
- Generated code is not (type-)checked, might cause runtime crashes
- Core parsing/Pretty printing is incomplete and might be partially broken.
TODO: - Constructor applications (mkCon) always have to be fully saturated. (move to acoreTagTup) - Haskell constructor names must be unambigous per module (mkHSCTag)
- data CModule
- data CImport
- data CExport
- data CDeclMeta
- data CDataCon
- data CExpr
- data CBind
- data CAlt
- data CPat
- data CPatFld
- mkUnit :: EHCOpts -> CExpr
- mkInt :: EHCOpts -> Int -> CExpr
- mkInteger :: EHCOpts -> Integer -> CExpr
- mkString :: EHCOpts -> String -> CExpr
- mkError :: EHCOpts -> String -> CExpr
- mkUndefined :: EHCOpts -> CExpr
- mkVar :: HsName -> CExpr
- mkLet1Plain :: HsName -> CExpr -> CExpr -> CExpr
- mkLet1Strict :: HsName -> CExpr -> CExpr -> CExpr
- mkLetRec :: [CBind] -> CExpr -> CExpr
- mkLam :: [HsName] -> CExpr -> CExpr
- mkApp :: CExpr -> [CExpr] -> CExpr
- mkBind1 :: HsName -> CExpr -> CBind
- mkBind1Nm1 :: HsName -> CBind
- mkCTag :: HsName -> HsName -> Int -> Int -> CTag
- destructCTag :: a -> (HsName -> HsName -> Int -> Int -> a) -> CTag -> a
- ctagUnit :: CTag
- ctagTup :: CTag
- ctagTrue :: EHCOpts -> CTag
- ctagFalse :: EHCOpts -> CTag
- ctagCons :: EHCOpts -> CTag
- ctagNil :: EHCOpts -> CTag
- mkCaseDflt :: CExpr -> [CAlt] -> Maybe CExpr -> CExpr
- mkAlt :: CPat -> CExpr -> CAlt
- mkPatCon :: CTag -> CPatRest -> [CPatFld] -> CPat
- mkPatRestEmpty :: CPatRest
- mkPatFldBind :: (HsName, CExpr) -> CBind -> CPatFld
- mkTagTup :: CTag -> [CExpr] -> CExpr
- mkModule :: HsName -> [CExport] -> [CImport] -> [CDeclMeta] -> CExpr -> CModule
- mkImport :: HsName -> CImport
- mkExport :: HsName -> CExport
- mkMetaData :: HsName -> [CDataCon] -> CDeclMeta
- mkMetaDataCon :: HsName -> Int -> Int -> CDataCon
- mkMetaDataConFromCTag :: CTag -> Maybe CDataCon
- mkMain :: HsName -> CExpr
- parseExpr :: EHCOpts -> String -> Either [String] CExpr
- printModule :: EHCOpts -> CModule -> PP_Doc
- module UHC.Light.Compiler.Base.API
Core AST
The datatypes making up a Core program.
Construction functions
Constants
Creates a string expression. The expression represents a packed String, which can be passed to Haskell generated Core functions.
Generates an error expression, failing with the given string when evaluated. (error
in haskell)
mkUndefined :: EHCOpts -> CExpr Source
Generates an undefined expression, failing when evaluated. (undefined
in haskell)
Variables
Let Bindings
Creates a (non-recursive) let binding.
:: HsName | The identifer. |
-> CExpr | The expression to bind. Will be evaluated to WHNF, before the body is evaluated. |
-> CExpr | The body. |
-> CExpr |
Creates a let binding, which is strict in the bound expression.
Creates a let binding, where the bindings may be mutually recursive.
Abstraction
Application
Applies the first expression to all given arguments.
Binds/Bounds
mkBind1Nm1 :: HsName -> CBind Source
Constructor tags
:: HsName | Fully qualified Datatype name. |
-> HsName | Fully qualified Constructor name. |
-> Int | Tag number. |
-> Int | Arity. |
-> CTag |
Creates a constructor tag.
:: a | Algebra for record/tuple case. |
-> (HsName -> HsName -> Int -> Int -> a) | Algebra for datatype case. Order of arguments is the same as in |
-> CTag | |
-> a |
Destruct a CTag
.
Case
Scrutinizes an expression and executes the appropriate alternative. The scrutinee of a case statement is required to be in WHNF (weak head normal form).
:: CExpr | The scrutinee. Required to be in WHNF. |
-> [CAlt] | The alternatives. |
-> Maybe CExpr | The default value. (TODO what is the behaviour if it is Nothing?) |
-> CExpr |
A Case expression, possibly with a default value.
:: CPat | The pattern with which to match the case scrutinee. |
-> CExpr | The value of this alternative. |
-> CAlt |
Creates an alternative of a case statement.
Matches the case scrutinee with the given constructor tag.
mkPatRestEmpty :: CPatRest Source
patrest, empty TODO what does it mean?
Datatypes
mkTagTup :: CTag -> [CExpr] -> CExpr Source
Creates a new tuple/record with the given values. Has to be fully applied, partial application is not allowed.
Module
:: HsName | The name of the module. |
-> [CExport] | The exports. |
-> [CImport] | The imports (only direct imports, not transitive ones). |
-> [CDeclMeta] | The meta information. |
-> CExpr | The body of the module. |
-> CModule |
Creates a module.
Creates the metadata for one datatype.
:: HsName | The fully qualified name of the constructor. |
-> Int | The tag of this constructor. |
-> Int | The arity of this constructor. |
-> CDataCon |
Creates the metadata for one constructor.
Utilities
Creates the main entry point, calling the given function when run. The given function to call has to be in scope (either define it in the same module, or import it). In addition, the module UHC.Run has to be imported!
printModule :: EHCOpts -> CModule -> PP_Doc Source
Re-exports (or not???)
module UHC.Light.Compiler.Base.API