traq
Safe HaskellSafe-Inferred
LanguageHaskell2010

Traq.Compiler.Prelude

Synopsis

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 #

Instances

Instances details
HasUniqNamesCtx UniqNamesCtx # 
Instance details

Defined in Traq.Compiler.Prelude

HasUniqNamesCtx (LoweringCtx sizeT) # 
Instance details

Defined in Traq.Compiler.Prelude

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

Instances details
Generic (LoweringCtx sizeT) # 
Instance details

Defined in Traq.Compiler.Prelude

Associated Types

type Rep (LoweringCtx sizeT) :: Type -> Type #

Methods

from :: LoweringCtx sizeT -> Rep (LoweringCtx sizeT) x #

to :: Rep (LoweringCtx sizeT) x -> LoweringCtx sizeT #

HasUniqNamesCtx (LoweringCtx sizeT) # 
Instance details

Defined in Traq.Compiler.Prelude

HasDefault (LoweringCtx sizeT) # 
Instance details

Defined in Traq.Compiler.Prelude

Methods

default_ :: LoweringCtx sizeT #

HasTypingCtx (LoweringCtx sizeT) # 
Instance details

Defined in Traq.Compiler.Prelude

Methods

_typingCtx :: sizeT0 ~ SizeType (LoweringCtx sizeT) => Lens' (LoweringCtx sizeT) (TypingCtx sizeT0) #

type Rep (LoweringCtx sizeT) # 
Instance details

Defined in Traq.Compiler.Prelude

type SizeType (LoweringCtx sizeT) # 
Instance details

Defined in Traq.Compiler.Prelude

type SizeType (LoweringCtx sizeT) = sizeT

data ProcSignature size #

Signature of a compiled uproc/proc: inputs, outputs, ancilla (for unitary)

Constructors

ProcSignature 

Fields

Output

data LoweringOutput size #

The outputs of lowering

Instances

Instances details
Monoid (LoweringOutput size) # 
Instance details

Defined in Traq.Compiler.Prelude

Semigroup (LoweringOutput size) # 
Instance details

Defined in Traq.Compiler.Prelude

addProc :: MonadWriter (LoweringOutput size) m => ProcDef size -> m () #

Env

type LoweringEnv ext = FunCtx ext #

Read-only compiler env