on master help sign in
Handle BuiltIn properly
35e90f6Evan Czaplicki
compiler/AST/Variable.hs+11−15
@@ -1,4 +1,4 @@
1−
1+{-# OPTIONS_GHC -W #-}
2module AST.Variable where
2module AST.Variable where
3
3
4import Data.Binary
4import Data.Binary
@@ -6,10 +6,6 @@ import Control.Applicative ((<$>), (<*>))
6import Text.PrettyPrint as P
6import Text.PrettyPrint as P
7import AST.PrettyPrint
7import AST.PrettyPrint
8
8
9−import qualified Data.List as List
10−import qualified Text.PrettyPrint as P
11−import AST.PrettyPrint
12−
13newtype Raw = Raw String
9newtype Raw = Raw String
14 deriving (Eq,Ord,Show)
10 deriving (Eq,Ord,Show)
15
11
@@ -37,6 +33,7 @@ instance ToString Canonical where
37 toString (Canonical home name) =
33 toString (Canonical home name) =
38 case home of
34 case home of
39 Local -> name
35 Local -> name
36+ BuiltIn -> name
40 Module path -> path ++ "." ++ name
37 Module path -> path ++ "." ++ name
41
38
42-- | A listing of values. Something like (a,b,c) or (..) or (a,b,..)
39-- | A listing of values. Something like (a,b,c) or (..) or (a,b,..)
@@ -59,12 +56,7 @@ instance Pretty Raw where
59 pretty (Raw var) = variable var
56 pretty (Raw var) = variable var
60
57
61instance Pretty Canonical where
58instance Pretty Canonical where
62− pretty (Canonical home name) =
59+ pretty var = P.text (toString var)
63− P.text (home' ++ name)
64− where
65− home' = case home of
66− Local -> ""
67− Module name -> name ++ "."
68
60
69instance Pretty a => Pretty (Listing a) where
61instance Pretty a => Pretty (Listing a) where
70 pretty (Listing explicits open) =
62 pretty (Listing explicits open) =
@@ -84,12 +76,14 @@ instance Binary Canonical where
84 put (Canonical home name) =
76 put (Canonical home name) =
85 case home of
77 case home of
86 Local -> putWord8 0 >> put name
78 Local -> putWord8 0 >> put name
87− Module path -> putWord8 1 >> put path >> put name
79+ BuiltIn -> putWord8 1 >> put name
80+ Module path -> putWord8 2 >> put path >> put name
88
81
89 get = do tag <- getWord8
82 get = do tag <- getWord8
90 case tag of
83 case tag of
91 0 -> Canonical Local <$> get
84 0 -> Canonical Local <$> get
85+ 1 -> Canonical BuiltIn <$> get
92− 1 -> Canonical . Module <$> get <*> get
86+ 2 -> Canonical . Module <$> get <*> get
93 _ -> error "Unexpected tag when deserializing canonical variable"
87 _ -> error "Unexpected tag when deserializing canonical variable"
94
88
95instance Binary Value where
89instance Binary Value where
@@ -97,14 +91,16 @@ instance Binary Value where
97 let put' n info = putWord8 n >> put info in
91 let put' n info = putWord8 n >> put info in
98 case portable of
92 case portable of
99 Value name -> put' 0 name
93 Value name -> put' 0 name
94+ Alias name -> put' 1 name
100 ADT name ctors ->
95 ADT name ctors ->
101− do put' 1 name
96+ do put' 2 name
102 put ctors
97 put ctors
103
98
104 get = do tag <- getWord8
99 get = do tag <- getWord8
105 case tag of
100 case tag of
106 0 -> Value <$> get
101 0 -> Value <$> get
102+ 1 -> Alias <$> get
107− 1 -> ADT <$> get <*> get
103+ 2 -> ADT <$> get <*> get
108 _ -> error "Error reading valid import/export information from serialized string"
104 _ -> error "Error reading valid import/export information from serialized string"
109
105
110instance (Binary a) => Binary (Listing a) where
106instance (Binary a) => Binary (Listing a) where