[Mono-list] C++ to CIL compilers?
Miguel de Icaza
21 Jan 2002 12:49:58 -0500
> > It took me only 8-months of part-time work on the compiler to write a C#
> > compiler, so it is something within the scope of a one semester class to
> > create other languages.
> Sure, if these languages are designed to target CIL and are (therefore)
> pretty much just an alternative syntax for C#.
> If you want your language to do anything that CIL doesn't directly
> support, or you need to interoperate with CIL but your language doesn't
> have all the features of CIL (or at least the CLS) then you are going to
> have a much tougher time writing a compiler.
There are a number of reasons why I believe that adapting g++ to support
"Managed C++" is not that hard:
* Supporting the C-like constructs is already possible by the
CLR. Pointer arithmetic is there, value types are there and
roll-your-own vtable support is there as well.
* An existing "reference" implementation exists, it should be
relatively simple to learn from the Microsoft Managed C++
compiler what needs do be done, and how the language maps to
I agree that starting from scratch would be a much harder task.
> C# is going to be the easiest case, as it is practically the same
> feature set as CIL. The more different your language is from C#, the
> more work you are going to have to do.
I kind of disagree with this general statement. If your language
implements features that are hard to express with the current CIL you
will require to spend a significant amount of time researching the
mapping, but if your language can be properly expressed in CIL terms
then the work is less.
For example, consider a primitive BASIC compiler (for the sake of
proving my point), targeting the CIL for a BASIC compiler should be
trivial and straight forward.
In the particular case of C++, the language is large, the feature set is
large, but we also have two bits already done: C++ and its semantic
analysis and an existing "mapping" of C++ to CIL exists that illustrates
what needs to be done.
> I would certainly think modifying gcc to be like the Managed C++
> compiler would be way way more work than 1 semester.
You might be right. I am known for never guessing correctly schedule