From 1e820e50668631a239cfc3188137cc90c34cf738 Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Fri, 11 Oct 2024 16:19:21 -0600 Subject: 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. --- src/Language/Fiddle/Compiler/Qualification.hs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/Language/Fiddle/Compiler/Qualification.hs') 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 -- cgit