D to Javascript converter (a hacked up dmd)
Adam D. Ruppe
destructionator at gmail.com
Tue Feb 28 19:11:36 PST 2012
On Wednesday, 29 February 2012 at 02:42:38 UTC, Piotr Szturmaj
wrote:
> 44 KB - that's not bad!
It actually gets better: 9kb if you trim the mangled names
down to size (I've written a mangle name trimmer and an
unused function cutter; hello world is about 200 bytes.).
The reason it didn't work before wasn't just dollar, but also
ref params. This was a bit of a pain.. without pointers, how
can I implement this?
After thinking on it for almost an hour, I decided on passing
lambdas instead:
void a(ref b) { b = 10; }
int c = 5;
a(c);
assert(c == 10);
The JS looks like this:
function a(b) { b(10); }
var c = 5;
a(function(set) { if(typeof set != "undefined") c = set; return
c; });
c == 5 || _d_assert();
My implementation right now is a filthy hack... but std.algorithm
is basically working. assumeSorted's constructor is missing for
some reason, but the algorithm itself actually worked.
(I spent time making class constructors work, but I think I
neglected struct constructors, so probably easy fix.)
But, I think the best thing to do though isn't to port phobos
implementations, but instead port the interface as much as
possible.
sort can be a wrapper of Array.prototype.sort() from Javascript,
thus letting us leave out the implementation. Odds are the native
method will be faster anyway.
> Some time ago, I was interested in translation to JS, but I
> rather thought about binary translation, like in
> http://bellard.org/jslinux/. There's similar "emscripten"
> project which translates LLVM bytecode to JS:
I've heard of these two, but they seem a lot bigger than
I like.
I want the generated JS to be as small as possible while
still covering a good chunk of D features.
More information about the Digitalmars-d-announce
mailing list