*                 SIGMA 5/7         BPM:EVEXSQZ
***********************************************************************
*M*      SQZ      EVALUATE EXPRESSIONS AND SQUEEZE ROOT'S EXPR. STACK
***********************************************************************
*P*      NAME:    SQZ
*P*      PURPOSE: ENTRY/EXIT FROM PS2.
*P*               EVALUATES EXPRESSIONS AND SQUEEZES ROOT'S EXPRESSION
*P*                    STACK.
*P*      DESCRIPTION: WHEN THE SQUEEZ ROUTINE IS ENTERED,EXTENDED
*P*               MEMORY MODE IS IN EFFECT AND EVEXSQZ HAS JUST BEEN
*P*               CALLED BY PS2 TO EVALUATE ALL EXPRESSIONS FOR THE
*P*               ROOT THAT WERE FORMED DURING THE FIRST PASS. SQUEEZ
*P*               REMOVES FROM THE ROOT'S EXPRESSION STACK THOSE
*P*               EXPRESSIONS WHICH ARE NOT CORE EXPRESSIONS AND HAVE
*P*               BEEN EVALUATED,AND WHOSE VALUES HAVE BEEN STORED AWAY
*P*               FOR THE TARGET DEFS AND FORWARD REFERENCES. FINALLY,
*P*               SQUEEZ ADJUSTS THE EXPRESSION STACK POINTER
*P*               DOUBLEWORD AND,IN THE TREE,ADJUSTS THE SIZE OF THE
*P*               ROOT'S EXPRESSION STACK AND THE STARTING ADDRESS OF
*P*               EACH OVERLAY SEGMENT'S EXPRESSION STACK TO REFLECT
*P*               THE DECREASE IN STACK SIZE.
*P*      REFERENCE: THE OVERLAY LOADER TECHNICAL MANUAL.
***********************************************************************
         SYSTEM   SIG7FDP
MODE     EQU      1
         DO       MODE=1
SD       EQU      1
         ELSE
SD       EQU      0
         FIN
         CSECT    1
         DEF      MCSQ
MCSQ     EQU      %
         REF      M2
         REF      M6
         REF      M15
         REF      M16
         REF      MN2
         REF      MN16
         REF      Y001
         REF      Y008
         REF      Y00C
         REF      RFDFBAS
         REF      EXPRBAS
         REF      EXPRSTK
         REF      EXPRSTK1
         REF      BSEG2
         REF      LOCCT
         REF      RFDFDIS
         REF      EXPRDIS
         REF      Y018
         REF      CSEG1
         DEF      EVEXSQZ
         DEF      SQUEEZ
         REF      KICKOUT
         REF      CODE
         DO       SD=1
         REF      SYMBOLTB,SYMTOP,M30
         FIN
         PAGE
BGEZ     EQU      X'681'
BE       EQU      X'683'
BNEZ     EQU      X'693'
BGE      EQU      X'681'
BL       EQU      X'691'
BAZ      EQU      X'684'
BCR8     EQU      X'688'
BCR10    EQU      X'68A'
BLE      EQU      X'682'
BEZ      EQU      X'683'
BNE      EQU      X'693'
         REF      MESSAGE
*        QUIT     ERROR,CONDITION
QUIT     CNAME
         PROC
LF       EQU      %
         DO       NUM(AF)=3
         DO       AF(2)~=0
         GEN,12,20  AF(2),%+4+MODE
         FIN
         STW,AF(3) CODE
         ELSE
         DO       AF(2)~=0
         GEN,12,20  AF(2),%+3+MODE
         FIN
         FIN
         LI,R3    AF(1)
         DO       MODE=1
         LI,R4    AF(3)=SR3
         FIN
         B        MESSAGE
         PEND
*        SNAP     FROM,TO,TEXT1,TEXT2
SNAP     CNAME
         PROC
