uhc-light-1.1.7.3: Part of UHC packaged as cabal/hackage installable library

Safe HaskellNone
LanguageHaskell98

UHC.Light.Compiler.Core.API

Contents

Description

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)

Synopsis

Core AST

The datatypes making up a Core program.

data CExpr Source

Instances

Eq CExpr 
Data CExpr 
Show CExpr

Explicit dummy instances instead of derived ones which not really are used except as context for PP

Serialize CExpr 
PP CExpr 
Typeable * CExpr 

Construction functions

Constants

mkUnit :: EHCOpts -> CExpr Source

Creates the unit expresssion.

mkInt :: EHCOpts -> Int -> CExpr Source

Creates an Int constant.

mkInteger Source

Arguments

:: EHCOpts 
-> Integer

The integer.

-> CExpr 

Creates a Core Integer constant.

mkString Source

Arguments

:: EHCOpts 
-> String

The string.

-> CExpr 

Creates a string expression. The expression represents a packed String, which can be passed to Haskell generated Core functions.

mkError Source

Arguments

:: EHCOpts 
-> String

The error message.

-> CExpr 

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

mkVar :: HsName -> CExpr Source

Creates a variable expression.

Let Bindings

mkLet1Plain Source

Arguments

:: HsName

The identifier.

-> CExpr

The expression to bind.

-> CExpr

The body.

-> CExpr 

Creates a (non-recursive) let binding.

mkLet1Strict Source

Arguments

:: 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.

mkLetRec Source

Arguments

:: [CBind]

The bindings.

-> CExpr

The body.

-> CExpr 

Creates a let binding, where the bindings may be mutually recursive.

Abstraction

Application

mkApp Source

Arguments

:: CExpr

The lambda to apply.

-> [CExpr]

The arguments (the empty list is allowed).

-> CExpr 

Applies the first expression to all given arguments.

Binds/Bounds

Constructor tags

mkCTag Source

Arguments

:: HsName

Fully qualified Datatype name.

-> HsName

Fully qualified Constructor name.

-> Int

Tag number.

-> Int

Arity.

-> CTag 

Creates a constructor tag.

destructCTag Source

Arguments

:: a

Algebra for record/tuple case.

-> (HsName -> HsName -> Int -> Int -> a)

Algebra for datatype case. Order of arguments is the same as in makeCTag.

-> CTag 
-> a 

Destruct a CTag.

ctagUnit :: CTag Source

CTag for unit values ('()' in haskell).

ctagTup :: CTag Source

CTag of tuple/records.

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).

mkCaseDflt Source

Arguments

:: 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.

mkAlt Source

Arguments

:: CPat

The pattern with which to match the case scrutinee.

-> CExpr

The value of this alternative.

-> CAlt 

Creates an alternative of a case statement.

mkPatCon Source

Arguments

:: CTag

The constructor to match.

-> CPatRest

???

-> [CPatFld]

???

-> CPat 

Matches the case scrutinee with the given constructor tag.

mkPatRestEmpty :: CPatRest Source

patrest, empty TODO what does it mean?

mkPatFldBind Source

Arguments

:: (HsName, CExpr)

lbl, offset ???

-> CBind

??

-> CPatFld 

TODO ??? pat field

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

mkModule Source

Arguments

:: 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.

mkImport Source

Arguments

:: HsName

The module to import.

-> CImport 

Creates an import.

mkMetaData Source

Arguments

:: HsName

The name of the dataype.

-> [CDataCon]

The constructors of the dataype.

-> CDeclMeta 

Creates the metadata for one datatype.

mkMetaDataCon Source

Arguments

:: 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.

mkMetaDataConFromCTag Source

Arguments

:: CTag

CTag to export.

-> Maybe CDataCon

The constructor description. Nothing if it is a record/tuple constructor.

Utilities

mkMain Source

Arguments

:: HsName

The function containing the user code to call.

-> CExpr 

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!

parseExpr :: EHCOpts -> String -> Either [String] CExpr Source

Parses an expression.

Re-exports (or not???)