;       ~c0/./&\l/
        .title stak
        .ident /30jn7a/
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;
; global symbol definitions
; these may be adjusted without much worry
;
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	small=0 ;1=yes, 0=no
        .if eq small-1
        prime==257.      ;size of hash table must be prime < 511.
        maxsym==30.      ;maximum number of symbols
        extmac==95.      ;maximum number of mac lib macros
        sz.mtext==7500.  ;size of the macro libr text area
        dm.mtext==450.   ;max number of lines in macro library
        stksiz==60.      ;number of entries allowed in string stack (even only)
        stkbyt=400.      ;size in bytes of string stack
        .iff
        maxsym==50.      ;maximum number of symbols
        prime==503.      ;size of hash table must be prime < 511.
        extmac==120.     ;maximum number of mac lib macros
        sz.mtext==10000.  ;size of the macro libr text area
        dm.mtext==575.   ;max number of lines in macro library
        stksiz==60.      ;number of entries allowed in string stack (even only)
        stkbyt=500.      ;size in bytes of string stack
        .endc
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        .enabl lc

inreg:: .asciz /(r5)/           ;string appended to var on #@{arg}
        				;if arg is in symbol table
        .even

        .list ttm

        .macro table a
        .pnt = .pnt + 1
        .asciz /a/
        .endm

        .macro notable a
        .pnt = .pnt + 1
        .byte 76,0
        .endm

        .mcall mac,gcmlb$,exit$s
        mac s
        rset
        globck off
        globck stackoff
        stack
        estack
        fdb ,mac,mpp,4		;3 files plus the get-cmd-line processor
$lin$:: .word   0      ;store last line read address
in::    file INPUT 3
out::   file OUTPUT 4
m.lb::  file INPUT 10. ;macro lib input
nolib:: .word 0         ;flag used by init and mcall
lib.flag:: .word 0		;flag indication of lib read in
pplev:: .word 0		;pretty printer level
ppflg:: .word 0		;pretty printer flag
lnumber:: .word 0		;line number

        .psect stak
;
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; define the variable symbol table
; and the type array (for each symbol).
; also the pointers.  when a symbol is looked up it's
; location in the symbol table is effectively swapped
; with the preceding symbol in the table. the pointers are
; swapped instead of the symbols. (the search is sequential but
; the order is defined by the pointer array . This is probably
; no longer implemented.)
;
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        def.str <..symbols , maxsym*10.+20. , maxsym>
..types:: .blkw maxsym
..spoint:: .blkw maxsym	;the pointers for lookup
..nsym:: .word 0		;the number of entries into the
        				;symbol table
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
stkovr::				;stack overflow entry
        pri r0 <out of stack space>
        exit$s
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        .pnt=0
.opcodes::
        table   LET       ;1
        table   CL        ;2
        table   S%N       ;3 number stuff
        table   **        ;4 rept
        table   I%R       ;5 if recursive
        table   CMP.      ;6 cmp. word,word
        table   MOV       ;7 mov word hardware directive
        table   M%OV      ;8
        table   I%EXP     ;9 if an expression
        table   ??        ;10 gen labels
        table   ?-        ;11 push
        table   ?+        ;12 pop
        table   ?--       ;13 push stack 2
        table   ?++       ;14 pop stack 2
        table    C%SYM	;15 clear symbol table
        table	.MACRO
        NOtable
        NOtable
        NOtable
        NOtable
        NOtable
        NOtable
        NOtable
        table   I%DIN
        table	I%DOUT
        table	I%IN
        table	I%ERR
        table   S%LEN
        table	E%S	;enter symbol
        table   T%YP
        table   I%B
        table   I%NB
        table   I%IDN
        table   I%DF
        table   I%SW      ;if switch is set
        table   S%SW      ;set/reset switch
        table   D%SYM     ;dump symbols
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        nbnops=.-.opcodes ;number of bytes for opcodes
exttab: .blkb   extmac*5.  ;room for extension of more (macros)
        .even
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
.lopcodes:: .word   nbnops  ;length in bytes of opcodes - current
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
.nopcodes:: .word   .pnt      ;number of opcodes current
        macent==.pnt            ;opcode number of last built-in opcode
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        ys=true
        no=false
