A for loop would be nice. Do-while is implemented as |a|(code)ʌʟ|a| and while as ʌʟ|b||a|(code)ʟ|a||b|. For loops are complex currently, and a Forth-like do ... loop would simplify things.
Close-mid to open front vowels are available. Open vowels available.
For-Loop
FOR: ɑ (end start -- ). Pops 2 for index bounds. Loop jumps back to here+1 if index < end.
GETIDX: e ( -- index). Pushes the current loop's index. NOP if not in a loop.
SETIDX: ø (value -- ) Sets the current loop's index to value.
LOOP: ɒ ( -- ). If index < limit, jump to associated For. Else, continue.
EXIT: ε ( -- ). Discards the current loop's data from the loop stack, and exits the loop.
Implementation Thoughts
2 new Lex tokens FOR/LOOPSTART and LOOPEND
LOOP always after FOR
How to keep track of the index? (loop stack) [1]
What about nesting? (loop stack) [1]
FOR pushes end and start onto the loop stack. start becomes index. L( -- end index)
EXIT should pop and discard 2 values from the loop stack, and jump to just after the next LOOP. `L(end index -- )
Uses
Easy counting loops, so less label spaghetti
Loops == "easier" to follow code
LOOP doesn't increment, so can use math ops and SETIDX to do custom IDX incrementation (i+=2, multiplication, division, etc)
IDX is always less than limit, but going negative can be done with INV.
A for loop would be nice. Do-while is implemented as
|a|(code)ʌʟ|a|
and while asʌʟ|b||a|(code)ʟ|a||b|
. For loops are complex currently, and a Forth-likedo ... loop
would simplify things.Close-mid to open front vowels are available. Open vowels available.
For-Loop
ɑ (end start -- )
. Pops 2 for index bounds. Loop jumps back to here+1 ifindex < end
.e ( -- index)
. Pushes the current loop's index. NOP if not in a loop.ø (value -- )
Sets the current loop's index tovalue
.ɒ ( -- )
. Ifindex < limit
, jump to associated For. Else, continue.ε ( -- )
. Discards the current loop's data from the loop stack, and exits the loop.Implementation Thoughts
end
andstart
onto the loop stack.start
becomesindex
.L( -- end index)
Uses
Things to do
[1]: see https://stackoverflow.com/questions/6949434/how-to-implement-loop-in-a-forth-like-language-interpreter-written-in-c