flocc-pffb

Stabilityexperimental
Maintainerdeveloper@flocc.net
Safe HaskellNone

Compiler.Back.Graph

Description

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

Synopsis

Documentation

trace' :: String -> a -> a

data Tree a

Constructors

Lf a 
(Tree a) :-> (Tree a) 
Tup [Tree a] 

Instances

Eq a => Eq (Tree a) 
Ord a => Ord (Tree a) 
Show a => Show (Tree a) 

treeIndexBase :: Int

treeIndexBase. Index of first element of |a tree tuple.

showTree :: Show a => Tree a -> String

flattenTree :: Tree v -> [v]

flattenTree tree. Flattens tree using a depth first traversal, |returning the list of its leaves.

treeLeaf :: Show a => String -> Tree a -> a

treeLeaf takes a tree and if it is a leaf, returns it, or otherwise |throws the error message given.

alignTrees :: Show a => Show b => String -> Tree a -> Tree b -> [(a, Tree b)]

alignTrees treeA treeB aligns treeA and treeB to produce |a mapping from treeA leaves to treeB nodes. If the trees |don't fit/have the same shape, then an error is thrown.

zipTrees :: (Show a, Show b) => String -> Tree a -> Tree b -> Tree (a, Tree b)

zipTrees treeA treeB. Assuming treeA is a subset of treeB |returns a new tree with all children in b dangling from those |in a. Throws error otherwise.

zipSubTrees :: (Show a, Show b) => Tree a -> Tree b -> [(Tree a, Tree b)]

zipSubTrees treeA treeB. Returns a list of associated subtrees, for e.g. | zipSubTrees (Tup [Tup [Lf a, Lf b], Lf c]) (Tup [Lf x, Tup [Lf y, Lf z]]) = | [(Tup [Lf a, Lf b], Lf x), (Lf c, Tup [Lf y, Lf z])]. This will fail if two |tuples at the same level have different numbers of children, or if a tuple is |at the same level as a lambda etc.

visitTreeM :: Monad m => (a -> m (Tree b)) -> Tree a -> m (Tree b)

visitTreeM visits the tree using a depth first traversal |and creates a new tree using the monadic function to transform |its leaf values.

visitTree :: (a -> Tree b) -> Tree a -> Tree b

mapTree f tree. Returns a tree where all leaf values have been transformed |using f.

mapTree :: (a -> b) -> Tree a -> Tree b

mapTree f tree. Returns a tree where all leaf values have been transformed |using f.

treeToList :: Tree a -> [a]

treeToList takes a tree and returns a list of its elements |created using a depth first traversal

type TreePath = [Int]

visitTreeWithPath :: Monad m => (TreePath -> a -> m (Tree b)) -> TreePath -> Tree a -> m (Tree b)

growTree :: (Show a, Show b) => String -> (TreePath -> a -> b -> c) -> Tree a -> Tree b -> Tree c

growTree smallTree largeTree newLeaf. Grows smallTree |to be the same size and shape of largeTree, by creating |new nodes with newLeaf.

lookupTreeNodeMaybe :: Show a => Tree a -> TreePath -> Maybe (Tree a)

lookupTreeNodeMaybe tree path. Looks up the node at path |in tree, or returns Nothing if doesn't exist.

lookupTreeNode :: Show a => String -> Tree a -> TreePath -> Tree a

lookupTreeNode errMsg tree path. Looks up the node at path |in tree, or throws an error if it does not exist.

lookupTreeNodeOrLeaf :: Show a => String -> Tree a -> TreePath -> Tree a

lookupTreeNodeOrLeaf errMsg tree path. Follows the tree path, |to return either the node at the path, or a leaf, |whatever comes first.

replaceTreeNode :: Show a => TreePath -> Tree a -> Tree a -> Tree a

replaceTreeNode path newNode oldTree. Returns oldTree where the node |at path has been replaced with newNode, or throws error if no such path |exists in oldTree.

