Browse code

(primes.tal) Removed macros

neauoire authored on 10/03/2022 17:37:11
Showing 2 changed files
... ...
@@ -118,9 +118,9 @@ contexts:
118 118
         - match: '\}'
119 119
           pop: true
120 120
 
121
-    - match: '\( '
121
+    - match: '\s?\(\s?'
122 122
       scope: comment
123 123
       push:
124 124
         - meta_scope: comment.line
125
-        - match: ' \)'
125
+        - match: '\s\)\s'
126 126
           pop: true
... ...
@@ -2,56 +2,42 @@
2 2
 	An integer greater than one is called a prime number 
3 3
 	if its only positive divisors are one and itself. )
4 4
 
5
-%RTN { JMP2r }
6
-%HALT { #0101 #0e DEO2 }
7
-%MOD2 { DIV2k MUL2 SUB2 }
8
-%EMIT { #18 DEO }
9
-
10 5
 |0100 ( -> ) @main
11 6
 
12 7
 	#0000 #0001
13 8
 	&loop
14 9
 		DUP2 ,is-prime JSR #00 EQU ,&skip JCN
15
-			DUP2 ,print-hex/short JSR
16
-			#20 EMIT
10
+			DUP2 ,print/short JSR
11
+			#20 ( emit ) #18 DEO
17 12
 			&skip
18 13
 		INC2 NEQ2k ,&loop JCN
19 14
 	POP2 POP2
20
-	HALT
15
+	#0101 #0e DEO2
21 16
 	
22 17
 BRK
23 18
 
24 19
 @is-prime ( number* -- flag )
25 20
 
26 21
 	DUP2 #0001 NEQ2 ,&not-one JCN
27
-		POP2 #00 RTN
22
+		POP2 #00 JMP2r
28 23
 		&not-one
29 24
 	STH2k
30 25
 	( range ) #01 SFT2 #0002
31 26
 	&loop
32
-		STH2kr OVR2 MOD2 #0000 NEQ2 ,&continue JCN
27
+		STH2kr OVR2 ( mod2 ) [ DIV2k MUL2 SUB2 ] ORA ,&continue JCN
33 28
 			POP2 POP2 
34
-			POP2r #00 RTN
29
+			POP2r #00 JMP2r
35 30
 			&continue
36 31
 		INC2 GTH2k ,&loop JCN
37 32
 	POP2 POP2 
38 33
 	POP2r #01
39 34
 
40
-RTN
35
+JMP2r
41 36
 
42
-@print-hex ( value* -- )
43
-	
44
-	&short ( value* -- )
45
-		SWP ,&echo JSR 
46
-	&byte ( value -- )
47
-		,&echo JSR
48
-	RTN
49
-
50
-	&echo ( value -- )
51
-	STHk #04 SFT ,&parse JSR EMIT
52
-	STHr #0f AND ,&parse JSR EMIT
53
-	RTN
54
-	&parse ( value -- char )
55
-		DUP #09 GTH ,&above JCN #30 ADD RTN &above #09 SUB #60 ADD RTN
56
-
57
-RTN
58 37
\ No newline at end of file
38
+@print ( short* -- )
39
+
40
+	&short ( short* -- ) SWP ,&byte JSR
41
+	&byte ( byte -- ) DUP #04 SFT ,&char JSR
42
+	&char ( char -- ) #0f AND DUP #09 GTH #27 MUL ADD #30 ADD ( emit ) #18 DEO
43
+
44
+JMP2r