Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit a0bf65f

Browse files
committed
Move Edge into Concrete.
1 parent 7c24672 commit a0bf65f

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

semantic-core/src/Analysis/Concrete.hs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ newtype Frame = Frame
5959

6060
type Heap = IntMap.IntMap Concrete
6161

62+
data Edge = Lexical | Import
63+
deriving (Eq, Ord, Show)
64+
6265

6366
-- | Concrete evaluation of a term to a value.
6467
--
@@ -153,14 +156,14 @@ runHeap = runState mempty
153156
-- > λ let (heap, res) = concrete [ruby]
154157
-- > λ writeFile "/Users/rob/Desktop/heap.dot" (export (addressStyle heap) (heapAddressGraph heap))
155158
-- > λ :!dot -Tsvg < ~/Desktop/heap.dot > ~/Desktop/heap.svg
156-
heapGraph :: (Precise -> Concrete -> a) -> (Either Core.Edge User -> Precise -> G.Graph a) -> Heap -> G.Graph a
159+
heapGraph :: (Precise -> Concrete -> a) -> (Either Edge User -> Precise -> G.Graph a) -> Heap -> G.Graph a
157160
heapGraph vertex edge h = foldr (uncurry graph) G.empty (IntMap.toList h)
158161
where graph k v rest = (G.vertex (vertex k v) `G.connect` outgoing v) `G.overlay` rest
159162
outgoing = \case
160163
Unit -> G.empty
161164
Bool _ -> G.empty
162165
String _ -> G.empty
163-
Closure _ _ _ env -> foldr (G.overlay . edge (Left Core.Lexical)) G.empty env
166+
Closure _ _ _ env -> foldr (G.overlay . edge (Left Lexical)) G.empty env
164167
Record frame -> foldr (G.overlay . uncurry (edge . Right)) G.empty (Map.toList frame)
165168

166169
heapValueGraph :: Heap -> G.Graph Concrete
@@ -173,10 +176,10 @@ heapAddressGraph = heapGraph (\ addr v -> (Value v, addr)) (fmap G.vertex . (,)
173176
addressStyle :: Heap -> G.Style (EdgeType, Precise) Text
174177
addressStyle heap = (G.defaultStyle vertex) { G.edgeAttributes }
175178
where vertex (_, addr) = pack (show addr) <> " = " <> maybe "?" fromConcrete (IntMap.lookup addr heap)
176-
edgeAttributes _ (Slot name, _) = ["label" G.:= name]
177-
edgeAttributes _ (Edge Core.Import, _) = ["color" G.:= "blue"]
178-
edgeAttributes _ (Edge Core.Lexical, _) = ["color" G.:= "green"]
179-
edgeAttributes _ _ = []
179+
edgeAttributes _ (Slot name, _) = ["label" G.:= name]
180+
edgeAttributes _ (Edge Import, _) = ["color" G.:= "blue"]
181+
edgeAttributes _ (Edge Lexical, _) = ["color" G.:= "green"]
182+
edgeAttributes _ _ = []
180183
fromConcrete = \case
181184
Unit -> "()"
182185
Bool b -> pack $ show b
@@ -186,7 +189,7 @@ addressStyle heap = (G.defaultStyle vertex) { G.edgeAttributes }
186189
showPos (Pos l c) = pack (show l) <> ":" <> pack (show c)
187190

188191
data EdgeType
189-
= Edge Core.Edge
192+
= Edge Edge
190193
| Slot User
191194
| Value Concrete
192195
deriving (Eq, Ord, Show)

semantic-core/src/Data/Core.hs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
ScopedTypeVariables, StandaloneDeriving, TypeFamilies, TypeOperators, UndecidableInstances #-}
33
module Data.Core
44
( Core(..)
5-
, Edge(..)
65
, rec
76
, (>>>)
87
, unseq
@@ -50,9 +49,6 @@ import Data.Text (Text)
5049
import GHC.Generics (Generic1)
5150
import GHC.Stack
5251

53-
data Edge = Lexical | Import
54-
deriving (Eq, Ord, Show)
55-
5652
data Core f a
5753
-- | Recursive local binding of a name in a scope; strict evaluation of the name in the body will diverge.
5854
--

0 commit comments

Comments
 (0)