utoh / pygmy64

Frank Sergeant's Pygmy Forth for Desktops (anywhere Python runs)
http://pygmy.utoh.org/pygmy64.html
MIT License
15 stars 2 forks source link

THRU loads blocks in reverse order #9

Open eekee opened 1 year ago

eekee commented 1 year ago

THRU loads blocks from "last" to "first" because it uses the index value of a FOR loop. This is the reverse of all other Forths I use, including Pygmy for DOS. I solved the issue by copying the THRU definition from Pygmy for DOS, pygmy.scr block 83 to pygmy.fth, producing this:

: THRU ( first last -)
  OVER - 1+ FOR ( n) DUP PUSH LOAD POP 1+ NEXT    DROP ;

With the attached block file, thru-test.scr.txt, before the fix we see this:

> " thru-test.scr.txt" OPEN
 ok
> 1 LOAD
loading   2 4 THRU
block 5
block 4
block 3
HI ?

With the fix applied, it runs like this:

> " thru-test.scr.txt" OPEN
 ok
> 1 LOAD
loading   2 4 THRU
block 2
block 3
block 4
block 5
 ok
> BYE