SuperScript:

A graphics language that compiles to PostScript

SuperScript is an imperative language, with variables, procedures and conventional control-flow constructs, that compiles to Adobe PostScript.

Its principal benefit is to make hacking PostScript much easier: PostScript is very powerful, but it requires the programmer to do a lot of book-keeping to maintain the stack invariants. SuperScript is a simple imperative language that manages this complexity, by ensuring that the programmer can manipulate the stack only in well-defined ways; also, it performs static type checking on the operands to operators. In other words, it's just like a regular C-to-ASM compiler.

PostScript is so clean that implementing the compiler was extremely straightforward: the basics were all working in less than 8 hours. Of course, the code is not very efficient.

Those who recall Logo (a.k.a. Turtle Graphics) from the early 80s will find this style of programming familiar.

Status:

  • [7 May 2003] Currently, the implementation of procedure calls is inefficient, as it always uses a dictionary for arguments. Ideally, the compiler will not store formal-parameters in a dict where possible, so, the function:
        function f(x, y, z)
        { 
            return x * y + z;
        }
    
    would compile to just /f { roll 3 mul add } def instead of:
    /f {
        3 dict begin
        /z exch def
        /y exch def
        /x exch def
        x y mul z add
        end
    } def
    

    (Thanks to Mitch Stary (starman at frontiernet dot net) for the use of local dictionaries in v1.03; prior to this, procedure calling was broken.)

    The compiler also has a number of problems (it's very new): And I have a wishlist of basic features:

    I would also like to implement a Scheme version using some kind of explicit staged-computation, allowing some computation to be performed during "compile" time, perhaps using macros. This would allow more useful applications, taking command arguments from the host platform and referring to files, etc.

    Download

    The compiler has been developed in C++ on Linux, though the source should port easily to other platforms (you will need Flex + Bison).

    The sources and binaries are here: ss-1.03.tar.gz (~400KB). Simply type 'make' to build it. Let me know if you have any problems. This software is released under the GNU General Public License.

    Language spec

    I will add this soon. Learn by example -- see below.

    The primary novelty of this language over say, C, which it otherwise resembles, is that it supports tuples as values. A PostScript operator that requires 3 operands may thus be invoked with three scalars, a pair and a scalar, or a triple, so long as the types match. (This is not unlike Perl.) See the example in args.ss below.

    Examples:

    Links


    adonovan@csail.mit.edu
    Last updated: 15 November 2004