1- {-# LANGUAGE FlexibleContexts, FlexibleInstances, LambdaCase, MultiParamTypeClasses, NamedFieldPuns, RecordWildCards, TypeOperators, UndecidableInstances #-}
1+ {-# LANGUAGE FlexibleContexts, FlexibleInstances, LambdaCase, MultiParamTypeClasses, NamedFieldPuns, OverloadedStrings, RecordWildCards, TypeOperators, UndecidableInstances #-}
22module Analysis.Concrete
33( Concrete (.. )
44, concrete
@@ -29,6 +29,7 @@ import Data.Loc
2929import qualified Data.Map as Map
3030import Data.Monoid (Alt (.. ))
3131import Data.Name
32+ import Data.Text (Text , pack )
3233import Prelude hiding (fail )
3334
3435type Precise = Int
@@ -41,7 +42,7 @@ data Concrete
4142 = Closure Loc Name Core. Core Precise
4243 | Unit
4344 | Bool Bool
44- | String String
45+ | String Text
4546 | Obj Frame
4647 deriving (Eq , Ord , Show )
4748
@@ -60,7 +61,7 @@ type Heap = IntMap.IntMap Concrete
6061
6162-- | Concrete evaluation of a term to a value.
6263--
63- -- >>> snd (concrete [File (Loc "bool" emptySpan) (Core.Bool True)])
64+ -- >>> map fileBody ( snd (concrete [File (Loc "bool" emptySpan) (Core.Bool True)]) )
6465-- [Right (Bool True)]
6566concrete :: [File Core. Core ] -> (Heap , [File (Either (Loc , String ) Concrete )])
6667concrete
@@ -184,28 +185,32 @@ heapValueGraph h = heapGraph (const id) (const fromAddr) h
184185heapAddressGraph :: Heap -> G. Graph (EdgeType , Precise )
185186heapAddressGraph = heapGraph (\ addr v -> (Value v, addr)) (fmap G. vertex . (,) . either Edge Slot )
186187
187- addressStyle :: Heap -> G. Style (EdgeType , Precise ) String
188+ addressStyle :: Heap -> G. Style (EdgeType , Precise ) Text
188189addressStyle heap = (G. defaultStyle vertex) { G. edgeAttributes }
189- where vertex (_, addr) = maybe (show addr <> " = ? " ) ((( show addr <> " = " ) <> ) . fromConcrete) (IntMap. lookup addr heap)
190+ where vertex (_, addr) = pack (show addr) <> " = " <> maybe " ? " fromConcrete (IntMap. lookup addr heap)
190191 edgeAttributes _ (Slot name, _) = [" label" G. := fromName name]
191192 edgeAttributes _ (Edge Core. Import , _) = [" color" G. := " blue" ]
192193 edgeAttributes _ (Edge Core. Lexical , _) = [" color" G. := " green" ]
193194 edgeAttributes _ _ = []
194195 fromConcrete = \ case
195196 Unit -> " ()"
196- Bool b -> show b
197- String s -> show s
197+ Bool b -> pack $ show b
198+ String s -> pack $ show s
198199 Closure (Loc p (Span s e)) n _ _ -> " \\\\ " <> fromName n <> " [" <> p <> " :" <> showPos s <> " -" <> showPos e <> " ]"
199200 Obj _ -> " {}"
200- showPos (Pos l c) = show l <> " :" <> show c
201+ showPos (Pos l c) = pack ( show l) <> " :" <> pack ( show c)
201202 fromName (User s) = s
202203 fromName (Gen sym) = fromGensym sym
203- fromName (Path p) = show p
204+ fromName (Path p) = pack $ show p
204205 fromGensym (Root s) = s
205- fromGensym (ss :/ (s, i)) = fromGensym ss <> " ." <> s <> show i
206+ fromGensym (ss :/ (s, i)) = fromGensym ss <> " ." <> s <> pack ( show i)
206207
207208data EdgeType
208209 = Edge Core. Edge
209210 | Slot Name
210211 | Value Concrete
211212 deriving (Eq , Ord , Show )
213+
214+
215+ -- $setup
216+ -- >>> :seti -XOverloadedStrings
0 commit comments