Naming conventions and operation summary
Table 2.1 outlines the opcode typing convention.
The expression ``a above b'' means that `a' is on top
of the stack with `b' below it.
Table 2.3 describes each of the opcodes.
The character `*' at the end of a name specifies that
all operations with the root prefix
are summarized by one entry.
Table 2.2 gives the codes used
to describe the type inline data expected by each instruction.
Corresponds to the Pascal procedure
causes execution to end with a post-mortem backtrace as if a run-time
Causes the second part of the block mark to be created, and
bytes of local variable space to be allocated and cleared to zero.
Stack overflow is detected here.
is the first line of the body of this section for error traceback,
and the inline string (length s) the character representation of its name.
and used to begin the main program when the ``p''
option is disabled so that the post-mortem backtrace will be inhibited.
Complementary to the operators
exits the current block, calling the procedure
to flush buffers for and release any local files.
Restores the environment of the caller from the block mark.
If this is the end for the main program, all files are
and the interpreter is exited.
Saves the current line number, return address, and active display entry pointer
in the first part of the block mark, then transfers to the entry point
given by the relative address
that is the beginning of a
Used to make space for the return value of a
returns to remove the arguments from the stack.
Transfer control to relative address
or part of a structured statement.
Transfer control to an absolute address as part of a non-local
or to branch over procedure bodies.
Set current line number to
For consistency, check that the expression stack is empty
as it should be (as this is the start of a statement.)
This consistency check will fail only if there is a bug in the
interpreter or the interpreter code has somehow been damaged.
Increment the statement count and if it exceeds the statement limit,
Transfer control to address
that is in the block at level
Causes each block to be exited as if with
flushing and freeing files with
until the current display entry is at level
Duplicate the word or long on the top of
This is used mostly for constructing sets.
If and relational operators
The interpreter conditional transfers all take place using this operator
that examines the Boolean value on the top of the stack.
the next code is executed,
otherwise control transfers to the specified address.
These take two arguments on the stack,
and the sub-operation code specifies the relational operation to
be done, coded as follows with `a' above `b' on the stack:
Each operation does a test to set the condition code
appropriately and then does an indexed branch based on the
sub-operation code to a test of the condition here specified,
pushing a Boolean value on the stack.
Consider the statement fragment:
\*bif\fR a = b \*bthen\fR
are integers this generates the following code:
IF \fIElse part offset\fR
\fI\&... Then part code ...\fR
manipulate values on the top of the stack.
All Boolean values are kept in single bytes in memory,
or in single words on the stack.
Zero represents a Boolean \fIfalse\fP, and one a Boolean \fItrue\fP.
Right value, constant, and assignment operators
The right value operators load values on the stack.
They take a block number as a sub-opcode and load the appropriate
number of bytes from that block at the offset specified
in the following word onto the stack. As an example, consider
\fBcvtbl\fR (lc)+,r0 #r0 has display index
\fBaddl3\fR _display(r0),(lc)+,r1 #r1 has variable address
\fBpushl\fR (r1) #put value on the stack
Here the interpreter places the display level in r0.
It then adds the appropriate display value to the inline offset and
pushes the value at this location onto the stack.
Control then returns to the main
operators have short inline data that
reduces the space required to address the first 32K of
stack space in each stack frame.
provide explicit conversion to long as the data
This saves the generation of
The constant operators load a value onto the stack from inline code.
Small integer values are condensed and loaded by the
operator, that is given by
Here note that little work was required as the required constant
must be incremented before moving the constant.
takes a length specification in the sub-opcode and can be used to load
strings and other variable length data onto the stack.
provide explicit conversion to long as the constant is pushed.
The assignment operators are similar to arithmetic and relational operators
in that they take two operands, both in the stack,
but the lengths given for them specify
first the length of the value on the stack and then the length
The target address in memory is under the value to be stored.
is a full-length, 4 byte, integer,
will generate the code sequence
that is really given as a block number in the sub-opcode and an
offset in the following word,
onto the stack, occupying a single word.
that is a single word instruction,
then loads the constant 1,
that is in its sub-opcode,
Since there are not one byte constants on the stack,
this becomes a 2 byte, single word integer.
The interpreter then assigns a length 2 integer to a length 4 integer using
Thus the interpreter gets the single word off the stack,
extends it to be a 4 byte integer
gets the target address off the stack,
and finally stores the value in the target.
This is a typical use of the constant and assignment operators.
The most common operation done by the interpreter
is the ``left value'' or ``address of'' operation.
\fBcvtbl\fR (lc)+,r0 #r0 has display index
\fBaddl3\fR _display(r0),(lc)+,\-(sp) #push address onto the stack
It calculates an address in the block specified in the sub-opcode
by adding the associated display entry to the
offset that appears in the following word.
operator has a short inline data that reduces the space
required to address the first 32K of stack space in each call frame.
The offset operator is used in field names.
Thus to get the address of
would generate the sequence
given its block in the sub-opcode and offset in the following word,
and the interpreter then adds the offset of the field
in its record to get the correct address.
takes its argument in the sub-opcode if it is small enough.
The example above is incomplete, lacking a check for a
The code generated would be
pointer and generates the appropriate runtime error if it is.
A pointer to the specified length inline data is pushed
This is primarily used for
(see sections 3.6 and 3.8)
are used for subscripting.
For example, the statement
``array [1..1000] of real''
operation takes the address of
and places it on the stack.
is then placed on top of this on the stack.
The array address is indexed by the
length 4 index (a length 2 index would use
where the individual elements have a size of 8 bytes.
\fBcvtwl\fR (lc)+,r0 #r0 has size of records
\fBcvtwl\fR (lc)+,r1 #r1 has lower bound
\fBmovzwl\fR (lc)+,r2 #r2 has upper-lower bound
\fBsubl3\fR r1,(sp)+,r3 #r3 has base subscript
\fBcmpl\fR r3,r2 #check for out of bounds
\fBmull2\fR r0,r3 #calculate byte offset
\fBaddl2\fR r3,(sp) #calculate actual address
\fBmovw\fR $ESUBSCR,_perrno
Here the lower bound is subtracted, and range checked against the
The offset is then scaled to a byte offset into the array
and added to the base address on the stack.
Multi-dimension subscripts are translated as a sequence of single subscriptings.
For indirect references through
the interpreter has a set of indirection operators that convert a pointer
on the stack into a value on the stack from that address.
operators are necessary because of the possibility of different
operators do conversions to long
The interpreter has many arithmetic operators.
All operators produce results long enough to prevent overflow
unless the bounds of the base type are exceeded.
The basic operators available are
Multiplication: MUL*, SQR*
Division: DIV*, DVD*, MOD*
The interpreter has several range checking operators.
The important distinction among these operators is between values whose
legal range begins at zero and those that do not begin at zero,
a subrange variable whose values range from 45 to 70.
For those that begin at zero, a simpler ``logical'' comparison against
the upper bound suffices.
For others, both the low and upper bounds must be checked independently,
requiring two comparisons.
both checks are done using a single index instruction
so the only gain is in reducing the inline data.
The interpreter includes three operators for
statements that are used depending on the width of the
For each width, the structure of the case data is the same, and
is represented in figure 2.4.
case statement operators do a sequential search through the
If they find the label value, they take the corresponding entry
from the transfer table and cause the interpreter to branch to the
If the specified label is not found, an error results.
operators take the number of cases as a sub-opcode
Three different operators are needed to handle single byte,
word, and long case transfer table values.
operator has the following code sequence:
\fBcvtwl\fR (lc)+,r0 #r0 has length of case table
\fBmovaw\fR (lc)[r0],r2 #r2 has pointer to case labels
\fBmovzwl\fR (sp)+,r3 #r3 has the element to find
\fBlocc\fR r3,r0,(r2) #r0 has index of located element
\fBbeql\fR caserr #element not found
\fBmnegl\fR r0,r0 #calculate new lc
\fBcvtwl\fR (r2)[r0],r1 #r1 has lc offset
\fBmovw\fR $ECASE,_perrno
Here the interpreter first computes the address of the beginning
of the case label value area by adding twice the number of case label
values to the address of the transfer table, since the transfer
table entries are 2 byte address offsets.
It then searches through the label values, and generates an ECASE
error if the label is not found.
If the label is found, the index of the corresponding entry
in the transfer table is extracted and that offset is added
to the interpreter location counter.
Operations supporting pxp
The following operations are defined to do execution profiling.
Causes the interpreter to allocate a count buffer
and to clear them to zero.
The count buffer is placed within an image of the
.I "PXP Implementation Notes."
The contents of this buffer are written to the file
Increments the counter specified by
Used at the entry point to procedures and functions,
combining a transfer to the entry point of the block with
an incrementing of its entry count.
The following operations are more interesting.
Takes the cardinality of a set of size
bytes on top of the stack, leaving a 2 byte integer count.
opcode to successively count the number of set bits in the set.
This operation requires a non-trivial amount of work,
checking bounds and setting individual bits or ranges of bits.
This operation sequence is slow,
and motivates the presence of the operator
include the number of elements
the lower and upper bounds of the set,
and a pair of values on the stack for each range in the set, single
elements in constructed sets being duplicated with
to form degenerate ranges.
specifies the size of the set,
values the lower and upper bounds of the set.
The value on the stack is checked to be in the set on the stack,
on a constructed set without constructing it.
is on top of the stack followed by the number of pairs in the
and then the pairs themselves, all as single word integers.
Pairs designate runs of values and single values are represented by
a degenerate pair with both value equal.
This operator is generated in grammatical constructs such as
\fBif\fR character \fBin\fR [`+', '\-', `*', `/']
\fBif\fR character \fBin\fR [`a'..`z', `$', `_']
These constructs are common in Pascal, and
makes them run much faster in the interpreter,
as if they were written as an efficient series of
Other miscellaneous operators that are present in the interpreter
that causes the program to end if the Boolean value on the stack is not
that convert between different length arithmetic operands for
use in aligning the arguments in
calls, and with some untyped built-ins, such as
Finally, if the program is run with the run-time testing disabled, there
are special operators for
and special indexing operators for arrays
that have individual element size that is a power of 2.
The code can run significantly faster using these operators.
The transcendental functions
are taken from the standard UNIX
These functions take double precision floating point
values and return the same.
take a double precision floating point number.
returns an integer representing the machine
representation of its argument's exponent,
returns the integer part of its argument, and
returns the rounded integer part of its argument.
System functions and procedures
A line limit and a file pointer are passed on the stack.
If the limit is non-negative the line limit is set to the
specified value, otherwise it is set to unlimited.
The default is unlimited.
A statement limit is passed on the stack. The statement limit
No limit is enforced when the ``p'' option is disabled.
returns the number of milliseconds of user time used by the program;
returns the number of milliseconds of system time used by the program.
The number of seconds since some predefined time is
returned. Its primary usefulness is in determining
elapsed time and in providing a unique time stamp.
The other system time procedures are
that copy an appropriate text string into a pascal string array.
returns the number of command line arguments passed to the program.
takes an index on the stack and copies the specified
command line argument into a pascal string array.
Pascal procedures and functions
They function as a memory to memory move with several
They do no ``unpacking'' or ``packing'' in the true sense as the
interpreter supports no packed data types.
allocates a record of a specified size and puts a pointer
to it into the pointer variable.
deallocates the record pointed to by the pointer
converts a suitably small integer into an ascii character.
Its primary purpose is to do a range check.
if its argument is odd and returns