packages feed

copilot-c99 3.11 → 3.12

raw patch · 3 files changed

+41/−19 lines, 3 filesdep ~copilot-corePVP ok

version bump matches the API change (PVP)

Dependency ranges changed: copilot-core

API changes (from Hackage documentation)

Files

CHANGELOG view
@@ -1,3 +1,8 @@+2022-11-07+        * Version bump (3.12). (#389)+        * Removed deprecated flag from cabal file. (#380)+        * Generate type declarations in separate header file. (#373)+ 2022-09-07         * Version bump (3.11). (#376)         * Update to support language-c99-0.2.0. (#371)
copilot-c99.cabal view
@@ -1,6 +1,6 @@ cabal-version             : >= 1.10 name                      : copilot-c99-version                   : 3.11+version                   : 3.12 synopsis                  : A compiler for Copilot targeting C99. description               :   This package is a back-end from Copilot to C.@@ -38,18 +38,14 @@   default-language        : Haskell2010   hs-source-dirs          : src -  -- The following -Wno-deprecations is temprary and related to issue-  -- https://github.com/Copilot-Language/copilot/issues/237-  -- It should be removed in a future version, when this library hides-  -- internal modules.-  ghc-options             : -Wall -Wno-deprecations+  ghc-options             : -Wall   build-depends           : base                >= 4.9 && < 5                           , directory           >= 1.3 && < 1.4                           , filepath            >= 1.4 && < 1.5                           , mtl                 >= 2.2 && < 2.4                           , pretty              >= 1.1 && < 1.2 -                          , copilot-core        >= 3.11  && < 3.12+                          , copilot-core        >= 3.12  && < 3.13                           , language-c99        >= 0.2.0 && < 0.3                           , language-c99-simple >= 0.2.2 && < 0.3 
src/Copilot/Compile/C99/Compile.hs view
@@ -38,6 +38,7 @@   | otherwise   = do let cfile = render $ pretty $ C.translate $ compilec cSettings spec            hfile = render $ pretty $ C.translate $ compileh cSettings spec+           typeDeclnsFile = safeCRender $ compileTypeDeclns cSettings spec             cmacros = unlines [ "#include <stdint.h>"                              , "#include <stdbool.h>"@@ -45,6 +46,7 @@                              , "#include <stdlib.h>"                              , "#include <math.h>"                              , ""+                             , "#include \"" ++ prefix ++ "_types.h\""                              , "#include \"" ++ prefix ++ ".h\""                              , ""                              ]@@ -53,6 +55,7 @@        createDirectoryIfMissing True dir        writeFile (dir </> prefix ++ ".c") $ cmacros ++ cfile        writeFile (dir </> prefix ++ ".h") hfile+       writeFile (dir </> prefix ++ "_types.h") typeDeclnsFile  -- | Compile a specification to a .h and a .c file. --@@ -74,21 +77,10 @@     streams  = specStreams spec     triggers = specTriggers spec     exts     = gatherexts streams triggers-    exprs    = gatherexprs streams triggers -    declns = mkstructdeclns exprs ++ mkexts exts ++ mkglobals streams+    declns = mkexts exts ++ mkglobals streams     funs   = genfuns streams triggers ++ [mkstep cSettings streams triggers exts] -    -- Write struct datatypes-    mkstructdeclns :: [UExpr] -> [C.Decln]-    mkstructdeclns es = catMaybes $ map mkdecln utypes-      where-        mkdecln (UType ty) = case ty of-          Struct x -> Just $ mkstructdecln ty-          _        -> Nothing--        utypes = nub $ concatMap (\(UExpr _ e) -> exprtypes e) es-     -- Make declarations for copies of external variables.     mkexts :: [External] -> [C.Decln]     mkexts exts = map mkextcpydecln exts@@ -171,3 +163,32 @@     stepdecln :: C.Decln     stepdecln = C.FunDecln Nothing (C.TypeSpec C.Void)                     (cSettingsStepFunctionName cSettings) []++-- | Generate a C translation unit that contains all type declarations needed+-- by the Copilot specification.+compileTypeDeclns :: CSettings -> Spec -> C.TransUnit+compileTypeDeclns _cSettings spec = C.TransUnit declns []+  where+    declns = mkTypeDeclns exprs++    exprs    = gatherexprs streams triggers+    streams  = specStreams spec+    triggers = specTriggers spec++    -- Generate type declarations.+    mkTypeDeclns :: [UExpr] -> [C.Decln]+    mkTypeDeclns es = catMaybes $ map mkTypeDecln uTypes+      where+        uTypes = nub $ concatMap (\(UExpr _ e) -> exprtypes e) es++        mkTypeDecln (UType ty) = case ty of+          Struct _ -> Just $ mkstructdecln ty+          _        -> Nothing++-- * Auxiliary definitions++-- | Render a C.TransUnit to a String, accounting for the case in which the+-- translation unit is empty.+safeCRender :: C.TransUnit -> String+safeCRender (C.TransUnit [] []) = ""+safeCRender transUnit           = render $ pretty $ C.translate transUnit