Add ?do. Passed test of ?do

This commit is contained in:
Koichi Nakamura 2021-01-15 18:47:52 +09:00
parent f321addd29
commit f61ee0bab0
2 changed files with 15 additions and 3 deletions

View file

@ -1478,6 +1478,18 @@ do-stack 16 cells + do-sp !
here >do do-mark >do
; immediate
\ compile: ( -- ... )
: ?do
compile 2dup
compile >r \ save start
compile >r \ save limit
compile <>
compile 0branch
0 ,
here >do do-mark >do
here cell- >do leave-mark >do
; immediate
: leave ( -- do: orig mark )
compile branch
here >do
@ -2543,7 +2555,7 @@ need-defined (read)
if else then unless begin until again while repeat
recurse case of rangeof endof endcase
do loop +loop unloop leave i j k
do ?do loop +loop unloop leave i j k
char [char] key emit spaces
.s . .r u. u.r dec. hex. type typen

View file

@ -267,7 +267,7 @@ T{ 5 0 QD -> 0 1 2 3 4 }T
T{ 50 1 QD1 -> 1 11 21 31 41 }T
T{ 50 0 QD1 -> 0 10 20 30 40 }T
: QD2 ?do i 3 > if LEAVE else i then loop ;
: QD2 ?do i 3 > if leave else i then loop ;
T{ 5 -1 QD2 -> -1 0 1 2 3 }T
: QD3 ?do i 1 +loop ;
@ -294,7 +294,7 @@ variable INCRMNT
?do
1 ITERS +!
i
ITERS @ 6 = if LEAVE then
ITERS @ 6 = if leave then
INCRMNT @
+loop ITERS @
;