POLGEN is a procedure for generation of a polish string from an arithmetic expression consisting of the operators given in the string PRI and operands which are single letters. It is written in the PLASYD of the second version of PLN 2.
As stated in the first paragraph of PLN 1 more effort is made to simplify flow of control than data manipulation in PLASYD. There will probably, therefore, be a tendency among PLASYD progranmers to use all control facilities equally although some will produce much more efficient object code than others. In general this should not cause too much inefficiency since the extra code generated (to restore the contents of accumulators after a test for example) would be required anyway. Where the number of instructions generated is of great importance the programmer can however restrict himself to facilities which have direct machine code equivalents. To help this an extra facility is being introduced and the table below shows the size of the code produced for various types of relations in IF statements. Note that WHILE statements also contain conditions which are dealt with in a similar way and that FOR statements have an implied NOT = condition.
The new facility is to allow the operator CH to appear before the right hand side of a condition involving <, <=, >, or >= and integer operands. This implies that a TXL can be used i.e. the comparison is between character sequences or both the items being tested are of the same sign (e.g. addresses). CH is implied if the RHS is a character sequence. Thus
X1 < CH '%' and X1 < '%'
are equivalent.
The table of code production below gives the conditions in an approximate order of efficiency. Conditions such as OVERFLOW and all those above the double line do not corrupt accumulators and therefore do not generate restore operations which may be unneccessary in some cases. Thus if the accumulator contents do not need to be preserved in the cases below the double line and efficiency is paramount the programmer should do his own subtractions and compare with zero. Only integer and real are considered in the table. Long integer is a fairly obvious extension of integer (one extra TXV or TXL or a separate comparison of the second word). Long real has not been even remotely considered. As a general point note that < and ≥ are always the least efficient relations.
| Relation | RHS of Condition | Type | Generated Code |
|---|---|---|---|
| = NOT = < ≥ | 0 or 0.0 | Integer or Real if 076 is available | One instruction (05 group or 076). |
| ≤ > | 0 or 0.0 | Integer or Real if 076 is available | Two instructions (05 group or 076). |
| = NOT = ≥ CH > | Non zero | Integer | Two instructions (026 or 027 and 074) plus one lower location if RHS is a value. |
| ≤ CH > CH | Non zero | Integer | Four instructions (026, 027 and two 074) plus lower location as above. |
| < ≥ | Non zero | Integer | 4 instructions (003 or 103, 05 group, 001 or 101, 001 or 101) plus a lower location if RHS is a value of more than 12 bits. |
| = NOT = < ≥ | Non zero | Real with 076 available | 4 instructions (133, 076, 132, 132) plus two lower locations if RHS is a value. |
| > ≤ | Non zero | Real with 076 available or Integer | As above plus one extra 076 or 05 group instruction. |
If 076 is not available real conditions are carried out by generating the following instructions:-
FSB (absent if test is with zero)
Dump X1 in a common area
SFP in a common area, say WS
LDX 1 WS
FAD to restore A1 (absent if test with zero)
The test is then carried out as an integer test involving X1 only, since the FP operations are normalized. In this case considerable savings can be made if the programmer knows of fixed point accumulators with unwanted contents or if A1 need not be restored. In the first case however the code produced may not be the fastest if the 076 is available.
Alternatively, does anyone know what the effect of SFP 7 is?
GENERAL LISTING (XRLP) 22/08/62
1 PROCEDURE POLGEN (X0);
2 BEGIN LOWER INTEGER OP(10)=(0),PR(10)=(0),PRI(4)=("00)=+-/*010 ");
3 [PRIORITY VECTOR] LOWEND;
4 GLOBAL BUFF :INTEGER IN(19) , OUT(18) GLOBEND;
5 ACC MODI SYN X1, MOD0 SYN X2 ,MODP0 SYN X3 , [POINTERS FOR ARRAYS]
6 ALPHS SYN X6 ;
7 MODI←£IN ; MOD0←£OUT ; MODP0←0 ;ALPHA ←0;[ASSIGN BASE ADDRESS
8 TO MODIFIERs AND CLEAR SWITCH]
9 IN(MODI+18) ←0 ; [SET TO ZERO TO TERMINATE INPUT STRING]
10 XCHAR :X4 ←CH IN(MODI) ; MODI ←MODI +MODI +CHAR ;[PICK UP NEXT CHARACTER]
11 IF X4 <='Z' AND X4 >='A' THEN [IS IT AN OPERAND?]
12 BEGIN OUT(MOD0) ←X4 ; [PLACE IN OUT STACK]
13 MOD0 ←MOD0 +CHAR ; ALPHA ←1 END ;
14 X5 ←MODI ; MODI ←0 ; [STORE POINTER]
15 WHILE X4 NOT= PRI(MODI) DO MODI ←MODI +CHAR ;[SEARCH FOR OPERATOR
16 IN PRIORITY VECTOR]
17 MODI ← MODI SLC 1; X7 ←MODI AND #77 + 1; [OBTAIN PRIORITY FROM
18 MODIFIER]
19 MODI ← X5 ; [RESTORE POINTER]
20 FIN : X5←OP(MODP0); [PICKUP LAST OPERATOR]
21 IF X5 ='(' THEN IF X4 =')' THEN [IF BRACKETS THEN SET POINTER
22 IGNORE BRACKET IN STACK] BEGIN MODP0 ← MODP0 SLC 2 -1 SRC 2;
23 GO TO XCHAR END
24 ELSE GO TO ALPH ;
25 IF X7 <= PR(MODP0) THEN [IF PRIORITY IN STACK LESS MOVE THE
26 OPERATOR TO OUT STACK]
27 BEGIN OUT(MOD0) ←X5 ; MOD0 ← MOD0 +CHAR ;
28 MODP0 ← MODP0 SLC 2 -1 SRC 2;
29 GO TO FIN END;
30 IF X4 = 0 THEN GO TO EXT ;
31 ALPH :IF ALPHA =0 THEN IF X4 ='+' THEN GO TO XCHAR [SEARCH FOR A
32 PLUS OR MINUS] ELSE IF X4 ='-' THEN
33 BEGIN X4 ←'+' ;
34 X7 ← 6 END;
35 MODP0 ←MODP0 +CHAR ; [PLACE OPERATOR & PRIORITY IN STACK]
36 OP(MODP0) ←X4 ;PR(MODP0) ←X7;
37 ALPHA ←0;
38 GO TO XHAR ;
39 EXT: END