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

Safe HaskellSafe
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 (Type Name))

How the super is imported

-> Maybe (ExportSource Name (Type 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

ErrorBindNone

Binder has BNone form, binds no variable.

ErrorImportInvalid

Invalid import.

ErrorTypeInvalid

A local variable has an invalid type.

Fields

ErrorNoTopLevelLetrec

Modules must contain a top-level letrec.

Fields

ErrorFunctionInvalid

An invalid function definition.

Fields

ErrorParameterInvalid

An invalid function parameter.

Fields

ErrorBodyInvalid

An invalid function body.

Fields

ErrorBodyMustPassControl

A function body that does not explicitly pass control.

Fields

ErrorStmtInvalid

An invalid statement.

Fields

ErrorAltInvalid

An invalid alternative.

Fields

ErrorRValueInvalid

An invalid RValue.

Fields

ErrorArgInvalid

An invalid function argument.

Fields

ErrorPrimCallInvalid

An invalid primitive call

Fields

Instances

Show a => Show (Error a) Source # 

Methods

showsPrec :: Int -> Error a -> ShowS #

show :: Error a -> String #

showList :: [Error a] -> ShowS #

Pretty (Error a) Source # 

Associated Types

data PrettyMode (Error a) :: * #

Methods

pprDefaultMode :: PrettyMode (Error a) #

ppr :: Error a -> Doc #

pprPrec :: Int -> Error a -> Doc #

pprModePrec :: PrettyMode (Error a) -> Int -> Error a -> Doc #