fdedden / language-c99-simple Goto Github PK
View Code? Open in Web Editor NEWSimplified C AST that translates to language-c99
License: MIT License
Simplified C AST that translates to language-c99
License: MIT License
For this version we apply a minor version bump, as only a feature has been added, no semantics have changed.
How do I get an #include <stdio.h>
? Is it possible, or do I need to drop down to language-c99
?
For this version we apply a minor version bump, as only a dependency version has changed.
(Originally reported at Copilot-Language/copilot#335 (comment).)
After upgrading to language-c99-simple-0.2.0.0
, I noticed that array initializers were being pretty-printed in a different order than what older versions of the library would print. Here is a minimal example that demonstrates the issue, with some light CPP used to paper over API differences between the two major versions of the library:
#!/usr/bin/env cabal
{- cabal:
build-depends: base, language-c99, language-c99-simple
-}
{-# LANGUAGE CPP #-}
module Main where
import GHC.Exts (IsList(..))
import Language.C99.Pretty
import Language.C99.Simple
arr :: Init
arr =
#if MIN_VERSION_language_c99_simple(0,2,0)
InitList $
#else
InitArray $
#endif
fromList [ boolInit True
, boolInit False
, boolInit False
, boolInit False
, boolInit False
]
#if MIN_VERSION_language_c99_simple(0,2,0)
boolInit :: Bool -> InitItem
boolInit = InitItem Nothing . InitExpr . LitBool
#else
boolInit :: Bool -> Init
boolInit = InitExpr . LitBool
#endif
main :: IO ()
main = print $ pretty $ transinit arr
Running this program with language-c99-simple-0.1.*
gives this order, as expected:
$ cabal run Bug.hs --constraint="language-c99-simple<0.2"
<snip>
{(true), (false), (false), (false), (false)}
On the other hand, running this program with language-c99-simple-0.2.*
gives an unexpected order:
$ cabal run Bug.hs --constraint="language-c99-simple>=0.2"
<snip>
{(false), (false), (false), (false), (true)}
Notice that the true
element is now at the end of the array instead of the beginning. Bisecting reveals that commit 86fe2b3 is responsible for this regression.
For this version we apply a major version bump, as we broke the public interface.
Unlike FunDecln
, which is defined as:
FunDecl (Maybe StorageSpec) Type Ident [Param]
a FunDef
does not include a StorageSpec
(optional or not):
FunDef Type Ident [Param] [Decln] [Stmt]
This prevents us from adding the keyword static
to local functions, which is a requirement for compliance with MISRA C 2012 in Copilot (see Copilot-Language/copilot#472), which we really want to get.
For this specific release we will do a minor version bump even though the API has changed. The previous release erroneously changed the API, this release fixes that again.
I'm able to compile language-c99-simple with mtl 2.3 if I adjust the version bounds in the cabal file to read:
mtl >= 2.2.0 && < 2.4
Does the version bound on mtl need to be so strict?
Things have changed in base 4.12. This library no longer compiles:
Configuring language-c99-simple-0.1.0.0...
Building language-c99-simple-0.1.0.0...
Preprocessing library language-c99-simple-0.1.0.0...
[1 of 5] Compiling Language.C99.Simple.AST ( src/Language/C99/Simple/AST.hs, dist/dist-sandbox-11467d12/build/Language/C99/Simple/AST.o )
[2 of 5] Compiling Language.C99.Simple.Expr ( src/Language/C99/Simple/Expr.hs, dist/dist-sandbox-11467d12/build/Language/C99/Simple/Expr.o )
[3 of 5] Compiling Language.C99.Simple.Util ( src/Language/C99/Simple/Util.hs, dist/dist-sandbox-11467d12/build/Language/C99/Simple/Util.o )
[4 of 5] Compiling Language.C99.Simple.Translate ( src/Language/C99/Simple/Translate.hs, dist/dist-sandbox-11467d12/build/Language/C99/Simple/Translate.o )
src/Language/C99/Simple/Translate.hs:302:5: error:
• No instance for (Control.Monad.Fail.MonadFail
Data.Functor.Identity.Identity)
arising from a do statement
with the failable pattern ‘(C.AbstractDeclrDirect ptr adeclr)’
For example something like this:
void *(*fptr)() = &bar;
where bar
has the type void* bar()
. I could not figure out how to express these types in the current data type Type
.
I just noticed that the AST does not define an instance for Eq
.
It would be useful to be able to compare AST branches for equality (for example, to ensure you are not generating the same expression twice, or to be able to put declarations in a set). Is there a fundamental reason why it cannot or should not be done
?
Version constraints to language-c99 and language-c99-util are defined with a wildcard (0.1.*), this can be problematic if the version is just 0.1
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.