flocc-pffb

Stabilityexperimental
Maintainerdeveloper@flocc.net
Safe HaskellNone

Compiler.Front.ExprTree

Description

For more information please see http://www.flocc.net/

Synopsis

Documentation

data Expr

Expression tree grammar

data Val

Value carriers

Instances

data NeverEq

A value where comparisons with itself are never equal

Constructors

NeverEq 

getExprId :: Expr -> Idx

Returns the expression idx of the expression

getIdxTreeIds :: IdxTree -> [Idx]

Returns a list of all the var ids in the idx tree

makeExprMap :: Expr -> [(Idx, Expr)]

Makes a lookup table mapping expr ids to expressions

showExprTreeWithIds :: Expr -> String

showExprTreeWithIds shows an expression with dangling expression ids for each term.

showExprTree :: a -> (a -> Idx -> String) -> Int -> Expr -> String

Shows expression tree with dangling data |Takes a context object, some function that takes a context and |an expr id and returns a string, an integer number of spaces to indent |and an expression and returns a string rendering of the expression with |relevent data from the context attached.

makeDemoGraph :: State IdxSet Expr

Initial index we think is safe to use for demo graph generation initidx = length globalTypes |Initial indices we think are safe to use for demo graph generation initidxs = [initidx, initidx, initidx]

Creates a new demo graph, in this case a matrix multiply

renewExprIds :: Monad a => Expr -> StateT IdxSet a Expr

Renew all expression ids in the expression

newExpr :: Monad m => (Idx -> a) -> StateT IdxSet m a

Creates a new expr with a new expression id using the data constructor passed

newExprId :: Monad m => StateT IdxSet m Idx

Creates a new expr id

newExprVarId :: Monad m => StateT IdxSet m Idx

Creates a new expr var id

renewIdAndExprIds :: Monad a => IdxTree -> Expr -> StateT IdxSet a (IdxTree, Expr)

Renew all expression ids and var ids in an idx pattern and expression

initExprVarIds :: Monad m => [(String, Idx)] -> Expr -> StateT IdxSet m Expr

Uses variable names to create new variable ids for all vars

initIdxTreeExpIds :: Monad m => IdxTree -> StateT IdxSet m IdxTree

Returns the same tree with the expression ids ialized

initIdxTreeVarIds :: Monad m => IdxTree -> StateT IdxSet m (IdxTree, [(String, Idx)])

Uses variable names to create new variable ids for all var ids

replaceIdxTreeIds :: Monad m => IdxTree -> StateT [(Idx, Idx)] (StateT IdxSet m) IdxTree

Replaces all expression ids with new ones |and creates new consistant variable ids.

replaceExprIds :: Monad m => Expr -> StateT [(Idx, Idx)] (StateT IdxSet m) Expr

Replaces all exp ids with new ones and create new |consistant variable ids.

visitExprTree :: Monad m => (a -> Expr -> m Expr) -> (a -> IdxTree -> m (IdxTree, a)) -> a -> Expr -> m Expr

visitIdxTree takes two functions,

visitExprTree takes three functions, one to process |exprs, another process idx trees, and one to combine |a (environment) values, such that one |can easily override basic expr visitor functionality. |Note: to recursively visit, exprF must call visitExprTree exprF idxF |unless expr is a leaf.

replaceExprIdsOnly :: Monad m => (Expr -> Bool) -> Expr -> StateT (Map Idx Idx) (StateT IdxSet m) Expr

Replaces all exp ids with new ones in exps for which the predicate holds, and leaves var ids as is.

class StructEq a where

Class for types that have structural equality defined on them

Methods

structEq :: a -> a -> Bool

getLetVarExprIds :: Expr -> [(String, Idx)]

getLetVarExprIds gets the expression ids for all of the let vars |in the program.

countExprs :: (Expr -> Bool) -> Expr -> Int

countExprs predFun expr. Counts how many expressions match |predFun in expre.

maxExpId :: Monad m => Expr -> m Idx

foldExpr :: (Expr -> a) -> (IdxTree -> a) -> (a -> a -> a) -> Expr -> a

filterExprs :: (Expr -> Bool) -> Expr -> [Expr]

filterExprs pred e. Returns a list of all expressions in exp that match the predicate pred.

removeFunApps :: (Expr -> Bool) -> Expr -> Expr

removeFunApps pred expr. Returns expr where all fun apps for which |pred returns true have been removed (i.e. replaced by their argument exp).