views:

83

answers:

1

This is just a thought for now, but I wonder how hard it would be to either use the Mono Compiler or write a new one while still outputting a Windows EXE?

The reason for this thought is that I see people "abusing" the C# language creatively to get some stuff like code contracts or aspect oriented programming up and running, and sometimes it feels like people are stretching too far.

The good thing about .net is that at the end, all we want is valid IL for the .net 2.0 CLR. However, the Microsoft C# compiler is closed and cannot be extended. Mixing different languages is only possible in different assemblies.

The thought (warning: May sound horrible) is to use a compiler that can be extended and run it as a sort of preprocessor. That way it would be possible to add new Keywords and language concepts while still returning valid IL.

The obvious downside is of course that a) it's not C# anymore but a C#-derivate that no one else understands, b) writing a compiler is hard as countless rules have to be respected to maintain a high quality and logical syntax.

But as said, that is only a thought for now. It's a little bit the same direction that Mono.Cecil takes, but a completely different approach.

+1  A: 

I am looking forward to the evolution of programming away from text and towards something more structured. Programs are already very structured, but are still edited as plain text, making IDEs a major exercise in ingenuity. Add compiler extensibility on top of this, and creating an IDE as friendly as Visual Studio sounds even more daunting.

AST-based macros + C# would go a long way in allowing even more "creative abuses" of the language, but I feel that the real way forward is Language-oriented programming. This approach has been advocated for years, but the first system of this paradigm that I personally found truly appealing is JetBrains' Meta Programming System. It doesn't seem to be very well-known yet, and I certainly haven't got hands-on experience in actually using it, but they have shipped an excellent product built using this system, so it must be reasonably practical. The tutorial shows off the extent to which it is extensible, which is truly amazing - especially if haven't seen language-oriented systems before.

If one were to go down this route then only parts of the existing Mono compiler are relevant. You could probably meaningfully reuse large parts of code gen, but obviously the parser is of no use at all.

A system similar to MPS but compiling down to .NET and integrating nicely into Visual Studio would be very welcome indeed.

(And to answer the question you're asking directly: I think it would be very hard to do this nicely enough to see wide adoption, but certainly not impossible for a couple of great and motivated developers)

romkyns
Here's a screencast showing an example of how to extend the language with a "lock" statement: http://www.jetbrains.com/mps/demos/screencast/lockstatement-language/buildingTheLanguage.html
romkyns