~aleteoryx/uxn

uxn/fold.tal -rw-r--r-- 610 bytes
55f239d0 — Aleteoryx ibm, fold, dos<->unix 2 months ago
                                                                                
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
31
32
33
34
35
36
37
38
@on-reset ( -> )
	;on-char #10 DEO2 BRK


@on-char ( linelen toklen -> linelen toklen )
	OVR INC #49 NEQ ?{
		NEQk ?{ put-token }
		#0a18 DEO #00 SWP
	}

	#0a12 DEI EQU ?newline
	#2012 DEI EQU ?space

	#12 DEI OVR STZ
	INC SWP INC SWP

	BRK

@newline ( linelen toklen -- linelen toklen )
	put-nonempty
	#0a18 DEO #00 SWP
	BRK
@space ( linelen toklen -- linelen toklen )
	SWP INC SWP
	put-nonempty
	#2018 DEO
	BRK

@put-nonempty ( linelen toklen -- linelen toklen )
	DUP #00 EQU ?{ put-token }
	JMP2r

@put-token ( linelen toklen -- linelen toklen )
	#00
	&loop
		LDZk #18 DEO
		INC NEQk ?/loop
	POP2 #00 JMP2r