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

Safe HaskellNone

DDC.Core.Salt

Contents

Description

Disciple Core Salt.

This is what happens to C when you leave it out in the sun for too long.

Salt is a fragment of System-F2 that contains just those features that can be easily mapped onto C or LLVM code. It has functions, case expressions and primops, but no partial application, data types, or nested functions. All operations on algebraic data need to have been expanded to primitive store operations.

Salt exposes raw store and control primops, so its possible for functions written directly in Salt to corrupt the heap (if they are wrong).

Synopsis

Language profile

profile :: Profile NameSource

Language profile for Disciple Core Salt.

Conversion

seaOfSaltModuleSource

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.

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) 
(Show a, Pretty a) => Pretty (Error a) 

Names

data Name Source

Names of things used in Disciple Core Salt.

Constructors

NameVar String

A type or value variable.

NameCon String

Constructor names.

NameObjTyCon

The abstract heap object type constructor.

NamePrimTyCon PrimTyCon

A primitive type constructor.

NamePrimOp PrimOp

A primitive operator.

NameLitVoid

The void literal.

NameLitBool Bool

A boolean literal.

NameLitNat Integer

A natural number literal.

NameLitInt Integer

An integer number literal.

NameLitTag Integer

A constructor tag literal.

NameLitWord Integer Int

A WordN# literal, of the given width.

Instances

Eq Name 
Ord Name 
Show Name 
Typeable Name 
Pretty Name 
NFData Name 

data PrimTyCon Source

Primitive type constructors.

Constructors

PrimTyConVoid

Void# the Void type has no values.

PrimTyConBool

Bool# unboxed booleans.

PrimTyConNat

Nat# natural numbers. Enough precision to count every object in the heap, but NOT enough precision to count every byte of memory.

PrimTyConInt

Int# signed integers. Enough precision to count every object in the heap, but NOT enough precision to count every byte of memory. If N is the total number of objects that can exist in the heap, then the range of Int# is at least (-N .. +N) inclusive.

PrimTyConWord Int

WordN# machine words of the given width.

PrimTyConFloat Int

FloatN# floating point numbers of the given width.

PrimTyConVec Int

VecN# a packed vector of N values. This is intended to have kind (Data -> Data), so we use concrete vector types like Vec4.

PrimTyConAddr

Addr# a relative or absolute machine address. Enough precision to count every byte of memory. Unlike pointers below, an absolute Addr# need not refer to memory owned by the current process.

PrimTyConPtr

Ptr# should point to a well-formed object owned by the current process.

PrimTyConTag

Tag# data constructor tags. Enough precision to count every possible alternative of an enumerated type.

PrimTyConString

String# of UTF8 characters.

These are primitive until we can define our own unboxed types.

Instances

data PrimOp Source

Primitive operators implemented directly by the machine or runtime system.

Constructors

PrimArith PrimArith

Arithmetic, logic, comparison and bit-wise operators.

PrimCast PrimCast

Casting between numeric types.

PrimStore PrimStore

Raw store access.

PrimCall PrimCall

Special function calling conventions.

PrimControl PrimControl

Non-functional control flow.

Instances

Eq PrimOp 
Ord PrimOp 
Show PrimOp 
Pretty PrimOp 
NFData PrimOp 

data PrimCast Source

Primitive cast between two types.

The exact set of available casts is determined by the target platform. For example, you can only promote a Nat# to a Word32# on a 32-bit system. On a 64-bit system the Nat# type is 64-bits wide, so casting it to a Word32# would be a truncation.

Constructors

PrimCastConvert

Convert a value to a new representation with the same precision.

PrimCastPromote

Promote a value to one of similar or larger width, without loss of precision.

PrimCastTruncate

Truncate a value to a new width, possibly losing precision.

Instances

primCastPromoteIsValidSource

Arguments

:: Platform

Target platform.

-> PrimTyCon

Source type.

-> PrimTyCon

Destination type.

-> Bool 

Check for a valid promotion primop.

primCastTruncateIsValidSource

Arguments

:: Platform

Target platform.

-> PrimTyCon

Source type.

-> PrimTyCon

Destination type.

-> Bool 

Check for valid truncation primop.

data PrimCall Source

Primitive ways of invoking a function, where control flow returns back to the caller.

Constructors

PrimCallTail Int

Tailcall a function

Instances

data PrimControl Source

Primitive non-returning control flow.

Constructors

PrimControlFail

Ungraceful failure -- just abort the program. This is called on internal errors in the runtime system. There is no further debugging info provided, so you'll need to look at the stack trace to debug it.

PrimControlReturn

Return from the enclosing function with the given value.

data PrimStore Source

Raw access to the store.

Constructors

PrimStoreSize

Number of bytes needed to store a value of a primitive type.

PrimStoreSize2

Log2 of number of bytes need to store a value of a primitive type.

PrimStoreCreate

Create a heap of the given size. This must be called before alloc# below, and has global side effect. Calling it twice in the same program is undefined.

PrimStoreCheck

Check whether there are at least this many bytes still available on the heap.

PrimStoreRecover

Force a garbage collection to recover at least this many bytes.

PrimStoreAlloc

Allocate some space on the heap. There must be enough space available, else undefined.

PrimStoreRead

Read a value from the store at the given address and offset.

PrimStoreWrite

Write a value to the store at the given address and offset.

PrimStorePlusAddr

Add an offset in bytes to an address.

PrimStoreMinusAddr

Subtract an offset in bytes from an address.

PrimStorePeek

Read a value from a pointer plus the given offset.

PrimStorePoke

Write a value to a pointer plus the given offset.

PrimStorePlusPtr

Add an offset in bytes to a pointer.

PrimStoreMinusPtr

Subtract an offset in bytes from a pointer.

PrimStoreMakePtr

Convert an raw address to a pointer.

PrimStoreTakePtr

Convert a pointer to a raw address.

PrimStoreCastPtr

Cast between pointer types.

Instances

data PrimArith Source

Primitive arithmetic, logic, and comparison opretors. We expect the backend/machine to be able to implement these directly.

For the Shift Right operator, the type that it is used at determines whether it is an arithmetic (with sign-extension) or logical (no sign-extension) shift.

Constructors

PrimArithNeg

Negation

PrimArithAdd

Addition

PrimArithSub

Subtraction

PrimArithMul

Multiplication

PrimArithDiv

Division

PrimArithMod

Modulus

PrimArithRem

Remainder

PrimArithEq

Equality

PrimArithNeq

Negated Equality

PrimArithGt

Greater Than

PrimArithGe

Greater Than or Equal

PrimArithLt

Less Than

PrimArithLe

Less Than or Equal

PrimArithAnd

Boolean And

PrimArithOr

Boolean Or

PrimArithShl

Shift Left

PrimArithShr

Shift Right

PrimArithBAnd

Bit-wise And

PrimArithBOr

Bit-wise Or

PrimArithBXOr

Bit-wise eXclusive Or

Instances

Name parsing

readName :: String -> Maybe NameSource

Read the name of a variable, constructor or literal.

Program lexing

lexModuleStringSource

Arguments

:: String

Source file name.

-> Int

Starting line number.

-> String

String to parse.

-> [Token (Tok Name)] 

Lex a string to tokens, using primitive names.

lexExpStringSource

Arguments

:: String

Source file name.

-> Int

Starting line number.

-> String

String to parse.

-> [Token (Tok Name)] 

Lex a string to tokens, using primitive names.