KSP-KOS/KOS — pull request #89 by Dunbaratu (2014-05-08 11:56:51+00:00)
Title: Implemented an AGAIN keyword for WHEN & ON.  Resolves #86

"AGAIN" was chosen over "PRESERVE" because it was implemented
using a premature break (like a 'return' statement), and we thought
"AGAIN" sounded more like it implies you're starting over and not
doing the rest of the block.

SYNTAX:
The keyword AGAIN is analagous to the keyword CONTINUE in many
languages. CONTINUE causes a loop to quit where it is now and
go back to the top to run the next iteration. Similarly, AGAIN
causes a WHEN or ON clause to quiit where it is now and (importantly)
skip over the bit where it would otherwise have removed its trigger.
When a WHEN or ON clause issues the AGAIN command, it causes kOS to
keep it around for another re-triggering. A WHEN clause that
unconditionally executes AGAIN at the end of its body could in
principle last forever until the program ends.

IMPLEMENTATION NOTE:
The keyword AGAIN is implemented just like the keyword BREAK,
where each instance of AGAIN translates into a jump opcode,
the target of which is decided after the loop ends, and assigned
to all the places the AGAIN jump existed in the body. The target
of the jump is the end of the body's function, just after the
RemoveTrigger opcode. Note that if we wanted to, we could also
use the same infrasttructure to make AGAIN into a 'continue' for
loops as well, by adding just one line at the top and one line at
the bottom of their Visit...Node methods. But as that is a bigger
syntax change not required for the current 'THEN' problems, it's
deliberately left out of this commit and left for a future commit.