| SuperScript:A graphics language that compiles to 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.
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):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.
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.
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.