~rabbits/uxnfor

8921d77159f464a8dc0f327a3468250134f099b5 — neauoire 5 months ago 3ceb306
Better handling of parens
1 files changed, 34 insertions(+), 35 deletions(-)

M src/uxnfor.tal
M src/uxnfor.tal => src/uxnfor.tal +34 -35
@@ 74,9 74,9 @@

@walk ( c -- )
	.last LDZ #20 NEQ ?scope/put
	DUP LIT "( NEQ ?{
	DUP #28 NEQ ?{
		[ LIT2 01 _&mute ] STR }
	DUP LIT ") NEQ ?{
	DUP #29 NEQ ?{
		[ LIT2 00 _&mute ] STR }
	[ LIT &mute $1 ] ?scope/put
	DUP LIT "@ NEQ ?scope/put


@@ 88,12 88,12 @@
	( first scope ) LDAk LIT "@ NEQ ?&w
	#01 ;<emit-break>/nest STA
	( | definition )
	<emit-word>
	INC2k LDA LIT "( NEQ ?{ <emit-comment>
	<emit-word>/
	INC2k LDA #28 NEQ ?{ <emit-comment>
		INC2 !&>no-relpad }
	INC2 LDAk LIT "& NEQ ?{ <emit-space>
		!&w }
	LDAk [ LIT "[ ] NEQ ?{ <emit-space>
	LDAk #5b NEQ ?{ <emit-space>
		!&w }
	LDAk LIT "$ NEQ ?&>no-relpad
		<emit-space>


@@ 104,8 104,8 @@
		DUP2 #0001 SUB2 LDA #20 NEQ ?{
			LDAk LIT "| EQU ?handle-padabs
			LDAk LIT "$ EQU ?handle-padrel
			LDAk LIT "[ EQU ?handle-block
			LDAk LIT "( EQU ?handle-comment
			LDAk #5b EQU ?handle-block
			LDAk #28 EQU ?handle-comment
			LDAk LIT "& EQU ?handle-sublab
			LDAk LIT "{ EQU ?handle-lambda
			LDAk LIT "} EQU ?handle-lambda-end


@@ 128,7 128,7 @@
	&w ( -- )
		DUP2 #0001 SUB2 LDA #20 NEQ ?{
			LDAk LIT "| EQU ?handle-padabs
			LDAk LIT "( EQU ?handle-comment }
			LDAk #28 EQU ?handle-comment }
		LDAk <emit>
		INC2 LDAk ?&w
	!eval-scope/end


@@ 137,9 137,9 @@
	#01 ;<emit-break>/nest STA
	INC2k is-pad-zp ?&zp
	INC2k is-pad-reset ?&reset
	DUP2 #0002 SUB2 LDA LIT ") NEQ ?{ #0a <emit> }
	DUP2 #0002 SUB2 LDA #29 NEQ ?{ #0a <emit> }
	#0a <emit>
	DUP2 <emit-word>
	DUP2 <emit-word>/
	<emit-space>
	( | if end of scope, no breaks )
	SWP2 wlen #0005 EQU2 ?eval-scope/continue


@@ 149,17 149,17 @@
		#01 .zp STZ
		#0a <emit>
		#0a <emit>
		<emit-word>
		<emit-word>/
		!eval-scope/continue
	&reset ( -- )
		#00 .zp STZ
		#0a <emit>
		#0a <emit>
		<emit-word>
		<emit-word>/
		!eval-scope/continue

@handle-padrel ( addr* -- addr* )
	<emit-word>
	<emit-word>/
	;mem/scope INC2 LDA ciuc ?&collapse
	INC2k LDA #00 EQU ?&collapse
	<emit-break>


@@ 171,26 171,26 @@
@handle-sublab ( addr* -- addr* )
	LDA2k LIT2 "&> EQU2 ?&tail
	LDA2k LIT2 "& 20 EQU2 ?&anon
	DUP2 wcap/ INC2 LDA LIT "( EQU ?&defined
	<emit-word>
	DUP2 wcap/ INC2 LDA #28 EQU ?&defined
	<emit-word>/
	<emit-space>
	!eval-scope/continue
	&tail ( -- )
		<emit-word>
		<emit-word>/
		( | Do not break when followed by label )
		DUP2 wcap/ INC2 LDA LIT "& EQU ?&>no-break
		DUP2 wcap/ INC2 LDA LIT "( EQU ?&>no-break
		DUP2 wcap/ INC2 LDA #28 EQU ?&>no-break
			<emit-break> &>no-break
		!eval-scope/w
	&anon ( -- )
		<emit-word>
		<emit-word>/
		<emit-space>
		INC2 LDAk LIT "( NEQ ?{ <emit-comment> }
		INC2 LDAk #28 NEQ ?{ <emit-comment> }
		!eval-scope/w
	&defined ( -- )
		#01 ;<emit-break>/nest STA
		<emit-break-once>
		<emit-word>
		<emit-word>/
		#00 ;<emit-break>/nest STA
		INC2 <emit-space>
		<emit-comment>


