.globl	plstop
.globl	plmac
.globl	plwarn
.globl	plins
.globl	addenv
/macro case -- make delimiter structure ...
/...adjacent to replacement text
	.text
plmac:
	mov	stoppt,srcpt
	mov	eriapt,r1
	inc	r1
	bic	$1,r1
	mov	r1,dstpt
	mov	r1,eriapt
	mov	idlen,r1
	jsr	pc,_fmove
	mov	inffpt,r1
	inc	r1
	bic	$1,r1
	mov	r1,stoppt
	mov	eriapt,r1
	add	idlen,r1
	mov	r1,ffpt
	mov	offset,r1
	add	eriapt,r1
	sub	stoppt,r1
	mov	r1,offset
	mov	ffpt,r1
	sub	stoppt,r1
	mov	r1,idlen
	jbr	addenv
/warning case
plwarn:
	cmp	delct,$1.
	jne	erlia
	tst	optyp
	jeq	plwg
	mov	hashpt,r1
	add	$72.,r1
	mov	r1,lotemp
	mov	$6.,*lotemp
	jbr	addenv
plwg:
	mov	$6.,glbwsw
	jbr	addenv
/stop marker case
plstop:
	cmp	delct,$1.
	jne	erlia
	jbr	addenv
/insert case
plins:
	cmp	delct,$2.
	jne	erlia
/add to environment
addenv:
	mov	stoppt,idpt
	cmp	optyp,$1.
	jeq	locdef
	jsr	pc,mkroom
	add	idlen,idpt
	jsr	pc,opexit
	jbr	pld1
/local case
locdef:	jsr	pc,opexit
	mov	idlen,r1
	jsr	pc,declf
	mov	lfpt,ndefpt
pld1:
	mov	spt,bespt
	mov	idpt,srcpt
	mov	ndefpt,dstpt
	mov	idlen,r1
	jsr	pc,_bmove
	mov	ndefpt,r1
	add	offset,r1
	jsr	pc,loschn
	jmp	macerr
chn7:	mov	chanpt,r1
	add	$2.,r1
	mov	r1,idpt
	mov	*idpt,idlen
	add	$2.,idpt
	mov	idpt,r1
	add	idlen,r1
	dec	r1
	mov	r1,spt
	jsr	pc,mdfind
	mov	htabpt,r1
	sub	hashpt,r1
	mov	r1,offset
	cmp	ndefpt,lfpt
	jeq	gl43
/find end of locals
fenloc:
	cmp	*htabpt,lfpt
	jlo	gl43
	cmp	*htabpt,endpt
	jhis	gl43
	mov	*htabpt,htabpt
	jbr	fenloc
gl43:	mov	chanpt,r1
	sub	$2.,r1
	mov	r1,tempt
	mov	*htabpt,*tempt
	mov	tempt,*htabpt
	cmp	ndefpt,lfpt
	jeq	pldch
	mov	hashpt,temapt
/add globals to all hash tables
bchsh:	mov	temapt,r1
	mov	74.(r1),r1
	mov	r1,temapt
	tst	r1
	jeq	pldch
	add	offset,r1
	mov	r1,srcpt
	cmp	*srcpt,*tempt
	jne	ngad
	mov	tempt,*srcpt
ngad:	jbr	bchsh
pldch:	jsr	pc,loechn
	jmp	chn7
	mov	bespt,spt
	jbr	bsnext
				.globl	ertest
ertest:	mov	r1,parnm
	mov	(sp)+,9f
	.bss;9:.=.+2;.text
	tst	r1
	jeq	erlia
	cmp	ntypsw,$1.
	jeq	gl44
	cmp	ntypsw,$4.
	jne	gl45
gl44:	jmp	*9b
gl45:	jbr	erlia
				.globl	getdel
getdel:	mov	(sp)+,9f
	.bss;9:.=.+2;.text
gdnext:
	mov	$3.,type
	jsr	pc,gsratm
	jmp	evexit
gd1:
	mov	spt,oldspt
	jsr	pc,keysrc
	jmp	gdkey
	cmpb	*idpt,*knpt
	jne	gd2
	cmp	idlen,$1.
	jne	trynod
/case of delimiter
gd2:
	cmp	type,$3.
	jne	gdw1
/place lid on fstack and link it up
	mov	ffpt,r1
	jsr	pc,snodch
	inc	ffpt
	bic	$1,ffpt
	clr	(ffpt)+
	cmp	ffpt,_last
	jhis	erlso