LF       CAL1,3   %+1
         DATA     0,AF(1),AF(2),AF(3),AF(4),X'02000000'
         PEND
         PAGE
*                 SYMBOLIC REGISTER DEFINITIONS.
R0       EQU      0
R1       EQU      1
R2       EQU      2
R3       EQU      3
R4       EQU      4
R5       EQU      5
R6       EQU      6
R7       EQU      7
SR1      EQU      8
SR2      EQU      9
SR3      EQU      10
SR4      EQU      11
D1       EQU      12
D2       EQU      13
D3       EQU      14
D4       EQU      15
         PAGE
*                 IMMEDIATE CONSTANTS FOR LOADER.
K0       EQU      0
K1       EQU      1
K2       EQU      2
K3       EQU      3
K4       EQU      4
K5       EQU      5
K6       EQU      6
K7       EQU      7
K8       EQU      8
K9       EQU      9
KA       EQU      X'A'
KB       EQU      X'B'
KC       EQU      X'C'
KD       EQU      X'D'
KE       EQU      X'E'
KF       EQU      X'F'
K10      EQU      X'10'
K11      EQU      X'11'
K12      EQU      X'12'
K13      EQU      X'13'
K16      EQU      X'16'
K17      EQU      X'17'
K19      EQU      X'19'
K1C      EQU      X'1C'
K1E      EQU      X'1E'
K1F      EQU      X'1F'
K20      EQU      X'20'
K22      EQU         X'22'
K24      EQU      X'24'
K26      EQU      X'26'
K39      EQU      X'39'
K3C      EQU      X'3C'
K3F      EQU      X'3F'
K40      EQU      X'40'
K43      EQU      X'43'
K6C      EQU      X'6C'
K78      EQU      X'78'
K80      EQU      X'80'
KF0      EQU      X'F0'
KF1      EQU      X'F1'
KF2      EQU      X'F2'
KFF      EQU      X'FF'
K100     EQU      X'100'
K120     EQU      X'120'
K1FF     EQU      X'1FF'
K200     EQU      X'200'
K202     EQU      X'202'
K256     EQU      X'256'
K800     EQU      X'800'
KC00     EQU      X'C00'
K2000    EQU      X'2000'
K3FFF    EQU      X'3FFF'
K4000    EQU      X'4000'
K7FFF    EQU      X'7FFF'
KFF00   EQU      X'FF00'
K8000    EQU      X'8000'
K1FE00   EQU      X'1FE00'
K1FFFF   EQU      X'1FFFF'
K20000   EQU      X'20000'
KN1      EQU      -1
KN2      EQU      -2
KN3      EQU      -3
KN4      EQU      -4
KN8      EQU      -8
KN16     EQU      -16
KN100    EQU      -100
KN200    EQU      -X'200'
KN3FE    EQU      -X'3FE'
KN400    EQU      -X'400'
KTE      EQU      'E'
KTR      EQU      'R'
         PAGE
*                                   THIS ROUTINE DECODES AND EVALUATES
*                                   AN EXPRESSION IF IT IS NOT ALREADY
*                                   MARKED AS EVALUATED. R6 POINTS TO
*                                   THE EXPRESSION. SR2 IS SET TO Y008
*                                   IF THE EXPRESSION IS SUCCESSFULLY
*                                   EVALUATED.
EVEXP    LW,R7    *R6
         CW,R7    Y00C                                                  730
         BANZ     *SR4
EVEXP1   PSW,SR4  *R0                                                   730
         LI,SR1   K0
         LH,D1    *R6
         AND,D1   M6
         LW,R7    D1
         AW,R7    R6
         AI,R7    KN1
         LI,D2    K0
         STW,D2   *R7
         LI,R7    K1
