	.TITLE	ARITHMETIC STATEMENT COMPILER
/
/  20 FEB 74 (JAF,JAS) FIX UP 'RETURN' FROM ASF
/   7 FEB 74 (JAF) ADD CODE FOR ARITHMETIC STATEMENT FUNCTIONS
/   5 SEP 72
/
	.GLOBL	ASCOM,ERRORS,WARN
	.GLOBL	EXPRES,AD2,CLEW2
	.GLOBL	PUNCH,OPCODE,CLUES,DRESS
	.GLOBL	VARAA,VARAC
	.GLOBL	LOCCNT,START,CLRACC
/
ASCOM	XX
/ COMPILE LHS; RESULT IS "A"
/
	LAW	LHSSW!CONILL!EXPILL!DFNSW
	JMS*	EXPRES	/ EXPRESSIONS,CONSTANTS ILLEGAL
	.DSA	ERRAS0
	.DSA	.+3
	.DSA	ERRAS2
	.DSA	ERRAS3
	LAC*	AD2
	DAC	VARAA	/ ADDRESS OF "A"
	LAC*	CLEW2
	DAC	VARAC	/ CLUES ABOUT "A"
/
/ COMPILE RHS;  RESULT IS "B"
/
	LAW	ASFBIT
	JMS*	EXPRES
	.DSA	ERRAS0
	.DSA	ERRAS1
	.DSA	.+2
	.DSA	ERRAS3
	LAC*	AD2
	DAC*	DRESS	/ ADDRESS OF "B"
	LAC*	CLEW2
	DAC*	CLUES	/ CLUES ABOUT "B"
