D to Javascript converter (a hacked up dmd)
Adam D. Ruppe
destructionator at gmail.com
Wed Feb 29 21:20:45 PST 2012
I probably should have been working today.... but instead
spent a good amount of time on this again.
New zip:
https://github.com/downloads/adamdruppe/dtojs/dtojs-0.3.zip
(I haven't cleaned up the github fork yet)
To give you an idea of what is working, check out
my tests.d file:
http://arsdnet.net/dtojs/tests.d
This compiles (raw) into this:
http://arsdnet.net/dtojs/tests.js
BTW, when compiling, be sure to put test/object.d
on your command line too, or the runtime functions
won't be present in your .js file!
23 KB (down to 11 KB if you run the included mangledown tool
on it. gcfunctions can often make a big difference, but not here,
since it removes what you don't use. A test that doesn't use
something is an incomplete test!)
I think I broke std.algorithm again :(, but fixed a lot of
other stuff. (it is the lambda generator in std.algorithm that
is breaking. The JS has the function, but it is nested too deep
and inaccessible to the actual algorithm.)
But, a lot of stuff works now, and the generated code isn't
half bad. I've started using more static type info to slightly
optimize it too, but only some basics.
One of the messiest things was try/catch. JS doesn't do
types like D, so I implemented it with a series of
if(dynamic_cast()), and ultimately rethrow if none matched.
A bit ugly, but it seems to pass the tests!
(The messiest compiler implementation so far is [0..$]. That
pesky dollar sign. In microd.c, you can see a couple global
variables there to hack things up. Poo. But, again, it works.)
Library wise, check out src/test/jslang and src/test/browser.
I tried for completeness there, but not full accuracy yet.
This gives free (no generated wrappers) access to regexps,
the array object, string functions, etc. as part of the
core language, and browser has things for the DOM, window,
history, location, canvas, style, json, ajax, etc. - all
just bindings to the native functions.
I'm to the point where I think I'm ready to write a program
with this thing!
More information about the Digitalmars-d-announce
mailing list