Re: Re: Any way to compile to .NET (Mono or MS's)
[email protected] Wed, 29 Jun 2005 08:49:22 +0200
| Newsgroups | gmane.comp.lang.eiffel.smalleiffel |
|---|---|
| Message-ID | <OF8A131EA2.57571FBF-ONC125702F.001E8273-C125702F.00257AA1@mpsa.com> |
Hello,
> >I agree with Dominique. When eventually we implement a .net backend,
> > I think we will directly generate CLI, not MSIL (as compile_to_jvm
> > generates Java bytecode).
> That's what I ment (notice I mentioned Mono). Maybe I didn't use the
> right terms.
OK then.
> I would love to start/help in such a project. Can you (I assume you're
> in the main team since you use "we" all the time ;-) give me some
> directions to go?
The first thing to do is, besides regularly retrieving the development
snapshot, to look at how the compiler works. The entry point of each tool
is in tools/commands. Look at e.g. COMPILE_TO_C and COMPILE_TO_JVM.
I think that a new back-end should not be hard-wired as c and jvm are;
instead they should use the Visitor pattern. BUT while looking at the
classes mentionned above you will gain understanding at how things
generally work.
A rough scheme is the following:
1- Create the plugin factory. This is used to implement external
"plug_in".
2- Parse options and/or ACE file.
3- Collect class information using the root class and procedure
(SMART_EIFFEL.get_started). That's the most important part of the compiler
(also the most complex).
4- Compile using the back-end generation (c is C_PRETTY_PRINTER.compile
while jvm is JVM.compile).
The steps 3 and 4 are encapsulated in SMART_EIFFEL.compile_to_c and
SMART_EIFFEL.compile_to_jvm. Note that I plan to merge those two features
since they are identical except for one thing that depends on the
back-end. The signature of the new feature will be `compile (backend:
CODE_PRINTER)'. I'll do that ASAP, so watch the change log ;-)
To make a new back-end, you have to:
1- write a PLUGIN class and a PLUGIN_FACTORY class (e.g. CLI_PLUGIN and
CLI_PLUGIN_FACTORY)
2- write a CODE_PRINTER class (e.g. CLI) that implements the Visitor
design pattern
3- write a root class (e.g. COMPILE_TO_CLI), it should be quite like
COMPILE_TO_JVM (maybe start from that one) and call
SMART_EIFFEL.compile(create {CLI}.make).
For the CODE_PRINTER class, look at C_PRETTY_PRINTER and JVM for examples
of implementation, still bearing in mind that yours will not use
hard-wired code in every class of the system, but rather the Visitor
design pattern.
Extra information about that Visitor design pattern: the exact pattern is
Acyclic Visitor (http://c2.com/cgi/wiki?AcyclicVisitor). There are some
examples in the compiler itself: Eiffeldoc heavily relies on it (see
tools/commands/eiffeldoc.e and tools/generation/eiffeldoc/*.e), some
helpers (tools/generation/short/manifest_generic_sample_printer.e, tools
/kernel/helpers/agent_creation_helper.e and so on) and the special class
tools/utils/in_out_visitor.e. Also look at my own project SmartFactor
(http://www.cadrian.net/~cyril/eiffel/index.html).
> Is there anyone else interested.
Look at Joseph Kiniry's answer.
Hope it helps,
Best regards,
--
Cyril ADRIAN -- ALPLOG
@ PSA Peugeot Citroën, Sochaux, France
tél. +33 (0)3 81 33 48 76
fax +33 (0)3 81 33 16 06
Vt Sol inter planetas,
Ita MVSICA inter Artes Liberales
in medio radiat
-- Heinrich Schütz, 1640