ddc-core-salt-0.4.2.1: Disciplined Disciple Compiler C code generator.

Safe HaskellNone
LanguageHaskell98

DDC.Core.Salt.Convert

Description

Convert the Disciple Core Salt into to real C code.

The input module needs to be: well typed, fully named with no deBruijn indices, have all functions defined at top-level, a-normalised, have a control-transfer primop at the end of every function body (these are added by DDC.Core.Salt.Convert.Transfer)

Synopsis

Documentation

seaOfSaltModule Source

Arguments

:: Show a 
=> Bool

Whether to emit top-level include macros. Emitting makes the code easier to read during testing.

-> Platform

Target platform specification

-> Module a Name

Module to convert.

-> Either (Error a) Doc 

Convert a Disciple Core Salt module to C-source text.

initRuntime :: Config -> Module a Name -> Maybe (Module a Name) Source

If this it the Main module, then insert a main function for the posix entry point that initialises the runtime system and calls the real main function.

Returns Nothing if this is the Main module, but there is no main function.

seaNameOfSuper Source

Arguments

:: Maybe (ImportValue Name)

How the super is imported

-> Maybe (ExportSource Name)

How the super is exported

-> Name

Name of the super.

-> Maybe Doc 

Convert the Salt name of a supercombinator to a name we can use when defining the C function.

seaNameOfLocal :: Name -> Maybe Doc Source

Convert the Salt name of a local variable to a name we can use in the body of a C function.

sanitizeName :: String -> String Source

Rewrite a name to make it safe to export as an external C symbol.

Names containing unfriendly characters like & are prefixed with _sym_ and the & is replaced by ZAn. Literal Zs such a name are doubled to ZZ.

data Error a Source

Things that can go wrong when converting a Disciple Core Salt module to C source text.

Constructors

ErrorUndefined

Variable is not in scope.

Fields

errorVar :: Bound Name
 
ErrorBindNone

Binder has BNone form, binds no variable.

ErrorImportInvalid

Invalid import.

ErrorTypeInvalid

A local variable has an invalid type.

Fields

errorType :: Type Name
 
ErrorNoTopLevelLetrec

Modules must contain a top-level letrec.

Fields

errorModule :: Module a Name
 
ErrorFunctionInvalid

An invalid function definition.

Fields

errorExp :: Exp a Name
 
ErrorParameterInvalid

An invalid function parameter.

Fields

errorBind :: Bind Name
 
ErrorBodyInvalid

An invalid function body.

Fields

errorExp :: Exp a Name
 
ErrorBodyMustPassControl

A function body that does not explicitly pass control.

Fields

errorExp :: Exp a Name
 
ErrorStmtInvalid

An invalid statement.

Fields

errorExp :: Exp a Name
 
ErrorAltInvalid

An invalid alternative.

Fields

errorAlt :: Alt a Name
 
ErrorRValueInvalid

An invalid RValue.

Fields

errorExp :: Exp a Name
 
ErrorArgInvalid

An invalid function argument.

Fields

errorExp :: Exp a Name
 
ErrorPrimCallInvalid

An invalid primitive call

Fields

errorPrimOp :: PrimOp
 
errorArgs :: [Exp a Name]
 

Instances

Show a => Show (Error a) Source 
(Show a, Pretty a) => Pretty (Error a) Source