C to Mesa Translator
			  Charles Crowley
			  
		  (213) 615-2030 (until 31 july 1983)
	    (505) 277-3112 or (505) 268-7220 (after that)
	    
Further information on the C to Mesa translator can be found in the Star document OSBU South: Charles Crowley: C To Mesa.

This document gives a brief summary of the use of the C to Mesa translator.  There are three steps in using the C To Mesa translator in its present form.  Only the very simplest C programs will translate correctly with no fixups at all.  Fortunately almost all the fixups are quite simple.

(1) The first thing to do is to edit the original C program to elimate some things that will translate badly or will cause translator syntx errors.  The things to change here are:

	(1) remove all preprocessor statements and simulate there effect in the program.  This can be done with global substitutions in the editor.
	(2) remove all uses of the "comma" operator in C.  This is where two or more comma-separated expressions are placed where only one expression should go.  This change is very easy but necessary since they will cause syntax errors in the translator.
	(3) change all "typedef"ed names to their expanded version.  The translator does not handle typedefs, mainly because they cause syntax errors when they are used.  (It is necessdary to get the scanner to help you out of this problem and I have not gotten to that.)
	(4) if any procedures actually return values but are declared to default to returning and integer, these should be changed to include a specific declaration as a function.  If any functions are declared as procedures, declare them correctly.  If any function returns values from some places and not from others or is used as a statement and declared as a function, change these.  The translator will translate them correctly but they will cause Mesa errors and you might as well change them now.
	(5) often some gotos can be eliminated in the C code.  Do this here if possible.  Gotos will not cause the translator to quit but they will be translated into illegal Mesa and will have to be fixed up later in any case.  You must decide for each case whether it is cleaner to eliminate them here or ro wait and remove them from the translated Mesa.  The second option is best for cases where the goto is simulating a feature missing in C but present in Mesa (e.g., certain types of loop exits, such as a loop exit from inside a case statement).  By the way the gotos in case statements might give you a bit of trouble.  C programs contain them frequently and Mesa, of course, does not allow them.
	(6) C promises a DEFAULT initialization for all global variables.  The translated programs do not include this explicitly and Mesa does not do it either.  Change all of these to explicit initializations.
	
	
(2) The next step is to run the C to Mesa translator on the modified C program.

	(1) retrieve the translator frome
		[rain]crowley>ctomesa>ctomesa.bcd
        (2) it is best to run it in Tajo since it occasionally crashes.  Also it has a snall storage leak even when it doesn't crash.
	(3) Run it with a command line:
		> ctomesa prog.c
		> ctomesa prog.c/e
		> ctomesa prog.c/c
		> ctomesa prog.c/ce
The first command line will run the translator on "prog.c" and put the Mesa program in "prog.mesa".
The second command line will do this and also echo the output to "prog.mesa" to the executive window.
The third command line will do the translation but also include the original C program (prog.c) as comments in the translated program in "prog.mesa".
The fourth command line will combine the effects of lines two and three.


(3) Finally it will be necessary to make some fixes to the Mesa program before it will compile.  Mainly you will have to eliminate gotos.  Another common cause of Mesa errors is type problems in complicated expressions especially ones involving pointers.  Usually these fixups are fairly easy to make.


The C to Mesa translator requires two sorts of runtime support.  The first is included in "CRuntimeDefs.mesa" and "CRuntimeImpl.mesa".  These files includes source for a number of procedures used by the translator to make the translation easier.  An example of one of these is "PostIncrement".

The second is "CLibraryDefs.mesa" "CLibraryImpl.mesa" and this includes the system calls and other library routines that are found in object libraries on Unix/C systems.

These two interfaces are packed into Unix.bcd which creates a Unix window for translated programs to run in.