Ported js13k game underrun to D targeting webassembly

Dukc ajieskola at gmail.com
Mon Nov 19 11:13:52 UTC 2018


On Saturday, 17 November 2018 at 21:35:59 UTC, Sebastiaan Koppe 
wrote:
> [snip]

I had a look at your code, and just now I realized that spasm can 
really call JavaScript without any glue from JavaScript side.

This is huge! Now I can start to think about expanding my usage 
of D at the web page I'm developing, potentially replacing parts 
of my application made with Bridge.NET.

I know you did announce about Spasm earlier and I should have 
thanked you already. My fault: I realized that you made something 
that enables one to generate WebAsm, but didn't realize it 
enabled calling JS classes directly. Should have looked closer.

> Things like:
> - almost no use of phobos (even at CTFE)
>
> D could definitely use some love in that area. I was 
> specifically stumped that stdx.allocator doesn't work in 
> betterC; if somewhere is a good place to use stdx.allocator you 
> would expect it to be betterC, but alas.

I agree. I, neither, have managed to link allocators in. But I 
quess you can use Phobos more than you think. Seeing how great 
stuff you have done, It may be that what I'm stating here may 
already be plain obvious to you, but I say it just in case 
anyway. You need a way to link in non-templated code. Two way's 
I'm aware of:

1. Manually compile your code and parts of Druntime/Phobos 
targetting 32-bit X86, link them manually with llvm-link using 
--only-needed and only then compile to JavaScript (Haven't tried 
with WebAsm, but theoretically should compile the same way). This 
way you don't need to manually stub what you don't use -well, 
when the linkers have same ideas about what you're calling, 
which's not always the case.

2: Use Vladimir's DScripten. I haven't tried, as I was limited by 
not being aware of anything like spasm to call Web API, but 
probably easier than my method above and brings larger portions 
of Phobos into user's reach. Also IIRC Vladimir managed to get 
allocators working.

Even with my relatively meager method, pipeline-style programming 
with std.algorithm and std.range over (often static) arrays is 
doable and practical in my experience.



More information about the Digitalmars-d-announce mailing list