*                                   THIS IS THE GENERAL EXPRESSION
*                                   CONTROL BYTE DECODER.
EVWHATEC AI,R7    K1
         LB,D2    *R6,R7
         CI,D2    K0
         BE       EVWHATEC
         CI,D2    K1
         BE       EVADCON
         CI,D2    K2
         BE       EVEXPEND
         LW,R4    D2
         SLS,R4   -2
         CI,R4    KC
         BE       EVCHGRES
         BG       AABS
         B        EVGETVAL
*                                   ADD CONSTANT.
EVADCON  AW,SR1   *D1,R6
EVINCWD  AI,D1    K1
         B        EVWHATEC
*                                   CHANGE RESOLUTION.
EVCHGRES LW,R5    R6
         AI,R5    KN3
         AW,R5    D1
         LCI      2                                                     4730
         PSM,R1   *R0                                                   4730
         BAL,SR4  WHATRES
         B        EVCHGRS2
NEXTEC   LCI      2                                                     4730
         PLM,R1   *R0                                                   4730
         B        EVWHATEC
EVCHGRS2 AND,D2   MN2
         SW,R5    D2
         SLS,SR1  0,R2
         B        NEXTEC                                                4730
AABS     LI,D3    1
         CI,D2    8
         BAZ      %+2
         LI,D3    -1
         LI,4     3
         AND,D2   M2
         SW,4     D2
         SLS,4    3
         SLS,D3   0,4
         LH,R5    *R6
         AND,R5   M6
         AI,R5    -1                                                 B01
         AWM,D3   *R5,R6                                             B01
         B        EVWHATEC
EVEXPEND LW,SR2   Y008
*                                   EXPRESSION END. THE EXPRESSION
*                                   IS MARKED EVALUATED.
         STS,SR2  *R6
         LH,R4    *R6
         CI,R4    X'40'                                                 730
         BANZ     EVEXPUN1                                              730
*                                   THE VALUE OF THE EXPRESSION AND
*                                   THE RESOLUTION ARE INSERTED INTO
*                                   THE ENTRY IN THE REF/DEF STACK
*                                   IF IT IS NOT A CORE EXPRESSION AND
*                                   THE REF/DEF ENTRY IS MARKED DEFINED.
         AND,R4   M6
         STW,R4   R7
         AI,R4    KN2
         INT,R4   *R6,R4
         AI,R4    RFDFDIS
         LW,R4    *R4,R1
         AND,R4   M16
         SLS,R4   1
         AW,R4    R5
         LW,R5    *R4
         CW,R5    Y001
         BANZ     EVEXPUN1
         LW,R5    Y001
         STS,R5   *R4
         AI,R4    K1
         STW,SR1  *R4
         AW,R6    R7
         AI,R6    KN1
         AI,R4    K1
         LW,R5    *R6
         SW,R6    R7
         AI,R6    K1
         STW,R5   *R4
         B        EVEXPUN1
EVEXPUND LCI      K2
         PLM,R1   *R0
*                                   EXIT.
EVEXPUN1 PLW,SR4  *R0
         B        *SR4
*                                   THIS ROUTINE PICKS UP THE VALUE OF
*                                   A REF/DEF ENTRY POINTED TO BY AN
*                                   EXPRESSION. IF THE DEF DOES NOT
*                                   HAVE A VALUE THE EXPRESSION IS STILL
*                                   UNDEFINED. THE VALUE IS SHIFTED
*                                   TO THE APPROPRIATE RESOLUTION
*                                   ACCORDING TO THE RESOLUTION OF
*                                   THE DEF. THE RESOLUTION OF THE
*                                   EXPRESSION IS ADJUSTED APPROPRIATELY
EVGETVAL INT,R4   *D1,R6
         AI,R4    RFDFDIS
         LW,R4    *R4,R1
         AND,R4   M16
         SLS,R4   1
         AW,R5    R4
         LCI      K2
         PSM,R1   *R0
         LW,R2    *R5
         CW,R2    Y001
         BAZ      EVEXPUND
         STW,D2   SR2
         STW,D2   D3
         LW,D2    R5
         AI,D2    K1
         BAL,SR4  WHATRES
         LI,R2    K5                                                    730
         AND,SR2  M2
         LW,R4    D2
         LW,R5    *D2
         XW,R5    SR1
         CI,R2    5                                                     730
         BE       %+3                                                   730
         SW,R2    SR2                                                   730
         SLS,SR1  0,R2
         XW,R5    SR1
         CI,D3    8
         BAZ      %+2
         LCW,R5   R5
         AW,SR1   R5
         LH,R5    *R6
         AND,R5   M6
         AW,R5    R6
         STW,R6   R1
         AI,R4    K1
         LW,R6    *R4
         CI,R2    5                                                     730
         BE       %+2                                                   730
         SLS,R2   3
         SLS,R6   0,R2
         STW,R6   R4
         LW,R6    R1
         LI,R2    KN4
