diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2024-10-11 16:19:21 -0600 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2024-10-11 16:19:21 -0600 |
commit | 1e820e50668631a239cfc3188137cc90c34cf738 (patch) | |
tree | c2f2271d17199d97b91b397be46da075a569b21c /src/Language/Fiddle/Compiler/Qualification.hs | |
parent | 8082f91fd9fd1bdcbde5ebf74ed4710cdbb0c6c5 (diff) | |
download | fiddle-1e820e50668631a239cfc3188137cc90c34cf738.tar.gz fiddle-1e820e50668631a239cfc3188137cc90c34cf738.tar.bz2 fiddle-1e820e50668631a239cfc3188137cc90c34cf738.zip |
Further implement C backend.
There is a problem where I'm mixing up bits and bytes. I think I'll try
to resolve that using more type-level constraints.
Diffstat (limited to 'src/Language/Fiddle/Compiler/Qualification.hs')
-rw-r--r-- | src/Language/Fiddle/Compiler/Qualification.hs | 19 |
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 |