[Mono-dev] C# source-to-source compiler

jmalcolm malcolm.justin at gmail.com
Fri Nov 5 01:08:31 EDT 2010



kcleung wrote:
> 
> 
> I am also looking for developing C#-based language extension, which
> the compiler will compile to C# 4.0 code that calls *my* runtime
> library.  The emitted C# 4.0 code will then go to the original dmcs
> compiler, which will then produce CLI bytecode.
> 
> Thanks!
> 
> Qichang
> 
> 

I guess I am also confused as to why you would need to have C# to C# as an
intermediate step.

Are you thinking that you would want to manually edit and maintain the
generated C#?  I mean are you really seeing your modified C# as a Domain
Specific Language (DSL) that is really just a code generator?

It would seem easier to modify the C# compiler to directly generate CIL
(Common Intermediate Language) that calls your runtime library.

You can call your runtime library from CIL just as easily as you can from C#
code.  The C# compiler already spits out CIL.  Just modify it to spit out
CIL that calls into your runtime library.  This will be much easier than
what you are proposing.

I am not sure how familiar you are with CIL.  It is what all .NET languages
like C#, Visual Basic, and Boo are compiled down to.  It is often described 
to be like assembly language but it really is not.  It is really a pretty
high-level OO language in it's own right.

CIL is like assembly in that it lacks many structured language features,
like looping constructs, and instead uses jumps and conditional branches
(like goto and if statements if you like) to achieve equivalent results. 
However, it is fully object-oriented and supports classes, fields, and
methods with full support for inheritance, polymorphism, and virtual
methods.  Access levels like public and private or modifiers like static
(singleton) are all supported as well.  It also has a wide range of
operators and a complex type system with integers, floating point types, and
even arrays and generics.  CIL has full access to the .NET framework and
method calls are by name and argument signature.  You can easily call into
your library from CIL just as you would from C#.

I do not believe that you need to have C# as an intermediate step.
-- 
View this message in context: http://mono.1490590.n4.nabble.com/C-source-to-source-compiler-tp3026549p3028181.html
Sent from the Mono - Dev mailing list archive at Nabble.com.


More information about the Mono-devel-list mailing list