Using non mscorlib assemblies

Developer
May 22, 2009 at 5:25 PM

Is it possible to use any other assemblies? It is defaulting to 'call type [mscorlib] func' in the IL.

Coordinator
May 22, 2009 at 5:34 PM

It is possible, but it requires a small hack in your import file:

// myassembly.d

class myassembly { }
class assembly : myassembly { }

This trick is used in System.di and you can read more here:

http://the-free-meme.blogspot.com/2008/12/hello-net-d-here-calling.html

Developer
May 23, 2009 at 4:32 AM

I already tried playing with that a little but its not going to work. I've added this to my System.di:

 public class Windows
{
 public class Forms
 {
  public class Application
  {
  public static void EnableVisualStyles();
  }
 }
}

 

And tried changing the start of the file to:

class mscorlib { }
class System.Windows.Forms { }
class assembly : mscorlib { }
class assembly : System.Windows.Forms { }

It has dots in the name, doesn't appear to have any way of selecting which one and the syntax is kinda ugly too.

There needs to be a special way of decorating it. I think there should be a way of decorating the module which becomes the default, then the individual classes, sub classes will use its immediate parent as the default. Finally there is the issue with partial classes so each class memeber should be decorated.

I'm not sure how powerfull pragmas are so there may need to be a unique syntax.

Coordinator
May 23, 2009 at 6:38 AM

You are right, that case is not going to work, the "class assembly" hack only works once per import file.

I will have to talk to Walter about ways to changing the front-end.

Your idea sounds interesting can you elaborate?

Developer
May 23, 2009 at 7:30 AM

C# has attributes which can appear on just about anything but I think it is too similar to array syntax and sometimes it may appear ambiguous to the compiler to which thing it refers to. http://msdn.microsoft.com/en-us/library/b3787ac0(VS.71).aspx

Java has annotations which use an @ but are very similar.

In D we have pragmas which I hope could be used but I dont know my way around the dmd front end yet so are these powerfull enough? Can you see which thing it refers to easily?

Contents of System.di:

pragma(CLR_Assembly, "mscorlib"); //sets default for this file

pragma(CLR_Assembly, "System.Windows.Forms") public class Windows //assembly is System.Windows.Forms.dll
{
 public class Forms //these inherit
 {
  public class Application
  {
  public static void EnableVisualStyles(); //still in System.Windows.Forms
  }
 }
}

public class GC //mscorlib
{
  static public void Collect();
  static public void WaitForPendingFinalizers();
}

Coordinator
May 23, 2009 at 9:22 PM

This is an interesting start. One requirement is that import files can be generated automatically from assemblies using reflection, and I think your proposal may work.

If we are going to go this route there's another place it could be used: D properties are currently not compatible with C# / .NET properties. Take "length" for example. If we could mark it explicitly as a property in the source code then we could generate set_Length and get_Length.

Feel free to email me directly, I think this is a very constructive discussion.