~rabbits/uxnlin

uxnlin/src/uxnlin.tal -rw-r--r-- 14.7 KiB
e8aba07cneauoire Reset token/last on mute 28 days 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
( Usage: uxncli uxnlin.rom src.tal )

|10 @Console &vector $2 &read $1 &pad $5 &write $1 &error $1
|a0 @File &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2

|0000

	@src $40
	@token $30 &last $30 &last2 $30
	@stats &lines $2 &tokens $2

(
@|vectors )

|0100 ( -> )

	;await-src .Console/vector DEO2
	;dict/input ;pstr JSR2

BRK

@await-src ( -> )

	.Console/read DEI .src ;skey JSR2
		,on-ready JCN

BRK

@on-ready ( -> )

	#0a18 DEO
	;src ,lint JSR
	( halt )
	#010f DEO

BRK

(
@|core )

@lint ( src* -- )

	( parse )
	.File/name DEO2
	#0001 .File/length DEO2
	&s
		;&c .File/read DEO2
		.File/success DEI2 #0000 EQU2 ,&eof JCN
		[ LIT &c $1 ] ,walk JSR
		,&s JMP
	&eof ;print-summary ( .. )

JMP2

@walk ( char -- )

	#0a EQUk NIP ,&line JCN
	LIT "( EQUk NIP ,&toggle-sleep JCN
	LIT ") EQUk NIP ,&toggle-sleep JCN
	LIT "[ EQUk NIP ,&toggle-mute JCN
	LIT "] EQUk NIP ,&toggle-mute JCN
	[ LIT &sleep $1 ] ,&skip JCN
	[ #20 ] GTHk NIP ,&append JCN
	;token ;slen JSR2 ORA ,parse JCN
	&skip
	POP

JMP2r
	&append ;token ;sput JMP2
	&toggle-sleep LIT "( EQU ,&sleep STR JMP2r
	&toggle-mute LIT "[ EQU ,parse/mute STR ;token/last ;sclr JSR2 JMP2r
	&line .stats/lines LDZ2k INC2 ROT STZ2 ( , )

@parse ( char -- recipe* )

	( char ) POP
	( is mute ) [ LIT &mute $1 ] ;&ignore JCN2
	( incr tokens ) .stats/tokens LDZ2k INC2 ROT STZ2

	( token length )

	;token ;slen JSR2 #0019 LTH2 ,&no-clip JCN
		;tokenlen ;print-warn JSR2
		&no-clip

	( chain include )

	;token LDA LIT "~ NEQ ,&no-inc JCN
		;src
			DUP2 ;sclr JSR2
			;token INC2 OVR2 ;scpy JSR2
			.File/name DEO2
			#0000 .stats/lines STZ2
		;&cleanup JMP2
		&no-inc

	( 2 elements )

	;rules2/end ;rules2
	&loop2
		( a ) DUP2 ;token/last ;scmp-wild JSR2 STH ;scap JSR2 INC2
		( b ) DUP2 ;token ;scmp-wild JSR2 STH ;scap JSR2 INC2
		ANDr STHr #00 EQU ,&skip2 JCN
			LDA2k ;print-warn2 JSR2
			&skip2
		INC2 INC2 GTH2k ,&loop2 JCN
	POP2 POP2

	( 3 elements )

	;rules3/end ;rules3
	&loop3
		( a ) DUP2 ;token/last2 ;scmp-wild JSR2 STH ;scap JSR2 INC2
		( b ) DUP2 ;token/last ;scmp-wild JSR2 STH ;scap JSR2 INC2
		( c ) DUP2 ;token ;scmp-wild JSR2 STH ;scap JSR2 INC2
		ANDr ANDr STHr #00 EQU ,&skip3 JCN
			LDA2k ;print-warn3 JSR2
			&skip3
		INC2 INC2 GTH2k ,&loop3 JCN
	POP2 POP2

	( static arithmetic sequence )

	;token ;is-arithmetic JSR2 #00 EQU ,&no-ari JCN
	;token/last ;is-static JSR2 #00 EQU ,&no-ari JCN
	;token/last2 ;is-static JSR2 #00 EQU ,&no-ari JCN
		;static ;print-warn2 JSR2
		&no-ari

	( literal duplicates )

	;token ;is-static JSR2 #00 EQU ,&no-lit JCN
	;token ;token/last ;scmp JSR2 #00 EQU ,&no-lit JCN
		;static-dup ;print-warn2 JSR2
		&no-lit

	&cleanup
	;token/last ;token/last2 ;scpy JSR2
	;token ;token/last ;scpy JSR2

	&ignore
	;token ;sclr ( .. )

JMP2

@is-arithmetic ( token* -- flag )

	,&t STR2
	;ariopcodes/end ;ariopcodes
	&loop
		DUP2 [ LIT2 &t $2 ] ;scmp3 JSR2 ,&found JCN
		#0004 ADD2 GTH2k ,&loop JCN
	POP2 POP2
	#00

JMP2r
	&found POP2 POP2 #01 JMP2r

@is-litbyte ( str* -- flag )

	LDAk LIT "# EQU ,&continue JCN
		POP2 #00 JMP2r
		&continue
	;slen JSR2 #0003 EQU2

JMP2r

@is-litshort ( str* -- flag )

	LDAk LIT "# EQU ,&continue JCN
		POP2 #00 JMP2r
		&continue
	;slen JSR2 #0005 EQU2

JMP2r

@is-static ( token* -- flag )

	LDAk LIT "; EQU ,&pass JCN
	LDAk LIT ". EQU ,&pass JCN
	LDAk LIT "# EQU ,&pass JCN
	POP2 #00

JMP2r
	&pass POP2 #01 JMP2r

@print-warn ( str* -- )

	LIT "- #18 DEOk DEO #2018 DEO
	;token ;pstr JSR2 #2018 DEO
	LIT "" #18 DEO ;pstr JSR2 LIT "" #18 DEO
	;print-line ( .. )

JMP2

@print-warn2 ( str* -- )

	LIT "- #18 DEOk DEO #2018 DEO
	;token/last ;pstr JSR2 #2018 DEO
	;token ;pstr JSR2 #2018 DEO
	LIT "" #18 DEO ;pstr JSR2 LIT "" #18 DEO
	;print-line ( .. )

JMP2

@print-warn3 ( str* -- )

	LIT "- #18 DEOk DEO #2018 DEO
	;token/last2 ;pstr JSR2 #2018 DEO
	;token/last ;pstr JSR2 #2018 DEO
	;token ;pstr JSR2 #2018 DEO
	LIT "" #18 DEO ;pstr JSR2 LIT "" #18 DEO

@print-line ( -- )

	;dict/line-txt ;pstr JSR2
	;src ;pstr JSR2 LIT ": #18 DEO
	.stats/lines LDZ2 INC2 ;pdec JSR2
	#0a18 DEO

JMP2r

@print-summary ( -- )

	;dict/linted-txt ;pstr JSR2
	;src ;pstr JSR2 #2018 DEO
	;dict/with-txt ;pstr JSR2 #2018 DEO
	.stats/tokens LDZ2 ;pdec JSR2 #2018 DEO
	;dict/tokens-txt ;pstr JSR2 LIT ", #18 DEO #2018 DEO
	.stats/lines LDZ2 ;pdec JSR2 #2018 DEO
	;dict/lines-txt ;pstr JSR2 LIT ". #18 DEO #0a18 DEO

JMP2r

(
@|stdlib )

@scap ( str* -- end* ) LDAk #00 NEQ JMP JMP2r &w INC2 LDAk ,&w JCN JMP2r
@sput ( chr str* -- ) ,scap JSR STA JMP2r
@slen ( str* -- len* ) DUP2 ,scap JSR SWP2 SUB2 JMP2r
@scmp ( a* b* -- f ) STH2 &l LDAk LDAkr STHr ANDk #00 EQU ,&e JCN NEQk ,&e JCN POP2 INC2 INC2r ,&l JMP &e NIP2 POP2r EQU JMP2r
@sclr ( str* -- ) LDAk ,&w JCN POP2 JMP2r &w STH2k #00 STH2r STA INC2 LDAk ,&w JCN POP2 JMP2r
@scpy ( src* dst* -- ) OVR2 LDA ,&e JCN POP2 POP2 JMP2r &e STH2 &w LDAk STH2kr STA INC2r INC2 LDAk ,&w JCN POP2 #00 STH2r STA JMP2r
@skey ( key buf -- proc ) OVR #21 LTH ,&eval JCN #00 SWP ;sput JSR2 #00 JMP2r &eval POP2 #01 JMP2r
@pstr ( str* -- ) &w LDAk #18 DEO INC2 LDAk ,&w JCN POP2 JMP2r

@scmp-wild ( a* b* -- flag )

	OVR2 OVR2 ;scmp JSR2 ,&pass JCN

	SWP2
	( literals )
	LDA2k LIT "# LIT "_  NEQ2 ,&no-lit JCN
		DUP2 ;slen JSR2 #0003 NEQ2 ,&no-byte JCN
			OVR2 ;is-litbyte JSR2 ,&pass JCN
			&no-byte
		DUP2 ;slen JSR2 #0005 NEQ2 ,&no-short JCN
			OVR2 ;is-litshort JSR2 ,&pass JCN
			&no-short
		&no-lit
	( references )
	( a ) OVR2 LDA LIT ". EQU STH
	( b ) LDA2k LIT2 "._ EQU2 STHr
		AND ,&pass JCN
	( a ) OVR2 LDA LIT "; EQU STH
	( b ) LDA2k LIT2 ";_ EQU2 STHr
		AND ,&pass JCN

	POP2 POP2 #00

JMP2r
	&pass POP2 POP2 #01 JMP2r

@scmp3 ( a* b* -- flag )

	LDA2k ROT2 LDA2k ROT2 EQU2 STH
	INC2 LDA2 SWP2 INC2 LDA2 EQU2 STHr
	AND

JMP2r

@phex ( short* -- )

	SWP ,&byte JSR
	&byte ( byte -- ) DUP #04 SFT ,&char JSR
	&char ( char -- ) #0f AND DUP #09 GTH #27 MUL ADD #30 ADD #18 DEO

JMP2r

@pdec ( short* -- )

	#00 ,&z STR
	#2710 ,&parse JSR
	#03e8 ,&parse JSR
	#0064 ,&parse JSR
	#000a ,&parse JSR
	NIP
	&emit
		DUP [ LIT &z $1 ] EQU ,&skip JCN
		#ff ,&z STR DUP #30 ADD #18 DEO
		&skip
	POP

JMP2r
	&parse
		DIV2k DUP ,&emit JSR MUL2 SUB2
	JMP2r

(
@|assets )

@ariopcodes
	"ADD $1 "SUB $1 "MUL $1 "DIV $1
	"GTH $1 "LTH $1 "EQU $1 "NEQ $1
	"AND $1 "ORA $1 "EOR $1 "SFT $1
	"INC $1
	&end

@dict
	&input "Input(.tal): 20 $1
	&line-txt ", 20 "at 20 $1
	&linted-txt "Linted 20 $1
	&with-txt "with $1
	&tokens-txt "tokens $1
	&lines-txt "lines $1

(
@|hints )

@redundance "Redundance $1 ( opcode effects cancel each other )
@static "Static-Arithmetic $1 ( arithmetic opcode on two static literals )
@static-dup "Static-Duplicate $1 ( two identical static literals )
@keep "Unkept $1 ( opcode should use non-destructive keep mode )
@unsafe "Unsafe $1 ( bitwise opcode used in relative jump )
@unstashed "Unstashed $1 ( literal was created on the wrong stack )
@latestack "Late-stack $1 ( arithmetic performed after stashing )
@eagerstack "Eager-stack $1 ( arithmetic performed before stashing )
@tokenlen "Token-length $1 ( token is longer than 24 characters )
@combine "Combine $1 ( sequences of two literal bytes )

@inc "INC $1 @inc2 "INC2 $1
@inc-twice "INC 20 "INC $1
@inc2-twice "INC2 20 "INC2 $1
@pop2 "POP2 $1
@pop2r "POP2r $1
@ovrk "OVRk $1
@ovr2k "OVR2k $1
@swpk "SWPk $1
@equk "EQUk $1
@neqk "NEQk $1
@gthk "GTHk $1
@lthk "LTHk $1
@addk "ADDk $1
@subk "SUBk $1
@mulk "MULk $1
@divk "DIVk $1
@andk "ANDk $1
@orak "ORAk $1
@eork "EORk $1
@sftk "SFTk $1
@inck "INCk $1
@inc2k "INC2k $1
@jmp "JMP $1
@jmp2 "JMP2 $1
@ora "ORA $1
@nip "NIP $1 @nip2 "NIP2 $1
@and "AND $1
@sft01 "#01 20 "SFT $1
@sft02 "#02 20 "SFT $1
@sft03 "#03 20 "SFT $1
@sft04 "#04 20 "SFT $1
@sft05 "#05 20 "SFT $1
@sft06 "#06 20 "SFT $1
@sft07 "#07 20 "SFT $1
@sft10 "#10 20 "SFT $1
@sft20 "#20 20 "SFT $1
@sft30 "#30 20 "SFT $1
@sft40 "#40 20 "SFT $1
@sft50 "#50 20 "SFT $1
@sft60 "#60 20 "SFT $1
@sft70 "#70 20 "SFT $1
@sft201 "#01 20 "SFT2 $1
@sft202 "#02 20 "SFT2 $1
@sft203 "#03 20 "SFT2 $1
@sft204 "#04 20 "SFT2 $1
@sft205 "#05 20 "SFT2 $1
@sft206 "#06 20 "SFT2 $1
@sft207 "#07 20 "SFT2 $1
@sft210 "#10 20 "SFT2 $1
@sft220 "#20 20 "SFT2 $1
@sft230 "#30 20 "SFT2 $1
@sft240 "#40 20 "SFT2 $1
@sft250 "#50 20 "SFT2 $1
@sft260 "#60 20 "SFT2 $1
@sft270 "#70 20 "SFT2 $1
@00ovr "#00 20 "OVR $1
@0000ovr2 "#0000 20 "OVR2 $1
@dup "DUP $1
@dup2 "DUP2 $1
@dupadd "DUP 20 "ADD $1
@dup2add2 "DUP2 20 "ADD2 $1
@orak00equ "ORAk 20 "#00 20 "EQU $1
@rotswp "ROT 20 "SWP $1
@rot2swp2 "ROT2 20 "SWP2 $1
@ldakrsthr "LDAkr 20 "STHr $1
@ldaksth "LDAk 20 "STH $1
@inc2ora "INC2 20 "ORA $1


(
@|rules )

@rules2

	"STH   $1 "STHr   $1 =redundance
	"STH2  $1 "STH2r  $1 =redundance
	"STHr  $1 "STH    $1 =redundance
	"STH2r $1 "STH2   $1 =redundance
	"DUP   $1 "SWP    $1 =redundance
	"DUP2  $1 "SWP2   $1 =redundance
	"SWP   $1 "SWP    $1 =redundance
	"SWP2  $1 "SWP2   $1 =redundance
	"SWPr  $1 "SWPr   $1 =redundance
	"SWP2r $1 "SWP2r  $1 =redundance
	"DUP   $1 "POP    $1 =redundance
	"DUP2  $1 "POP2   $1 =redundance
	"STH   $1 "STHkr  $1 =redundance
	"STH2  $1 "STH2kr $1 =redundance
	"STHr  $1 "STHk   $1 =redundance
	"STH2r $1 "STH2k  $1 =redundance
	"JMP2r $1 "JMP2r  $1 =redundance
	"JMP2  $1 "JMP2r  $1 =redundance
	"JMP2  $1 "BRK    $1 =redundance
	"JMP   $1 "BRK    $1 =redundance
	"BRK   $1 "BRK    $1 =redundance
	"SWP   $1 "ADD    $1 =redundance
	"SWP2  $1 "ADD2   $1 =redundance
	"SWP   $1 "MUL    $1 =redundance
	"SWP2  $1 "MUL2   $1 =redundance
	"SWP   $1 "EQU    $1 =redundance
	"SWP2  $1 "EQU2   $1 =redundance
	"SWP   $1 "NEQ    $1 =redundance
	"SWP2  $1 "NEQ2   $1 =redundance
	"#ff   $1 "GTH    $1 =redundance
	"#ffff $1 "GTH2   $1 =redundance
	"#00   $1 "LTH    $1 =redundance
	"#0000 $1 "LTH2   $1 =redundance
	"#00   $1 "ADD    $1 =redundance
	"#0000 $1 "ADD2   $1 =redundance
	"#00   $1 "SUB    $1 =redundance
	"#0000 $1 "SUB2   $1 =redundance
	"#01   $1 "MUL    $1 =redundance
	"#0001 $1 "MUL2   $1 =redundance
	"#01   $1 "DIV    $1 =redundance
	"#0001 $1 "DIV2   $1 =redundance
	"#ff   $1 "AND    $1 =redundance
	"#ffff $1 "AND2   $1 =redundance
	"#00   $1 "ORA    $1 =redundance
	"#0000 $1 "ORA2   $1 =redundance
	"#00   $1 "EOR    $1 =redundance
	"#0000 $1 "EOR2   $1 =redundance
	"#00   $1 "SFT    $1 =redundance
	"#00   $1 "SFT2   $1 =redundance
	"AND   $1 "JMP    $1 =unsafe
	"ORA   $1 "JMP    $1 =unsafe
	"EOR   $1 "JMP    $1 =unsafe
	";__   $1 "STH2   $1 =unstashed
	".__   $1 "STH    $1 =unstashed
	"#__   $1 "STH    $1 =unstashed
	"#____ $1 "STH2   $1 =unstashed
	"LDZ $1 "STH $1 =latestack
	"LDZ2 $1 "STH2 $1 =latestack
	"DEIk $1 "STH $1 =latestack
	"DEI2k $1 "STH2 $1 =latestack
	"LDZk $1 "STH $1 =latestack
	"LDZ2k $1 "STH2 $1 =latestack
	"DEI $1 "STH $1 =latestack
	"DEI2 $1 "STH2 $1 =latestack
	"STH2r $1 "ADD $1 =eagerstack
	"STH2r $1 "SUB $1 =eagerstack
	"STH2r $1 "MUL $1 =eagerstack
	"STH2r $1 "DIV $1 =eagerstack
	"STH2r $1 "EQU $1 =eagerstack
	"STH2r $1 "NEQ $1 =eagerstack
	"STH2r $1 "GTH $1 =eagerstack
	"STH2r $1 "LTH $1 =eagerstack
	"STH2r $1 "LDA $1 =eagerstack
	"STH2 $1 "ADDr $1 =eagerstack
	"STH2 $1 "SUBr $1 =eagerstack
	"STH2 $1 "MULr $1 =eagerstack
	"STH2 $1 "DIVr $1 =eagerstack
	"STH2 $1 "EQUr $1 =eagerstack
	"STH2 $1 "NEQr $1 =eagerstack
	"STH2 $1 "GTHr $1 =eagerstack
	"STH2 $1 "LTHr $1 =eagerstack
	"STH2 $1 "LDAr $1 =eagerstack
	"#__   $1 "#__    $1 =combine
	"DUP   $1 "DUP    $1 =keep
	"DUP2  $1 "DUP2   $1 =keep
	"DUP   $1 "INC    $1 =keep
	"DUP2  $1 "INC2   $1 =keep
	"DUP   $1 "STH    $1 =keep
	"DUP2  $1 "STH2   $1 =keep
	"DUP   $1 "LDA    $1 =keep
	"DUP2  $1 "LDA2   $1 =keep
	"DUP   $1 "LDR    $1 =keep
	"DUP2  $1 "LDR2   $1 =keep
	"DUP   $1 "LDZ    $1 =keep
	"DUP2  $1 "LDZ2   $1 =keep
	"DUP   $1 "DEI    $1 =keep
	"DUP2  $1 "DEI2   $1 =keep
	"DUP2  $1 "SWP2   $1 =swpk
	"DUP2  $1 "OVR    $1 =ovrk
	"OVR   $1 "DUP2   $1 =ovrk
	"DUP2  $1 "EQU    $1 =equk
	"DUP2  $1 "NEQ    $1 =neqk
	"DUP2  $1 "GTH    $1 =gthk
	"DUP2  $1 "LTH    $1 =lthk
	"DUP2  $1 "ADD    $1 =addk
	"DUP2  $1 "SUB    $1 =subk
	"DUP2  $1 "MUL    $1 =mulk
	"DUP2  $1 "DIV    $1 =divk
	"DUP2  $1 "AND    $1 =andk
	"DUP2  $1 "ORA    $1 =orak
	"DUP2  $1 "EOR    $1 =eork
	"DUP2  $1 "SFT    $1 =sftk
	"SWP   $1 "POP    $1 =nip
	"SWP2  $1 "POP2   $1 =nip2
	"#01   $1 "ADD    $1 =inc
	"#0001 $1 "ADD2   $1 =inc2
	"#02   $1 "ADD    $1 =inc-twice
	"#0002 $1 "ADD2   $1 =inc2-twice
	"POP   $1 "POP    $1 =pop2
	"NIP   $1 "POP    $1 =pop2
	"POPr  $1 "POPr   $1 =pop2r
	"POP   $1 "NIP    $1 =pop2
	"OVR   $1 "OVR    $1 =dup2
	"#0101 $1 "EQU2   $1 =and
	"#0000 $1 "NEQ2   $1 =ora
	"#0000 $1 "GTH2   $1 =ora
	"#ffff $1 "NEQ2 $1 =inc2ora
	"#02   $1 "DIV    $1 =sft01
	"#0002 $1 "DIV2   $1 =sft201
	"#04   $1 "DIV    $1 =sft02
	"#0004 $1 "DIV2   $1 =sft202
	"#08   $1 "DIV    $1 =sft03
	"#0008 $1 "DIV2   $1 =sft203
	"#10   $1 "DIV    $1 =sft04
	"#0010 $1 "DIV2   $1 =sft204
	"#20   $1 "DIV    $1 =sft05
	"#0020 $1 "DIV2   $1 =sft205
	"#40   $1 "DIV    $1 =sft06
	"#0040 $1 "DIV2   $1 =sft206
	"#80   $1 "DIV    $1 =sft07
	"#0080 $1 "DIV2   $1 =sft207
	"#02   $1 "MUL    $1 =sft10
	"#0002 $1 "MUL2   $1 =sft210
	"#04   $1 "MUL    $1 =sft20
	"#0004 $1 "MUL2   $1 =sft220
	"#08   $1 "MUL    $1 =sft30
	"#0008 $1 "MUL2   $1 =sft230
	"#10   $1 "MUL    $1 =sft40
	"#0010 $1 "MUL2   $1 =sft240
	"#20   $1 "MUL    $1 =sft50
	"#0020 $1 "MUL2   $1 =sft250
	"#40   $1 "MUL    $1 =sft60
	"#0040 $1 "MUL2   $1 =sft260
	"#80   $1 "MUL    $1 =sft70
	"#0080 $1 "MUL2   $1 =sft270
	"#00   $1 "#01    $1 =inck
	"#0000 $1 "#0001  $1 =inc2k
	"#10   $1 "SFT    $1 =dupadd
	"#10   $1 "SFT2   $1 =dup2add2
	"JSR2  $1 "JMP2r  $1 =jmp2
	"JSR   $1 "JMP2r  $1 =jmp
	"STH2kr $1 "LDA $1 =ldakrsthr
	"STH2k $1 "LDAr $1 =ldaksth
	"#ff $1 "NEQ $1 =inc
	"DUP2 $1 "NIP $1 =dup

&end

@rules3

	"DUP  $1 "#__   $1 "SWP   $1 =00ovr
	"DUP2 $1 "#____ $1 "SWP2  $1 =0000ovr2
	"ROT  $1 "ROT   $1 "ROT   $1 =redundance
	"ROT2 $1 "ROT2  $1 "ROT2  $1 =redundance
	"SFT  $1 "#__   $1 "SFT   $1 =combine
	"SFT2 $1 "#__   $1 "SFT   $1 =combine
	"SFT  $1 "#__   $1 "SFT2  $1 =combine
	"SFT2 $1 "#__   $1 "SFT2  $1 =combine
	"OVR  $1 "OVR   $1 "EQU   $1 =keep
	"OVR2 $1 "OVR2  $1 "EQU2  $1 =keep
	"OVR  $1 "OVR   $1 "NEQ   $1 =keep
	"OVR2 $1 "OVR2  $1 "NEQ2  $1 =keep
	"OVR  $1 "OVR   $1 "GTH   $1 =keep
	"OVR2 $1 "OVR2  $1 "GTH2  $1 =keep
	"OVR  $1 "OVR   $1 "LTH   $1 =keep
	"OVR2 $1 "OVR2  $1 "LTH2  $1 =keep
	"OVR  $1 "OVR   $1 "ADD   $1 =keep
	"OVR2 $1 "OVR2  $1 "ADD2  $1 =keep
	"OVR  $1 "OVR   $1 "SUB   $1 =keep
	"OVR2 $1 "OVR2  $1 "SUB2  $1 =keep
	"OVR  $1 "OVR   $1 "MUL   $1 =keep
	"OVR2 $1 "OVR2  $1 "MUL2  $1 =keep
	"OVR  $1 "OVR   $1 "DIV   $1 =keep
	"OVR2 $1 "OVR2  $1 "DIV2  $1 =keep
	"OVR  $1 "OVR   $1 "AND   $1 =keep
	"OVR2 $1 "OVR2  $1 "AND2  $1 =keep
	"OVR  $1 "OVR   $1 "ORA   $1 =keep
	"OVR2 $1 "OVR2  $1 "ORA2  $1 =keep
	"OVR  $1 "OVR   $1 "EOR   $1 =keep
	"OVR2 $1 "OVR2  $1 "EOR2  $1 =keep
	"OVR  $1 "OVR   $1 "SWP   $1 =keep
	"OVR2 $1 "OVR2  $1 "SWP2  $1 =keep
	"DUP2 $1 "#0000 $1 "EQU2  $1 =orak00equ
	"OVR  $1 "OVR   $1 "OVR   $1 =ovrk
	"OVR2 $1 "OVR2  $1 "OVR2  $1 =ovr2k
	"STH  $1 "SWP   $1 "STHr  $1 =rotswp
	"STH2 $1 "SWP2  $1 "STH2r $1 =rot2swp2

&end