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

Safe HaskellNone
LanguageHaskell98

UHC.Light.Compiler.Core.API

Contents

Description

Core Public API (provisional)

Intended for constructing basic Core Programs. This module does not offer any way to inspect the built Core Programs (on purpose), but the EHXX.Core module does.

Invariants: - Constructor applications (mkCon) always have to be fully saturated. (Should we handle this internally?) - Haskell constructor names must be unambigous per module (mkHSCTag) - TODO Tag ordering ?? What exactly are the invariants?

TODO Use AbstractCore instead of directly using the Constructors in the implementation

Synopsis

Documentation

data EHCOpts Source

The options to use.

defaultEHCOpts :: EHCOpts Source

The default EHC options.

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 

data HsName Source

Haskell name representation, exports of constructors only intented for internal use

Names

Names in UHC have to be of the form P1.P2....Pn.Ident . All names in module M must have the form M.Ident . Datatype and constructor names have to start with an uppercase letter, functions with a lowercase letter.

mkUniqueHsName Source

Arguments

:: String

Name prefix. Used to distinguish names generated by different API consumers, but may also be used to differentiate between different varieties by one API consumer. Use reverse-dns notation if possible, e.g. "nl.uu.agda.identOfVarietyA"

-> [String]

The module prefix.

-> String

The name to make unique.

-> HsName 

Creates a new Core name. All names generated with this function live in the "Core API" namespace and will not collide with names in other namespaces. Names in the "Core API" namespace cannot be called from Haskell code.

Use this function to create names used only inside Core code generated by your own Compiler, e.g. module-scoped or local functions.

mkHsName Source

Arguments

:: [String]

The module prefix.

-> String

The local name of the identifier.

-> HsName 

Creates a new Core name. The generated name lives in the default namespace, hence may clash with Haskell-defined names.

mkHsName1 :: String -> HsName Source

Creates a new Core name. The generated name lives in the default namespace, hence may clash with Haskell-defined names.

addHsNamePrefix :: String -> HsName -> HsName Source

Adds an additional prefix to a HsName. This can be used to derive a new unique name from an existing name.

Construction functions

Constants

acoreUnit :: EHCOpts -> CExpr Source

Creates the unit expresssion.

acoreInt :: AbstractCore e m b bound boundmeta bcat mbind t p pr pf a => EHCOpts -> Int -> e Source

Creates an Int constant.

acoreBuiltinInteger Source

Arguments

:: AbstractCore e m b bound boundmeta bcat mbind t p pr pf a 
=> EHCOpts 
-> Integer

The integer.

-> e 

Creates a Core Integer constant.

acoreBuiltinString Source

Arguments

:: AbstractCore e m b bound boundmeta bcat mbind t p pr pf a 
=> EHCOpts 
-> String

The string.

-> e 

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

acoreBuiltinError Source

Arguments

:: AbstractCore e m b bound boundmeta bcat mbind t p pr pf a 
=> EHCOpts 
-> String

The error message.

-> e 

Generates an error expression, failing with the given string when evaluated. (error in haskell)

acoreBuiltinUndefined :: AbstractCore e m b bound boundmeta bcat mbind t p pr pf a => EHCOpts -> e Source

Generates an undefined expression, failing when evaluated. (undefined in haskell)

Variables

acoreVar :: AbstractCore expr metaval bind bound boundmeta bindcateg metabind ty pat patrest patfld alt => HsName -> expr Source

Creates a variable expression.

Let Bindings

acoreLet1Plain Source

Arguments

:: (Eq bcat, AbstractCore e m b bound boundmeta bcat mbind t p pr pf a) 
=> HsName

The identifier.

-> e

The expression to bind.

-> e

The body.

-> e 

Creates a (non-recursive) let binding.

acoreLet1Strict Source

Arguments

:: (Eq bcat, AbstractCore e m b bound boundmeta bcat mbind t p pr pf a) 
=> HsName

The identifer.

-> e

The expression to bind. Will be evaluated to WHNF, before the body is evaluated.

-> e

The body.

-> e 

Creates a let binding, which is strict in the bound expression.

acoreLetRec Source

Arguments

:: (Eq bcat, AbstractCore e m b bound boundmeta bcat mbind t p pr pf a) 
=> [b]

The bindings.

-> e

The body.

-> e 

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

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

acoreCaseDflt Source

Arguments

:: AbstractCore e m b bound boundmeta bcat mbind t p pr pf a 
=> e

The scrutinee. Required to be in WHNF.

-> [a]

The alternatives.

-> Maybe e

The default value. (TODO what is the behaviour if it is Nothing?)

-> e 

A Case expression, possibly with a default value.

acoreAlt Source

Arguments

:: AbstractCore expr metaval bind bound boundmeta bindcateg metabind ty pat patrest patfld alt 
=> pat

The pattern with which to match the case scrutinee.

-> expr

The value of this alternative.

-> alt 

Creates an alternative of a case statement.

acorePatCon Source

Arguments

:: AbstractCore expr metaval bind bound boundmeta bindcateg metabind ty pat patrest patfld alt 
=> CTag

The constructor to match.

-> patrest

???

-> [patfld]

???

-> pat 

Matches the case scrutinee with the given constructor tag.

acorePatRestEmpty :: AbstractCore expr metaval bind bound boundmeta bindcateg metabind ty pat patrest patfld alt => patrest Source

patrest, empty TODO what does it mean?

acorePatFldBind Source

Arguments

:: AbstractCore expr metaval bind bound boundmeta bindcateg metabind ty pat patrest patfld alt 
=> (HsName, expr)

lbl, offset ???

-> bind

??

-> patfld 

TODO ??? pat field

Abstraction

acoreLam :: AbstractCore e m b bound boundmeta bcat mbind t p pr pf a => [HsName] -> e -> e Source

Application

acoreApp Source

Arguments

:: AbstractCore e m b bound boundmeta bcat mbind t p pr pf a 
=> e

The lambda to apply.

-> [e]

The arguments (the empty list is allowed).

-> e 

Applies the first expression to all given arguments.

Datatypes

acoreTagTup :: AbstractCore e m b bound boundmeta bcat mbind t p pr pf a => CTag -> [e] -> e Source

Creates a new tuple/record with the given values.

Binds/Bounds

acoreBind1 :: AbstractCore e m b bound boundmeta bcat mbind t p pr pf a => HsName -> e -> b Source

acoreBind1Nm1 :: AbstractCore e m b bound boundmeta bcat mbind t p pr pf a => HsName -> b Source

Module

makeModule Source

Arguments

:: HsName

The name of the module.

-> [CImport]

The imports (only direct imports, not transitive ones).

-> [CDeclMeta]

The meta information.

-> CExpr

The body of the module.

-> CModule 

Creates a module.

makeImport Source

Arguments

:: HsName

The module to import.

-> CImport 

Creates an import.

makeMetaData Source

Arguments

:: HsName

The name of the dataype.

-> [CDataCon]

The constructors of the dataype.

-> CDeclMeta 

Creates the metadata for one datatype.

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

Utilities

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