Safe Haskell | None |
---|
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)
- seaOfSaltModule :: Show a => Bool -> Platform -> Module a Name -> Either (Error a) Doc
- initRuntime :: Config -> Module a Name -> Maybe (Module a Name)
- seaNameOfSuper :: Maybe (ImportSource Name) -> Maybe (ExportSource Name) -> Name -> Maybe Doc
- seaNameOfLocal :: Name -> Maybe Doc
- sanitizeName :: String -> String
- data Error a
- = ErrorUndefined { }
- | ErrorBindNone
- | ErrorImportInvalid { }
- | ErrorTypeInvalid { }
- | ErrorNoTopLevelLetrec {
- errorModule :: Module a Name
- | ErrorFunctionInvalid { }
- | ErrorParameterInvalid { }
- | ErrorBodyInvalid { }
- | ErrorBodyMustPassControl { }
- | ErrorStmtInvalid { }
- | ErrorAltInvalid { }
- | ErrorRValueInvalid { }
- | ErrorArgInvalid { }
- | ErrorPrimCallInvalid {
- errorPrimOp :: PrimOp
- errorArgs :: [Exp a Name]
Documentation
:: 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.
:: Maybe (ImportSource 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 DocSource
Convert the Salt name of a local variable to a name we can use in the body of a C function.
sanitizeName :: String -> StringSource
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 Z
s such a name are doubled to ZZ
.
Things that can go wrong when converting a Disciple Core Salt module to C source text.
ErrorUndefined | Variable is not in scope. |
ErrorBindNone | Binder has BNone form, binds no variable. |
ErrorImportInvalid | Invalid import. |
ErrorTypeInvalid | A local variable has an invalid type. |
ErrorNoTopLevelLetrec | Modules must contain a top-level letrec. |
| |
ErrorFunctionInvalid | An invalid function definition. |
ErrorParameterInvalid | An invalid function parameter. |
ErrorBodyInvalid | An invalid function body. |
ErrorBodyMustPassControl | A function body that does not explicitly pass control. |
ErrorStmtInvalid | An invalid statement. |
ErrorAltInvalid | An invalid alternative. |
ErrorRValueInvalid | An invalid RValue. |
ErrorArgInvalid | An invalid function argument. |
ErrorPrimCallInvalid | An invalid primitive call |
|