	.TITLE	CALCP
/ THE FOLLOWING ARE THE GLOBL VARIABLES:
/
/
/ IN WATRAN
/   ADDRESSES:
	.GLOBL	ERRORS,CHI,CHIEND
/
/ IN IDENT
/   ADDRESSES:
	.GLOBL	SAVCMN,STSIZE,MODPTR,TBPOSN,BITPTR,CPOINT
/   SUBROUTINES:
	.GLOBL	WDSIZE
/   SWITCHES:
	.GLOBL	COMSW,TYPESW
/
/ IN SEARCH -
/   ADDRESSES:
	.GLOBL	FLTFLG,VANTED,VANT1
/
/ IN CALCP -
/   ADDRESSES:
	.GLOBL DTABLE,OTABLE,PTABLE,PTEND,PSIZE
	.GLOBL DTNEXT,OTNEXT,TBADDR,INTAB,OPLACE,NAMPNT
/
/   SUBROUTINES:
	.GLOBL	CALCP,GETOTB,GETADR,DLOTAB
/
DTNEXT			/ INITIALLY POINTS TO 1ST WORD OF DTABLE
OTNEXT			/ INITIALLY POINTS TO OTABLE-1
/
TYPE
INTAB
ADDRS;TBPOSN;TEMP;NAMPNT;OPLACE;TBADDR
PBOX
VNTD
COUNTR
/
/ THE SYMBOL TABLES FLOAT ACCORDING TO THE CORE SIZE AND
/  THE AMOUNT AVAILABLE. THUS THE FOLLOWING ADDRESSES ARE USED TO
/   KEEP TABS ON THEIR LOCATIONS, FOR THE PTABLE MUST BE INITIALIZED
/   AT START OF NEW JOB.
DTABLE
OTABLE
PTABLE
PTEND
/
/ THIS TABLE IS ALTERED ACCORDING TO THE TYPE OF WORD WE WISH
/  TO STORE IN THE SYMBOL TABLE. THE APPROPIATE ONE IS CHANGED
/  TO 'JMP FOUND ' SUCH THAT ALL VARIABLES OF THAT TYPE MAY BE
/  CHECKED TO SEE IF THE WORD IS ALREADY IN THE TABLES.
/
TABLE	JMP	AGAIN	/VARIABLES
	JMP	AGAIN	/STATEMENTS
	JMP	AGAIN	/CONSTANTS
	JMP	AGAIN	/ HIDDEN
	JMP	AGAIN	/COMMON