gtloop:
	inc	ffpt
	bic	$1,ffpt
	mov	idlen,(ffpt)+
	cmp	ffpt,_last
	jhis	erlso
	mov	ffpt,dstpt
	mov	idlen,r1
	jsr	pc,bumpff
	mov	ffpt,r1
	inc	r1
	bic	$1,r1
	mov	r1,ffpt
	mov	idpt,srcpt
	mov	idlen,r1
	jsr	pc,_fmove
/look ahead for with or withs
	mov	idpt,exidpt
	jsr	pc,gsratm
	jmp	gtexit
	jsr	pc,keysrc
	jmp	gdwith
gtexit:
	cmp	$spcsrp,exidpt
	jne	gl47
	inc	ffpt
	bic	$1,ffpt
	mov	spcsmk,(ffpt)+
	cmp	ffpt,_last
	jhis	erlso
gl47:
	mov	oldspt,spt
	mov	ffpt,nodept
	inc	ffpt
	bic	$1,ffpt
	clr	(ffpt)+
	cmp	ffpt,_last
	jhis	erlso
gd4:
	tst	optlev
	jne	gl48
	inc	delct
gl48:	mov	$1.,r1
	mov	r1,keysw
	mov	r1,nodesw
	jmp	*9b
/test for withs or with
gdwith:
	cmp	type,$2.
	jge	gtexit
	tst	type
	jne	el14
	cmp	$spcsrp,exidpt
	jeq	el14
	inc	ffpt
	bic	$1,ffpt
	mov	withmk,(ffpt)+
	cmp	ffpt,_last
	jhis	erlso
	jbr	gdw2
el14:
	inc	ffpt
	bic	$1,ffpt
	mov	wthsmk,(ffpt)+
	cmp	ffpt,_last
	jhis	erlso
gdw2:	clr	r1
	mov	r1,nodesw
	mov	r1,keysw
	jsr	pc,gsratm
	jmp	erlia
	jbr	gd1
/subsequently returning here to perform checking
gdw1:
	cmp	type,$1.
	jne	el15
	cmpb	*idpt,$sprep
	jne	gtloop
/convert   withs space   to   with spaces
	mov	ffpt,r1
	sub	$2.,r1
	mov	r1,lotemp
	mov	withmk,*lotemp
	mov	$spcsrp,idpt
	jbr	gtloop
el15:	movb	*idpt,r1
	tstb	_tstchr(r1)
	jlt	gtloop
	movb	*exidpt,r1
	tstb	_tstchr(r1)
	jlt	gtloop
	jbr	erlia
/case of keyword
gdkey:	mov	keysw,r1
	jsr	pc,ertest
	clr	keysw
	mov	$0f,-(sp)
	mov	$type,-(sp)
	jmp	_goswitch
	.data
0:
	erlia
	erlia
	evopt
	evor
	gdall
/action at all
	.text
gdall:	jsr	pc,joinch
	mov	allpt,nodept
	clr	consw
	mov	lfpt,srcpt
	mov	$allpt,dstpt
	mov	$6.,r1
	jsr	pc,_fmove
	add	$6.,lfpt
	dec	optlev
	jbr	gd4
/node is false alarm
gd3:
	dec	idpt
	jbr	gd2
/test for node
trynod:	inc	idpt
	jsr	pc,lonum
	jmp	gd3
	mov	nodesw,r1
	jsr	pc,ertest
	clr	nodesw
/test whether placing or go to
	jsr	pc,gsratm
	jmp	ndgo
	jsr	pc,keysrc
	jmp	ndkey
/case of placing
ndplac:
	tst	meval
	jeq	erlia
	mov	$1.,consw
	jsr	pc,plnode
	jmp	gnod1
	cmp	*nnodpt,$1.
	jeq	erlia
	mov	ffpt,r1
	jsr	pc,snodch
	mov	tempt,nodept
gnod1:
	mov	$1.,*nnodpt
	mov	nnodpt,r1
	add	$2.,r1
	mov	r1,lotemp
	mov	ffpt,*lotemp
	jbr	gnod4
ndkey:	mov	$0f,-(sp)
	mov	$type,-(sp)
	jmp	_goswitch
	.data
0:
	erlia
	erlia
	ndplac
	ndgo
	ndgo
/node is gone to
	.text
