Can we ease WASM in D ?

Hipreme msnmancini at hotmail.com
Wed Nov 23 22:24:35 UTC 2022


On Wednesday, 16 November 2022 at 22:51:31 UTC, bioinfornatics 
wrote:
> Dear community,
>
> I look some day ago to the D wasm page:
> -> https://wiki.dlang.org/Generating_WebAssembly_with_LDC
>
> And since then I ask myself can we at  compile time convert a D 
> code to an extern C code for wasm ?
>
> Indeed, if a library/framework  would wrap this to let end user 
> write his code in plain D that would be awesome.
>
> So did you think it is possible to do it by using 
> metaprogramming, mixin, mixin template, mixin string … ?
>
> Thanks for your ideas


It should not be too hard to do that using mixin templates. The 
concept is the same from my `@ExportD` that I'm using on my 
engine.

What `@ExportD` does is to create a new function based on the 
function target function  [or even classes] which all it does is 
call that (or even attach a GC.root as needed ), and generates 
factory functions for classes or create some `extern(C) export` 
the function.

I have done the same thing also for Lua and Java, don't seem that 
hard to do it with WASM. The only difference is that you will 
need to mixin template yourself (I do it at the end of file), 
then I iterate through the module members containing your `@wasm` 
UDAs, and generate the functions needed.

Remember that you could also use things such as 
`@wasm("myNewFunctionName")` and handle such cases.

But for me, working with D without a D runtime is simply not 
worth. That being said, if we had a working D runtime for WASM I 
would be adapting my engine to support it too.


More information about the Digitalmars-d-learn mailing list