www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - BetterC + WASM Update

reply Mike Brown <mikey.be gmail.com> writes:
Hi all,

I'd like to make a WASM project, and looking into options.

I can see that LDC supports WASM output, and I believe this 
requires BetterC to be enabled? The documentation states that 
classes are not supported by BetterC, but its preferable/required 
for me.

I have done some tests, and it appears that classes are supported 
(LDC 1.22.0)? Is it possible to get an update on what is and 
still isn't supported in BetterC?

After a stable experience, so if you can also let me know if 
these features are beta etc too?

Kind regards,
Mike
Aug 19 2020
next sibling parent Adam D. Ruppe <destructionator gmail.com> writes:
On Wednesday, 19 August 2020 at 21:24:23 UTC, Mike Brown wrote:
 I can see that LDC supports WASM output, and I believe this 
 requires BetterC to be enabled?
Not really but anything beyond -betterC is still kinda diy right now. So I happened to do port my little tetris game in D to wasm just last week, you can read about it here: http://dpldocs.info/this-week-in-d/Blog.Posted_2020_08_10.html And it uses classes! But... I cheated. I did a minimal custom druntime and library port that has just enough to make that little game work. This is a viable approach and can lead to reasonably small compiled binaries, but it is kinda immature. For a full druntime, the author of spasm <https://github.com/skoppe/spasm/> is working on a port. See his fork here: https://github.com/skoppe/druntime/tree/wasm I say "full" but it will most likely leave some things out. Classes, GC (at least of D memory), and other features all should work already if you brave building it yourself, but threads do not work and exceptions are only partially supported. Read more here: https://gist.github.com/skoppe/7617ceba6afd67b2e20c6be4f922725d That may change in the future as wasm gets more standardized capabilities. Other libraries, including interop with javascript, are not covered by the druntime goal, but they will probably get easier with this.
 I have done some tests, and it appears that classes are 
 supported (LDC 1.22.0)? Is it possible to get an update on what 
 is and still isn't supported in BetterC?
How did you compile it? You can definitely make classes work but as far as I knew it didn't "just work" but maybe that changed with the recent release.
 After a stable experience, so if you can also let me know if 
 these features are beta etc too?
but yeah stability is probably a ways out still. Sebastiaan has been busy lately so his druntime work is on pause and mine was just one weekend so I'd have something to show off on the blog; I have no concrete plans of continuing right now. Good chance we'll get it all working eventually, but I wouldn't expect even beta stability - aside from the diy betterC stuff - any time soon. Maybe beta quality by the end of the year. Maybe.
Aug 19 2020
prev sibling next sibling parent aberba <karabutaworld gmail.com> writes:
On Wednesday, 19 August 2020 at 21:24:23 UTC, Mike Brown wrote:
 Hi all,

 I'd like to make a WASM project, and looking into options.
It's scattered in several places including https://gist.github.com/skoppe/7617ceba6afd67b2e20c6be4f922725d Are you aware of Spasm? https://github.com/skoppe/spasm
Aug 19 2020
prev sibling next sibling parent kinke <noone nowhere.com> writes:
On Wednesday, 19 August 2020 at 21:24:23 UTC, Mike Brown wrote:
 I have done some tests, and it appears that classes are 
 supported (LDC 1.22.0)?
extern(C++) classes are supported by -betterC. With LDC, D classes are supported to some extent too since v1.11, but this requires a custom object.d (custom Object base class).
Aug 19 2020
prev sibling parent reply Mike Brown <mikey.be gmail.com> writes:
Hi All,

Thank you for your replies. My tests have been via compiler 
explorer.

https://godbolt.org/z/4f9nKj I have done this without -BetterC, 
as the dynamic array fails. I guess that uses GC? Is there an 
alternative that works with BetterC for dynamic arrays?

Thank you for the other WASM links, I initially only need to call 
a single function, compute, and return a string. But the idea of 
the dlang side interacting with the JS side sounds useful and 
promising.

Is the use of classes in my example a special case? And more 
expanded usage will break?

Kind regards,
Mike Brown
Sep 01 2020
next sibling parent Seb <seb wilzba.ch> writes:
On Tuesday, 1 September 2020 at 20:39:58 UTC, Mike Brown wrote:
 Hi All,

 Thank you for your replies. My tests have been via compiler 
 explorer.

 https://godbolt.org/z/4f9nKj I have done this without -BetterC, 
 as the dynamic array fails. I guess that uses GC? Is there an 
 alternative that works with BetterC for dynamic arrays?
You could try http://mir-algorithm.libmir.org/mir_rc_array.html or the planned core.experimental.rcarray (https://github.com/dlang/druntime/pull/2679).
Sep 02 2020
prev sibling next sibling parent reply Mike Brown <mikey.be gmail.com> writes:
Hi again,

I now understand the issues at play. I get linking errors to the 
druntime features. I now understand the earlier replies.

I was able to resolve all but TypeInfo errors from the suggested 
druntime replacements. Coming from a C++ background - I’m not 
even sure how I’m using TypeInfo features so I don’t even know 
where to begin on rewriting my code to not use it. Also not sure 
how I’d go able altering the druntime to proceed. Happy to leave 
wasm with D at that.

I did however, get taken in by how small and precise the D code 
was compared to my C++ equivalent. The templating is beautiful, 
I’m now considering writing in D rather than C++ as the smaller 
and clearer code would be of real benefit.

Thanks again to all replies. I read all linked articles, which 
were all great reads. Hope wasm support arrives officially one 
day soon.

Kind Regards
Mike Brown
Sep 03 2020
parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Thu, Sep 03, 2020 at 06:18:00PM +0000, Mike Brown via Digitalmars-d-learn
wrote:
[...]
 I did however, get taken in by how small and precise the D code was
 compared to my C++ equivalent. The templating is beautiful, I’m now
 considering writing in D rather than C++ as the smaller and clearer
 code would be of real benefit.
[...] I also came from a C/C++ background, and D's conciseness, beautiful syntax, and general "hygiene" continue to impress me every day. I gave up C++ for D years ago, and have never looked back since. T -- Без труда не выловишь и рыбку из пруда.
Sep 03 2020
prev sibling parent Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= <aferust gmail.com> writes:
On Tuesday, 1 September 2020 at 20:39:58 UTC, Mike Brown wrote:
 Is there an alternative that works with BetterC for dynamic 
 arrays?
You may give these a try: https://github.com/aferust/dvector For associative arrays: https://github.com/aferust/bcaa
Sep 03 2020