;
;
;COPYRIGHT (C) 1975,1981,1982 BY
;DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS.
;
;
;THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND COPIED
;ONLY IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE AND WITH THE
;INCLUSION OF THE ABOVE COPYRIGHT NOTICE. THIS SOFTWARE OR ANY OTHER
;COPIES THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
;OTHER PERSON. NO TITLE TO AND OWNERSHIP OF THE SOFTWARE IS HEREBY
;TRANSFERRED.
;
;THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE
;AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT
;CORPORATION.
;
;DIGITAL ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF ITS
;SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY DIGITAL.
;
;

SUBTTL CODE GENERATION ROUTINES * CHECKARITH *
PROCEDURE CHECKARITH;
;..FORCE BINARY OPERANDS TO HAVE MATCHING ARITHMETIC TYPES;
; ERROR FLAG (T) IS SET IF TYPES ARE NOT ARITHMETIC
; (INTEGER OR REAL OR LONG REAL);
; ON ENTRY, OPERAND LEXEMES ARE IN LOP AND SYM.
; IF TYPES OF OPERANDS ARE NOT ALIKE, CODE IS GENERATED TO
; CONVERT ONE OPERAND TO THE TYPE OF THE OTHER
; (IN THE ORDER INTEGER => REAL => LONG REAL).
; OPERAND PORTIONS ARE LEFT CLOSED WITH LEXEMES
; IN LOP AND SYM.
BEGIN
IF SYM<TYPE> IS INT OR REAL OR LONG REAL
; AND LOP<TYPE> IS INT OR REAL OR LONG REAL;
TLNE SYM,$IRLR
T.IRLR (LOP);
THEN;..OPERANDS HAVE TYPES WHICH CAN BE MATCHED;
BEGIN
IF SYM<TYPE> NEQ LOP<TYPE>
F.TYPE (T,SYM);
F.TYPE (T1,LOP);
CAMN T,T1
GOTO FALSE
THEN;..TYPES DO NOT MATCH -- GENERATE CODE TO MATCH THEM;
BEGIN
IF SYM<TYPE> LSS LOP<TYPE>
CAML T,T1
GOTO FALSE
THEN
;..CONVERT SYM TO THE TYPE OF LOP;
PUSHJ SP,TCHECK ; [E044]
ELSE
;..CONVERT LOP TO THE TYPE OF SYM;
;..MUST REVERSE LEXEMES AND LEXEXES BECAUSE CONVERT WORKS ON SYM;
EXCH LOP,SYM
MOVNI REV,SYM+LOP(REV)
PUSHJ SP,TCHECK ; [E044]
EXCH SYM,LOP
MOVNI REV,SYM+LOP(REV)
FI;
ENDD;
FI;

SUBTTL CODE GENERATION ROUTINES * MARRY *
PROCEDURE MARRY
;..MAKE A SINGLE OPEN PORTION FOR TWO BINARY OPERANDS,
; REVERSING THE ORDER IF POSSIBLE;
; ON ENTRY, LEXEMES FOR THE OPERANDS ARE IN LOP AND SYM;
; UNLESS THE OPERATION = "^", MARRY WILL MAKE SURE THAT
; THE RESULT PORTION INCLUDES CODE TO LOAD
; THE "LEFT" OPERAND INTO AN AC;
BEGIN
IF SYM = SINGLE
T.SINGLE(SYM);
THEN;..SYM IS NOT A PORTION;
BEGIN
IF LOP NEQ SINGLE
TN.SINGLE(LOP);
THEN;..LOP IS A PORTION AND SYM IS NOT;
REOPEN(LOP);
ELSE;..BOTH LOP AND SYM ARE SINGLE;
BEGIN
IF OP NEQ "^"
TN.OPER (ZPOW);

THEN;..MAKE A PORTION TO PUT A VALUE IN AN ACC;
BEGIN
IF LOP = ONE-WORD CONSTANT AND OP IS REVERSIBLE
TLNN LOP,$VAR1
T.CONST (LOP);
TRNN T,$ODROP
GOTO FALSE
THEN;..REVERSE THE ORDER SO VARIABLE IS LOADED FIRST;
BEGIN
;..EXCHANGE THE LEXEMES;
EXCH LOP,SYM
;..SET REV ON;
MOVNI REV,LOP
ENDD
FI
LOAD(LOP,ANYAC);
REOPEN(LOP);
ENDD
;..ELSE NO PORTIONS ARE NECESSARY FOR POWERS;
FI
ENDD
FI
ENDD
ELSE;..SYM IS A PORTION;
BEGIN
REVORDER;
IF LOP = SINGLE
T.SINGLE(LOP);
THEN;..AFTER REORDERING, LOP IS STILL NOT A PORTION.
;..MAKE IT ONE AND MERGE WITH SYM;
BEGIN
LOAD(LOP,ANYAC);
MERGEPORTIONS;
ENDD

ELSE;..LOP IS A PORTION AFTER REORDERING;
IF SYM = SINGLE
T.SINGLE(SYM);
THEN;..THERE IS ONLY ONE PORTION;
REOPEN(LOP);
ELSE;..TWO PORTIONS;
BEGIN
IF LOP IS A POINTER
T.PTR (LOP);
THEN;..WE MAY HAVE TO EVALUATE LOP BEFORE MERGING;
BEGIN
IF REVERSAL NOT ALLOWED OR LOP IS A ONE WORD OPERAND
JUMPN T3,TRUE
;..(T3 IS A SWITCH WHICH IS SET BY REVORDER);
T.ONE (LOP);
THEN;..EVALUATE LOP NOW;
;..LOAD VALUE OF LOP INTO SAME ACC USED BY POINTER;
F.LOCN (T2,LOP);
LOAD(LOP,@T2);
FI
ENDD
FI
MERGEPORTIONS;
ENDD
FI
FI
ENDD
FI
ENDD ; MARRY

SUBTTL CODE GENERATION ROUTINES * SETUP *
PROCEDURE SETUP
;..SET UP THE OPERANDS FOR A BINARY OPERATION BY
; MAKING A SINGLE OPEN PORTION, REORDERED IF POSSIBLE,
; WITH THE VALUE OF THE (REORDERED) LEFT OPD (LOP) IN AN AC;
; ON ENTRY, OPERAND LEXEMES ARE IN LOP AND SYM;
; SETUP MAY CHANGE THE OPERATOR IF THE OPERATION
; IS REVERSIBLE, (E.G., "<" => ">", LFDV => RLFDV).
BEGIN
;..FIRST MAKE A SINGLE OPEN PORTION FOR THE OPERANDS;
MARRY;
IF REV
T.REV;
THEN;..PORTIONS WERE REVERSED BY MARRY;
BEGIN
;..EXCHANGE THE LEXEMES AGAIN;
EXCH LOP,SYM
;..SET REV OFF;
MOVNI REV,SYM
ENDD
FI
IF LOP NOT AN EXPRESSION IN ACC
TN.ACC (LOP);
THEN;..VALUE OF LOP IS NOT NOW IN AN AC;
BEGIN
IF VALUE OF SYM IN AN ACC
TLNE SYM,$AM-$ACC
GOTO FALSE
THEN;..WE MAY BE ABLE TO DO AN OPERATOR REVERSAL;
BEGIN
IF OP IS NOT REVERSIBLE
MOVE T,OP
TRNE T,$ODROP
GOTO FALSE