EVFIXRES LB,R1    R5,R2
         LB,D2    *R5,R2
         CI,D3    8
         BAZ      %+2
         LCW,R1   R1
         AW,D2    R1
         STB,D2   *R5,R2
         BIR,R2   EVFIXRES
         LCI      K2
         PLM,R1   *R0
         B        EVINCWD
*                                   THIS ROUTINE GOES THRU THE EXPRESSIO
*                                   STACK ATTEMPTING TO EVALUATE EACH
*                                   EXPRESSION IN ORDER. THE PROCESS
*                                   IS REPEATED UNTIL A PASS THRU THE
*                                   STACK HAS BEEN MADE WITH NO
*                                   EXPRESSIONS EVALUATED.
EVEXSQZ  PSW,SR4  *R0
         PSW,R4   *R0
EVEXPRS1 LI,SR2   K0
         LW,R5    CSEG1
         AW,R5    R1                POINT TO TREE ENTRY
         LW,SR3   EXPRDIS,R5        EXPRSTK CNTRL
         LH,R6    SR3               FIND END OF ALL STAKS
         AND,SR3  M16
         SLS,SR3  1
         AW,SR3   R6
         LW,R6    EXPRBAS
         BAL,SR4  %+3               SET RETURN FROM EVEXP
         LB,R7    *R6
         AW,R6    R7
         CW,R6    SR3
         BL       EVEXP
         CW,SR2   Y008
         BANZ     EVEXPRS1
EVEXEN   PLW,R4   *R0
         PLW,SR4  *R0
         B        *SR4
         SPACE    10
         PAGE
WHATRES  AI,R5    K3
*                                   THIS ROUTINE DETERMINES THE
*                                   RESOLUTION OF A REF/DEF. RETURN
*                                   IS +1 IF NONE OR MIXED,+2 WITH
*                                   0,1,2 OR 3 IF IT HAS RESOLUTION.
         LI,R1    KN4
WHATRES1 LB,R4    *R5,R1
         BNEZ     WHATRES4
         BIR,R1   WHATRES1
         B        WHATRES5
WHATRES2 LB,R4    *R5,R1
         BNEZ     WHATRES5
WHATRES3 BIR,R1   WHATRES2
         AI,SR4   K1
         B        *SR4
WHATRES4 STW,R1   R2
         AI,R2    K4
         CI,R4    K1
         BE       WHATRES3
         CI,R4    KFF
         BE       WHATRES3
WHATRES5 B        *SR4
         PAGE
