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 size) # 
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, TypeInferrable ext size) => (Program ext -> m ()) -> Program ext -> Either String (Program size) #

Run the given compiler on a full program.

proc builder

type ProcBuilderT size = WriterT (VarList size, [UStmt size], [Stmt size]) #

allocLocalWithPrefix :: IsProcBuilder m' size m => Ident -> VarType size -> m' Ident #

allocLocal :: IsProcBuilder m' size m => VarType size -> m' Ident #

addUStmt :: IsProcBuilder m' size m => UStmt size -> m' () #

withUStmt :: IsProcBuilder m' size m => (UStmt size -> UStmt size) -> m' a -> m' a #

addStmt :: IsProcBuilder m' size m => Stmt size -> m' () #

withStmt :: IsProcBuilder m' size m => (Stmt size -> Stmt size) -> m' a -> m' a #

buildUProc :: IsProcBuilder m' size m => Ident -> [Ident] -> [(Ident, VarType size)] -> m' () -> m (ProcDef size) #

buildProc :: IsProcBuilder m' size m => Ident -> [Ident] -> [(Ident, VarType size)] -> m' () -> m (ProcDef size) #

State

data LoweringCtx size #

A global lowering context.

Instances

Instances details
Generic (LoweringCtx size) # 
Instance details

Defined in Traq.Compiler.Prelude

Associated Types

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

Methods

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

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

HasUniqNamesCtx (LoweringCtx size) # 
Instance details

Defined in Traq.Compiler.Prelude

HasDefault (LoweringCtx size) # 
Instance details

Defined in Traq.Compiler.Prelude

Methods

default_ :: LoweringCtx size #

HasTypingCtx (LoweringCtx size) # 
Instance details

Defined in Traq.Compiler.Prelude

Methods

_typingCtx :: size0 ~ SizeType (LoweringCtx size) => Lens' (LoweringCtx size) (TypingCtx size0) #

type Rep (LoweringCtx size) # 
Instance details

Defined in Traq.Compiler.Prelude

type SizeType (LoweringCtx size) # 
Instance details

Defined in Traq.Compiler.Prelude

type SizeType (LoweringCtx size) = size

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