@@ -193,29 +193,64 @@ data Name = UN String -- ^ User-provided name
193193 | NS Name [String] -- ^ Root, namespaces
194194 | MN Int String -- ^ Machine chosen names
195195 | NErased -- ^ Name of somethng which is never used in scope
196+ | SN SpecialName -- ^ Decorated function names
196197 deriving (Eq, Ord)
197198{-!
198199deriving instance Binary Name
199200!-}
200201
202+data SpecialName = WhereN Int Name Name
203+ | InstanceN Name [String]
204+ | ParentN Name String
205+ | MethodN Name
206+ | CaseN Name
207+ deriving (Eq, Ord)
208+{-!
209+deriving instance Binary SpecialName
210+!-}
211+
201212instance Sized Name where
202213 size (UN n) = 1
203214 size (NS n els) = 1 + length els
204215 size (MN i n) = 1
205− size NErased = 1
216+ size _ = 1
206217
207218instance Pretty Name where
208219 pretty (UN n) = text n
209220 pretty (NS n s) = pretty n
210221 pretty (MN i s) = lbrace <+> text s <+> (text . show $ i) <+> rbrace
222+ pretty (SN s) = text (show s)
211223
212224instance Show Name where
213225 show (UN n) = n
214226 show (NS n s) = showSep "." (reverse s) ++ "." ++ show n
215227 show (MN _ "underscore") = "_"
216228 show (MN i s) = "{" ++ s ++ show i ++ "}"
229+ show (SN s) = show s
217230 show NErased = "_"
218231
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
238+
239+-- Show a name in a way decorated for code generation, not human reading
240+showCG :: Name -> String
241+showCG (UN n) = n
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"
251+showCG NErased = "_"
252+
253+
219254-- |Contexts allow us to map names to things. A root name maps to a collection
220255-- of things in different namespaces with that name.
221256type Ctxt a = Map.Map Name (Map.Map Name a)
@@ -223,6 +258,9 @@ emptyContext = Map.empty
223258
224259tcname (UN ('@':_)) = True
225260tcname (NS n _) = tcname n
261+tcname (SN (InstanceN _ _)) = True
262+tcname (SN (MethodN _)) = True
263+tcname (SN (ParentN _ _)) = True
226264tcname _ = False
227265
228266implicitable (NS n _) = implicitable n
@@ -761,6 +799,11 @@ nextName (UN x) = let (num', nm') = span isDigit (reverse x)
761799 where
762800 readN "" = 0
763801 readN x = read x
802+nextName (SN x) = SN (nextName' x)
803+ where
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)
764807
765808type Term = TT Name
766809type Type = Term