*                                   SQUEEZ EXAMINES THE ROOT'S EXPR
*                                   STACK REMOVING THOSE DEFINING
*                                   EXPRESSIONS FOR DEFS AND FWD REFS
*                                   (HAVING CORRES. ENTRIES IN THE R/D
*                                   STACK) WHICH HAVE BEEN EVALUATED BY
*                                   EVEXPRS. NOTE THAT CORE EXPRS ARE
*                                   RETAINED AS WELL AS ALL UNEVALUATED
*                                   EXPR ENTRIES.
SQUEEZ   EQU      %
         PSW,SR4  *R0
         PSW,R4   *R0
         LW,R6    EXPRBAS           BASE OF ORIGINAL EXPR STACK
         LW,R5    R6                BASE OF SQUEEZED EXPR STACK
         LW,R7    EXPRDIS,R1        SIZE OF ROOT'S EXPR STACK
         SLS,R7   -16
         CI,R7    K0
         BNEZ     %+3
         STW,R1   KICKOUT
         B        SQZEXIT
         LW,SR2   EXPRSTK
         AW,R7    R6                R7 POINTS TO END OF ROOT'S EXPR STK
         LH,R4    *R6               CHECK FOR SPECIAL EXPR ENTRY
         CI,R4    K384                (N=3, E=1, DISP=4)
         BE       SQZLIB
         CI,R4    K80               HAS EXPR BEEN EVALUATED?
         BANZ     SQZADV            YES.
*                                   RETAIN THIS (1ST) ENTRY
         SLS,R4   -8                  BY SIMPLY MOVING POINTERS TO
         AW,R6    R4                  ORIGINAL AND
         AW,R5    R4                  SQUEEZED STACKS.
         B        SQZADV1
*                                   SQUEEZE OUT THIS ENTRY.
SQZADV   SLS,R4   -8
         AWM,R4   KICKOUT           NO. OF WORDS REGAINED
         AW,R6    R4                ADVANCE TO NEXT ENTRY
SQZADV1  CW,R6    R7
         BGE      SQZEND            END OF ROOT'S STACK
         LH,R4    *R6
         CI,R4    K384
         BE       SQZLIB
         CI,R4    K80
         BANZ     SQZADV            CHECK NEXT ENTRY
*                                   UNEVALUATED ENTRIES MUST BE MOVED
*                                     INTO SQUEEZED STACK
SQZMOVE  SLS,R4   -8
SQZMOVE1 AW,R6    R4
         AW,R5    R4
         LCW,R4   R4
         LW,SR1   *R6,R4
         STW,SR1  *R5,R4
         BIR,R4   %-2
         B        SQZADV1           R5 & R6 ALREADY POINT TO NXT ENTRIES
*                                   THE SPECIAL EXPR ENTRY SAYS A LIB
*                                   LMN'S STACK HAS BEEN FOUND.
SQZLIB   EQU      %
         LW,R3    1,R6              DISP OF SPECIAL REF/DEF ENTRY
         AW,R3    RFDFBAS
         AI,R6    K3                REMOVE SPECIAL EXPR STACK ENTRY
         MTW,3    KICKOUT
         LW,D2    2,R3              EXPR DISP FIELD OF SPECIAL R/D ENTRY
         SW,D2    KICKOUT             FOR LIB LMN MUST BE DECREMENTED BY
         STW,D2   2,R3                VALUE IN KICKOUT
         SLS,D2   -16               SIZE OF LIB LMN'S EXPR STACK
         AW,D2    R6                D2 POINTS TO END OF LIB LMN'S STACK
         LI,D3    K0                INITIALIZE CNT OF ENTRIES SQUEEZED
*                                     FROM LIB LMN'S EXPR STACK
*                                     LMN'S STACK
SQZLIB2  EQU      %
         LH,R4    *R6
         CI,R4    K80
         BANZ     SQZLIB6
         SLS,R4   -8                CURRENT ENTRY HAS NOT BEEN EVALUATED
         AW,R6    R4                  AND MUST BE RETAINED AS PART OF
         AW,R5    R4                  SQUEEZED EXPR STACK
         LCW,R4   R4
         LW,SR1   *R6,R4
         STW,SR1  *R5,R4
         BIR,R4   %-2
SQZLIB4  EQU      %
         CW,R6    D2                HAS END OF LIB LMN'S STACK BEEN HIT
         BNE      SQZLIB2             NO
         AWM,D3   KICKOUT           ADD NO. OF ENTRIES SQUEEZED FROM LIB
         SLS,D3   16
         LW,D2    2,R3              EXPR SIZE FIELD OF SPECIAL R/D ENTRY
         SW,D2    D3                  FOR LIB LMN MUST BE DECREMENTED BY
