Browse code

(system.catch) Improved test file.

Devine Lu Linvega authored on 16/07/2023 04:46:04
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,102 @@
1
+|00 @System &catch $2 &expansion $2 &pad $2 &metadata $2 &r $2 &g $2 &b $2 &debug $1 &halt $1
2
+|10 @Console &vector $2 &read $1 &pad $4 &type $1 &write $1 &error $1
3
+
4
+|0100
5
+
6
+@on-reset ( -> )
7
+	;on-error .System/catch DEO2
8
+	;on-console .Console/vector DEO2
9
+	;dict/instruction <print-str>
10
+	BRK
11
+
12
+@on-console ( -> )
13
+	[ LIT2 &id =tests ] INC2k INC2 ,&id STR2
14
+	LDA2 JSR2 BRK
15
+
16
+@on-error ( addr* inst code -> )
17
+	#00 SWP DUP ADD ;err ADD2 LDA2 <print-str>
18
+	;dict/error <print-str>
19
+	<print-opcode>
20
+	;dict/at <print-str>
21
+	<print-hex>
22
+	LIT ". #18 DEO
23
+	BRK
24
+
25
+@try-divzero ( -- )
26
+	#02 #00 DIV JMP2r
27
+
28
+@try-underflow ( -- )
29
+	POP2 JMP2r
30
+
31
+@try-overflow ( -- )
32
+	#00
33
+	&l ( -- )
34
+		#ffff ROT INC DUP ?&l
35
+	POP JMP2r
36
+
37
+@exit ( -> )
38
+	#0000 .Console/vector DEO2
39
+	#800f DEO
40
+	BRK
41
+
42
+@<print-opcode> ( byte -- )
43
+	DUP #20 EQU ?&jci
44
+	DUP #40 EQU ?&jmi
45
+	DUP #60 EQU ?&jsi
46
+	DUP #00 EQU ?&brk
47
+	#00 OVR #1f AND #20 SFT2 ;opcodes ADD2 <print-str>
48
+	DUP #20 AND #00 EQU ?&>no-2
49
+		LIT "2 #18 DEO &>no-2
50
+	DUP #1f AND #00 EQU ?&>no-k
51
+	DUP #80 AND #00 EQU ?&>no-k
52
+		LIT "k #18 DEO &>no-k
53
+	DUP #40 AND #00 EQU ?&>no-r
54
+		LIT "r #18 DEO &>no-r
55
+	POP JMP2r
56
+	&brk POP ;opcodes/brk !<print-str>
57
+	&jmi POP ;opcodes/jmi !<print-str>
58
+	&jci POP ;opcodes/jci !<print-str>
59
+	&jsi POP ;opcodes/jsi !<print-str>
60
+
61
+@<print-hex> ( short* -- )
62
+	SWP <print-hex>/b
63
+	&b ( byte -- )
64
+		DUP #04 SFT <print-hex>/c
65
+	&c ( char -- )
66
+		#0f AND DUP #09 GTH #27 MUL ADD #30 ADD #18 DEO
67
+		JMP2r
68
+
69
+@<print-str> ( str* -- )
70
+	&w ( -- )
71
+		LDAk #18 DEO
72
+		INC2 LDAk ?&w
73
+	POP2 JMP2r
74
+
75
+@tests
76
+	=try-divzero =try-underflow =try-overflow =exit
77
+
78
+@err
79
+	=dict/unknown =dict/underflow =dict/overflow =dict/divzero
80
+
81
+@dict ( )
82
+	&error "error, 20 "during 20 $1
83
+	&unknown "Unkown 20 $1
84
+	&underflow "Underflow 20 $1
85
+	&overflow "Overflow 20 $1
86
+	&divzero "Division 20 "by 20 "zero 20 $1
87
+	&at ", 20 "at 20 "# $1
88
+	&instruction "Press 20 "enter 20 "to 20 "test 20 "each 20 "error. 0a $1
89
+
90
+@opcodes
91
+	[
92
+	"LIT $1 "INC $1 "POP $1 "NIP $1
93
+	"SWP $1 "ROT $1 "DUP $1 "OVR $1
94
+	"EQU $1 "NEQ $1 "GTH $1 "LTH $1
95
+	"JMP $1 "JCN $1 "JSR $1 "STH $1
96
+	"LDZ $1 "STZ $1 "LDR $1 "STR $1
97
+	"LDA $1 "STA $1 "DEI $1 "DEO $1
98
+	"ADD $1 "SUB $1 "MUL $1 "DIV $1
99
+	"AND $1 "ORA $1 "EOR $1 "SFT $1
100
+	&brk "BRK $1 &jmi "JMI $1 &jci "JCI
101
+	$1 &jsi "JSI $1 ]
102
+
0 103
deleted file mode 100644
... ...
@@ -1,96 +0,0 @@
1
-|00 @System &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1
2
-|10 @Console &vector $2 &read $1 &pad $5 &write $1
3
-
4
-|0100
5
-
6
-	;on-halt .System/vector DEO2
7
-	;on-console .Console/vector DEO2
8
-	;dict/instruction pstr
9
-
10
-BRK
11
-
12
-@on-console ( -> )
13
-
14
-	[ LIT2 &id =tests ] INC2k INC2 ,&id STR2 LDA2 JSR2
15
-
16
-BRK
17
-
18
-@tests
19
-	=try-divzero
20
-	=try-underflow
21
-	=try-overflow
22
-	=exit
23
-
24
-@try-divzero ( -- ) #02 #00 DIV JMP2r
25
-@try-underflow ( -- ) POP JMP2r
26
-@try-overflow ( -- ) #00 &l #ffff ROT INC DUP ?&l POP JMP2r
27
-@exit ( -- ) #0000 .Console/vector DEO2 #800f DEO BRK
28
-
29
-@on-halt ( addr* inst code -> )
30
-
31
-	#00 SWP DUP ADD ;err ADD2 LDA2 pstr
32
-	;dict/error pstr
33
-	print-opcode
34
-	;dict/at pstr
35
-	phex LIT ". #18 DEO
36
-
37
-BRK
38
-
39
-@print-opcode ( byte -- )
40
-
41
-	DUP #20 EQU ?&jci
42
-	DUP #40 EQU ?&jmi
43
-	DUP #60 EQU ?&jsi
44
-	DUP #00 EQU ?&brk
45
-	#00 OVR #1f AND #20 SFT2 ;opcodes ADD2 pstr
46
-	DUP #20 AND #00 EQU ?&no-2 LIT "2 #18 DEO &no-2
47
-	DUP #1f AND #00 EQU ?&no-k
48
-	DUP #80 AND #00 EQU ?&no-k LIT "k #18 DEO &no-k
49
-	DUP #40 AND #00 EQU ?&no-r LIT "r #18 DEO &no-r
50
-	POP
51
-
52
-JMP2r
53
-	&brk POP ;opcodes/brk !pstr
54
-	&jmi POP ;opcodes/jmi !pstr
55
-	&jci POP ;opcodes/jci !pstr
56
-	&jsi POP ;opcodes/jsi !pstr
57
-
58
-@phex ( short* -- )
59
-
60
-	SWP phex/b
61
-	&b ( byte -- ) DUP #04 SFT phex/c
62
-	&c ( char -- ) #0f AND DUP #09 GTH #27 MUL ADD #30 ADD #18 DEO
63
-
64
-JMP2r
65
-
66
-@pstr ( str* -- )
67
-
68
-	&w
69
-		LDAk #18 DEO
70
-		INC2 LDAk ?&w
71
-	POP2
72
-
73
-JMP2r
74
-
75
-@err
76
-	=dict/unknown
77
-	=dict/underflow
78
-	=dict/overflow
79
-	=dict/divzero
80
-
81
-@dict
82
-	&error "error, 20 "during 20 $1
83
-	&unknown "Unkown 20 $1
84
-	&underflow "Underflow 20 $1
85
-	&overflow "Overflow 20 $1
86
-	&divzero "Division 20 "by 20 "zero 20 $1
87
-	&at ", 20 "at 20 "# $1
88
-	&instruction "Press 20 "enter 20 "to 20 "test 20 "each 20 "error. 0a $1
89
-
90
-@opcodes
91
-	"LIT $1 "INC $1 "POP $1 "NIP $1 "SWP $1 "ROT $1 "DUP $1 "OVR $1
92
-	"EQU $1 "NEQ $1 "GTH $1 "LTH $1 "JMP $1 "JCN $1 "JSR $1 "STH $1
93
-	"LDZ $1 "STZ $1 "LDR $1 "STR $1 "LDA $1 "STA $1 "DEI $1 "DEO $1
94
-	"ADD $1 "SUB $1 "MUL $1 "DIV $1 "AND $1 "ORA $1 "EOR $1 "SFT $1
95
-	&brk "BRK $1 &jmi "JMI $1 &jci "JCI $1 &jsi "JSI $1
96
-