/
/ CHECK IF THE MODES OF THE RHS AND LHS ARE COMPATIBLE
	AND	(17
	TAD	(TABLE-1
	DAC	POINT	/ ADDRESS OF REQUIRED WORD BASED ON "B"
	LAC	VARAC
	AND	(17
	TAD	(LRS   -1
	DAC	.+2
	LAC	(400040
	XX		/ SET UP TO TEST THE BIT ACCORDING TO "A"
	AND*	POINT
	SNA
	JMP	MODEOK	/ MODE IS OKAY
	AND	(77
	SNA
	JMP	ERRAS4	/ ILLEGAL MIXED MODES
WRNAS5	JMS*	WARN	/ COMPLEX INTO INTEGER OR REAL
	.SIXBT	'AS5'	/ ISSUE WARNING & CONTINUE
/
/ NOW SORT OUT WHICH OPCODES TO COMPILE. IF IT IS A SIMPLE
/ EXPRESSION A=B WHERE THE MODES ARE THE SAME THEN SET LINK 
/ TO COMPILE MOVE OPCODE, (CHARACTERS ARE ALWAYS LOAD & STORE).
/ IF RHS WAS AN EXPRESSION COMPILE THE STORE OPCODE.
/
MODEOK	LAC*	CLUES
	XOR	VARAC
	AND	(17
	SNA!CLL		/ CHECK MODES; SET L=1 IF
	CML		/ MODES ARE THE SAME.
	LAC*	CLUES	/ RELOAD ALL CLUE BITS ABOUT "B"
	AND	(INACC	/ INACC=1 => RHS IS AN EXPRESSION
	SZA!CLL		/ AC=0 IF NOT AN EXPRESSION
	JMP	OK	/ RHS IS EXPRESSION. COMPILE 'STORE'
/
/ THE RHS IS NOT EXPRESSION. FORM A=B. IF CHARACTER COMPILE
/ 'LOAD & STORE'. IF MODES SAME, COMPILE 'MOVE'.
	LAC*	CLUES
	AND	(17
	SAD	(CHARM
	CLL		/ FOR CHARACTERS, COMPILE LOAD AND STORE
	LAC	VARAC	/ CLUE BITS FOR RHS
	LMQ
	LAC*	CLUES	/ CLUE BITS FOR RHS
	OMQ
	AND	(FORMAL	/ COMPILE LOAD - STORE IF EITHER VARIABLE
	SZA		/ WAS A FORMAL PARAMETER
	CLL
/
/ PUNCH OUT LOAD OR MOVE1 OPCODE
	LAC	(MOVE1*M	/ CHECK THE MODES
	SNL		/ ARE THEY THE SAME?
	LAC	(LOAD*M	/ NO
	DAC*	OPCODE
	JMS*	PUNCH	/ COMPILE "B"
/
/ PUNCH OUT 'STORE' OR 'MOVE CODES.
	LAC*	PUNCH
	RAL		/ PUT THE LINK BACK IN
OK	LAC	(INVERT
	AND*	CLUES
	SZA		/ DO WE COMPLEMENT?
	JMP	NEGIT	/ YES
	LAC	(MOVE*M
	SNL
	LAC	(STORE*M	/ NO
OK2	DAC*	OPCODE
	LAC	VARAA
	DAC*	DRESS	/ ADDRESS OF "A"
	LAC	VARAC
	DAC*	CLUES	/ CLUES ABOUT "A"
	AND	(FUNCAL		/CHECK IF THIS WAS AN ASF
	SZA
	JMP	WASASF		/IT WAS
	JMS*	PUNCH	/ COMPILE "A"
	JMP*	ASCOM	/ FINI
/
/ COMPILE COMPLEMENT
/
NEGIT	LAC	(MOVEN*M
	SNL
	LAC	(STOREN*M
	JMP	OK2
/
/  JUST COMPILED STATEMENT FUNCTION.	FINISH IT OFF!
/  TO ENSURE THAT ANY OUTSTANDING NEGATION AND MODE CONVERSION
/  IS DONE, PERFORM A STORE FOLLOWED BY A LOAD.
/
WASASF	LAC	(CHARM!FUNCAL	/NO NEED TO CONVERT IF CHARACTER
	SAD*	CLUES		/IS STORE-LOAD NEEDED?
	JMP	NONOT		/NO
	JMS*	PUNCH		/COMPILE STORE
	LAC	(LOAD*M
	DAC*	OPCODE
	JMS*	PUNCH		/COMPILE LOAD
NONOT	LAC	(1
	DAC*	DRESS		/ RETURN 1
	LAC	(RTRN*M
	DAC*	OPCODE
	JMS*	PUNCH		/GENERATE 'RETURN'
/
/  RESET START ADDRESS OF MAINLINE TO ALLOW FOR
/  SPACE USED BY STATEMENT FUNCTION.
/
	LAW	-1
	TAD*	LOCCNT
	DAC*	START
	JMS*	CLRACC		/DROP ALL TEMPORARY ACCUMULATORS USED
	JMP*	ASCOM
/
/
/ TABLE OF LEGAL MIXED MODES WHERE THE MODE OF:
/         "B" (RHS) IS THE WORD INDEX
/         "A" (LHS) IS THE BIT INDEX OF THE SELECTED WORD
/  THAT BIT BEING A 1 => ILLEGAL MIXED MODE OR WARNING
/                   0 => ALL IS O.K.
/
TABLE	.DSA	377700	/ L
	.DSA	406500	/ I*2
	.DSA	406500	/ I*4
	.DSA	406500
	.DSA	406500	/ R*4
	.DSA	406500	/ R*8
	.DSA	406530
	.DSA	406530
	.DSA	406533	/ C*8
	.DSA	406533
	.DSA	406533	/ C*16
	.DSA	006400	/ CHAR
/
/ ERRORS FROM ASCOM
/
ERRAS0  JMS*    ERRORS  / ILLEGAL TERMINATING COMMA
        .SIXBT  'AS0'
/
ERRAS1  JMS*    ERRORS  / ILLEGAL TERMINATING EQUALS SIGN
        .SIXBT  'AS1'
/
ERRAS2  JMS*    ERRORS  / ILLEGAL END OF STATEMENT
        .SIXBT  'AS2'
/
ERRAS3  JMS*    ERRORS  / ILLEGAL TERMINATING  BRACKET
        .SIXBT  'AS3'
/
ERRAS4  JMS*    ERRORS  / ILLEGAL MIXED MODES
        .SIXBT  'AS4'
/
/ POINTER STORAGE LOCATIONS
/
VARAA	0	/ POINTS TO ADDRESS OF "A"
VARAC	0	/   "    "   CLUES ABOUT "A"
POINT	0	/ A DUMMY
	.END
