A betterC modular standard library?

Mike via Digitalmars-d digitalmars-d at puremagic.com
Tue Dec 20 06:52:13 PST 2016


On Tuesday, 20 December 2016 at 12:49:53 UTC, Walter Bright wrote:
> I don't propose forcing anyone to use Druntime.

Perhaps this is not part of Ilya's concern, but druntime is 
required to get a build.

   //----test.d---------
   module test;

   void main() { }

   dmd -m64 -defaultlib= -debuglib= -conf= test.d

   Error: cannot find source code for runtime library file 
'object.d'
        dmd might not be correctly installed. Run 'dmd -man' for 
installation
        instructions.
        config file: (null)
   Specify path to file 'object.d' with -I switch


There's nothing here that really requires druntime, unless you 
want to count the plumbing required to call DMain.  In that case, 
we can just call CMain directly:

   module test;

   extern(C) void main() { }

   Same Error:
   Error: cannot find source code for runtime library file 
'object.d'


Try with the -betterC switch:

   dmd -m64 -defaultlib= -debuglib= -conf= -betterC test.d

   Same Error:
   Error: cannot find source code for runtime library file 
'object.d'

Ok, fine, let's add an empty object.d

   //object.d
   module object;

   //test.d
   module test;

   extern(C) void main() { }

   dmd -m64 -defaultlib= -debuglib= -conf= -betterC object.d test.d

   Error: undefined identifier 'Error'
   Error: undefined identifier 'Error'

Ok, now I need something called 'Error'.  I don't see anywhere in 
my code where that's necessary, but it must be important because 
it told me twice.

   //object.d
   module object;

   class Throwable { }

   class Error : Throwable { }

   //test.d
   module test;

   extern(C) void main() { }

   dmd -m64 -defaultlib= -debuglib= -conf= -betterC object.d test.d

   object.d(3): Error: class object.Throwable missing or corrupt 
object.d

Ok, that's weird. I just added it.  Luckily I've done this 
before, so I know what to do.

   //object.d
   module object;

   class Object { }

   class Throwable { }

   class Error : Throwable
   {
       this(string x) { }
   }

   //test.d
   module test;

   extern(C) void main() { }

   dmd -m64 -defaultlib= -debuglib= -conf= -betterC object.d test.d

   Error: no constructor for Error
   Error: no constructor for Error

Hmm. Again with the double error messages.  Ok, let's add a 
constructor.

   //object.d
   module object;

   class Object { }

   class Throwable { }

   class Error : Throwable
   {
       this(string x) { }
   }

   //test.d
   module test;

   extern(C) void main() { }

   dmd -m64 -defaultlib= -debuglib= -conf= -betterC object.d test.d

   object.d(9): Error: undefined identifier 'string'

At least its only telling me once.  Easy fix.

   //object.d
   module object;

   alias immutable(char)[] string;

   class Object { }

   class Throwable { }

   class Error : Throwable
   {
       this(string x) { }
   }

   //test.d
   module test;

   extern(C) void main() { }

   dmd -m64 -defaultlib= -debuglib= -conf= -betterC object.d test.d

   Error: TypeInfo not found. object.d may be incorrectly 
installed or corrupt,
     compile with -v switch

I could go on, but I'm not going to.  The final result to get a 
build looks like this, but you have to link with --gc-sections to 
avoid having to implement a buch of other stuff.

   module object;

   extern(C) void __dmd_personality_v0() { }

   extern(C) void _d_dso_registry() { }

   alias immutable(char)[] string;

   class Object { }

   class TypeInfo { }

   class TypeInfo_Class : TypeInfo
   {
       ubyte[136] ignore;
   }

   alias TypeInfo_Class ClassInfo;

   class Throwable { }

   class Error : Throwable
   {
       this(string x) { }
   }

   //test.d
   module test;

   extern(C) void main() { }

   dmd -m64 -defaultlib= -debuglib= -conf= -betterC object.d 
test.d -L=--gc-sections

If you add structs or classes to your code, you have to add even 
more druntime stuff.

The point I'm trying to make here is druntime is required just to 
get a build, even though your code doesn't need it.

Mike


More information about the Digitalmars-d mailing list