Wiki

Ticket #91 (new enhancement)

Opened 15 years ago

Last modified 14 years ago

Bring in the Mono C# compiler backend

Reported by: Chuck Owned by:
Priority: medium Milestone:
Component: Cobra Compiler Version: 0.8.0
Keywords: Cc:

Description

In April 2008, the Mono C# 2.0 compiler was released under the unrestrictive MIT license. Previous versions had been under GPL which was not compatible with Cobra's MIT license (we would have had to change it).

See  http://www.mono-project.com/news/archive/2008/Apr-08.html

I believe the initial approach we can take for this ticket is the following:

  • Get the Mono mcs.exe compiler rebuilt as mono-sharp.dll
  • Ensure that mono-sharp.dll has public API calls to compile source code from memory (a .NET string) and to take options.
    • That eliminates disk I/O.
  • Have cobra.exe reference mono-sharp.dll and invoke it.
    • That eliminates process launching.

The ability to generate C# to disk and invoke the compiler should be left in place for some time in case we find ourselves in need of it.

Change History

Changed 15 years ago by Chuck

I think this is better than writing an IL backend due to the advantages of leverage. A lot of work has been put into their compiler; no need to reinvent the wheel if backends are now becoming commodities.

Changed 15 years ago by Chuck

This may be easier than I thought:

But it might not work so well on .NET:

Also, note that since the Mono compiler went to the MIT license in 2008, it may not be possible to do this for .NET 2.0.

Changed 15 years ago by Chuck

Btw it was starting with Mono 2.0 that the Mono C# compiler went to MIT license.

Changed 15 years ago by Chuck

Another mention of the C# DLL is here:
 http://www.mono-project.com/Release_Notes_Mono_2.2

Changed 15 years ago by Chuck

Note that .NET can treat .NET .exe files as libraries/assemblies. So you can, for example, load gmcs.exe as an assembly with Assembly.loadFile at run-time. You could also ref it at compile-time, but I think you would then have to put it in the GAC or copy it to your local directory.

Changed 14 years ago by Chuck

This is actually done on the *nix/Mono side with a wee bit of hacking on the Mono source code. However, the Mono C# compiler won't run under the Microsoft CLR which is kind of strange given that the Mono C# compiler is a CLR program producing CLR programs. There are some internal things they do that MS chokes on. However, we may be able to fix this by hacking on their compiler some more.

Note: See TracTickets for help on using tickets.