-
-
Notifications
You must be signed in to change notification settings - Fork 608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add ImportC C compiler #12507
add ImportC C compiler #12507
Conversation
|
Thanks for your pull request, @WalterBright! Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#12507" |
|
This is a 3000 line pr... and preliminary support for parsing a related but different language it's labeled trivial... |
This is a bit baffling. The declarations in the code are correct. |
6c98d04
to
b9d030b
Compare
|
C: typedef float real;
typedef struct impl {
void* x;
char lazy;
} module;
void does(int x)
{
module copy;
}D: import cdecl;
extern(C)
int main()
{
impl g;
module x;
pragma(msg, __traits(allMembers, impl)); //tuple("x", "lazy")
return g.lazy;
} |
|
This appears completely useless to me. First, it doesn't "just work" since you need to run cpp over the file before you can use it, and since that expands macros, it must be done for each different target, meaning it must be part of the build system. This offers no advantage over the (not great) existing solutions and shares many of their problems including creating huge files. Even if that just worked, C bindings tend to rely on the preprocessor to do common and necessary tasks like defining constants. Without that, you can't even reasonably use real world C headers. Possibly a limited processor could translate them, but even that data is gone after cpp goes through it, so there's no real hope to recover it into a usable form. I think trying to run the cpp over a whole D file like dpp does is problematic... but like something must be done. dstep's approach actually does a reasonably good job, at the cost of requiring a bit of hand editing and some setting up of other files too. I do think there's some potential in integrating with dmd... but this PR as it is looks like more harm than good. And I'm not sure it is worth the time sink it will take to get it to a positive point. |
|
@adamdruppe All good points, and I anticipated this reaction. But may I ask that the discussion of "should we do this at all" be moved to the newsgroup? I expect it to be long, and threading in the n.g. will make it easier to navigate. I already started the thread on it. Please keep this one confined to a review of the PR. Thanks! |
|
I think this is an interesting prototype. I don't see it as useless. It needs some work ofc, but it could potentially become quite handy |
struct context;
struct context {
float fps;
}; Fails to compile with |
|
@maxhaton That one fails because the semantic processing is in the D part. I haven't addressed that yet. |
|
@WalterBright try to follow the "separations of concern" design principle when implementing the c compiler. Don't be afraid of creating new files for this. |
|
Buildkite Style appears to have a problem: Looks like Style's list of tokens needs updating. |
|
I don't know why the bot doesn't add the comments but you can always refer to their website, see e.g. |
|
Thank you, that's what I need! |
b3cd9aa
to
90da945
Compare
|
@MoonlightSentinel unfortunately the coverage results for cparse.d are not being updated. |
|
All coverage pipelines sucessfully uploaded their report for |
|
At the top the coverage page says: which sounds relevant, but I don't know specifically what it means. |
|
Probably the most practical way to move forward with coverage testing is to pull this. |
|
CodeCov recently changed the algorithm which determines the base commit (changelog), seems like it selects the wrong base commit for this repository.....
You can run the coverage test locally: rdmd src/build.d clean
rdmd src/build.d ENABLE_COVERAGE=1
rdmd test/run.d compilable/testcstuff1.dAt first glance, a |
|
I'm going to defer the fail_compilation tests at this time, mainly because they are less important, and due to the fluid nature of this prototype are subject to constant change. |
Thanks, that's working beautifully! |
|
It's about as far as coverage testing will go without modifying the rest of the front end. |
| scope p = new CParser!AST(this, buf, cast(bool) docfile, | ||
| cast(ubyte) target.c.longsize, cast(ubyte) target.c.long_doublesize, cast(ubyte) target.c.twchar_t.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you instead pass a const copy/reference to target.c, this would allow me to quickly add the other types immediately after this gets pulled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted cparse.d to have minimal dependencies on anything else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What you could do is move TargetC to globals.d, just the data fields, not the member functions. That would sever its dependencies. Change twchar_t to a size rather than a Type, then the struct can stand alone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CParser is already a template though, so the cparse.d module need not import dmd.target.
|
So open discussions and remaining issues like #12507 (comment) were ignored again... |
|
This PR introduced a regression https://issues.dlang.org/show_bug.cgi?id=23548 |
This adds an ANSI C11 C compiler to dmd so it can import and compile C files directly. See
changelog/ImportC.mdfor details.This is a prototype implementation, known shortcomings are in the changelog.
It doesn't alter D in any way.