Proposed strategy to support WASM in D

Pierce Ng pierce at samadhiweb.com
Sat Nov 19 03:12:14 UTC 2022


On Saturday, 19 November 2022 at 01:57:21 UTC, Adam D Ruppe wrote:
> On Saturday, 19 November 2022 at 01:16:00 UTC, Pierce Ng wrote:
>> Without modifying TIC-80 source code, is there a way to do 
>> some 'namespace' thingie for D like how Zig does it?
>
> All D symbols are namespaced by their module name. You can 
> expose the JS functions in different modules.

Thanks. I misremembered, the trouble isn't with time() but with 
trying to use WASI libc's sinf() and cosf(). If I try to use D's 
std.math instead, the code doesn't compile in BetterC mode:

```
% make
dub build --quiet --build release --compiler ldc2 --arch 
wasm32-unknown-unknown-wasm
/home/pierce/pkg/ldc/include/d/core/stdc/math.d(4433,13): Error: 
undefined identifier `c_long`
/home/pierce/pkg/ldc/include/d/core/stdc/math.d(4435,13): Error: 
undefined identifier `c_long`
/home/pierce/pkg/ldc/include/d/core/stdc/math.d(4437,13): Error: 
undefined identifier `c_long`
/home/pierce/pkg/ldc/include/d/core/stdc/math.d(4537,13): Error: 
undefined identifier `c_long`
/home/pierce/pkg/ldc/include/d/core/stdc/math.d(4539,13): Error: 
undefined identifier `c_long`
/home/pierce/pkg/ldc/include/d/core/stdc/math.d(4541,13): Error: 
undefined identifier `c_long`
/home/pierce/pkg/ldc/include/d/core/stdc/math.d(4558,13): Error: 
undefined identifier `c_long`
/home/pierce/pkg/ldc/include/d/core/stdc/math.d(4560,13): Error: 
undefined identifier `c_long`
/home/pierce/pkg/ldc/include/d/core/stdc/math.d(4562,13): Error: 
undefined identifier `c_long`
/home/pierce/pkg/ldc/include/d/core/stdc/fenv.d(875,5): Error: 
undefined identifier `fenv_t`
/home/pierce/pkg/ldc/include/d/core/stdc/fenv.d(878,5): Error: 
undefined identifier `fexcept_t`
/home/pierce/pkg/ldc/include/d/core/stdc/fenv.d(880,5): Error: 
undefined identifier `fexcept_t`
/home/pierce/pkg/ldc/include/d/core/stdc/fenv.d(888,5): Error: 
undefined identifier `fenv_t`
/home/pierce/pkg/ldc/include/d/core/stdc/fenv.d(890,5): Error: 
undefined identifier `fenv_t`
/home/pierce/pkg/ldc/include/d/core/stdc/fenv.d(939,9): Error: 
undefined identifier `fenv_t`
ldc2 failed with exit code 1.
make: *** [Makefile:7: build] Error 2
```

In TIC-80's case there is no JS. TIC-80 embeds the 
[wasm3](https://github.com/wasm3/wasm3) standalone runtime and 
makes its (TIC-80's) APIs available to Wasm programs

(Well, TIC-80 also embeds Duktape, thus making it programmable 
with JS, but that's not relevant here.)

> Always use real D unless it is impractical to do so. No point 
> going through suffering when you don't have to.

Good point.

Let me update D, TIC-80, etc. and try again.


More information about the Digitalmars-d mailing list