| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Traq.Compiler.Prelude
Synopsis
- type UniqNamesCtx = Set Ident
- class HasUniqNamesCtx s where
- newIdent :: forall s m. (MonadError String m, MonadState s m, HasUniqNamesCtx s) => Ident -> m Ident
- mkQProcName :: Ident -> Ident
- mkUProcName :: Ident -> Ident
- type CompilerT ext = RWST (LoweringEnv ext) (LoweringOutput (SizeType ext)) (LoweringCtx (SizeType ext)) (Either String)
- compileWith :: forall ext size m. (m ~ CompilerT ext, size ~ SizeType ext, HasFreeVars ext) => (Program ext -> m ()) -> Program ext -> Either String (Program size)
- data LoweringCtx sizeT
- data ProcSignature size = ProcSignature {}
- _procSignatures :: Lens' (LoweringCtx size) (Map Ident (ProcSignature size))
- data LoweringOutput size
- _loweredProcs :: Lens' (LoweringOutput size) [ProcDef size]
- addProc :: MonadWriter (LoweringOutput size) m => ProcDef size -> m ()
- type LoweringEnv ext = FunCtx ext
Utilities for generating identifiers
type UniqNamesCtx = Set Ident #
A set of already used names. This is used to generate new unique identifiers.
class HasUniqNamesCtx s where #
Methods
_uniqNamesCtx :: Lens' s UniqNamesCtx #
Instances
| HasUniqNamesCtx UniqNamesCtx # | |
Defined in Traq.Compiler.Prelude Methods | |
| HasUniqNamesCtx (LoweringCtx sizeT) # | |
Defined in Traq.Compiler.Prelude Methods _uniqNamesCtx :: Lens' (LoweringCtx sizeT) UniqNamesCtx # | |
newIdent :: forall s m. (MonadError String m, MonadState s m, HasUniqNamesCtx s) => Ident -> m Ident #
Generate a new identifier with the given prefix.
mkQProcName :: Ident -> Ident #
get the name of the compiled (cq) proc given the source fun name
mkUProcName :: Ident -> Ident #
get the name of the compiled uproc given the source fun name
Compilation Monad
type CompilerT ext = RWST (LoweringEnv ext) (LoweringOutput (SizeType ext)) (LoweringCtx (SizeType ext)) (Either String) #
Monad to compile source programs to CQPL programs. This should contain the _final_ typing context for the input program, that is, contains both the inputs and outputs of each statement.
compileWith :: forall ext size m. (m ~ CompilerT ext, size ~ SizeType ext, HasFreeVars ext) => (Program ext -> m ()) -> Program ext -> Either String (Program size) #
Run the given compiler on a full program.
State
data LoweringCtx sizeT #
A global lowering context.
Instances
data ProcSignature size #
Signature of a compiled uproc/proc: inputs, outputs, ancilla (for unitary)
Constructors
| ProcSignature | |
_procSignatures :: Lens' (LoweringCtx size) (Map Ident (ProcSignature size)) #
Output
data LoweringOutput size #
The outputs of lowering
Instances
| Monoid (LoweringOutput size) # | |
Defined in Traq.Compiler.Prelude Methods mempty :: LoweringOutput size # mappend :: LoweringOutput size -> LoweringOutput size -> LoweringOutput size # mconcat :: [LoweringOutput size] -> LoweringOutput size # | |
| Semigroup (LoweringOutput size) # | |
Defined in Traq.Compiler.Prelude Methods (<>) :: LoweringOutput size -> LoweringOutput size -> LoweringOutput size # sconcat :: NonEmpty (LoweringOutput size) -> LoweringOutput size # stimes :: Integral b => b -> LoweringOutput size -> LoweringOutput size # | |
_loweredProcs :: Lens' (LoweringOutput size) [ProcDef size] #
addProc :: MonadWriter (LoweringOutput size) m => ProcDef size -> m () #
Env
type LoweringEnv ext = FunCtx ext #
Read-only compiler env