$optable::
;             1  2  3  4  5  6  7  8  9  10 11 12 13 14 15
;	      16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
        .byte no,no,ys,ys,ys,no,ys,no,no,ys,ys,ys,no,no,no ;1-15
        .byte ys,no,no,no,no,no,no,no,no,ys,ys,ys,no,no,ys ;16-30
        .byte ys,ys,ys,ys,ys,ys,ys,ys			   ;31-38
        .even
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; the macro library data structures
; they include:
;	1. mnames	string array for names
;	2. mtext	string array for macro text
;	3. mfst		word array for pointer of first string in mtext
;	4. mlst		word array for pointer of last  string in mtext
;	5. mlcnt	word containing the number of macros read in
;	6. mlnum	word containing the line number of macro text
; their lengths are computed using the label "extmac"
; also see labels "sz.mtext" and "dm.mtext" which define mtext sizes
;
; note that the opcode table and the pointer table are extended at
; run time to include the macro library names.
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        def.str <mnames,extmac*5.+50.,extmac>
        def.str <mtext,sz.mtext,dm.mtext>
mfst::  .blkw	extmac
mlst::  .blkw	extmac
txpnt:: .word 0
        .blkw dm.mtext-1		;pointer to each line in macro text
mlcnt:: .word	0
mlnum:: .word	0
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; switch tables:
;	swtab points to the ascii two letter switches
;	swval points to the words set/reset on presence of flags
;	nsw   is the number of switches
; switches may be added here by placing a two letter switch in the
; table (swtab's ascii statement) and adding a word in the corresponding
; position below swval and placing a global label on the word.
; the subroutine init.mac processes the command line and sets these
; flags where a switch is set.
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SWTAB:: .ASCII /NLDAISMEMLOPTRNIMDPP/   ;SWITCHES CAN'T HAVE SUBSTRINGS IN TABLE
        .ASCII/UNX2X3X4X5X6X7X8X9X0/
        .ASCII/Y1Y2Y3Y4Y5Y6Y7Y8Y9Y0/
        .ASCII/LMNANB/			;two MORE
        NSW==<.-SWTAB>/2
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SWVAL::
NLIS::  .WORD 0 ;no .print statements
DBUGER::.WORD 0 ;not used inside pre-processor (for user macros)
ISTRNG::.WORD 0 ;
ME.SWITCH:: .WORD 0	;macro expansion switch
LOCLIB::.WORD 0 ;use local macro library (in user uic not [1,1])
OP.SWITCH:: .WORD 0 ;compile only non-optimised functions
DE.SWITCH:: .WORD 0	;debugger switch (for use by this pre-processor)
NI.SWITCH:: .WORD 0 ;no internal macros included
MD.SWITCH:: .WORD 0 ;macro call dump
PP.SWITCH:: .WORD 0	;pretty printer
XX.SWITCH:: .WORD 0,0,0,0,0,0,0,0,0,0 ;all 20 switches used by macro libs
XY.SWITCH:: .WORD 0,0,0,0,0,0,0,0,0,0 ;10 more
LM.SWITCH:: .WORD 0	;local macros switch
na.SWITCH:: .WORD 0	;no assignment check
nb.SWITCH:: .WORD 0	;unused stack suppress unless low
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
num$::  .blkw 51.	;number array for s%n and #@#n
..CNT:: .WORD 0
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;
; macro arg string stack and pointer
;
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        def.str <$stack,stkbyt,stksiz>
        .even
sp1::   				;all these $'s and .'s were dumb
$.cnt:: .word -1          ;-1 means need to init $stack
sp2::   				;sp1 and sp2 are better names for stack pointers
$.cnt2::.word -1          ;-1 means need to init $stack
        $cnt2==   30.     ;initial value of second stack
        .even
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; opcode pointers
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        opnum==.pnt+extmac
opword::.blkw opnum     ;pointer to address of strings
oplen:: .blkw opnum     ;length of opcodes
opini:: .byte 0         ;indicates this table is set up
        .even
htable::	.blkb prime+1
	.even
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; each macro expanded has a s,t,n,l quad which contains the expansion
; text broken into arguments (which are also the local var's of a
; macro instance), the number of arguments and a boolean label flag.
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
slevel::	.word -1	;for keeping track of recursive statement level
mlsp::  .word	mlstk-2	;macro lib external stack pointer
mlstk:: .blkw	50.	;contains ptr's to expansion records
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
cs::    gcmlb$ 1,mpp               ;get command line stuff
        .even
        .end
