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

Commit 1bd25ac

Browse files
committed
Represent user variables as Text.
1 parent 7583226 commit 1bd25ac

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

semantic-core/src/Analysis/Concrete.hs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{-# LANGUAGE FlexibleContexts, FlexibleInstances, GeneralizedNewtypeDeriving, LambdaCase, MultiParamTypeClasses, NamedFieldPuns, RecordWildCards, TypeApplications, TypeOperators, UndecidableInstances #-}
1+
{-# LANGUAGE FlexibleContexts, FlexibleInstances, GeneralizedNewtypeDeriving, LambdaCase, MultiParamTypeClasses, NamedFieldPuns, OverloadedStrings, RecordWildCards, TypeApplications, TypeOperators, UndecidableInstances #-}
22
module Analysis.Concrete
33
( Concrete(..)
44
, concrete
@@ -29,7 +29,7 @@ import Data.Loc
2929
import qualified Data.Map as Map
3030
import Data.Monoid (Alt(..))
3131
import Data.Name
32-
import Data.Text (Text, unpack)
32+
import Data.Text (Text, pack)
3333
import Prelude hiding (fail)
3434

3535
type Precise = Int
@@ -185,25 +185,25 @@ heapValueGraph h = heapGraph (const id) (const fromAddr) h
185185
heapAddressGraph :: Heap -> G.Graph (EdgeType, Precise)
186186
heapAddressGraph = heapGraph (\ addr v -> (Value v, addr)) (fmap G.vertex . (,) . either Edge Slot)
187187

188-
addressStyle :: Heap -> G.Style (EdgeType, Precise) String
188+
addressStyle :: Heap -> G.Style (EdgeType, Precise) Text
189189
addressStyle heap = (G.defaultStyle vertex) { G.edgeAttributes }
190-
where vertex (_, addr) = maybe (show addr <> " = ?") (((show addr <> " = ") <>) . fromConcrete) (IntMap.lookup addr heap)
190+
where vertex (_, addr) = maybe (pack (show addr) <> " = ?") (((pack (show addr) <> " = ") <>) . fromConcrete) (IntMap.lookup addr heap)
191191
edgeAttributes _ (Slot name, _) = ["label" G.:= fromName name]
192192
edgeAttributes _ (Edge Core.Import, _) = ["color" G.:= "blue"]
193193
edgeAttributes _ (Edge Core.Lexical, _) = ["color" G.:= "green"]
194194
edgeAttributes _ _ = []
195195
fromConcrete = \case
196196
Unit -> "()"
197-
Bool b -> show b
198-
String s -> show s
199-
Closure (Loc p (Span s e)) n _ _ -> "\\\\ " <> fromName n <> " [" <> unpack p <> ":" <> showPos s <> "-" <> showPos e <> "]"
197+
Bool b -> pack $ show b
198+
String s -> pack $ show s
199+
Closure (Loc p (Span s e)) n _ _ -> "\\\\ " <> fromName n <> " [" <> p <> ":" <> showPos s <> "-" <> showPos e <> "]"
200200
Obj _ -> "{}"
201-
showPos (Pos l c) = show l <> ":" <> show c
201+
showPos (Pos l c) = pack (show l) <> ":" <> pack (show c)
202202
fromName (User s) = s
203203
fromName (Gen sym) = fromGensym sym
204-
fromName (Path p) = show p
205-
fromGensym (Root s) = s
206-
fromGensym (ss :/ (s, i)) = fromGensym ss <> "." <> s <> show i
204+
fromName (Path p) = pack $ show p
205+
fromGensym (Root s) = pack s
206+
fromGensym (ss :/ (s, i)) = fromGensym ss <> "." <> pack s <> pack (show i)
207207

208208
data EdgeType
209209
= Edge Core.Edge

semantic-core/src/Data/Name.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ import Control.Monad.IO.Class
2626
import qualified Data.Char as Char
2727
import Data.HashSet (HashSet)
2828
import qualified Data.HashSet as HashSet
29-
import Data.Text (Text)
29+
import Data.Text as Text (Text, any, unpack)
3030
import Data.Text.Prettyprint.Doc (Pretty (..))
3131
import qualified Data.Text.Prettyprint.Doc as Pretty
3232

3333
-- | User-specified and -relevant names.
34-
type User = String
34+
type User = Text
3535

3636
-- | The type of namespaced actions, i.e. actions occurring within some outer name.
3737
--
@@ -57,14 +57,14 @@ instance Pretty Name where
5757
User n -> pretty n
5858
Path p -> pretty (show p)
5959

60-
reservedNames :: HashSet User
60+
reservedNames :: HashSet String
6161
reservedNames = [ "#true", "#false", "let", "#frame", "if", "then", "else"
6262
, "lexical", "import", "#unit", "load"]
6363

6464
-- | Returns true if any character would require quotation or if the
6565
-- name conflicts with a Core primitive.
6666
needsQuotation :: User -> Bool
67-
needsQuotation u = HashSet.member u reservedNames || any (not . isSimpleCharacter) u
67+
needsQuotation u = HashSet.member (unpack u) reservedNames || Text.any (not . isSimpleCharacter) u
6868

6969
-- | A ‘simple’ character is, loosely defined, a character that is compatible
7070
-- with identifiers in most ASCII-oriented programming languages. This is defined

0 commit comments

Comments
 (0)