Browse code

(fizzbuzz.tal) Housekeeping

neauoire authored on 06/09/2023 03:05:14
Showing 1 changed files
... ...
@@ -1,33 +1,30 @@
1 1
 ( FizzBuzz: From 1 to 100, for multiples of 3 print "Fizz", of 5 "Buzz" and for both "FizzBuzz" )
2 2
 
3
-|0100
4
-
5 3
 @on-reset ( -> )
6 4
 	#6400
7
-	&loop ( integer )
8
-		DUP print-dec #2018 DEO
9
-		DUP #03 mod ?&>no-3
10
-			;dict/fizz print-str &>no-3
11
-		DUP #05 mod ?&>no-5
12
-			;dict/buzz print-str &>no-5
5
+	&loop ( -- )
6
+		DUP <print-dec>
7
+		#2018 DEO
8
+		DUP #03 DIVk MUL SUB ?{ ;dict/fizz <print-str>/ }
9
+		DUP #05 DIVk MUL SUB ?{ ;dict/buzz <print-str>/ }
13 10
 		#0a18 DEO
14 11
 		INC GTHk ?&loop
15 12
 	POP2
16
-	( halt ) #010f DEO
13
+	( exit ) #800f DEO
17 14
 	BRK
18 15
 
19
-@mod ( a b -- c )
20
-	DIVk MUL SUB JMP2r
16
+@<print-dec> ( num -- )
17
+	( x0 ) DUP #0a DIV <print-num>
18
+	( 0x ) #0a DIVk MUL SUB
19
+	( >> )
21 20
 
22
-@print-dec ( num -- )
23
-	( x0 ) DUP #0a DIV print-dec/num
24
-	( 0x ) #0a DIVk MUL SUB &num #30 ADD #18 DEO
21
+@<print-num> ( num -- )
22
+	#30 ADD #18 DEO
25 23
 	JMP2r
26 24
 
27
-@print-str ( addr* -- )
28
-	&while ( -- )
29
-		LDAk #18 DEO
30
-		INC2 LDAk ?&while
25
+@<print-str> ( addr* -- )
26
+	LDAk #18 DEO
27
+	INC2 & LDAk ?<print-str>
31 28
 	POP2 JMP2r
32 29
 
33 30
 @dict ( strings )