druntime redesign

IGotD- nise at nise.com
Wed May 6 12:18:04 UTC 2020


On Tuesday, 17 March 2020 at 20:37:04 UTC, Jacob Carlborg wrote:
>
> 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"));

I see many occurrences like this insinde the version blocks:

import core.sys.platform.subfunctionality : subFuncImpl;
alias functionality = subFuncImpl;

We could provide with an abstract interface like this as you 
suggested.

mixin(import_("core", "sys", platform, "semaphore")) : 
SemaphoreAcquireImpl;
The Semaphore class can use SemaphoreAcquireImpl.

SemaphoreAcquireImpl would have a type like this where 
SemaphoreOSType also needs to be imported in similar fashion:
void SemaphoreAcquireImpl(SemaphoreOSType sem), but this function 
would be the same for every system. I think this type of 
interface could be repeated for almost all OS dependent 
functionality. The type of the semaphore descriptor must also be 
be provided, as some are a descriptor on certain systems or a 
pointer type on others.

Some functions can just be aliased
mixin(import_("core", "sys", platform, "process")) : getPidImpl;
alias getpid = getPidImpl;


This type of interface could just be added under one version 
block like:

version(druntimeAbstractInterface)
{
    ...
}



Something that we all can work on is a generic C library 
interface for "C library style OS" for compatibility. This of 
course would have limited functionality but could provide basic 
functionality. This also makes important to selectively choose 
what to support. A stub would be an alternative, that just goes 
through silently or raises a "not implemented exception". Nim has 
an --os:any option which means it will just use the C library.




More information about the Digitalmars-d mailing list