@@ 210,14 210,14 @@

@handle-lambda ( addr* -- addr* )
	;<emit-break>/lambda LDA INC ;<emit-break>/lambda STA
	<emit-word>
	<emit-word>/
	<emit-space>
	DUP2 count-lambda #0005 LTH2 ?{ <emit-break> }
	!eval-scope/continue

@handle-lambda-end ( addr* -- addr* )
	;<emit-break>/lambda LDA #01 SUB ;<emit-break>/lambda STA
	<emit-word>
	<emit-word>/
	<emit-space>
	<emit-break>
	!eval-scope/continue


@@ 225,16 225,16 @@
@handle-jxi ( addr* -- addr* )
	INC2k LDA LIT "{ EQU ?handle-lambda
	INC2k is-defined-before #00 EQU ?{ #01 ;<emit-break>/nest STA }
	<emit-word>
	<emit-word>/
	<emit-space>
	INC2k LDA LIT "} EQU ?&>eof
	INC2k LDA #00 EQU ?&>eof
		<emit-break> &>eof
	INC2k LDA LIT "} EQU ?eval-scope/continue
	INC2k LDA #00 EQU ?eval-scope/continue
	<emit-break>
	!eval-scope/continue

@handle-include ( addr* -- addr* )
	#0a <emit>
	<emit-word>
	<emit-word>/
	!eval-scope/continue

@save-file ( -- )


@@ 286,7 286,7 @@

@is-sub-def ( addr* -- f )
	( a ) LDAk LIT "& EQU STH
	( b ) wcap/ INC2 LDA LIT "( EQU
	( b ) wcap/ INC2 LDA #28 EQU
	( res ) STHr AND JMP2r

@is-pad-zp ( str* -- f )


@@ 312,7 312,7 @@
@count-block ( str* -- length* )
	LIT2r 0000
	&w ( -- )
		LDAk LIT "] EQU ?&end
		LDAk #5d EQU ?&end
		INC2r INC2 LDAk ?&w
	&end POP2 STH2r JMP2r



@@ 340,7 340,7 @@
	DUP2 count-block #0027 GTH2 ?<emit-long-block>
	&w ( -- )
		LDAk <emit>
		LDAk LIT "] EQU ?&end
		LDAk #5d EQU ?&end
		INC2 LDAk ?&w
	LDAk <emit>
	&end INC2 JMP2r


@@ 355,11 355,11 @@
		LDAk <emit>
		LDAk #20 NEQ ?&>no-ws
		STHkr [ LIT &lb $1 ] AND ?&>no-spacer
		INC2k LDA LIT "] EQU ?&>no-spacer
		INC2k LDA #5d EQU ?&>no-spacer
			<emit-break> &>no-spacer
			INC2r &>no-ws
		LDAk #00 EQU ?&end
		INC2 LDAk LIT "] NEQ ?&w
		INC2 LDAk #5d NEQ ?&w
	LDAk <emit>
	&end INC2 POP2r JMP2r



@@ 369,14 369,14 @@
	&w ( -- )
		LDAk <emit>
		LDAk #00 EQU ?&end
		INC2 LDAk LIT ") NEQ ?&w
		INC2 LDAk #29 NEQ ?&w
	LDAk <emit>
	&end ( str* -- str* )
		INC2 JMP2r

@<emit-line-comment> ( str* -- str* )
	<emit-comment>/w
	DUP2 wcap/ INC2 LDA LIT "( EQU ?{ <emit-break> }
	DUP2 wcap/ INC2 LDA #28 EQU ?{ <emit-break> }
	JMP2r

@<emit-mark> ( str* -- str* )


@@ 411,7 411,6 @@
	#20 !<emit>

@<emit-word> ( str* -- str* )
	!&
	&w ( -- )
		LDAk <emit>
		INC2 & LDAk #20 GTH ?&w