subPaths :: [(TreePath, a)] -> TreePath -> [(TreePath, a)]

subPaths pathList pathPrefix. Filters pathList returning only |those for which pathPrefix is a prefix. Note: Here first element |is root of tree.

createTreeFromPaths :: Show v => [(TreePath, v)] -> TreePath -> Tree v

createTreeFromPaths paths currentPathPrefix. Takes a list of tree paths, with labels and leaves |and builds them into a labelled tree.Note: head element of paths is root node in tree.

searchTree :: (a -> [b]) -> Tree a -> [b]

searchTree searchFun tree. Visits all leaves |returning a list of values generated by the searchFun.

filterTree :: (a -> Bool) -> Tree a -> [a]

filterTree pred tree. Accumulates all leaf values for which the |predicate pred holds.

treeContains :: (a -> Bool) -> Tree a -> Bool

treeContains pred tree. Returns true if tree contains |a leaf for which the predicate pred holds.

tidyTree :: Tree a -> Tree a

tidyTree tree. Pulls up tuples of length 1.

data LabelledTree l v

LabelledTree l v - a tree where every node has a label

Constructors

LLf l v 
LFun l (LabelledTree l v) (LabelledTree l v) 
LTup l [LabelledTree l v] 

Instances

(Eq l, Eq v) => Eq (LabelledTree l v) 
(Show a, Show l) => Show (LabelledTree l a)

Show instance for labelled trees

flattenLTree :: LabelledTree l v -> [(l, v)]

flattenLTree tree. Flattens tree using a depth first |traversal, returning a list of its leaves and their labels.

treeLabel :: Show l => Show v => LabelledTree l v -> l

treeLabel tree. Returns the label of a labelled tree.

labelledTreePath :: (Show a, Show b) => LabelledTree a b -> TreePath -> LabelledTree a b

labelledTreePath tree path. Looks up the node at path |in tree, or throws an error if it does not exist.

zipLabelledTrees :: (Show l1, Show l2, Show v1, Show v2) => LabelledTree l1 v1 -> LabelledTree l2 v2 -> LabelledTree l1 (v1, LabelledTree l2 v2)

zipLabelledTrees treeA treeB. Assuming treeA is a subset of treeB |returns a new tree with all children in b dangling from those |in a. Throws error otherwise. Keeps labels from treeA.

toLabelledTree :: Tree a -> LabelledTree () a

toLabelledTree tree. Converts a tree to a labelled tree.

fromLabelledTree :: LabelledTree a b -> Tree b

Converts from a labelled tree back to a normal |tree, disgarding the labels.

visitLabelledTreeM :: Monad m => (l -> a -> m (LabelledTree l b)) -> LabelledTree l a -> m (LabelledTree l b)

visitLabelledTreeM visits the tree using a depth first traversal |and creates a new tree using the monadic function to transform |its leaf values.

mapLabels :: (l1 -> a -> b) -> (l1 -> l2) -> LabelledTree l1 a -> LabelledTree l2 b

mapLabels f tree. Natural transformation of labelled tree labels.

createTreePathTree :: TreePath -> LabelledTree a b -> LabelledTree TreePath ()

createTreePathTree rootPath tree. Returns a tree with labels that are |tree paths for each node.

data LfTy

Contains vars instance for Tree

Data types

Instances

type Ty = Tree LfTy

type TyScheme = Scheme Ty

Contains vars instance for LfTy

funTy :: Graph -> Ty

lfTy :: String -> [Ty] -> Tree LfTy

isScalTy :: Ty -> Bool

isScalTy type. Returns if type is a |scalar type.

getVarsInLfTy :: LfTy -> Set String

getVarTys lfTy. Returns the set of var ids in a leaf type.

mapGraphsInTyM :: Monad m => (Graph -> m Graph) -> Ty -> m Ty

mapGraphsInTy f ty. Applies f to all graphs in ty.

mapGraphsInTy :: (Graph -> Graph) -> Ty -> Ty

