Jump to page: 1 2
Thread overview
September 13

Greetings!

Many people in the development community are very excited about
WebAssembly, because it allows the browser to interpret more robust
languages than JS.

Rumor has it that D can compile to Wasm, but only in the "BetterC"
subset.

LLVM can compile to Wasm, but unfortunately it may not support
systems IO calls because of the lack of operating system access.
Emscripten is a compiler that can transform C into something that
can run on Wasm without holes in the Standard Library. It does
this by simulating an operating system, which adds overhead to the
runtime, but allows a full range of C to be used, to my understanding.

With D not being able to be run on Wasm in a meaning way: Why can't
we just compile D code to C, as a compiler output, and then run that
through Emscripten?

September 13

On Monday, 13 September 2021 at 16:19:31 UTC, Kenneth Dallmann wrote:

>

Why can't
we just compile D code to C, as a compiler output, and then run that
through Emscripten?

The immediate problem is that a D->C compiler does not exist.

September 13
On Monday, 13 September 2021 at 16:19:31 UTC, Kenneth Dallmann wrote:
>    Rumor has it that D can compile to Wasm, but only in the "BetterC" subset.

See some of my little demos here:

http://webassembly.arsdnet.net/

a blog post about it
http://dpldocs.info/this-week-in-d/Blog.Posted_2020_08_10.html

and some source for the support code
http://github.com/adamdruppe/webassembly/


the approach I took is a miniature custom runtime but there's also the possibility of a druntime port to the wasi emscripten uses

https://github.com/skoppe/druntime/tree/wasm

though none of these are complete.


Anyway, the point of my little demo is in 50 KB of webasm I had my basic game demos running in the browser.

I did partial source ports that just call out to javascript instead of relying on a copied stdlib. Makes more sense that way to me and also produces smaller binaries.
September 13

On Monday, 13 September 2021 at 16:29:45 UTC, jfondren wrote:

>

On Monday, 13 September 2021 at 16:19:31 UTC, Kenneth Dallmann wrote:

>

Why can't
we just compile D code to C, as a compiler output, and then run that
through Emscripten?

The immediate problem is that a D->C compiler does not exist.

https://theartofmachinery.com/2018/12/20/emscripten_d.html explains that C isn't necessary:

>

Emscripten is a toolchain designed for C/C++, but the C/C++ part is just a frontend. The toolchain actually compiles LLVM intermediate representation (IR). You can generate LLVM IR bitcode from D using LDC, so it should be possible to feed that through Emscripten and run D in a browser, just like C/C++.

September 13

On Monday, 13 September 2021 at 16:29:45 UTC, jfondren wrote:

>

On Monday, 13 September 2021 at 16:19:31 UTC, Kenneth Dallmann wrote:

>

Why can't
we just compile D code to C, as a compiler output, and then run that
through Emscripten?

The immediate problem is that a D->C compiler does not exist.

I read somewhere that BetterC can though, and maybe that's how it works.
Although, with the LLVM you can compile it to Wasm, it just won't have
the standard library, a technical nightmare.

Maybe a D to C compiler would be a good project, to increase the portability of D.

September 13

On Monday, 13 September 2021 at 16:19:31 UTC, Kenneth Dallmann wrote:

>

With D not being able to be run on Wasm in a meaning way: Why can't
we just compile D code to C, as a compiler output, and then run that
through Emscripten?

The D language runtime uses inline assembly for some low-level features (e.g., threads), and therefore cannot be compiled to C.

Emscripten itself has similar limitations.

September 13
On Monday, 13 September 2021 at 16:33:28 UTC, Adam D Ruppe wrote:
> On Monday, 13 September 2021 at 16:19:31 UTC, Kenneth Dallmann wrote:
>>    Rumor has it that D can compile to Wasm, but only in the "BetterC" subset.
>
> See some of my little demos here:
>
> http://webassembly.arsdnet.net/
>

How funny I was playing your tetris game earlier today. I found it in a blog post
on the same topic.

September 13

On Monday, 13 September 2021 at 16:36:28 UTC, Paul Backus wrote:

>

On Monday, 13 September 2021 at 16:19:31 UTC, Kenneth Dallmann wrote:

>

With D not being able to be run on Wasm in a meaning way: Why can't
we just compile D code to C, as a compiler output, and then run that
through Emscripten?

The D language runtime uses inline assembly for some low-level features (e.g., threads), and therefore cannot be compiled to C.

Emscripten itself has similar limitations.

Inline assembly is described here for the C language.
https://en.cppreference.com/w/c/language/asm#:~:text=Inline%20assembly%20(typically%20introduced%20by,as%20an%20extension%20in%20C.

September 13

On Monday, 13 September 2021 at 16:36:28 UTC, Paul Backus wrote:

>

On Monday, 13 September 2021 at 16:19:31 UTC, Kenneth Dallmann wrote:

>

With D not being able to be run on Wasm in a meaning way: Why can't
we just compile D code to C, as a compiler output, and then run that
through Emscripten?

The D language runtime uses inline assembly for some low-level features (e.g., threads), and therefore cannot be compiled to C.

Emscripten itself has similar limitations.

My bad, you got that correct. I guess someone would have to write a compiler/RTL specifically
for D to run it on Wasm. I noticed that threads is one feature disabled in BetterC, and maybe that's why it has been ported to Wasm.

September 13

On Monday, 13 September 2021 at 16:19:31 UTC, Kenneth Dallmann wrote:

>

Greetings!

Many people in the development community are very excited about
WebAssembly, because it allows the browser to interpret more robust
languages than JS.

Rumor has it that D can compile to Wasm, but only in the "BetterC"
subset.

LLVM can compile to Wasm, but unfortunately it may not support
systems IO calls because of the lack of operating system access.
Emscripten is a compiler that can transform C into something that
can run on Wasm without holes in the Standard Library. It does
this by simulating an operating system, which adds overhead to the
runtime, but allows a full range of C to be used, to my understanding.

With D not being able to be run on Wasm in a meaning way: Why can't
we just compile D code to C, as a compiler output, and then run that
through Emscripten?

You don't need to compile d code to c. You can use d code with emscripten. Sebastiaan Koppe was working on druntime1 to make it possible to use it with webassembly. Dunno its current status. Here is also my d game using wasm. It even links with c libraries compiled with emscripten.

https://aferust.github.io/drawee/
https://github.com/aferust/drawee

« First   ‹ Prev
1 2