digitalmars.D.ldc - WebAssembly + Custom Runtime + Associative Arrays
- Remi (15/15) Nov 10 2020 Hi all,
- Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= (3/19) Nov 10 2020 AA needs druntime. Adam's repo does not include a custom AA
- Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= (3/7) Nov 10 2020 Uhh you did it in your repo. Sorry.
- Johan (5/10) Nov 10 2020 I know almost nothing about webassembly, but I think 0 (`null`)
- Adam D. Ruppe (7/8) Nov 10 2020 Looks like you fixed the array append function but the one in my
- Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= (5/21) Nov 10 2020 It is weird, but if you pass pointer aa as ref it works.
- Remi (4/10) Nov 10 2020 Wow thanks! Can't believe I didn't think of that. Seems to work
- Adam D. Ruppe (4/6) Nov 10 2020 I don't understand why that would work though..
- Remi (4/10) Nov 10 2020 Well, it seems my troubles aren't finished though. I'm having
- Remi (4/17) Nov 10 2020 Also that fixes makes it crash in the x86 build now. So yeah Adam
- Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= (7/25) Nov 10 2020 As kinke mentioned, your AA does not implement everything needed.
- Remi (4/12) Nov 11 2020 Thanks I'll probably have a look if I find my implementation too
- kinke (11/12) Nov 10 2020 [I've just glanced at the code, not run and debugged anything.] I
- kinke (6/6) Nov 10 2020 Ouch, it's compiler bug - the compiler's hardcoded prototype for
- Remi (6/12) Nov 11 2020 That's kind of what I saw, AA* worked in x86 but AA** worked in
- Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= (4/17) Nov 11 2020 Please contribute to Adam's WebAssembly when your druntime works
Hi all, I've been trying to compile a game project to WebAssembly for a while. It had been going quite well but I'm hitting an issue with associative arrays now and I don't know if it's a compiler bug or something on my side. I uploaded some code with a broken example here: https://github.com/speps/dwasmaa If you clone it then run a HTTP server and navigate to index.htm, it will output the wrong message as described in the README. If you compile+run it with `dub --arch=x86` it displays the correct message (sorry that arch only works in Windows for now as I'm not using the runtime and only hooked up Win32 API console output). Anyway, where am I going wrong? Thanks. - Remi Gillig.
Nov 10 2020
On Tuesday, 10 November 2020 at 18:24:03 UTC, Remi wrote:Hi all, I've been trying to compile a game project to WebAssembly for a while. It had been going quite well but I'm hitting an issue with associative arrays now and I don't know if it's a compiler bug or something on my side. I uploaded some code with a broken example here: https://github.com/speps/dwasmaa If you clone it then run a HTTP server and navigate to index.htm, it will output the wrong message as described in the README. If you compile+run it with `dub --arch=x86` it displays the correct message (sorry that arch only works in Windows for now as I'm not using the runtime and only hooked up Win32 API console output). Anyway, where am I going wrong? Thanks. - Remi Gillig.AA needs druntime. Adam's repo does not include a custom AA implementation.
Nov 10 2020
On Tuesday, 10 November 2020 at 19:20:42 UTC, Ferhat Kurtulmuş wrote:On Tuesday, 10 November 2020 at 18:24:03 UTC, Remi wrote:Uhh you did it in your repo. Sorry.[...]AA needs druntime. Adam's repo does not include a custom AA implementation.
Nov 10 2020
On Tuesday, 10 November 2020 at 18:24:03 UTC, Remi wrote:Hi all, I've been trying to compile a game project to WebAssembly for a while. It had been going quite well but I'm hitting an issue with associative arrays now and I don't know if it's a compiler bug or something on my side.I know almost nothing about webassembly, but I think 0 (`null`) is a valid memory address. Could that be the reason for the troubles? (some object allocated on address 0?) -Johan
Nov 10 2020
On Tuesday, 10 November 2020 at 18:24:03 UTC, Remi wrote:Anyway, where am I going wrong? Thanks.Looks like you fixed the array append function but the one in my repo was broken af until... well right now, I just pushed. The way that function works is bizarre. But I think you did it right here... just like... that's where I'd focus attention first to confirm it actually works before digging much deeper.
Nov 10 2020
On Tuesday, 10 November 2020 at 18:24:03 UTC, Remi wrote:Hi all, I've been trying to compile a game project to WebAssembly for a while. It had been going quite well but I'm hitting an issue with associative arrays now and I don't know if it's a compiler bug or something on my side. I uploaded some code with a broken example here: https://github.com/speps/dwasmaa If you clone it then run a HTTP server and navigate to index.htm, it will output the wrong message as described in the README. If you compile+run it with `dub --arch=x86` it displays the correct message (sorry that arch only works in Windows for now as I'm not using the runtime and only hooked up Win32 API console output). Anyway, where am I going wrong? Thanks. - Remi Gillig.It is weird, but if you pass pointer aa as ref it works. extern (C) void* _aaGetY(ref AA* aa, const TypeInfo_AssociativeArray aati, in size_t valuesize, in void* pkey)
Nov 10 2020
On Tuesday, 10 November 2020 at 21:23:07 UTC, Ferhat Kurtulmuş wrote:On Tuesday, 10 November 2020 at 18:24:03 UTC, Remi wrote:Wow thanks! Can't believe I didn't think of that. Seems to work indeed.[...]It is weird, but if you pass pointer aa as ref it works. extern (C) void* _aaGetY(ref AA* aa, const TypeInfo_AssociativeArray aati, in size_t valuesize, in void* pkey)
Nov 10 2020
On Tuesday, 10 November 2020 at 22:36:40 UTC, Remi wrote:Wow thanks! Can't believe I didn't think of that. Seems to work indeed.I don't understand why that would work though.. you don't change aa itself, just the aa.impl which should go through the pointer already.....
Nov 10 2020
On Tuesday, 10 November 2020 at 22:38:30 UTC, Adam D. Ruppe wrote:On Tuesday, 10 November 2020 at 22:36:40 UTC, Remi wrote:Well, it seems my troubles aren't finished though. I'm having another _aaGetY crash to figure out by using the WASM debugger in Firefox...Wow thanks! Can't believe I didn't think of that. Seems to work indeed.I don't understand why that would work though.. you don't change aa itself, just the aa.impl which should go through the pointer already.....
Nov 10 2020
On Tuesday, 10 November 2020 at 22:53:59 UTC, Remi wrote:On Tuesday, 10 November 2020 at 22:38:30 UTC, Adam D. Ruppe wrote:Also that fixes makes it crash in the x86 build now. So yeah Adam you might be right, it doesn't really fix it in the right way. I'm still not sure why it's doing that.On Tuesday, 10 November 2020 at 22:36:40 UTC, Remi wrote:Well, it seems my troubles aren't finished though. I'm having another _aaGetY crash to figure out by using the WASM debugger in Firefox...Wow thanks! Can't believe I didn't think of that. Seems to work indeed.I don't understand why that would work though.. you don't change aa itself, just the aa.impl which should go through the pointer already.....
Nov 10 2020
On Tuesday, 10 November 2020 at 22:57:27 UTC, Remi wrote:On Tuesday, 10 November 2020 at 22:53:59 UTC, Remi wrote:As kinke mentioned, your AA does not implement everything needed. You should port the entire thing in druntime/blob/master/src/rt/aaA.d. Some time ago, I created a malloc-free-based port of it. It does not provide required symbols to compiler as you did there though. https://github.com/aferust/bcaa/blob/master/source/bcaa.dOn Tuesday, 10 November 2020 at 22:38:30 UTC, Adam D. Ruppe wrote:Also that fixes makes it crash in the x86 build now. So yeah Adam you might be right, it doesn't really fix it in the right way. I'm still not sure why it's doing that.On Tuesday, 10 November 2020 at 22:36:40 UTC, Remi wrote:Well, it seems my troubles aren't finished though. I'm having another _aaGetY crash to figure out by using the WASM debugger in Firefox...Wow thanks! Can't believe I didn't think of that. Seems to work indeed.I don't understand why that would work though.. you don't change aa itself, just the aa.impl which should go through the pointer already.....
Nov 10 2020
On Wednesday, 11 November 2020 at 05:18:25 UTC, Ferhat Kurtulmuş wrote:On Tuesday, 10 November 2020 at 22:57:27 UTC, Remi wrote: [...] As kinke mentioned, your AA does not implement everything needed. You should port the entire thing in druntime/blob/master/src/rt/aaA.d. Some time ago, I created a malloc-free-based port of it. It does not provide required symbols to compiler as you did there though. https://github.com/aferust/bcaa/blob/master/source/bcaa.dThanks I'll probably have a look if I find my implementation too slow, which will probably be the case :)
Nov 11 2020
On Tuesday, 10 November 2020 at 18:24:03 UTC, Remi wrote:Anyway, where am I going wrong? Thanks.[I've just glanced at the code, not run and debugged anything.] I don't see where you actually grow the heap (wasm_growMemory() never used AFAICT), certainly not in your malloc(), which initializes `nextFree` with &__heap_base and then bumps that pointer for the next allocation (likely breaking some alignment btw - rounding up to the next multiple of 8 or 16 should be safe). Note that you shouldn't have to get the size of and grow the linear memory in JS, there are LLVM intrinsics you can use (just copy the declarations): https://github.com/ldc-developers/druntime/blob/412467a452e2d12f561a2eace933dd44014af3c6/src/ldc/intrinsics.di#L678-L697
Nov 10 2020
Ouch, it's compiler bug - the compiler's hardcoded prototype for _aaInX() uses a `void*` as first param, not a `AA` struct wrapping the impl pointer. So this assumes the ABI/calling convention treats both types identically, which isn't currently the case for LDC's wasm ABI. So using `void* _aaInX(AAImpl* aaimpl, ...)` works around this.
Nov 10 2020
On Wednesday, 11 November 2020 at 02:05:25 UTC, kinke wrote:Ouch, it's compiler bug - the compiler's hardcoded prototype for _aaInX() uses a `void*` as first param, not a `AA` struct wrapping the impl pointer. So this assumes the ABI/calling convention treats both types identically, which isn't currently the case for LDC's wasm ABI. So using `void* _aaInX(AAImpl* aaimpl, ...)` works around this.That's kind of what I saw, AA* worked in x86 but AA** worked in WASM and vice versa. I did try to find where the compiler actually generated the call to _aaInX but couldn't find it by a simple search. Thanks for the help, it seems to work in both architectures now :)
Nov 11 2020
On Wednesday, 11 November 2020 at 08:30:09 UTC, Remi wrote:On Wednesday, 11 November 2020 at 02:05:25 UTC, kinke wrote:Please contribute to Adam's WebAssembly when your druntime works is complete, or publish your own library so that others and I can use it :)Ouch, it's compiler bug - the compiler's hardcoded prototype for _aaInX() uses a `void*` as first param, not a `AA` struct wrapping the impl pointer. So this assumes the ABI/calling convention treats both types identically, which isn't currently the case for LDC's wasm ABI. So using `void* _aaInX(AAImpl* aaimpl, ...)` works around this.That's kind of what I saw, AA* worked in x86 but AA** worked in WASM and vice versa. I did try to find where the compiler actually generated the call to _aaInX but couldn't find it by a simple search. Thanks for the help, it seems to work in both architectures now :)
Nov 11 2020