@@ -193,29 +193,64 @@ data Name = UN String -- ^ User-provided name
193 | NS Name [String] -- ^ Root, namespaces
193 | NS Name [String] -- ^ Root, namespaces
194 | MN Int String -- ^ Machine chosen names
194 | MN Int String -- ^ Machine chosen names
195 | NErased -- ^ Name of somethng which is never used in scope
195 | NErased -- ^ Name of somethng which is never used in scope
196+ | SN SpecialName -- ^ Decorated function names
196 deriving (Eq, Ord)
197 deriving (Eq, Ord)
198deriving instance Binary Name
199deriving instance Binary Name
202+data SpecialName = WhereN Int Name Name
203+ | InstanceN Name [String]
204+ | ParentN Name String
209+deriving instance Binary SpecialName
201instance Sized Name where
212instance Sized Name where
202 size (UN n) = 1
213 size (UN n) = 1
203 size (NS n els) = 1 + length els
214 size (NS n els) = 1 + length els
204 size (MN i n) = 1
215 size (MN i n) = 1
205− size NErased = 1
216+ size _ = 1
207instance Pretty Name where
218instance Pretty Name where
208 pretty (UN n) = text n
219 pretty (UN n) = text n
209 pretty (NS n s) = pretty n
220 pretty (NS n s) = pretty n
210 pretty (MN i s) = lbrace <+> text s <+> (text . show $ i) <+> rbrace
221 pretty (MN i s) = lbrace <+> text s <+> (text . show $ i) <+> rbrace
222+ pretty (SN s) = text (show s)
212instance Show Name where
224instance Show Name where
213 show (UN n) = n
225 show (UN n) = n
214 show (NS n s) = showSep "." (reverse s) ++ "." ++ show n
226 show (NS n s) = showSep "." (reverse s) ++ "." ++ show n
215 show (MN _ "underscore") = "_"
227 show (MN _ "underscore") = "_"
216 show (MN i s) = "{" ++ s ++ show i ++ "}"
228 show (MN i s) = "{" ++ s ++ show i ++ "}"
229+ show (SN s) = show s
217 show NErased = "_"
230 show NErased = "_"
232+instance Show SpecialName where
233+ show (WhereN i p c) = show p ++ ", " ++ show c
234+ show (InstanceN cl inst) = showSep ", " inst ++ " instance of " ++ show cl
235+ show (MethodN m) = "method " ++ show m
236+ show (ParentN p c) = show p ++ "#" ++ c
237+ show (CaseN n) = "case block in " ++ show n
239+-- Show a name in a way decorated for code generation, not human reading
240+showCG :: Name -> String
242+showCG (NS n s) = showSep "." (reverse s) ++ "." ++ show n
243+showCG (MN _ "underscore") = "_"
244+showCG (MN i s) = "{" ++ s ++ show i ++ "}"
245+showCG (SN s) = showCG' s
246+ where showCG' (WhereN i p c) = show p ++ ":" ++ show c ++ ":" ++ show i
247+ showCG' (InstanceN cl inst) = '@':show cl ++ '$':show inst
248+ showCG' (MethodN m) = '!':show m
249+ showCG' (ParentN p c) = show p ++ "#" ++ show c
250+ showCG' (CaseN c) = show c ++ "_case"
219-- |Contexts allow us to map names to things. A root name maps to a collection
254-- |Contexts allow us to map names to things. A root name maps to a collection
220-- of things in different namespaces with that name.
255-- of things in different namespaces with that name.
221type Ctxt a = Map.Map Name (Map.Map Name a)
256type Ctxt a = Map.Map Name (Map.Map Name a)
@@ -223,6 +258,9 @@ emptyContext = Map.empty
224tcname (UN ('@':_)) = True
259tcname (UN ('@':_)) = True
225tcname (NS n _) = tcname n
260tcname (NS n _) = tcname n
261+tcname (SN (InstanceN _ _)) = True
262+tcname (SN (MethodN _)) = True
263+tcname (SN (ParentN _ _)) = True
226tcname _ = False
264tcname _ = False
228implicitable (NS n _) = implicitable n
266implicitable (NS n _) = implicitable n
@@ -761,6 +799,11 @@ nextName (UN x) = let (num', nm') = span isDigit (reverse x)
762 readN "" = 0
800 readN "" = 0
763 readN x = read x
801 readN x = read x
802+nextName (SN x) = SN (nextName' x)
804+ nextName' (WhereN i f x) = WhereN i f (nextName x)
805+ nextName' (CaseN n) = CaseN (nextName n)
806+ nextName' (MethodN n) = MethodN (nextName n)
765type Term = TT Name
808type Term = TT Name
766type Type = Term
809type Type = Term