Minimal druntime?
Mike Franklin
slavo5150 at yahoo.com
Sat Jul 27 14:06:51 UTC 2019
On Saturday, 27 July 2019 at 12:51:23 UTC, Ethan wrote:
> So. Is there a working minimal druntime out there? Or a process
> that can be applied for any given DMD release?
This is the most minimal runtime you can use:
object.d
```
module object;
```
That's right, an empty object.d file. Unfortunately, the
compiler still requires an object.d file to exist in order to get
a build. I've tried a few pull requests to change that, but
they've all failed scrutiny.
Assuming you use the above minimal runtime, you can create the
following minimal hello world program on Linux.
main.d
```
private extern(C) void __d_sys_exit(long arg1)
{
asm
{
mov RAX, 60;
mov RDI, arg1;
syscall;
}
}
private long __d_sys_write(long arg1, in void* arg2, long arg3)
{
long result;
asm
{
mov RAX, 1;
mov RDI, arg1;
mov RSI, arg2;
mov RDX, arg3;
syscall;
}
return result;
}
void write(immutable(char)[] text)
{
__d_sys_write(2, text.ptr, text.length);
}
private extern(C) void _start()
{
main();
__d_sys_exit(0);
}
void main()
{
write("Hello, World!\n");
}
```
See it in action at https://run.dlang.io/is/Ix22Eo
From there, the world's your oyster. Start programming in D, and
if the compiler or linker can't find something, either copy it
from druntime, or implement your own.
I suspect that's not much use to you, but it is indeed the most
"minimal runtime". The motivation for using a minimal runtime is
to incrementally port D to a new platform and implement only what
is needed in a pay-as-you-go fashion.
Some of us are slowly improving the experience, but it still has
a long way to go. It's MUCH better than it was a few years ago,
though.
Mike
More information about the Digitalmars-d
mailing list