I am interested in converting some legacy code from Modula 2 to a C
based language like C, C++, C# or Java. Are there any code
converters?? I'd be grateful is someone could point me in the correct
direction.
I checked the Modula-2 FAQ at
http://groups.google.com/group/comp.lang.modula2/browse_frm/thread/ef5b25f54a521602/bfdafb562e736513?hl=en&lnk=st&q=modula+2+converter++to+C%2B%2B#bfdafb562e736513
It addresses this topic in section 4.5. However all of the links there
do not work.
I also tried Canterbury Modula-2 for Java from http://www.mhccorp.com/downloads.shtml
- but I could not figure out how to get that to work.
Thanks a lot.
O.O.
Maybe GNU M2? AFAIK That works as a frontend to GCC:
However, typically these sorts of convertors are merely using C as a code
generator - they weren't designed to produce human-readable / maintainable
code.
My experience with code convertors, even when used with languages that are
more closely related in capabilities than Modula-2 / C (e.g. Pascal to
Oberon) is that they are useful for converting selected procedures - not
complete applications. When you write a program in Modula-2 you usually
start off with a different design approach than you would if you were using
C.
An alternative approach would be to port the legacy code to the .NET
framework using the Gardens Point Modula-2 CLR compiler:
http://plas.fit.qut.edu.au/gpm/
and then, if you really wanted to translate it, you could use Lutz Roeder's
Reflector to decompile the resulting DLL's / EXE's to C#:
http://www.aisto.com/roeder/dotnet/
As you can call the Modula-2 code from C# code you would not have to
translate it all at once.
--
Chris Burrows
CFB Software
http://www.cfbsoftware.com/modula2
Thanks Chris for your quick response.
I forgot to mention in my original post that I use only WinXp. I have
Cygwin though - but I usually prefer not to use it if possible -
because I can never get it to work.
I looked at "GNU Modula-2 Compiler" at http://www.nongnu.org/gm2/ -
and it seems to have only installations for Debian on Linux.
I then went to Gardens Point Modula-2 in http://plas.fit.qut.edu.au/gpm/
- It does not seem to have a Windows Version of the Installation - at
least in the List of Downloads that they have. I however looked at the
Release Notes (the last PDF at the bottom) which seems to say that I
have to use an "Install Shield" etc. which sounds Windows Like - but
I don't know where to download this from.
I also noticed at the side there was an " Online GPM/CLR Compiler" at
http://plas.fit.qut.edu.au/gpm/online_compiler.aspx . However with the
sample Hello.mod I get an error saying that it could not find the
entry point and hence could not create the EXE. I also tried giving it
one of my own files - and it crashes i.e. I get a page telling me that
the application has crashed and due to security reasons it would not
tell me what the error was.
Lutz Roeder's Reflector might work for me - but first let me get this
Gardens Point Modula-2 to work, because only then it would be useful.
I would also want to know how to call Modula-2 Code from C# code - but
I don't think you need to answer that until I have got Gardens Point
Modula-2 working.
Thank you for your interest.
O.O.
Maybe you can try XDS 'via C' modula2 compiler? But Chris said you ...
it's never that easy.
http://www.excelsior-usa.com/xds.html
JP2R
The Windows .NET versions are the ones identified as gpm-clr (clr = the .NET
common language runtime).
I however looked at the
> Release Notes (the last PDF at the bottom) which seems to say that I
> have to use an "Install Shield" etc. which sounds Windows Like - but
> I don't know where to download this from.
>
You don't need InstallShield. They are just explaining that they used it to
produce the installation setup files.
Thank you for the information. I could not figure out if I should use
Whidbey or Everett. I Googled this - but I got confused with what I
got i.e. I got something on Whidbey but not much on Everett so I did
not know the difference. Anyway I decided to download the CLR for
Whidbey.
I installed it. Then I tried the example that they have in the
documentation on Hello World - this did not work. I keep getting
something like: (gpx /cg hello.mod)
#gpmx: can't create tmp file
Aborting ...
I cant figure out what I am doing wrong - or where the tmp file is
attempted to be made.
Is there a mailing list or some forum for this Gardens Point
Modula-2? Or should I simply email the people on the website?
Thanks a lot.
O.O.
They were the pre-release codenames for Visual Studio:
Everett --> VS 2003 (.NET 1.1)
Whidbey --> VS 2005 (.NET 2.0)
> I installed it. Then I tried the example that they have in the
> documentation on Hello World - this did not work. I keep getting
> something like: (gpx /cg hello.mod)
>
> #gpmx: can't create tmp file
> Aborting ...
>
>
> I cant figure out what I am doing wrong - or where the tmp file is
> attempted to be made.
>
Maybe you haven't got the TEMP environment variable defined, or haven't got
write access to the corresponding directory? Try compiling with the verbose
option
gpx /cgV
and see if that gives any additional clues.
If you make some progress with this and decide to attempt to port your
applications, let me know as I have an experimental version of my Component
Pascal IDE
http://www.cfbsoftware.com/cpide which supports Modula-2 source code that
you are welcome to try. It's infinitely easier than trying to use a text
editor and the command-line for compiling.
> Is there a mailing list or some forum for this Gardens Point
> Modula-2? Or should I simply email the people on the website?
>
GPM support contacts are the same as for Gardens Point Component Pascal:
email: gpcp at qut.edu.au
newsgroup: http://tech.groups.yahoo.com/group/GPCP/
Dear Chris,
Thanks for your prompt response. I have yet to read your email
properly because I am in a hurry. Its almost morning here, and I need
to get some sleep.
With the Verbose option I get something like:
gpmx: m2 to CIL version of <no version time>
Opening "Hello.mod" as input
... Target configuration file C:\gpm\gpmd\GPMsym\gp2d.cfg
... Importing <InOut> from C:\gpm\gpmd\clrsyms\inout.syx
-- mod <InOut> key = 3575173240
Returning recursion
#gpmx: can't create tmp file
Aborting ...
I have TEMP=C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp and TMP=C:
\DOCUME~1\ADMINI~1\LOCALS~1\Temp
So I think that this is Ok, because other applications can write to
it.
Thanks a lot for your interest.
O.O.
In the past I have used mtc translator from the coctail suite. Trying
today web seach for mtc I only got (a lot of) dead links. But I still
have the sources on my hard drive -- if you are interesed I can put
them in a public place. I have Linux binary, but for Windows you
would have to compile it yourself (probably under Cygwin). To get
my version I had to fix a few compilation problems (the orignal
sources were intended for Sun OS) -- so do not expect clean
compilation on Windows.
There is another translator, m2c by Vladimir Makarov. I tried it
and I have found out that is has serious bug -- it generates incorrect
code for nested function calls. That is, things like:
F(G(x), H(y))
do not work.
--
Waldek Hebisch
heb...@math.uni.wroc.pl
Try:
ftp://ftp.uni-potsdam.de/pub/lang/modula/mtc.tar.Z
Thanks again.
O.O.
A late answer... I have a huge code base in Modula-2, and was left
stranded when Stonybrook chose to sell out, and what I eventually
found was that the simplest, and above all the safest, was to do hand
translation to plain C. I can now literally convert procudeure by
procedure and module by module to C with almost no logical errors at
all and if you already have programmed in C (I hadn't) it should be no
problem. To ease the pain, first rewrite the Modula-2 code to be more
C-like and in this part of the translation take advantage of that
Modula-2 is a safer language (to remove all nested procedures is of
course a typical thing to do before converting to C).
Now, since the Stonybrook compiler is very very stable and runs well
on Vista etc. (which make it all the sader that they did not
continue...), a total conversion is not extremly urgent so in practise
I have so far only converted all my general purpose libraries and some
of my programs that I want to be in a language that can be taken over
by someone else if need be. However, from this I have learned that the
conversion is not an actual problem, it is only a matter of time and
the result is predictable.