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 here >do do-mark >do
; immediate ; 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 ) : leave ( -- do: orig mark )
compile branch compile branch
here >do here >do
@ -2543,7 +2555,7 @@ need-defined (read)
if else then unless begin until again while repeat if else then unless begin until again while repeat
recurse case of rangeof endof endcase 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 char [char] key emit spaces
.s . .r u. u.r dec. hex. type typen .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 1 QD1 -> 1 11 21 31 41 }T
T{ 50 0 QD1 -> 0 10 20 30 40 }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 T{ 5 -1 QD2 -> -1 0 1 2 3 }T
: QD3 ?do i 1 +loop ; : QD3 ?do i 1 +loop ;
@ -294,7 +294,7 @@ variable INCRMNT
?do ?do
1 ITERS +! 1 ITERS +!
i i
ITERS @ 6 = if LEAVE then ITERS @ 6 = if leave then
INCRMNT @ INCRMNT @
+loop ITERS @ +loop ITERS @
; ;