POSTSCRIPT arrays, strings, and dictionaries are examples of composite objects. These objects have values that are separate from the object itself. That is, the character codes making up a string are stored in a different location in a POSTSCRIPT machine than the string object that POSTSCRIPT directly manipulates. Note that composite objects can share values. A dup operation on a string duplicates the object, but not its value. The duplicate object looks to the same place in the machine’s memory for its value.
When an array is created with a line such as
[1 2 3 (O’Leary)]
the square brackets play a more active role than is immediately evident. The left bracket is a POSTSCRIPT operator that leaves an object called a mark on the stack.
As the interpreter continues through the program line, it puts more objects on the stack until it encounters a right bracket, which is an operator that creates an array containing the stack contents back to the topmost mark. The mark is dropped from the stack and the array remains.
PostScript arrays are one-dimensional collections of objects. These objects are numbered from zero, so that a ten-item array is numbered from zero to nine. POSTSCRIPT arrays are different from those in other languages in that their elements need not all be of the same type. That is, a single array may contain, for example, strings, integers, dictionaries, and other arrays. An array in a program is denoted by any collection of PostScript objects surrounded by square brackets. Thus, the lines
[16 (twelve) 8]
[(sum) 6 14 add]
both set up arrays. The first has three members: two numbers and a string. The second array has two items in it: the string sum and the number 20. (Note that operators within an array definition are carried out as the array is being defined.) Arrays may also be defined by the array operator. This operator takes a number from the stack and constructs an array of that length. The line
10 array
would leave a ten-place array on the stack. The elements of this array are initially all POSTSCRIPT null objects.
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). 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.
Search for the name in user dictionary, if not found then
Search for the name in system dictionary, then
execute the procedure associated with the name in the dictionary.
As the interpreter continues through the program Line, it puts more objects on the stack Until it encounters a Right bracket, which is an operator that creates an array containing the stack contents back To the topmost mark. The mark is dropped from the stack, and the array remains.
When the Scanner encounters right bracet, then Allocates space for the array in virtual memory, Creates the array object and pushes it To the operand stack.
Recent Comments