*                                     VALUE IN D3
         BNEZ     %+2               TO AVOID PROBLEMS IN MAPER, MUST NOT
         LI,D2    K384                ALLOW RES WD TO BECOME ZERO
         STW,D2   2,R3
         B        SQZADV1           END OF THIS LIB LMN'S STACK SQUEEZE
SQZLIB6  EQU      %
         SLS,R4   -8                CURRENT ENTRY HAS BEEN EVALUATED.
         AW,D3    R4
         AW,R6    R4
         B        SQZLIB4
*                                   BEFORE EXITING, VARIOUS TREE TABLE
*                                   POINTERS MUST BE ADJUSTED.
SQZEND   EQU      %
         LW,R3    SR2
         CW,R6    R3                HAVE WE REACHED END OF PATH'S STK
         BGE      SQZEND0
         SW,R3    R6
         LI,R4    0
         AI,R3    K1
         LW,SR1   *R6,R4            NO.  MOVE REST OF STACK.
         STW,SR1  *R5,R4
         AI,R4    1
         BDR,R3   %-3
SQZEND0  EQU      %
         LW,R3    R1                TREE POINTER
         LW,D2    LOCCT
         AI,D2    3                 POINT TO ROMT POINTER IN LOCCT
         LW,D2    *D2               D2 POINTS TO 1ST WORD BEYOND TREE
         LW,R6    EXPRDIS,R3
         SLD,R6   -16
         LW,R4    R6                ORIGINAL SIZE OF ROOT'S EXPR STK
         SW,R6    KICKOUT
         CI,R6    1                 IF REMAINING EXPR. STACK HAS EVEN
         BAZ      SQZEND01          NUMBER OF WORDS,EVERYTHING IS O.K.
         MTW,-1   KICKOUT           IF ODD, ADJUST TO BECOME EVEN.
         AI,R6    K1
         SLS,R7   -15
         AW,R7    R6
         LW,D1    Y018
         STW,D1   -1,R7
         SW,R7    R6
         SLS,R7   15
SQZEND01 EQU      %
         SLD,R6   16
         STW,R6   EXPRDIS,R3        ADJUST SIZE OF ROOT'S EXPR STACK
         LCW,D1   KICKOUT           ADJUST STACK POINTER DW TO REFLECT
         DO       MODE=1
         AWM,D1   BSEG2             FOR CP-V MUST ALSO MOVE
         AWM,D1   SYMBOLTB            THE INTERNAL SYMBOL TABLE
         AWM,D1   SYMTOP              POINTERS
         FIN
         AND,D1   M16                 EXPR SIZE REDUCTION
         LW,SR1   EXPRSTK1
         AND,SR1  M15
         SW,SR1   R4                EXPR STK SIZE FOR REMAINDER OF PATH
         MSP,D1   EXPRSTK
SQZEND1  EQU      %
         AI,R3    KB                TREE SIZE
         CW,R3    D2
         BGE      SQZEXIT
         LW,R6    EXPRDIS,R3        ADJUST STARTING ADDR OF EACH
*                                     OVERLAY SEG'S EXPR STACK.
         LW,R7    R6
         SLS,R6   1
         AND,R7   MN16
         SLS,R7   -16               SIZE OF THIS SEG'S EXPR STK
         SW,SR1   R7
         BLZ      SQZEXIT
         SW,R6    KICKOUT
         SLS,R6   -1
         STW,R6   EXPRDIS,R3
         MTW,0    SR1
         BEZ      SQZEXIT
         B        SQZEND1
SQZEXIT  EQU      %
         PLW,R4   *R0
         PLW,SR4  *R0
         B        *SR4
K384     EQU      X'0384'
         END

