summary refs log tree commit diff
path: root/flow-control.e
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-09-14 20:57:48 -0700
committerIrene Knapp <ireneista@irenes.space>2026-09-14 20:59:37 -0700
commit54ac5e763cc26aee8c6fc9502398ce7b61281ec8 (patch)
tree6c86ad3812d95181e5a8aa6b5e83fc5bc3b479f5 /flow-control.e
parentaa4ce11c8ad9323e308e1d81c3f9b2c857934fb0 (diff)
place a trap inside the hex-transformed nlabel-transform-one
this will be used to cause it to apply a tilde alternate, but the lexing code for that needs to be refactored first

also, this has an implementation of nexit, a new flow-control word for a scary style of metaprogramming

Force-Push: yes
Change-Id: Ic7fe2d50a8ee21cf9fa5fef1fef4408c2935bb4c
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! ;
+