Is it possible that someday it will be possible to compile from D 2.0 to Javascript?

A long-term C ++ programmer (that I) study other languages ​​and wonder if it's worth learning a lot about D 2.0 . (This is a pure slate rewriting of D.) So far, I liked what I see - a lot of pragmatic and wise decisions. Now I want to know a little more and want to know if it is ever possible to do the following:

  • Enter the code in D 2.0. (Perhaps this is a well-defined subset of D 2.0.)
  • Compile the code from 1.
  • Get Javascript source code from compiler.

In general, I would like to have a D 2.0 compiler with a backend capable of generating Javascript.

So my question has two parts:

  • Does such a compiler already exist?
  • If such a compiler does not exist, and if I decided to implement it, where would it be best to start?

In context, the reason I would like to dwell above is that I could implement a bunch of business logic in D 2.0 and then use this business logic in pure Javascript (this is not Flash / Silverlight / Java). Web Application.

Update

I had three answers, two of which were related, and the other was not and therefore are ignored.

@FeepingCreature believes this will never happen because "it is too incompatible with the D environment." I am curious to know what this means and asked.

@Nekuromento, by contrast, points out that this is already theoretically possible using LDC, followed by LLVM Javascript. I checked both links. LDC support for D 2.0 looks like work. But I guess he will get there at some point. LLVM Javascript is neither optimized nor optimized, but it shows that they work. Therefore, I think this is enough to be useful, at least.

Update 2

OK - this seems like the best solution to date.

  • LDC call. (@Nekuromento) LDC integrates Digital Mars interface with LLVM backend.
  • Follow the output from 1. through the LvvM Javscript backend. (@Nekuromento)
  • Follow the output from 2. although Closure (@BCS)

I will choose the best answer pretty soon, but I would like a more informed opinion.

Update 3

More info on why I want to do this.

Here is a concrete example of one project that I want to implement. It will be a geometric modeling library, which is probably written only by me, takes several years to write, and ends with approximately 100,000 lines of code. I would like it to contain errors as close to zero as possible, and therefore I do not want to implement it in Javascript. I would like it to run on the server, on the desktop and in the browser. (In β€œin the browser,” I mean without the help of any plug-in, such as Flash, Silverlight, or Java.) The truth is, the code in the browser running on Javascript is here to stay for a short while. Projects will increasingly need a strategy to solve this problem.

Update 4

I was hoping for a few answers, but did not receive them. Good, never mind. Thanks for all the reviews, including @dsimicha, stimulating comments. (I hope it’s normal to sometimes disagree technically, while at the same time maintaining civil status.) I accepted @Nekuromento's answer.

+7
source share
3 answers

Such a compiler does not currently exist, but there is some work on javascript LLVM-backend .

How is LDC . It uses DMD front-end and LLVM, so theoretically you can add javascript output to it.

+4
source

Stay tuned for D newsgroups over the next few days, I’m working on what might interest you (more precisely, exactly what you want). It is currently compiling:

int foo() { if (true) { return 3; } } 

I hope to get some kind of alpha / beta in the next week.

+2
source

Short answer: None.

Long answer: Indeed. Not.

Less Snarky Answer: It is too incompatible with the D-environment.

If you decide to realize one thing - hell, more power for you, but you have your work cut for you. It's probably best to start by reading the DMD interface, which is FOSS (and, afaik, is distributed in a standard lightning fast format).

+1
source

All Articles