summary refs log tree commit diff
path: root/flow-control.e
diff options
context:
space:
mode:
Diffstat (limited to 'flow-control.e')
-rw-r--r--flow-control.e22
1 files changed, 22 insertions, 0 deletions
diff --git a/flow-control.e b/flow-control.e
index bee5038..25a1931 100644
--- a/flow-control.e
+++ b/flow-control.e
@@ -127,3 +127,25 @@
   6 8 * + swap drop + swap drop -1 * ,
   ; make-immediate
 
+
+~   This is a helper which does non-local exit by directly overwriting the
+~ control stack, then calling regular "exit" (implicitly as part of its own
+~ semicolon). The name "nexit" is short for n-exit, meaning that it takes a
+~ parameter which tells it how many times to exit.
+~
+~   1 nexit is equivalent to regular "exit". 2 nexit is equivalent to asking
+~ your own caller to exit. 0 nexit does nothing.
+~
+~   This style of programming isn't encouraged, but may be useful when doing
+~ code that transforms other code.
+~
+~   This is much lower-level than the other flow-control stuff, but it isn't
+~ compatible with the label transform due to relying on r0, so it needs to go
+~ somewhere other than core.e, and this was the closest fit.
+~
+~   Anecdotally, this feature is traditionally called "shunt", and sometimes
+~ "rdrop".
+~
+~ (count --)
+: nexit 8 * control@ + r0 @ min control! ;
+