ndgo:
	tst	meval
	jeq	ndn0
	tst	nodept
	jeq	erlia
	jsr	pc,plnode
	jmp	nunode
	cmp	*nnodpt,$1.
	jeq	oldnod
	mov	tempt,r1
	jsr	pc,loschn
	jmp	nund1
chn8:	jsr	pc,loechn
	jmp	chn8
	mov	nodept,r1
	sub	chanpt,r1
	mov	r1,*chanpt
	jbr	gnod3
nunode:
	clr	*nnodpt
nund1:	mov	nnodpt,r1
	add	$2.,r1
	mov	r1,lotemp
	mov	nodept,*lotemp
gnod3:	clr	nodept
gnod4:
	mov	oldspt,spt
	jbr	gdnext
/going to old node
oldnod:	mov	tempt,r1
	jsr	pc,snodch
	jbr	gnod3
/node n0
ndn0:	mov	nodept,r1
	jsr	pc,loschn
	jmp	erlia
chn9:
	mov	exclmk,*chanpt
	jsr	pc,loechn
	jmp	chn9
	mov	$1.,exitsw
	jbr	gnod3
				.globl	gsratm
gsratm:	mov	(sp)+,9f
	.bss;9:.=.+2;.text
gsr1:	mov	stoppt,r1
	sub	spt,r1
	cmp	r1,$1.
	jne	gl49
	jmp	*9b
gl49:	jsr	pc,gtatom
	jsr	pc,lulayk
	jmp	gsr1
	add	$4*1.,9b
	jmp	*9b
				.globl	joinch
joinch:	mov	(sp)+,9f
	.bss;9:.=.+2;.text
	tst	optlev
	jeq	erlia
/add nodept chain to head of allpt chain
	mov	nodept,r1
	jsr	pc,loschn
	jmp	jc1
chn10:	jsr	pc,loechn
	jmp	chn10
	tst	allpt
	jeq	gl50
	mov	allpt,r1
	sub	chanpt,r1
	mov	r1,*chanpt
gl50:
	mov	nodept,allpt
jc1:	jmp	*9b
				.globl	keysrc
keysrc:	mov	(sp)+,9f
	.bss;9:.=.+2;.text
	mov	$keychn,r1
	jsr	pc,ludel
	jmp	keyret
	mov	chanpt,r1
	mov	2.(r1),type
	jmp	*9b
keyret:	add	$4*1.,9b
	jmp	*9b
				.globl	plnode
plnode:	mov	(sp)+,9f
	.bss;9:.=.+2;.text
	mov	lnodpt,nnodpt
pln2:
	cmp	nnodpt,topspt
	jeq	pln1
	cmp	*nnodpt,meval
	jne	el16
	add	$2.,nnodpt
	mov	nnodpt,r1
	mov	2.(r1),tempt
	add	$4*1.,9b
	jmp	*9b
el16:	add	$6.,nnodpt
	jbr	pln2
/reserve new node
pln1:
	mov	lfpt,ollfpt
	mov	$6.,r1
	jsr	pc,declf
	cmp	lnodpt,ollfpt
	jeq	el17
	mov	ollfpt,srcpt
	mov	lfpt,dstpt
	mov	lnodpt,r1
	sub	ollfpt,r1
	jsr	pc,_fmove
el17:
	sub	$6.,lnodpt
	mov	meval,*lnodpt
	mov	lnodpt,r1
	add	$2.,r1
	mov	r1,nnodpt
	jmp	*9b
				.globl	snodch
snodch:	mov	r1,parnm
	mov	(sp)+,9f
	.bss;9:.=.+2;.text
	mov	r1,temapt
	mov	nodept,r1
	jsr	pc,loschn
	jmp	snd1
chn11:	mov	temapt,r1
	sub	chanpt,r1
	mov	r1,*chanpt
	jsr	pc,loechn
	jmp	chn11
	jmp	*9b
snd1:
	tst	consw
	jeq	erlia
	jmp	*9b
				.globl	tespac
tespac:	mov	(sp)+,9f
	.bss;9:.=.+2;.text
	cmp	*infopt,spcsmk
	jeq	tsp2
	cmp	*infopt,wthsmk
	jne	tsp1
tsp2:
	cmp	*idpt,withmk
	jne	tsp1
	mov	idpt,r1
	cmpb	4.(r1),$sprep
	jne	tsp1
	mov	idpt,r1
	add	$5.,r1
	inc	r1
	bic	$1,r1
	mov	r1,idpt
	jbr	tsp2
tsp1:	jmp	*9b
/input 491,output 422, 19.8% optimalized
