A Lisp interpreter written in Lisp (2017)
Glenn Reid wrote a PostScript partial evaluator in PostScript that optimized other PostScript drawning programs, called &quot;The Distillery&quot;. You would send still.ps to your PostScript printer, and then send another PostScript file that drew something to the printer. The first PostScript Distillery program would then partially evaluate the second PostScript drawing program, and send back a third PostScript program, an optimized drawing program, with all the loops and conditionals unrolled, calculations and transformations pre-computed, all in the same coordinate system.<p>It was originally John Warnock&#x27;s idea, that Glenn implemented. And it led to Adobe Acrobat&#x27;s &quot;Distiller&quot;. Acrobat is basically PostScript without the programming language.<p>No, you could not make it optimize itself by sending it to a PostScript printer two times in a row. It was not magic: all it did was intercept and capture the side-effects of the PostScript drawing commands (fill, stroke, show), read out the path, and optimize it in a uniform coordinate system. Since it didn&#x27;t do any drawing, so it would just output an empty program if run on itself. (Take that, halting problem!)<p><a href="https:&#x2F;&#x2F;donhopkins.com&#x2F;home&#x2F;archive&#x2F;postscript&#x2F;newerstill.ps.txt" rel="nofollow">https:&#x2F;&#x2F;donhopkins.com&#x2F;home&#x2F;archive&#x2F;postscript&#x2F;newerstill.ps...</a><p>&gt;From: greid@adobe.com (Glenn Reid)
Newsgroups: comp.lang.postscript
Subject: release 10 of the Distillery
Date: 10 Mar 89 10:21:52 GMT<p>&gt;Here is another release of the PostScript Language Distillery.  I know
it&#x27;s not terribly long after the last release, but there are some
significant enhancements, and I thought it would be worthwhile.<p>&gt;I finally took a closer look at user-defined fonts, which now seem to
be working fairly well.  In particular, it seems to handle the
Macintosh screen bitmap fonts that get used if the native font is
unavailable when the print file is genreated.  The entire user-defined
font is reverse-engineered to the output file as it stands, and is used
exactly like the original file used it.  I also fixed some rotate text
bugs, rotated charpath, and a few other things.<p>&gt;I want to emphasize that probably the two best uses of this program,
currently, are to do speed comparisons of various PostScript language
drivers and to convert &quot;non-conforming&quot; files into &quot;conforming&quot; files.
It is not particularly well suited to carefully hand-written programs,
especially not those which use looping constructs.  It works (usually),
but it unrolls the loops and makes the files much bigger.<p>It&#x27;s also possible to simply write a metacircular PostScript evaluator in PostScript:<p><a href="https:&#x2F;&#x2F;donhopkins.com&#x2F;home&#x2F;archive&#x2F;NeWS&#x2F;ps.ps" rel="nofollow">https:&#x2F;&#x2F;donhopkins.com&#x2F;home&#x2F;archive&#x2F;NeWS&#x2F;ps.ps</a><p><a href="https:&#x2F;&#x2F;donhopkins.medium.com&#x2F;the-shape-of-psiber-space-october-1989-19e2dfa4d91e#c699" rel="nofollow">https:&#x2F;&#x2F;donhopkins.medium.com&#x2F;the-shape-of-psiber-space-octo...</a><p>&gt;Printing Distilled PostScript<p>&gt;The data structure displays (including those of the Pseudo Scientific Visualizer, described below) can be printed on a PostScript printer by capturing the drawing commands in a file.<p>&gt;Glenn Reid’s “Distillery” program is a PostScript optimizer, that executes a page description, and (in most cases) produces another smaller, more efficient PostScript program, that prints the same image. [Reid, The Distillery] The trick is to redefine the path consuming operators, like fill, stroke, and show, so they write out the path in device space, and incremental changes to the graphics state. Even though the program that computes the display may be quite complicated, the distilled graphical output is very simple and low level, with all the loops unrolled.<p>&gt;The NeWS distillery uses the same basic technique as Glenn Reid’s Distillery, but it is much simpler, does not optimize as much, and is not as complete.<p>&gt;The Metacircular Postscript Interpreter<p>&gt;A program that interprets the language it is written in is said to be “metacircular”. [Abelson, Structure and Interpretation of Computer Programs] Since PostScript, like Scheme, is a simple yet powerful language, with procedures as first class data structures, implementing “ps.ps&quot;, a metacircular PostScript interpreter, turned out to be straightforward (or drawrofthgiarts, with respect to the syntax). A metacircular PostScript interpreter should be compatible with the &quot;exec&quot; operator (modulo bugs and limitations). Some of the key ideas came from Crispin Goswell&#x27;s PostScript implementation. [Goswell, An Implementation of PostScript]<p>&gt;The metacircular interpreter can be used as a debugging tool, to trace and single step through the execution of PostScript instructions. It calls a trace function before each instruction, that you can redefine to trace the execution in any way. One useful trace function animates the graphical stack on the PSIBER Space Deck step by step.<p>&gt;The meta-execution stack is a PostScript array, into which the metacircular interpreter pushes continuations for control structures. (forall, loop, stopped, etc…) A continuation is represented as a dictionary in which the state needed by the control structure is stored (plus some other information to help with debugging).<p>&gt;It is written in such a way that it can interpret itself: It has its own meta-execution stack to store the program’s state, and it stashes its own state on the execution stack of the interpreter that’s interpreting it, so the meta-interpreter’s state does not get in the way of the program it’s interpreting.<p>&gt;It is possible to experiment with modifications and extensions to PostScript, by revectoring functions and operators, and modifying the metacircular interpreter.<p>&gt;The metacircular interpreter can serve as a basis for PostScript algorithm animation. One very simple animation is a two dimensional plot of the operand stack depth (x), against the execution stack depth (y), over time.