feldspar-compiler-0.6.0.2: Compiler for the Feldspar language

Safe Haskell | None

Feldspar.Compiler.Imperative.FromCore.Interpretation

Contents

- Utility functions

Synopsis

- type CodeWriter = RWS Readers Writers States
- data Readers = Readers {
  - alias :: [(VarId, Expr)]
  - sourceInfo :: SourceInfo
  }
- initReader :: Readers
- data Writers = Writers {
  - block :: Block
  - def :: [Ent]
  }
- type Task = [Prog]
- data States = States {
  - fresh :: Integer
  }
- initState :: States
- type Location = Expr
- class Compile sub dom where
  - compileProgSym :: sub a -> Info (DenResult a) -> Location -> Args (AST (Decor Info dom)) a -> CodeWriter ()
  - compileExprSym :: sub a -> Info (DenResult a) -> Args (AST (Decor Info dom)) a -> CodeWriter Expr
- compileExprLoc :: Compile sub dom => sub a -> Info (DenResult a) -> Location -> Args (AST (Decor Info dom)) a -> CodeWriter ()
- compileProgFresh :: Compile sub dom => sub a -> Info (DenResult a) -> Args (AST (Decor Info dom)) a -> CodeWriter Expr
- compileProgDecor :: Compile dom dom => Location -> Decor Info dom a -> Args (AST (Decor Info dom)) a -> CodeWriter ()
- compileExprDecor :: Compile dom dom => Decor Info dom a -> Args (AST (Decor Info dom)) a -> CodeWriter Expr
- compileProg :: Compile dom dom => Location -> ASTF (Decor Info dom) a -> CodeWriter ()
- compileExpr :: Compile dom dom => ASTF (Decor Info dom) a -> CodeWriter Expr
- compileExprVar :: Compile dom dom => ASTF (Decor Info dom) a -> CodeWriter Expr
- compileNumType :: Signedness a -> BitWidth n -> Type
- compileTypeRep :: TypeRep a -> Size a -> Type
- mkVarName :: VarId -> String
- mkVar :: Type -> VarId -> Expr
- mkVariable :: Type -> VarId -> Var
- freshId :: CodeWriter Integer
- freshVar :: String -> TypeRep a -> Size a -> CodeWriter Expr
- declare :: Expr -> CodeWriter ()
- tellDef :: [Ent] -> CodeWriter ()
- tellProg :: [Prog] -> CodeWriter ()
- tellDecl :: [Def] -> CodeWriter ()
- assign :: Location -> Expr -> CodeWriter ()
- confiscateBlock :: CodeWriter a -> CodeWriter (a, Block)
- withAlias :: VarId -> Expr -> CodeWriter a -> CodeWriter a
- isVariableOrLiteral :: (Project (Variable :|| Type) dom, Project (Literal :|| Type) dom) => AST (Decor info dom) a -> Bool
- mkLength :: (Project (Literal :|| Type) dom, Project (Variable :|| Type) dom, Compile dom dom) => ASTF (Decor Info dom) a -> CodeWriter Expr

# Documentation

type CodeWriter = RWS Readers Writers States

Code generation monad

data Readers

Constructors

Readers |

Fields

alias :: [(VarId, Expr)]

  variable aliasing

sourceInfo :: SourceInfo

  Surrounding source info

initReader :: Readers

data Writers

Constructors

Writers |

Fields

block :: Block

  collects code within one block

def :: [Ent]

  collects top level definitions

Instances

Monoid Writers |

type Task = [Prog]

data States

Constructors

States |

Fields

fresh :: Integer

  The first fresh variable id

initState :: States

type Location = Expr

Where to place the program result

class Compile sub dom where

A minimal complete instance has to define either `compileProgSym` or `compileExprSym`.

Methods

compileProgSym :: sub a -> Info (DenResult a) -> Location -> Args (AST (Decor Info dom)) a -> CodeWriter ()

compileExprSym :: sub a -> Info (DenResult a) -> Args (AST (Decor Info dom)) a -> CodeWriter Expr

Instances

