[net.micro.mac] TML Pascal 2.0 Compiler Bug

brf@ho2cad.UUCP (#BRUCE R. FOWLER ) (09/30/86)

	< WHERE'S MY CAN OF BUG SPRAY ??? ... > 

I got my brandy-new TML Pascal Version 2.0, August 1986, and
proceeded to break it with my very first program.  Such is life.

It seems that the compiler is generating bogus code when a function
that returns an enumerated value is referenced in a case statement:
		...
	type	fruit = ( apple, pear, banana, orange, kumquat );
		...
	function salad_part : fruit;
	    begin
		...
	    end;
	begin	{ main }
		...
	    case salad_part of
		apple:	peelandcore(0.5*servings);
		...
		{ etc. }

When the program executes the case statement, it branches off to
never-never land (even with range checking enabled).  I haven't
studied the generated code in detail to determine the exact cause
of the problem, but there is an "AND A1,D7" instruction in the case
branch calculation that doesn't make much sense at first glance.
After spending a couple hours tracking this down, I reproduced it
with a simplified example, so I suspect it will occur whenever the
above construction is used.  The work-around is to assign the
function result to an intermediate variable and then use that in
the case.

I plan to write Tom Leonard to report this problem, but in the
meantime, maybe this posting will save somebody a hassle.

						Bruce Fowler
						{ihnp4}!ho2cad!brf
^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v
    "The Twilight Zone - Love it or Leave it..."