Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion brat/Brat/Compiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ printAST printRaw printAST file = do
writeDot :: [FilePath] -> String -> String -> IO ()
writeDot libDirs file out = do
env <- runExceptT $ loadFilename root libDirs file
-- Discard captureSets; perhaps we could incorporate into the graph
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have been removed in #117 too!

(_, _, _, graph, cs) <- eitherIO env
writeFile out (toDotString graph cs)
{-
Expand Down
13 changes: 11 additions & 2 deletions brat/Brat/Dot.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import qualified Data.GraphViz.Attributes.Complete as GV

import qualified Data.Map as M
import qualified Data.Set as S
import Data.List.NonEmpty (NonEmpty(..))
import Data.Text.Lazy (pack, unpack)
import Data.Maybe (fromMaybe)
import Data.Bifunctor (first)
Expand All @@ -29,11 +30,12 @@ instance (GV.PrintDot Name') where
toDot (Name' name) = GV.text . pack $ "\"" ++ show name ++ "\""


data EdgeType = EvalEdge | SrcEdge | GraphEdge (Val Z)
data EdgeType = EvalEdge | SrcEdge | CaseEdge | GraphEdge (Val Z)

instance Show EdgeType where
show EvalEdge = ""
show SrcEdge = ""
show CaseEdge = ""
show (GraphEdge ty) = show ty


Expand All @@ -54,6 +56,8 @@ toDotString (ns,ws) cs = unpack . GV.printDotGraph $ GV.graphElemsToDot params v
getRefEdge x (BratNode (Eval (Ex y _)) _ _) = [(Name' y, x, EvalEdge)]
getRefEdge x (KernelNode (Splice (Ex y _)) _ _) = [(Name' y, x, EvalEdge)]
getRefEdge x (BratNode (Box src tgt) _ _) = [(x, Name' src, SrcEdge), (x, Name' tgt, SrcEdge)]
getRefEdge x (BratNode (PatternMatch (p:|pats)) _ _) =
[ (x, Name' innerBox, CaseEdge) | (_, innerBox) <- (p:pats) ]
getRefEdge _ _ = []

-- Map from node to cluster. Clusters are identified by their containing Box node.
Expand All @@ -66,7 +70,11 @@ toDotString (ns,ws) cs = unpack . GV.printDotGraph $ GV.graphElemsToDot params v
-- reachable from src that can reach tgt
let srcReaches = reachable g (fromJust (toVert src))
reachesTgt = reachable (transposeG g) (fromJust (toVert tgt))
nodesUsedInBox = snd3 . toNode <$> (srcReaches ++ reachesTgt)
nodesReachedInBox = snd3 . toNode <$> (srcReaches ++ reachesTgt)
-- Add any Box nodes used by PatternMatch nodes in the cluster
matches = M.fromList [(n, p:ps) | n <- nodesReachedInBox,
Just (BratNode (PatternMatch (p:|ps)) _ _) <- [ns M.!? n]]
nodesUsedInBox = nodesReachedInBox ++ map snd (concat (M.elems matches))
-- exclude nodes that are captured by the box - these are not in the box
-- (TODO: we might consider adding extra edges from these to the box itself,
-- but for now they'll just have "normal" value edges *entering* the box)
Expand Down Expand Up @@ -105,6 +113,7 @@ toDotString (ns,ws) cs = unpack . GV.printDotGraph $ GV.graphElemsToDot params v
-- Do not repeat the internal links that have been turned into edges
showNodeType (BratNode (Box _ _) _ _) = "Box"
showNodeType (BratNode (Eval _) _ _) = "Eval"
showNodeType (BratNode (PatternMatch _) _ _) = "PatternMatch"
showNodeType (BratNode thing _ _) = show thing
showNodeType (KernelNode thing _ _) = show thing

Expand Down
15 changes: 15 additions & 0 deletions brat/test/compilation/closures.brat
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
f(Nat) -> { Nat -> Nat }
f(x) = { y => x + y }

g(Nat) -> { Nat -> { Nat -> Nat } }
g(x) = { y => { z => x + y + z } }


h(Nat) -> { Nat -> Nat }
h(x) = let y = x in { z => x + y + z }

ff(Vec(Nat,2)) -> { Nat -> Nat }
ff([a,b]) = { y => a + b*y }

ext "to_float" i2f :: {Int -> Float}

fi(Float) -> { Int -> Float }
fi(x) = { y => x + i2f(y) }
Loading