[Mono-list] MCS -cppoutput C# to C++ generator work in progress

Miguel de Icaza miguel@ximian.com
04 Jul 2002 14:17:52 -0400


Hello!

> Since porting last may's rev of mono to MSVC , I've been working on the C++
> output module for mcs.  Basically, cppoutput.cs is added to the mcs core,
> and from the parse tree generated by the main compiler, it generates a
> compatible set of .cpp, .h, and .inl files complete with nice #line
> directives for .cs debugging, and with the limited set of statements
> compiling, it seems to work nicely.

I am not sure that you will be able to do a complete translator by using
the internal parse tree, as this parse tree is lacking the semantic
analysis phase.  

For instance, during the `DoResolve' phase, names are resolved to their
actual meaning.  For instance:

	A += X;

A could mean a number of things depending on its context.  An assignment
to field variable;  An assignment to a property;  An event addition or
even an error if A is a type. 

My suggestion would be to add a different "Emit" method to the Statement
and Expression base classes (EmitCpp) that would generate the code that
you want, but the resulting code would look less than C#, and more close
to the real internal representation.

Btw, someone could also write an EmitJava method, and for some cases
generate code for a JVM.

> I tweaked mono's and binary vtable representations to coexist with C++
> efficiently so that mono could easily marshall and call c++ code as if it
> was doing an "internal_call", and c++ could call mono as well using
> mono_execute().  The solution I came up with was to put mono's vtable
> "before" the vtable structure, and the c++ vtable after it.   When you
> inherit in C++ from the Object class, you automatically get a set of 6
> vtable entries which reserve space in the C++ vtable for the mono vtable
> structure.  That way mono objects are C++ objects, and vica-versa, and each
> side conveniently marshals to the other transparently.

Pretty cool hack, I am reading with excitement the rest of your
message.  It looks really interesting.  

Miguel