-
-
Notifications
You must be signed in to change notification settings - Fork 146
dtoh, first draft #39
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
Conversation
} | ||
|
||
string[string] typeMapping = [ | ||
"int" : "long", // D int is fixed at 32 bit so I think this is more correct than using C int... |
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.
Huh? C int is 32 bit pretty much everywhere (on the platforms immediately relevant to us), whereas sizeof(long) == 4 holds only on Windows (LLP64).
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.
On Tue, Jan 15, 2013 at 01:11:57PM -0800, David Nadlinger wrote:
Huh? C int is 32 bit pretty much everywhere, whereas sizeof(long) == 4 holds only on Windows (LLP64).
I thought it was the opposite!
So is the correct mapping always going to be:
D C
int -> int
long -> long long
for both 32 and 64 bit?
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.
nvm, I looked it up. Old memories of 16 bit ints confused me!
it is fixed now
Code style should be consistent with the rest of the code bases of the DPL org, i.e. 4 space indentation, Allman brace style, spaces between operators and operands, space before statement keyword and parenthesis, etc. |
@alexrp what's the status of this? care to make the style pass? |
The updated code to work with newer versions of dmd is currently Cable guy is supposed to fix it at some point today, so I can most |
This should be in the compiler. Thanks to #2754 it's now easier to add than it has ever been before! |
@yebblies so how do we go about this? we have a bounty out for dtoh and it's somewhat urgent |
I'd say it is OK to have it as a separate tool for now, but it would be nice to have it in the compiler. |
So urgent it was left open for a year? I'm going to need something like this for the D conversion very soon. If this serves your needs, then I have no problem with you merging it. |
I don't know what the standards are for the /tools repository, but I think this has a number of quality issues. If that's a problem, I recommend against fast-tracking this until it has been thoroughly reviewed (I'll do my part later today). |
On 12/28/13, JakobOvrum notifications@github.com wrote:
Some of it has probably already been fixed on the copy I have on my The type stuff btw has been completely rewritten, since in January dmd The overall approach is unchanged, however. |
@adamdruppe Would you be interested/have the time soon to rewrite this as a compiler ast visitor? |
It's mostly a myriad of small to medium importance issues, such as an extreme amount of garbage memory production (as soon as the output is large enough to invoke that first GC cycle, performance takes a big hit from there on out), poor command line argument handling, duplicated code and some unnecessary code, poor variable naming, control flow that could be simplified, and a classic case of pokemon exception handling. There's also suboptimal readability (to put it mildly) due to reliance on indexes instead of standard algorithms (and it also results in fragile reliance on whitespace details). I was going to do line comments, but I'd rather wait to see the new version. If this was Phobos, these kind of issues would matter, and I'm wondering if the same quality standard is warranted for /tools. As to the actual source code generation I noticed two things, a) as function declarations without definitions are implicitly |
@yebblies love the visitor but there are disadvantages to integrating everything there is within the compiler. A more scalable approach is to have the compiler generate nice annotated json (somehow with lookup done in tow) that allows a lot of tools to visit the json ast. |
@andralex This tool is very similar to di and ddoc generation, which are both integrated into the compiler. Json generation is a half-way hack to get around the fact we don't provide compiler-as-a-library. The scalable approach is not to serialize the ast to json, then reconstruct it in a bunch of external tools - it is to re-use the well tested code inside the compiler. |
Good point.
Doing so still poses the issue of intermediate formats (of which json could be one). I don't see these as either-or.
But generating the ast would use the well tested code inside the compiler! It's just a walkthrough that spits out an intermediate format. I don't understand this. |
On 12/28/13, Daniel Murphy notifications@github.com wrote:
Probably not, at least not any time soon. When my cable gets back I'm |
On Sat, Dec 28, 2013 at 08:04:38AM -0800, JakobOvrum wrote:
Yeah, I wrote it pretty sloppily, but I don't think speed is hugely important Some of the other things you mentioned, but not all, should be better in the
I'm not sure if it does this anymore or not... But anyway, my cable finally got fixed so I updated the code. If this mostly |
The only intermediate format necessary is the in-memory ast. There are benefits to serializing the ast, but running passes on it is not one of them. I guess we'll see if this satisfies the needs of the D port. |
I'll leave the philosophical stuff aside and review the tool itself iteratively. First find:
testcpp.d:
testcpp.h
Also |
Type declarations with the same name but in different modules (unique in D), are not unique in C++ when headers are used, e.g.:
These two are unique, but in C++ header files they will conflict with each other. Probably a good option here is to wrap them in a namespace, for example: test1.h:
test1.h:
Alternatively, and if only generating C++ (rather than the optional C language feature your tool has via E.g. the generated output could be a single C++ header file: test.h
|
W.r.t. Andrei's bugzilla comment about the requirement for indentation. For really nice looking output I suggest to use an existing tool like uncrustify. DTOH would of course need to compare code before indentation in order to determine whether it has to overwrite a file in a subsequent generation (see Andrei's bugzilla comment about makefile friendliness). |
I'm not sure why you named this variable in your test-case (see zip file in bugzilla):
You could probably name it |
Btw, be careful (or just aware) with passing classes around. I ran into an ABI issue once that I wasn't aware of before. You can read about it here: http://forum.dlang.org/thread/mailman.1547.1346632732.31962.d.gnu@puremagic.com |
Some of those have been fixed recently. |
Enums seem to lack support: The |
To match semantics with D, I think in C++ you should define default constructors for types to match D's
So on the C++ side I'd assume you should generate:
I've added a |
My other comments still apply for the new version of dtoh:
|
On Tue, Feb 11, 2014 at 06:42:37AM -0800, Andrej Mitrovic wrote:
Oh yeah, int definitely isn't long... but is D's int always C's int? I keep thinking Alternatively, I could #include<stdint.h> and do them all that way. Which do you think is better? Looking at core.stdc.config, if I just avoid the type
I went with your default ctor idea which also covers other user-defined initializers |
On all x86/x86-64, yes.
That won't work for C++ long, unfortunately. On LP64 platforms, D's long maps to C++'s long. On everything else, it maps to |
In the generated output dtoh seemed to have translated D's |
@andralex: Are we ok with merging this? I suppose we can expect further pulls for adding new features, unless there's something missing right now. |
import std.string : replace, toUpper, indexOf, strip; | ||
import std.algorithm : map, startsWith, canFind; | ||
|
||
string getIfThere(Variant[string] obj, string key) { |
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 enjoy Egyptian braces (use them at work, too), but do we want to add another style to the existing one?
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.
On Sat, Mar 15, 2014 at 09:55:53PM -0700, Andrei Alexandrescu wrote:
I enjoy Egyptian braces (use them at work, too), but do we want to add another style to the existing one?
Yeah, I'm keeping it in my native style (so to speak) for now since I
expect several changes will need to come in in reply to early bug reports.
Once it passes the beta phase and is less likely to need to be completely
rewritten anyway, changing style becomes easy. (I can edit smaller pieces
in a different style but I'll fall back on my old habits for large modifications.)
I'll move forward and merge this now, in the understanding that it'll be easier to add to an existing codebase than to work on breaking the ice. @adamdruppe please fix the style in a future diff. Thanks! |
Yet another tool added without a formal review :( |
Why stay silent for 3 months and then suddenly complain? |
Because I had no idea it existed until Andrei posted about it in the newsgroup. Sure, I could subscribe to receive notifications about pull requests but I don't understand why these tools don't go through same review process the new modules in Phobos do. Yes, I've already heard the lack of manpower argument. |
Not all of us were silent, either.
I don't think this hurried script is going to be useful to a proper tool that doesn't do the job in an ad-hoc way. I guess it serves as a "better than nothing" tool, but I don't think there's much point in putting such in the official tools repository. More than anything though, I agree that it should've been taken up on the NG. |
No problem: #125 and let's review this. |
@jacob-carlborg you just volunteered as review manager. |
On Sun, Mar 16, 2014 at 02:54:23AM -0700, JakobOvrum wrote:
I think it was.... in January 2013 when the bugzilla issue was first But regardless, I haven't even used it myself on anything but a few |
@adamdruppe please add it to the proposals in review when you're ready. |
Fair enough. I guess I have to do that then. I'll sync up with Dicebot. |
@adamdruppe please let me know when you're and I'll set up the review. |
I added it to the review queue as "Work in progress". |
On Mon, Mar 17, 2014 at 07:06:22AM -0700, jacob-carlborg wrote:
just let me know the link where the discussion is happening. |
@adamdruppe do you have any documentation for dtoh or could you create some? Since this is a tool rather than an API perhaps documentation like this best suited: http://dlang.org/dmd-osx.html. |
@adamdruppe I've just started the review: http://forum.dlang.org/thread/lgspgg$2i8l$1@digitalmars.com |
Revert "Merge pull request #39 from adamdruppe/dtoh"
what is the status of this? |
This is more recent: dlang/dmd#5082 - it covers most of the C++ interfacing support in D. |
On Tue, Mar 29, 2016 at 11:45:34PM -0700, Seb wrote:
It is quite dead, apparently nobody cared enough to do real |
I have this basically working and want to get it out so other people can take a look. Should be usable for a decent amount of stuff already.
Associated with: http://d.puremagic.com/issues/show_bug.cgi?id=9285
see the zip I posted in the comments there for the example I was using to test