summaryrefslogtreecommitdiff
path: root/src/Language/Fiddle/Compiler/Qualification.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Language/Fiddle/Compiler/Qualification.hs')
-rw-r--r--src/Language/Fiddle/Compiler/Qualification.hs19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/Language/Fiddle/Compiler/Qualification.hs b/src/Language/Fiddle/Compiler/Qualification.hs
index e09725e..70378c3 100644
--- a/src/Language/Fiddle/Compiler/Qualification.hs
+++ b/src/Language/Fiddle/Compiler/Qualification.hs
@@ -45,14 +45,17 @@ type A = Commented SourceSpan
type M = Compile GlobalState
-uniqueString :: M String
-uniqueString = do
+uniqueString :: String -> M String
+uniqueString prefix = do
cnt <- gets uniqueCounter
modify $ \g -> g {uniqueCounter = cnt + 1}
- return $ "__anon" ++ show cnt
+ return $ "_" ++ prefix ++ show cnt
uniqueIdentifier :: a -> M (Identifier F a)
-uniqueIdentifier a = (\s -> Identifier (Data.Text.pack s) a) <$> uniqueString
+uniqueIdentifier a = (\s -> Identifier (Data.Text.pack s) a) <$> uniqueString "ident"
+
+uniqueReservedIdentifier :: a -> M (Identifier F a)
+uniqueReservedIdentifier a = (\s -> Identifier (Data.Text.pack s) a) <$> uniqueString "reserved"
instance CompilationStage Expanded where
type StageAfter Expanded = Qualified
@@ -82,6 +85,14 @@ instance
where
convertInStage _ ann _ = guaranteeM (uniqueIdentifier ann)
+instance
+ StageConvertible
+ Expanded
+ (When False String)
+ (When True String)
+ where
+ convertInStage _ _ _ _ = Present <$> uniqueString "reserved"
+
deriving instance AdvanceStage S ObjTypeBody
deriving instance AdvanceStage S DeferredRegisterBody