mapGraphsInTy f ty. Applies f to all graphs in ty.

getGraphsInTy :: Ty -> [Graph]

returns list of all graphs in this type.

data ScalVal

Scalar literals

scalValType :: ScalVal -> Ty

scalValType val. Returns the type of this literal value.

type NodeId = Int

Node ids

data NodeTy

Node types

Instances

Eq NodeTy 
Ord NodeTy 
Show NodeTy 
DotDrawable NodeTy

Instance of DotDrawable for graph node attributes.

data Node

DFG nodes

Constructors

Node 

Fields

nodeId :: NodeId
 
nodeIn :: [NodeId]
 
nodeOut :: [NodeId]
 
nodeTy :: NodeTy
 

Instances

Eq Node 
Ord Node 
Show Node 
DotDrawable Node

Instance of DotDrawable for graph nodes.

type NodeEnv a = IntMap a

Map from node ids to objects

lookupNode :: Show a => String -> NodeId -> NodeEnv a -> a

looks up a member from a node environment or throws an |error with the given message

lookupNodeMaybe :: Key -> IntMap a -> Maybe a

lookupNodeMaybe nodeId nodeEnv. Looks up the node, or |returns Nothing if it could not be found.

duplicateNodeEnvIds :: Show a => NodeEnv NodeId -> NodeEnv a -> NodeEnv a

duplicateNodeEnvIds newIds oldEnv. Duplicates all entries in oldEnv |that exist in newIds, giving them the new ids defined in newIds, and then |returns all the original entries, and these new duplicated ones.

buildNodeTree :: [Graph] -> NodeId -> Ty -> NodeTreeEx

buildNodeTree graph nodeId type. Takes a graph and a node, and returns a |node tree of all its neighbours node ids. However this tree now also contains |leaves that access tuple values within a given node, which are identified |by treepaths.

buildInputNodeTree :: [Graph] -> Node -> NodeTree

buildInputNodeTree graph node. Builds a node tree from the input nodes |of a node.

getInputNodeBeforeTuple :: [Graph] -> Node -> Node

If node is a TupAccNode and it's input is a TupNd, shortcuts them |to immediately get the original node.

buildOutputNodeTree :: [Graph] -> Node -> NodeTree

buildOutputNodeTree takes a node, and looks through all its outputs |for tuple accessors, creating a labelled tree of output nodes.

getGraphsInTys :: NodeEnv Ty -> [Graph]

Returns all graphs in a type env.

extendTyTree :: v1 -> LabelledTree v2 v3 -> LabelledTree (v1, TreePath) ()

extendTyTree nodeId typeTree. Converts type tree into a tree of labels |for paths into it.

extendNodeTreeWithType :: NodeTree -> Ty -> NodeTreeEx

extendNodeTreeWithType tree type. Align tree with the |type and expand any leaves of tree that have tuple type |to provide leaves to access each of the tuple parts.

data Graph

Instances

Eq Graph 
Ord Graph 
Show Graph 
DotDrawable Graph

Instance of DotDrawable for Digraphs.

showSubgraphs :: Graph -> String

showSubgraphs g. Shows g and all the subgraphs nested in FunNds.

newGraph :: [Node] -> NodeId -> NodeId -> Map String NodeId -> Graph

newGraph creates a new graph from a list of nodes

seqComposeGraphs :: Graph -> Graph -> Graph

Sequentially compose graphs so g2 is applied after g1.

graphsContain :: [Graph] -> NodeId -> Bool

graphsContain graph nodeId. Returns true if one of the graphs |contains a node with id nodeId.

findInGraph :: (Node -> Bool) -> Graph -> [Node]

findInGraph nodeTy graph. Searches graph for |nodes with nodeTy and returns a list of all the nodes |that do.

lookupGraphNodeMaybe :: String -> NodeId -> [Graph] -> Maybe Node

lookupGraphNodeMaybe nid graph. Searches up graphs, |checking the current graph, and if it doesn't contain it |checking it's parent.

