|Posted by H. S. Teoh|
in reply to bioinfornatics
Posted in reply to bioinfornatics
On Wed, Nov 16, 2022 at 10:51:31PM +0000, bioinfornatics via Digitalmars-d-learn 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.
Which actually gave me the idea of a D-based framework that uses compile-time introspection, etc., to auto-generate the necessary JS glue code (e.g., as a pre-compile step) so that the user does not actually have to write any JS manually for things to work.
 I.e., there'd be a special D helper tool that imports your user D code and performs introspection on it, and spits out JS glue code at runtime. So you'd run this as part of your build, and it creates the necessary JS file(s) that you need to insert into your HTML; in the meantime, you run a separate build command to compile the user D code into WASM. (This is why dub seriously needs to break out of its single executable modus operandi -- I don't think this can be easily bundled with dub right now.)
Having this tool is essential to making D's WASM experience tolerable; currently the insane amounts of JS boilerplate you have to write in order to get non-trivial D code off the ground is ridiculous. Trying to write a WASM function that does string processing, for example, requires a ton of hacks to work around the lack of a built-in string type. D could totally automate this crap away by having a wrapper tool that introspects your D code at compile-time and spits out the necessary JS boilerplate and any other needed shims in order to get this to work with a minimum of fuss. Also, interfacing with browser APIs like WebGL also needs to be doable with a minimum of fuss, which currently isn't possible because of the unavoidable JS component with its associated boilerplate.
Hey, anyone can ignore me and go ahead and do it that way. I wish you the best of luck -- sometimes us old coots are dead wrong -- but forgive me if I'm not going to be terribly sympathetic if you ignore my advice and things go badly! -- Walter Bright