[SLOF] [PATCH v2] fat-files: Fix access to FAT32 dir/files when cluster > 16-bits

Segher Boessenkool segher at kernel.crashing.org
Thu Jun 9 19:00:19 AEST 2016

On Thu, Jun 09, 2016 at 10:32:03AM +0200, Thomas Huth wrote:
> > Heh.  Nothing magic, just
> > 
> > BEGIN ... WHILE ... WHILE ... REPEAT ... ELSE ... THEN
> > 
> > 1:  BEGIN
> >      ...
> >     WHILE   \ if 0, goto 3
> >      ...
> >     WHILE   \ if 0, goto 2
> >      ...
> >     REPEAT  \ goto 1
> > 2:   ...
> >     ELSE    \ goto 4
> > 3:   ...
> >     THEN
> > 4:
> > 
> > so just an indeterminate loop with two exits.
> Wow ... and I thought I basically would be able nowadays to understand
> most of the Forth code that you wrote ... looks like I was wrong 8-)

The Forth structure words are not paired (if...then etc.); the compiler
does no lookahead, and no explicit nesting.

At compile time, structure words that jump forward leave an "orig"
on the compile stack; words like THEN and REPEAT resolve that.
Words like BEGIN leave a "dest"; words like AGAIN or REPEAT resolve
that.  Various words juggle the compile stack a bit, too.

The easy way to read "BEGIN WHILE WHILE REPEAT" is that it behaves
just like BEGIN WHILE REPEAT, except that the first WHILE is still
unresolved.  So you can put a THEN later, to have that WHILE jump
there; or an ELSE THEN if you have some code (between ELSE ... THEN)
that you want executed only when that first WHILE breaks out of the

   IF ... THEN
These are forward jumps, unconditional and conditional; AHEAD and IF
leave an orig on the compile stack that THEN resolves.

These are backward jumps, BEGIN leaves a dest, that AGAIN and UNTIL

ELSE is AHEAD, then swap the top two compile stacks elts, then THEN.
I.e. jump forward (don't know where yet), and then resolve where the
previous IF will jump to.

WHILE is IF followed by a swap on the compile stack, so jump forwards
but leave the dest of the previous BEGIN on the top of the compilation

REPEAT is AGAIN followed by THEN, so jump back to the BEGIN and then
resolve the WHILE.

And that is all really!  You can of course also make your own control
flow words if you really want...

Have you ever seen me use AHEAD directly?  Did I ever do [ 3 cs-roll ] ?
No, I like to keep things simple!  :-)


More information about the SLOF mailing list