Re: Building LDC runtime for a microcontroller
On Thursday, 17 September 2020 at 19:27:41 UTC, Adam D. Ruppe wrote: fyi my baby was just born i'll come back to this but it might be a day or two Oh probably most unexpected answer! Congratulations! Had 4 weeks myself, take care of your family, everything else can wait ;)
Re: Building LDC runtime for a microcontroller
On Thursday, 17 September 2020 at 09:53:57 UTC, Remi wrote: [snip] My problem here is mostly understanding the __initZ symbol and where it comes from. I mostly want classes and the bare minimum of std like you did for Tetris in WebAssembly for example. My project is OpenGL/SDL2 so there's a lot of glue code but just ruinning a simple example gives me problems I want to understand first. Well... I just found out that it wasn't an issue with the code but rather the order of files as given to the compiler: (ldc-1.23.0)speps:~/dlang/wasm/webassembly$ ldc2 -i=. -i=std -Iarsd-webassembly/ -L-allow-undefined -oftetris.wasm -mtriple=wasm32-unknown-unknown-wasm arsd-webassembly/object.d tetris.d arsd-webassembly/object.d(112): Error: Global variable type does not match previous declaration with same mangled name: _D11TypeInfo_Ai6__initZ arsd-webassembly/object.d(112):Previous IR type: %object.TypeInfo_Array = type { [1 x i8*]*, i8*, %object.TypeInfo* }, mutable, non-thread-local arsd-webassembly/object.d(112):New IR type: %object.TypeInfo_Ai = type { [1 x i8*]*, i8*, %object.TypeInfo* }, const, non-thread-local (ldc-1.23.0)speps:~/dlang/wasm/webassembly$ ldc2 -i=. -i=std -Iarsd-webassembly/ -L-allow-undefined -oftetris.wasm -mtriple=wasm32-unknown-unknown-wasm tetris.d arsd-webassembly/object.d (ldc-1.23.0)speps:~/dlang/wasm/webassembly$ If object.d is passed after tetris.d, everything works as expected. Otherwise you get issues with __initZ. It also means that I might have no control over what dub does with the order of files and I can't use dub to build my WASM project.
Re: Building LDC runtime for a microcontroller
On Wednesday, 16 September 2020 at 18:34:05 UTC, Adam D. Ruppe wrote: On Wednesday, 16 September 2020 at 17:59:41 UTC, Remi wrote: I tried to modify the hello.d example from your blog post. It works without changes but when I tried to do a string concatenation Yeah, concatenation is one of the features that uses druntime, and specifically, it is done through TypeInfo. I would actually personally skip it if you are doing a minimal custom thing. If you skip it, you can implement your own type instead of using the built-in array concat. You can make a struct with an operator overload to look basically the same, and it can give a slice to pass to other functions. This is much easier here - no druntime code needed and the user code will be clearer that they might have to manage the memory. Typical code with normal append tends to just assume there's no stomping, that the GC takes care of it, etc. I'm hitting linker errors related to TypeInfo: But if you do implement it, as of right now, you have to define TypeInfo. Which suckss because it is super tedious. There's a WIP pull request up there with dmd to templatize this which would help a lot. But right now it means implementing at least some of it. You'd need the base class TypeInfo, then TypeInfo_a (a == "char"), TypeInfo_Array, TypeInfo_Aa (which means "array of char"), then finally, TypeInfo_Aya, which is "array of immutable char", aka, string. Once you get enough of that up - and the compiler is picky about those right now - then the append operation is `_d_arrayappendcTX`, which takes TypeInfo as a param. Search these names in the druntime source to see their official implementations... it is a bit of a beast, which is why I recommend actually skipping them if you can. It quickly explodes in size and by the time you follow it to its final conclusion, you've reimplemented 3/4 of full druntime anyway and might as well have just done a port. I don't mind implementing enough to get my project running, I first tried Sebastiaan's WASM druntime port but I realised the project I'm working on wouldn't need that much to get running so I thought maybe I can slowly port each part until I get the project to run. My problem here is mostly understanding the __initZ symbol and where it comes from. I mostly want classes and the bare minimum of std like you did for Tetris in WebAssembly for example. My project is OpenGL/SDL2 so there's a lot of glue code but just ruinning a simple example gives me problems I want to understand first. I'll probably try what you describe in your "Zero-runtime classes" actually, and hopefully I can get away without the string manipulation or replace it with my own version of it.
Re: Building LDC runtime for a microcontroller
On Monday, 7 September 2020 at 22:13:20 UTC, Adam D. Ruppe wrote: On Monday, 7 September 2020 at 20:55:54 UTC, IGotD- wrote: I guess this was written before betterC existed. Well, -betterC existed even then, but it was *completely* useless. It didn't become useful until 2016 or 2017. But around that same time, going minimal runtime got even easier, so I never really got on the betterC train anyway. On my tetris webassembly thing last month, I went with a minimal druntime http://dpldocs.info/this-week-in-d/Blog.Posted_2020_08_10.html#druntime And it has some class support too in not a lot of code: https://github.com/adamdruppe/webassembly/blob/master/arsd-webassembly/object.d (and if you aren't doing classes and built-in arrays, you can cut a bunch of that out too). To be honest I like this approach better as it opens up for gradually adding functionality. Yes, indeed. betterC is nice that it gives a library community a shared target to rally around, but for your own custom application it is probably better to do your own thing (though betterC might work for you too, worth considering at least). I tried to modify the hello.d example from your blog post. It works without changes but when I tried to do a string concatenation, I'm hitting linker errors related to TypeInfo: lld: error: server/omg.o: undefined symbol: _D12TypeInfo_Aya6__initZ Using this in hello.d string tmp = "hello"; tmp ~= " world !"; writeln(tmp); I've hit this when trying to make a minimal runtime like yours but I couldn't figure out from the LDC source how that happens. Would you be able to help me understand how to solve this __init symbol issue? Thanks. - Remi.