Compile FeldDomain FeldDomain |
(Compile dom dom, Project (:|| Variable Type) dom) => Compile ParFeature dom |
(Compile dom dom, Project (CLambda Type) dom, Project (:|| Variable Type) dom) => Compile MutableToPure dom |
(Compile dom dom, Project (CLambda Type) dom) => Compile MutableReference dom |
(Compile dom dom, Project (CLambda Type) dom) => Compile MutableArray dom |
(Compile dom dom, Project (CLambda Type) dom) => Compile Mutable dom |
Compile Empty FeldDomain |
Compile dom dom => Compile Semantics dom | Converts symbols to primitive function calls
(Compile dom dom, Project (CLambda Type) dom) => Compile (MONAD Mut) dom |
(Compile dom dom, Project (CLambda Type) dom, Project ParFeature dom) => Compile (MONAD Par) dom |
(Compile dom dom, Project (CLambda Type) dom, Project (:|| Literal Type) dom, Project (:|| Variable Type) dom) => Compile (LoopM Mut) dom |
Compile dom dom => Compile (ConditionM m) dom |
Compile (CLambda Type) dom |
Compile dom dom => Compile (:|| Condition Type) dom |
(Compile dom dom, Project (CLambda Type) dom) => Compile (:|| Let Type) dom |
Compile (:|| Variable Type) dom |
Compile dom dom => Compile (:|| Select Type) dom |
Compile dom dom => Compile (:|| Tuple Type) dom |
Compile dom dom => Compile (:|| (Decor SourceInfo1 Identity) Type) dom |
Compile (:|| Literal Type) dom |
Compile dom dom => Compile (:|| PropSize Type) dom |
Compile dom dom => Compile (:|| Conversion Type) dom |
(Compile dom dom, Project (CLambda Type) dom, Project (:|| Literal Type) dom, Project (:|| Variable Type) dom) => Compile (:|| Loop Type) dom |
Compile dom dom => Compile (:|| FUTURE Type) dom |
(Compile dom dom, Project (CLambda Type) dom, Project (:|| Literal Type) dom, Project (:|| Variable Type) dom) => Compile (:|| Array Type) dom |
Compile dom dom => Compile (:|| Save Type) dom |
Compile dom dom => Compile (:|| FFI Type) dom |
Compile dom dom => Compile (:|| Trace Type) dom |
Compile dom dom => Compile (:|| NoInline Type) dom |
Compile dom dom => Compile (:|| INTEGRAL Type) dom |
Compile dom dom => Compile (:|| FRACTIONAL Type) dom |
Compile dom dom => Compile (:|| NUM Type) dom |
Compile dom dom => Compile (:|| FLOATING Type) dom |
Compile dom dom => Compile (:|| Error Type) dom |
Compile dom dom => Compile (:|| COMPLEX Type) dom |
Compile dom dom => Compile (:|| BITS Type) dom |
Compile dom dom => Compile (:|| Logic Type) dom |
Compile dom dom => Compile (:|| EQ Type) dom |
Compile dom dom => Compile (:|| ORD Type) dom |
(Compile sub1 dom, Compile sub2 dom) => Compile (:+: sub1 sub2) dom |

compileExprLoc :: Compile sub dom => sub a -> Info (DenResult a) -> Location -> Args (AST (Decor Info dom)) a -> CodeWriter ()

Implementation of `compileExprSym` that assigns an expression to the given location.

compileProgFresh :: Compile sub dom => sub a -> Info (DenResult a) -> Args (AST (Decor Info dom)) a -> CodeWriter Expr

Implementation of `compileProgSym` that generates code into a fresh variable.

compileProgDecor :: Compile dom dom => Location -> Decor Info dom a -> Args (AST (Decor Info dom)) a -> CodeWriter ()

compileExprDecor :: Compile dom dom => Decor Info dom a -> Args (AST (Decor Info dom)) a -> CodeWriter Expr

compileProg :: Compile dom dom => Location -> ASTF (Decor Info dom) a -> CodeWriter ()

compileExpr :: Compile dom dom => ASTF (Decor Info dom) a -> CodeWriter Expr

compileExprVar :: Compile dom dom => ASTF (Decor Info dom) a -> CodeWriter Expr

# Utility functions

compileNumType :: Signedness a -> BitWidth n -> Type

compileTypeRep :: TypeRep a -> Size a -> Type

mkVarName :: VarId -> String

mkVar :: Type -> VarId -> Expr

mkVariable :: Type -> VarId -> Var

freshId :: CodeWriter Integer

freshVar :: String -> TypeRep a -> Size a -> CodeWriter Expr

declare :: Expr -> CodeWriter ()

tellDef :: [Ent] -> CodeWriter ()

tellProg :: [Prog] -> CodeWriter ()

tellDecl :: [Def] -> CodeWriter ()

assign :: Location -> Expr -> CodeWriter ()

confiscateBlock :: CodeWriter a -> CodeWriter (a, Block)

Like `listen`, but also prevents the program from being written in the monad.

withAlias :: VarId -> Expr -> CodeWriter a -> CodeWriter a

isVariableOrLiteral :: (Project (Variable :|| Type) dom, Project (Literal :|| Type) dom) => AST (Decor info dom) a -> Bool

mkLength :: (Project (Literal :|| Type) dom, Project (Variable :|| Type) dom, Compile dom dom) => ASTF (Decor Info dom) a -> CodeWriter Expr