Tuesday, July 26, 2005

Xlib, C to D port: Third Iteration

O blimey!

When i said i would probably start again one more time on the Xlib C to D port... i sort of felt it. I'm not so sure i meant it, but i had to do exactly that this weekend.

When the Mythical Man Month says, plan to start from scratch at least once... its very true. Things get clearer if you not scared of starting over at least once. Infact... just plan for it.

I completed the second iteration of Xlib and had Xmd.d, X.d and Xlib.d as at Saturday, in the wee hours of morning. Then i tried to port a simple Xlib C program that draws a line to its D version. It was then my suspicions of gcc -E were confirmed. Most of the convenience macros and #define constructs were missing. The convenience macros are not really a problem, since D semantics will mean having to rely less on such trickery, but the #define constants are really important, as they are mostly values that are unique to a function etc.

Thus i decided to look at h2d at http://www.dsource.org/projects/h2d/

I tried it out, and my... it made my work even easier, and converted all the structs, typedefs, types for me. phew!!! time shaver, but still, the script it uses 'deeify' is still subject to the gcc -E problem, since it still employs it.

My third iteration, involved:

1. Using h2d's 'deeify' to run convert the .h file to a .d file.
2. Visually inspecting the .h file and copying over all the #define constants that have been left out by 'deeify'
3. convert the copied over #defines to either const declarations or enums (this part is still hard boring work)

Using this, i quickly went thru Xmd.h and X.d again, and they are ready in their first version. The last is Xlib.d, which has quite a number of boring constants to work on. I'm going to probably whip up a script to do those. But now that everything is *really* clear, i'm making progress.


Post a Comment

<< Home