lookupGraphVarNode :: String -> Node -> [Graph] -> [Graph] -> Node

lookupGraphVarNode msg node allGraphs graphs. If node is a varNode called |something other than in or out, then this function searches up the |graph stack for a node bound to that name. If one exists, it then searches |from the leaf graph up to the root again (using allGraphs) to find this node, |returning it if it is found, or throwing an error otherwise.

lookupNodeLeafGraph :: String -> NodeId -> [Graph] -> Maybe Node

lookupNodeLeafGraph errMsg nid graph. If in leaf graph, returns it. |If in parent graphs, returns Nothing. If in none of them, throws error.

maxNodeId :: Graph -> NodeId

maxNodeId graph. Finds the maximum node id |in the graph, grahp's parents, and all fun nodes of that graph.

replaceNodeIds :: IntMap NodeId -> Graph -> Graph

replaceNodeIds newNidMap graph. Returns a copy of the graph, |with the node ids replaced with the new ones in newNidMap.

removeParentNodes :: IntMap Node -> Graph -> Graph

removeParentNodes parNodes graph. Removes all nodes with |id's that exist in parNodes from graph. Also removes all |nodes with ids in parNodes or graph, from all graphs nested |in FunNd in graph.

getNodes :: String -> [Graph] -> [NodeId] -> [Node]

gets the nodes from node ids for a given graph

getNodeCons :: Graph -> NodeId -> NodeId -> Set [Int] -> (Set NodeId, Set NodeId)

getNodeCons graph prevNodeId curNodeId tupPaths. Recursively looks at node |outputs to find all consumers of the value identified by the |current node and tuple paths (which identify the relevant |subvalues of the current node's value). Returns a set of |all tup and tup acc that proceed the consumers, and the set of |consumers themselves.

getNodeConsumers :: Graph -> NodeId -> (Set NodeId, Set NodeId)

getConsumers graph nodeId. Searches through all outputs, |and tuple, and tuple accessor nodes, finding consumers of the |value produced by this node. Returns a set of the nodes that |proceed these consumer nodes (and so may receive |values from the consumers), and the node ids of the consumer |nodes themselves.

visitNodeM :: Monad m => ([Graph] -> Node -> m ()) -> [Graph] -> NodeId -> StateT (NodeEnv ()) m ()

visitNodeM f graph nodeId. if the node specified by nodeId has not already been visited |visits all its inputs, and then applies f to itself.

visitGraphM :: Monad m => ([Graph] -> Node -> m ()) -> [Graph] -> m ()

visitGraphM visitF graph. Depth first traversal of a graph, applying |visitF to each node, never visiting the same node twice.

maxDepthVisitor :: Monad m => [Graph] -> Node -> StateT (NodeEnv Int) m ()

maxDepthVisitor graph node. Records the maximum depth of this node in |the state. I.e. the number of nodes above it's deepest input.

type PartNodeFun m = [NodeId] -> m [[NodeId]]

visitDeepestNodeM :: Monad m => PartNodeFun m -> ([Graph] -> Node -> m ()) -> [Graph] -> NodeEnv Int -> NodeId -> StateT (NodeEnv ()) m ()

visitDeepestNodeM pf f graph depths nodeId. if the node specified by nodeId has not already been visited |visits all its inputs, in order of descending depth, and then applies f to itself. |Uses pf to partition node lists into different groups, where the groups should be visited |in the order they appear in the list, but where members of groups can appear in any order.

cycleVisitor :: Monad m => [Graph] -> Node -> StateT (Set Int, [Int]) m ()

cycleVisitor checks there are no cycles in our graph.

visitDeepestGraphM :: Monad m => PartNodeFun m -> ([Graph] -> Node -> m ()) -> [Graph] -> m ()

visitDeepestGraphM visitF graph. Visits the nodes in the graph in deepest |first depth first traversal. I.e. it visits the deepest leaves, before shallower |ones.