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 before the `*' are summarized by one entry. Table 2.2 gives the codes used to describe the type inline data expected by each instruction. .so table2.1.n .so table2.2.n .bp .so table2.3.n .bp Basic control operations
HALT Corresponds to the Pascal procedure halt ; causes execution to end with a post-mortem backtrace as if a run-time error had occurred. BEG s,W,w," Causes the second part of the block mark to be created, and W bytes of local variable space to be allocated and cleared to zero. Stack overflow is detected here. w 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. NODUMP s,W,w," Equivalent to BEG , and used to begin the main program when the ``p'' option is disabled so that the post-mortem backtrace will be inhibited. END Complementary to the operators CALL and BEG , exits the current block, calling the procedure pclose 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 flushed, and the interpreter is exited. CALL l,A Saves the current line number, return address, and active display entry pointer dp in the first part of the block mark, then transfers to the entry point given by the relative address A , that is the beginning of a procedure or function at level l. PUSH s Clears s bytes on the stack. Used to make space for the return value of a function just before calling it. POP s Pop s bytes off the stack. Used after a function or procedure returns to remove the arguments from the stack. TRA a Transfer control to relative address a as a local goto or part of a structured statement. TRA4 A Transfer control to an absolute address as part of a non-local goto or to branch over procedure bodies. LINO s Set current line number to s. 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, generate a fault. GOTO l,A Transfer control to address A that is in the block at level l of the display. This is a non-local goto. Causes each block to be exited as if with END , flushing and freeing files with pclose, until the current display entry is at level l. SDUP* Duplicate the word or long on the top of the stack. This is used mostly for constructing sets. See section 2.11. If and relational operators IF a The interpreter conditional transfers all take place using this operator that examines the Boolean value on the top of the stack. If the value is true , the next code is executed, otherwise control transfers to the specified address. REL* r 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: .mD
Code Operation |
0 a = b |
2 a <> b |
4 a < b |
6 a > b |
8 a <= b |
10 a >= b |
RV4:l a |
RV4:l b |
REL4 = |
IF Else part offset |
.T& |
c s. |
... Then part code ... |
The Boolean operators AND , OR , and NOT 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 false, and one a Boolean true. Right value, constant, and assignment operators
LRV* l,ARV* l,a
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 LRV4 : .mD _LRV4: cvtbl (lc)+,r0 #r0 has display index addl3 _display(r0),(lc)+,r1 #r1 has variable address pushl (r1) #put value on the stack jmp (loop) 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 interpreter loop. The RV* operators have short inline data that reduces the space required to address the first 32K of stack space in each stack frame. The operators RV14 and RV24 provide explicit conversion to long as the data is pushed. This saves the generation of STOI to align arguments to C subroutines. CON* r The constant operators load a value onto the stack from inline code. Small integer values are condensed and loaded by the CON1 operator, that is given by .mD _CON1: cvtbw (lc)+,-(sp) jmp (loop) Here note that little work was required as the required constant was available at (lc)+. For longer constants, lc must be incremented before moving the constant. The operator CON takes a length specification in the sub-opcode and can be used to load strings and other variable length data onto the stack. The operators CON14 and CON24 provide explicit conversion to long as the constant is pushed. AS* 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 of the target in memory. The target address in memory is under the value to be stored. Thus the statement i := 1 where i is a full-length, 4 byte, integer, will generate the code sequenceLV:l i |
CON1:1 |
AS24 |
LV l,w
The most common operation done by the interpreter is the ``left value'' or ``address of'' operation. It is given by: .mD _LLV: cvtbl (lc)+,r0 #r0 has display index addl3 _display(r0),(lc)+,-(sp) #push address onto the stack jmp (loop) 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. The LV operator has a short inline data that reduces the space required to address the first 32K of stack space in each call frame. OFF s The offset operator is used in field names. Thus to get the address of .LS p^.f1 .LE pi would generate the sequence .mDRV:l p |
OFF f1 |
RV:l p |
NIL |
OFF f1 |
LV:l a |
RV4:l i |
INX4:8 1,999 |
CON8 2.0 |
AS8 |
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 Addition: ADD*, SUCC* Subtraction: SUB*, PRED* Multiplication: MUL*, SQR* Division: DIV*, DVD*, MOD* Unary: NEG*, ABS* Range checking
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, for example 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. On the "VAX 11/780" both checks are done using a single index instruction so the only gain is in reducing the inline data. Case operators
The interpreter includes three operators for case statements that are used depending on the width of the case label type. For each width, the structure of the case data is the same, and is represented in figure 2.4. .so fig2.4.n
The CASEOP case statement operators do a sequential search through the case label values. If they find the label value, they take the corresponding entry from the transfer table and cause the interpreter to branch to the specified statement. If the specified label is not found, an error results.
The CASE operators take the number of cases as a sub-opcode if possible. Three different operators are needed to handle single byte, word, and long case transfer table values. For example, the CASEOP1 operator has the following code sequence: .mD _CASEOP1: cvtbl (lc)+,r0 bneq L1 cvtwl (lc)+,r0 #r0 has length of case table L1: movaw (lc)[r0],r2 #r2 has pointer to case labels movzwl (sp)+,r3 #r3 has the element to find locc r3,r0,(r2) #r0 has index of located element beql caserr #element not found mnegl r0,r0 #calculate new lc cvtwl (r2)[r0],r1 #r1 has lc offset addl2 r1,lc jmp (loop) caserr: movw $ECASE,_perrno jbr error
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.
PXPBUF w Causes the interpreter to allocate a count buffer with w four byte counters and to clear them to zero. The count buffer is placed within an image of the pmon.out file as described in the "PXP Implementation Notes." The contents of this buffer are written to the file pmon.out when the program ends. COUNT w Increments the counter specified by w . TRACNT w,A 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. Set operationsThe set operations: union ADDT, intersection MULT, element removal SUBT, and the set relationals RELT are straightforward. The following operations are more interesting.
CARD s Takes the cardinality of a set of size s bytes on top of the stack, leaving a 2 byte integer count. CARD uses the ffs opcode to successively count the number of set bits in the set. CTTOT s,w,w Constructs a 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 INCT below. The arguments to CTTOT include the number of elements s in the constructed set, the lower and upper bounds of the set, the two w values, and a pair of values on the stack for each range in the set, single elements in constructed sets being duplicated with SDUP to form degenerate ranges. IN s,w,w The operator in for sets. The value s specifies the size of the set, the two w values the lower and upper bounds of the set. The value on the stack is checked to be in the set on the stack, and a Boolean value of true or false replaces the operands. INCT The operator in on a constructed set without constructing it. The left operand of in is on top of the stack followed by the number of pairs in the constructed set, 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 .LS if character in [`+', '-', `*', `/'] .LE or .LS if character in [`a'..`z', `$', `_'] .LE These constructs are common in Pascal, and INCT makes them run much faster in the interpreter, as if they were written as an efficient series of if statements. MiscellaneousOther miscellaneous operators that are present in the interpreter are ASRT that causes the program to end if the Boolean value on the stack is not true, and STOI , STOD , ITOD , and ITOS that convert between different length arithmetic operands for use in aligning the arguments in procedure and function calls, and with some untyped built-ins, such as SIN and COS .
Finally, if the program is run with the run-time testing disabled, there are special operators for for statements 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. Mathematical Functions
The transcendental functions SIN , COS , ATAN , EXP , LN , SQRT , SEED , and RANDOM are taken from the standard UNIX mathematical package. These functions take double precision floating point values and return the same.
The functions EXPO , TRUNC , and ROUND take a double precision floating point number. EXPO returns an integer representing the machine representation of its argument's exponent, TRUNC returns the integer part of its argument, and ROUND returns the rounded integer part of its argument. System functions and procedures
LLIMIT 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. STLIM A statement limit is passed on the stack. The statement limit is set as specified. The default is 500,000. No limit is enforced when the ``p'' option is disabled. CLCKSCLCK
CLCK returns the number of milliseconds of user time used by the program; SCLCK returns the number of milliseconds of system time used by the program. WCLCK 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 DATE and TIME that copy an appropriate text string into a pascal string array. The function ARGC returns the number of command line arguments passed to the program. The procedure ARGV takes an index on the stack and copies the specified command line argument into a pascal string array. Pascal procedures and functions
PACK s,w,w,wUNPACK s,w,w,w
They function as a memory to memory move with several semantic checks. They do no ``unpacking'' or ``packing'' in the true sense as the interpreter supports no packed data types. NEW sDISPOSE s
An LV of a pointer is passed. NEW allocates a record of a specified size and puts a pointer to it into the pointer variable. DISPOSE deallocates the record pointed to by the pointer and sets the pointer to NIL .The function CHR* converts a suitably small integer into an ascii character. Its primary purpose is to do a range check. The function ODD* returns true if its argument is odd and returns false if its argument is even. The function UNDEF always returns the value false .