syntactic-1.0.1: Generic abstract syntax, and utilities for embedded languages

Safe HaskellNone

Language.Syntactic.Sharing.SimpleCodeMotion

Description

Simple code motion transformation performing common sub-expression elimination and variable hoisting. Note that the implementation is very inefficient.

The code is based on an implementation by Gergely Dévai.

Synopsis

Documentation

data BindDict dom Source

Interface for binding constructs

Constructors

BindDict 

Fields

prjVariable :: forall a. dom a -> Maybe VarId
 
prjLambda :: forall a. dom a -> Maybe VarId
 
injVariable :: forall a. ASTF dom a -> VarId -> dom (Full a)
 
injLambda :: forall a b. ASTF dom a -> ASTF dom b -> VarId -> dom (b :-> Full (a -> b))
 
injLet :: forall a b. ASTF dom b -> dom (a :-> ((a -> b) :-> Full b))
 

codeMotion :: forall dom a. (ConstrainedBy dom Typeable, AlphaEq dom dom dom [(VarId, VarId)]) => BindDict dom -> (forall a. dom a -> Bool) -> ASTF dom a -> State VarId (ASTF dom a)Source

Perform common sub-expression elimination and variable hoisting

reifySmart :: (AlphaEq dom dom ((Lambda :+: (Variable :+: dom)) :|| Typeable) [(VarId, VarId)], Syntactic a (HODomain dom Typeable)) => BindDict ((Lambda :+: (Variable :+: dom)) :|| Typeable) -> (forall a. ((Lambda :+: (Variable :+: dom)) :|| Typeable) a -> Bool) -> a -> ASTF ((Lambda :+: (Variable :+: dom)) :|| Typeable) (Internal a)Source

Like reify but with common sub-expression elimination and variable hoisting

reifySmartDefault :: (Let :<: dom, AlphaEq dom dom ((Lambda :+: (Variable :+: dom)) :|| Typeable) [(VarId, VarId)], Syntactic a (HODomain dom Typeable)) => (forall a. ((Lambda :+: (Variable :+: dom)) :|| Typeable) a -> Bool) -> a -> ASTF ((Lambda :+: (Variable :+: dom)) :|| Typeable) (Internal a)Source