Add 2>R and 2R>

This allows us to make DO..LOOP more compact.
This commit is contained in:
Virgil Dupras 2020-05-06 09:49:37 -04:00
parent b89fa2981f
commit f54b1dc504
5 changed files with 16 additions and 13 deletions

View File

@ -1,7 +1,9 @@
Return Stack Return Stack
>R n -- R:n Pops PS and push to RS >R n -- R:n Pops PS and push to RS
2>R x y -- R:x y Equivalent to SWAP >R >R
R> R:n -- n Pops RS and push to PS R> R:n -- n Pops RS and push to PS
2R> R:x y -- x y Equivalent to R> R> SWAP
I -- n Copy RS TOS to PS I -- n Copy RS TOS to PS
I' -- n Copy RS second item to PS I' -- n Copy RS second item to PS
J -- n Copy RS third item to PS J -- n Copy RS third item to PS

18
blk/326
View File

@ -1,13 +1,17 @@
CODE >R CODE >R
HL POPqq, HL POPqq, chkPS,
chkPS, 17 BCALL, ( 17 == pushRS )
( 17 == pushRS ) ;CODE
17 BCALL, CODE 2>R
DE POPqq, HL POPqq, chkPS,
17 BCALL, ( 17 == pushRS ) EXDEHL, 17 BCALL,
;CODE ;CODE
CODE R> CODE R>
( 20 == popRS ) 20 BCALL, ( 20 == popRS )
20 BCALL,
HL PUSHqq, HL PUSHqq,
;CODE ;CODE
CODE 2R>
20 BCALL, ( 20 == popRS ) EXDEHL, 20 BCALL,
HL PUSHqq, DE PUSHqq,
;CODE

View File

@ -3,11 +3,8 @@
: / /MOD SWAP DROP ; : / /MOD SWAP DROP ;
: MOD /MOD DROP ; : MOD /MOD DROP ;
( In addition to pushing H@ this compiles 2 >R so that loop ( In addition to pushing H@ this compiles 2>R so that loop
variables are sent to PS at runtime ) variables are sent to PS at runtime )
: DO : DO COMPILE 2>R H@ ; IMMEDIATE
COMPILE SWAP COMPILE >R COMPILE >R
H@
; IMMEDIATE

View File

@ -12,5 +12,5 @@
: LOOP : LOOP
COMPILE _ COMPILE (?br) COMPILE _ COMPILE (?br)
H@ - , H@ - ,
COMPILE R> COMPILE DROP COMPILE R> COMPILE DROP COMPILE 2R> COMPILE 2DROP
; IMMEDIATE ; IMMEDIATE

Binary file not shown.