TEMPTY	JMP	EMPTY	/EMPTY
TPEMPT	JMP	PEMPTY	/PSEUDO-EMPTY
TEND	JMP	END	/END	
/
LTYPE	TABLE
/
/
/RESET TABLE, AND SET UP EXIT FOR CHECKING
/
CALCP	XX
	DAC	TYPE
	DZM	INTAB		/INITIALIZE 'INTAB'
	LAC	(JMP	AGAIN
	DAC*	LTYPE		/WIPE OUT HISTORY
	LAC	TYPE		/PICK UP CLUE DIGITS
	TAD	(TABLE
	DAC	LTYPE		/SET LTYPE POINTER
	LAC	(JMP	FOUND	/SET UP ENTRY TO,
	DAC*	LTYPE		/FOUND SUBSECTION.
	LAC	(JMP	EMPTY
	DAC	TEMPTY		/RESET
	LAC	(JMP	PEMPTY
	DAC	TPEMPT		/RESET
	LAC	(JMP	END
	DAC	TEND		/RESET
/
/SET UP RANDOM ENTRY TO PTABLE
	LAC*	VANTED		/TO GENERATE RANDOM ENTRY...
	TAD*	VANT1		/ADD SYMBOL WORDS,
	CLL
	IDIV			/DIVIDE BY SIZE OF PTABLE
PSIZE	XX			/PTABLE SIZE INSERTED FROM MAIN
	TAD	PTABLE		/LOWEST LOCATION IN TABLE
AGA2	DAC	ADDRS		/STORE RESULT
AGAIN	ISZ	ADDRS
BEGIN	LAC*	ADDRS		/GET TABLE ENTRY
	AND	(7		/SAVE TYPE DIGITS
	TAD	(XCT	TABLE
	DAC	.+1
	XX
/
END	LAC	(JMP	ERRCP1
	DAC	TEND		/SECOND TIME AROUND TABLE TRAP
	LAC	PTABLE
	TAD	(-1
	JMP	AGA2
/
ERRCP1	JMS*	ERRORS
	.SIXBT	'CP1'
/
PEMPTY	LAC	(JMP	PTWO
	DAC	TEMPTY		/SPECIAL EXIT IF BLANKS FOUND
	LAC	(JMP	PTHREE
	DAC	TPEMPT		/SPECIAL EXIT IF P-BLANKS FOUND
	LAC	ADDRS
	DAC	PBOX		/SAVE ADDRESS
	JMP	AGAIN
PTHREE	LAC	ADDRS		/WATCH FOR FIRST P-BLANK
	SAD	PBOX
	JMP	PTWO+1		/NO BLANKS, JUST P-BLANKS
	JMP	AGAIN		/TRY AGAIN
PTWO	LAC	PBOX		/HAVE HIT A BLANK
	DAC	ADDRS		/ RESET TO FIRST P-BLANK
/
/
/EMPTY SUBSECTION TO FILL DTABLE
/
EMPTY	LAC	DTNEXT		/FILL PTABLE WORD WITH,
	CLQ!LLS+3 		/DTABLE POINTER AND THE,
	TAD	TYPE		/CLUE BITS FROM 'TYPE'
	DAC*	ADDRS
	LAC	TYPE
	SAD	(VARIAB		/IS ITEM A VARIABLE?
	JMP	VNAME		/YES
	SAD	(CONST		/NO,THEN IS IT A CONSTANT?
	JMP	CONSTT		/YES
	SAD	(COMNAM		/NO,THEN IS IT A COMMON NAME
	JMP	COMON		/YES
/
/ NOT ANY OF THE ABOVE ,THUS IT IS A STATEMENT NUMBER
/
	CLA
	LMQ
	LAC	(STOTB*100000	/ 2ND WORD THE INDICATOR
	TAD	DTNEXT	/ AND DTABLE POINTER
	JMS	GETOTB	/ FILL OTABLE
	CLQ!LLS+6
	DAC*	DTNEXT
	LAW	-1
	DAC	COUNTR		/SET COUNTER FOR # OF WORDS=1
	LAC	DTNEXT
	DAC	TBPOSN		/SET POINTER TO CONTROL BITS
	DAC*	BITPTR
	ISZ	DTNEXT
	LAC	VANTED
	JMS	FILL
	DZM*	DTNEXT	/ ZERO NEXT ENTRY IN CASE OF DO.S ENTRY.
			/ 'DTNEXT' IS INCREMENTED IN 'IDENT' SUBPROGRAM
	JMP*	CALCP
/
FILL	XX
	TAD	(-1
	DAC*	(AUTO10
	LAC*	AUTO10
	DAC*	DTNEXT		/FILL IN WORD
	ISZ	DTNEXT		/ INCREMENT:DTABLE POINTER
	ISZ	COUNTR		/	 COUNTER FOR # OF WORDS
	JMP	FILL+3		/RETURN UNTIL FINISHED
	JMP*	FILL
/
/
/IT IS A COMMON NAME
/
COMON	LAC	DTNEXT
	DAC	TBPOSN		/SET DTABLE POINTER
	DZM*	DTNEXT
	ISZ	DTNEXT
	LAW	-2
	DAC	COUNTR		/SET COUNTER FOR # OF WORDS
	LAC	VANTED
	JMS	FILL
	JMP*	CALCP
/
/
/IT IS A VARIABLE NAME
/
VNAME	LAC	DTNEXT
	DAC	TEMP
	JMS	TESTCM	/ GO TEST IF IN COMMON AND MAKE OTABLE ENTRY
	DAC*	DTNEXT		/DEPOSIT IN DTABLE
	LAC	DTNEXT	/ POINTS TO OTABLE ADDRESS+6 BIT MODE
	DAC*	MODPTR	/ SET POINTER IN IDENT TO THEM
	TAD	(3
	DAC	TBPOSN	/ POINTS AT CONTROL BITS
	DAC*	BITPTR	/ ALSO POINTS AT CONTROL BITS
	TAD	(1
	DAC*	CPOINT	/ POINTS TO CHARACTER SIZE IF CHARACTER VARIABLE
	ISZ	DTNEXT	/ NOW POINTS AT NAME
	LAW	-2
	DAC	COUNTR		/SET COUNTER FOR # NO. OF WORDS
	LAC	VANTED
	JMS	FILL	/ INSERT NAME IN DTABLE
	DZM*	DTNEXT	/ ZERO OUT CONTROL BITS WORD
	ISZ	DTNEXT	/ STEP FOR NEXT ENTRY
	LAC*	FLTFLG	/ CHECK IF VARIABLE IS CHARACTER
	SAD	(CHARM
	SKP
	JMP*	CALCP
	LAC*	STSIZE	/ AND EXTEND DTABLE ENTRY BY ONE WORD
	DAC*	DTNEXT	/ FOR THE CHARACTER SIZE
	ISZ	DTNEXT	/ ADVANCE DTNEXT
	JMP*	CALCP
/
/
TESTCM	XX
	CLQ
	LAC*	COMSW
	SNA		/ ARE WE IN COMMON
	JMP	OENTER	/ NO
	LAC	(200000	/ YES. MAKE COMMON ENTRY
	LMQ
	LAC*	SAVCMN	/ GET POINTER BACK TO COMMON NAME
	SKP
OENTER	LAC	TEMP	/ INSERT DTABLE POINTER FOR NON-COMMON ENTRIES
	JMS	GETOTB
	CLQ!LLS	6
	TAD*	FLTFLG	/ ADD IN MODE
	JMP*	TESTCM
/
/ IT IS A CONSTANT
/
CONSTT	LAC*	FLTFLG	/ GET MODE
	LMQ		/ PREPARE MQ IN ADVANCE
	LAC	DTNEXT
	DAC	TBPOSN	/ SET POINTER TO CONTROL BITS
	TAD	(CNOTB*100000+1	/ SET UP OTABLE ENTRY BITS
	JMS	GETOTB	/ CONSTANT IN DTABLE.!!! MAKE OTABLE ENTRIES
	CLQ!LLS+6
	TAD*	FLTFLG
	DAC*	DTNEXT		/DEPOSIT IN DTABLE
	ISZ	DTNEXT		/INCREMENT DTNEXT TO NAME
	LAC*	FLTFLG
	SAD	(CHARM!CONBIT	/ IS IT HOLLERITH?
	JMP	HOLRTH
	JMS*	WDSIZE	/ GET WORD SIZE
	CMA
	TAD	(1
	SKP
HOLRTH	LAC*	VANTED		/GET # OF WORDS FROM VANTED
	DAC	COUNTR
	LAC	VANTED
	JMS	FILL
	JMP*	CALCP
/
/
/TABLE OF SUBSECTION ADDRESSES FOR FOUND SUBSECTION .
/
TABLE2	VARBLE			/VARIABLES
	STATMT			/STATEMENT NUMBERS
	CONSTS			/CONSTANTS
	CONSTS			/BLANK
	COMMON			/COMMON
/
/
/FOUND SUBSECTION
/
FOUND	LAC	TYPE
	TAD	(JMP*	TABLE2	/SET UP BRANCHING TO,
	DAC	VARBLE-1		/SUBSECTION BASED ON 'TYPE'.
	LAC	VANTED
	DAC	VNTD		/SET VNTD TO START OF FILE
	LAC*	ADDRS
	CLL
	LRS+3			/GET DTABLE CONTROL BITS POINTER
	DAC	TBPOSN
	DAC	TEMP
	DAC*	MODPTR		/ LOAD POINTER IN IDENT ALSO
	DAC*	BITPTR
	TAD	(1
	DAC	NAMPNT
	XX
VARBLE	TAD	(2
	DAC	TBPOSN		/SET A POINTER TO THE RELATIVE
	DAC*	BITPTR		/ LOAD POINTER IN 'IDENT' ALSO
	TAD	(1
	DAC*	CPOINT	/ POINTS TO CHARACTER SIZE FOR CHARACTER VARIABLE
	LAW	-2
	JMS	CHECK
	LAC*	TEMP		/SET FLTFLG TO TRUE MODE
	AND	(37
	DAC*	FLTFLG
	LAC*	TBPOSN		/ TEST 'NOHERE'
	AND	(NOHERE
	SNA			/IS NOHERE BIT ON
	JMP	NOTNHR		/NO
	XOR*	TBPOSN		/ YES. REMOVE 'NOHERE'
	DAC*	TBPOSN		/ RETURN BITS
	JMS	TESTCM	/ TEST IF IN COMMON AND MAKE OTABLE ENTRY
	DAC*	TEMP
	JMP*	CALCP
/
NOTNHR	LAC*	COMSW
	SNA		/ ARE WE IN A COMMON STATEMENT
	JMP	INTABS	/ NO.
	LAC*	TEMP
	JMS	GETADR	/ GET OTABLE ADDRESSES TO CHANGE THE ENTRY
	DAC	ADDRS
	TAD	(-1
	DAC	PBOX
	LAC	(200000
	DAC*	ADDRS
	LAC*	SAVCMN
	DAC*	PBOX
	JMP	INTABS
/
STATMT	LAW	-1		/SET NUMBER OF WORDS FOR COUNTER
	JMS	CHECK
	JMP	INTABS
/
COMMON	LAW	-2		/SET NUMBER OF WORDS FOR COUNTER
	JMS	CHECK
	JMP	INTABS
/
CONSTS	LAC*	TEMP
	AND	(37		/GET MODE
	SAD*	FLTFLG		/ARE MODES THE SAME
	SKP
	JMP	AGAIN		/NO,TRY AGAIN
	SAD	(CHARM!CONBIT	/ IS IT A HOLLERITH
	JMP	HOLLRH	/ YES.
	JMS*	WDSIZE	/ GET WORD SIZE
	CMA
	TAD	(1
	SKP
HOLLRH	LAC*	VANTED		/GET # OF WORDS IN HOLLERITH
	JMS	CHECK
/
INTABS	ISZ	INTAB	/ MARK AS BEING IN TABLE ALREADY
/
POINTR	LAC*	TEMP		/SET UP ABSOLUTE POINTER
	CLL			/POINTER FOR OPLACE.
	LRS	6
	DAC	TBADDR
	RAL
	CMA
	TAD	(1
	TAD	OTABLE
	DAC	OPLACE
	JMP*	CALCP		/RETURN TO MAINLINE
/
/
/ CHECK SUBROUTINE
CHECK	XX
	DAC	COUNTR
LOOP2	LAC*	NAMPNT
	XOR*	VNTD
	SZA			/IS NAMPNT WORD SAME AS VNTD WORD?
	JMP	AGAIN		/NO,TRY AGAIN
	ISZ	NAMPNT		/GET NEXT WORD OF DTABLE
	ISZ	VNTD		/GET NEXT WORD OF VANTED
	ISZ	COUNTR		/INCREMENT COUNTER,IS IT ZERO?
	JMP	LOOP2		/NO,CONTINUE.
	JMP*	CHECK		/YES,RETURN.
/
/ THIS SUBROUTINE MAKES THE OTABLE ENTRIES PUTTING THE CONTENTS
/  OF THE AC IN THE SECOND WORD & THE CONTENTS OF MQ IN THE FIRST
/  WORD. IT RETURNS WITH THE RELATIVE OTABLE POINTER IN THE AC.
GETOTB	XX
	DAC*	OTNEXT	/ DEPOSIT AC IN 2ND WORD
	ISZ	OTNEXT
	LACQ
	DAC*	OTNEXT	/ DEPOSIT OMQ IN 1ST WORD
	LAC	OTNEXT
	DAC	OPLACE
	TAD	(-3
	DAC	OTNEXT	/ RESET OTNEXT TO 2ND WORD OF NEXT ENTRY
	TAD	(2
	CMA
	TAD	OTABLE	/ GET RELATIVE OTABLE POINTER
	RCR		/ DIVIDE BY TWO FOR OBJECT TIME ADDRESS
	DAC	TBADDR
	JMP*	GETOTB	/ POINTS TO 1ST WORD
/
/
/ THIS SUBROUTINE IS ENTERED WITH THE DTABLE ENTRY
/  CONTAINING THE RELATIVE OTABLE POINTER, IN THE AC. IT EXITS
/  LEAVING AN ABSOLUTE POINTER TO THE FIRST WORD OF OTABLE ENTRY
GETADR	XX
	CLL
	LRS	5	/ GET ADDRESS & MULTIPLY BY TWO
	CMA
	TAD	(1	/ 2'S COMP,+ACCOUNT FOR 1ST TWO FREE ENTRIES
	TAD	OTABLE	/ POINTS TO FIRST WORD OF ENTRY
	JMP*	GETADR
/
/
/ THIS SUBROUTINE RESCINDS THE OTABLE ENTRY WHICH HAS JUST BEEN
/ ASSIGNED. 'IT WAS CHOSEN TO 1ST ASSIGN THE OTABLE ENTRY AND
/ THEN DELETE IT TO AVOID TESTS ON EACH ENTRY. WE THUS  SAVE
/ AN OVERHEAD WHICH AMOUNTED TO 5 USEC PER ENTRY.'
/ THE OTABLE ENTRIES ARE DELETED FOR VARIABLE WHICH DO NOT
/ HAVE ENOUGH INFORMATION TO TELL IF THEY ARE FUNCTIONS OR NOT.
/
DLOTAB	XX
	LAC*	MODPTR	/ GET POINTER TO 1ST WORD IN DTABLE
	DAC	TEMP
	LAC*	TEMP
	AND	(000017	/ REMOVE ADDRESS (QUESTIONABLE IF THIS NECESSARY)
	DAC*	TEMP
	ISZ	OTNEXT	/ RESET OTABLE POINTERS
	ISZ	OTNEXT
	JMP*	DLOTAB
/
	.END
