[comp.lang.postscript] PostScript interpreter in PostScript bug fix

don@TUMTUM.CS.UMD.EDU (Don Hopkins) (08/28/89)

Oops, the interpreter did the wrong thing in the case that the
last object in an executable array was another executable array,
in an attempt to be properly tail-recursive.

The function that needs to be fixed is /arraytype, defined in the 
iexec-types dictionary. In the case that the array length is 1, it
should call iexec-token instead of PushExec on the element of 
the array, since there is a difference between what PostScript does 
when it executes an array, and what it does when it encounters an 
array during the execution of a containing array.

I found this bug by using the interpreter to trace through itsself.
(It was failing on the nullproc function.)

	-Don

  /arraytype { % array => ...
    dup length dup 0 eq { % array length
      pop pop %
    } { % array length
      1 eq { % array
        0 get %
%	PushExec % XXX causes tail recursion bug
	iexec-token %
      } { % array
        dup 0 get % array head
	% push rest of array to execute later
	exch 1 1 index length 1 sub getinterval % head tail
	PushExec % head
        iexec-token %
      } ifelse
    } ifelse
  } def