Building LDC runtime for a microcontroller

Remi remigillig at
Thu Sep 17 09:53:57 UTC 2020

On Wednesday, 16 September 2020 at 18:34:05 UTC, Adam D. Ruppe 
> 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 suckssssss 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 

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.

More information about the Digitalmars-d-learn mailing list