(primes.tal) Removed macros

This commit is contained in:
neauoire 2022-03-10 09:37:11 -08:00
parent 1ecbd571e0
commit cfedb19dca
2 changed files with 14 additions and 28 deletions

View File

@ -118,9 +118,9 @@ contexts:
- match: '\}' - match: '\}'
pop: true pop: true
- match: '\( ' - match: '\s?\(\s?'
scope: comment scope: comment
push: push:
- meta_scope: comment.line - meta_scope: comment.line
- match: ' \)' - match: '\s\)\s'
pop: true pop: true

View File

@ -2,56 +2,42 @@
An integer greater than one is called a prime number An integer greater than one is called a prime number
if its only positive divisors are one and itself. ) if its only positive divisors are one and itself. )
%RTN { JMP2r }
%HALT { #0101 #0e DEO2 }
%MOD2 { DIV2k MUL2 SUB2 }
%EMIT { #18 DEO }
|0100 ( -> ) @main |0100 ( -> ) @main
#0000 #0001 #0000 #0001
&loop &loop
DUP2 ,is-prime JSR #00 EQU ,&skip JCN DUP2 ,is-prime JSR #00 EQU ,&skip JCN
DUP2 ,print-hex/short JSR DUP2 ,print/short JSR
#20 EMIT #20 ( emit ) #18 DEO
&skip &skip
INC2 NEQ2k ,&loop JCN INC2 NEQ2k ,&loop JCN
POP2 POP2 POP2 POP2
HALT #0101 #0e DEO2
BRK BRK
@is-prime ( number* -- flag ) @is-prime ( number* -- flag )
DUP2 #0001 NEQ2 ,&not-one JCN DUP2 #0001 NEQ2 ,&not-one JCN
POP2 #00 RTN POP2 #00 JMP2r
&not-one &not-one
STH2k STH2k
( range ) #01 SFT2 #0002 ( range ) #01 SFT2 #0002
&loop &loop
STH2kr OVR2 MOD2 #0000 NEQ2 ,&continue JCN STH2kr OVR2 ( mod2 ) [ DIV2k MUL2 SUB2 ] ORA ,&continue JCN
POP2 POP2 POP2 POP2
POP2r #00 RTN POP2r #00 JMP2r
&continue &continue
INC2 GTH2k ,&loop JCN INC2 GTH2k ,&loop JCN
POP2 POP2 POP2 POP2
POP2r #01 POP2r #01
RTN JMP2r
@print-hex ( value* -- ) @print ( short* -- )
&short ( value* -- )
SWP ,&echo JSR
&byte ( value -- )
,&echo JSR
RTN
&echo ( value -- ) &short ( short* -- ) SWP ,&byte JSR
STHk #04 SFT ,&parse JSR EMIT &byte ( byte -- ) DUP #04 SFT ,&char JSR
STHr #0f AND ,&parse JSR EMIT &char ( char -- ) #0f AND DUP #09 GTH #27 MUL ADD #30 ADD ( emit ) #18 DEO
RTN
&parse ( value -- char )
DUP #09 GTH ,&above JCN #30 ADD RTN &above #09 SUB #60 ADD RTN
RTN JMP2r