druntime redesign

IGotD- nise at nise.com
Tue Mar 17 21:01:23 UTC 2020


On Tuesday, 17 March 2020 at 20:37:04 UTC, Jacob Carlborg wrote:
> On 2020-03-17 20:34, IGotD- wrote:
>
>> This is where something like
>> 
>> import core.sys.<compiletime identifier>.semaphore;
>> 
>> would be an absolute great help.
>
> Can be easily handled with a string mixin and a utility 
> function:
>
> version (linux)
>     enum platform = "linux";
> else version (Windows)
>     enum platform = "windows";
>
> string import_(string[] imports ...)
> {
>     string result;
>
>     foreach (i, imp; imports)
>     {
>         if (i != 0)
>             result ~= '.';
>
>         result ~= imp;
>     }
>
>     return "import " ~ result ~ ';';
> }
>
> mixin(import_("core", "sys", platform, "semaphore"));

Thank you, didn't know that mixins even works for imports. This 
greatly would help a generic ABI as the import would just select 
the specific files for the particular OS. The OS implementations 
could then have dedicated names that like SemapholeImpl as type 
and dedicated methods like SemapholeImpl.wait(). This really open 
ups the degrees of freedom.



More information about the Digitalmars-d mailing list