+The CURLYX/WHILEM pair of ops handle the most generic case of the /A*B/
+pattern, where A and B are subpatterns. (For simple A, CURLYM or
+STAR/PLUS/CURLY/CURLYN are used instead.)
+
+A*B is compiled as <CURLYX><A><WHILEM><B>
+
+On entry to the subpattern, CURLYX is called. This pushes a CURLYX
+state, which contains the current count, initialised to -1. It also sets
+cur_curlyx to point to this state, with any previous value saved in the
+state block.
+
+CURLYX then jumps straight to the WHILEM op, rather than executing A,
+since the pattern may possibly match zero times (i.e. it's a while {} loop
+rather than a do {} while loop).
+
+Each entry to WHILEM represents a successful match of A. The count in the
+CURLYX block is incremented, another WHILEM state is pushed, and execution
+passes to A or B depending on greediness and the current count.
+
+For example, if matching against the string a1a2a3b (where the aN are
+substrings that match /A/), then the match progresses as follows: (the
+pushed states are interspersed with the bits of strings matched so far):
+
+ <CURLYX cnt=-1>
+ <CURLYX cnt=0><WHILEM>
+ <CURLYX cnt=1><WHILEM> a1 <WHILEM>
+ <CURLYX cnt=2><WHILEM> a1 <WHILEM> a2 <WHILEM>
+ <CURLYX cnt=3><WHILEM> a1 <WHILEM> a2 <WHILEM> a3 <WHILEM>
+ <CURLYX cnt=3><WHILEM> a1 <WHILEM> a2 <WHILEM> a3 <WHILEM> b
+
+(Contrast this with something like CURLYM, which maintains only a single
+backtrack state:
+
+ <CURLYM cnt=0> a1
+ a1 <CURLYM cnt=1> a2
+ a1 a2 <CURLYM cnt=2> a3
+ a1 a2 a3 <CURLYM cnt=3> b
+)
+
+Each WHILEM state block marks a point to backtrack to upon partial failure
+of A or B, and also contains some minor state data related to that
+iteration. The CURLYX block, pointed to by cur_curlyx, contains the
+overall state, such as the count, and pointers to the A and B ops.
+
+This is complicated slightly by nested CURLYX/WHILEM's. Since cur_curlyx
+must always point to the *current* CURLYX block, the rules are:
+
+When executing CURLYX, save the old cur_curlyx in the CURLYX state block,
+and set cur_curlyx to point the new block.
+
+When popping the CURLYX block after a successful or unsuccessful match,
+restore the previous cur_curlyx.
+
+When WHILEM is about to execute B, save the current cur_curlyx, and set it
+to the outer one saved in the CURLYX block.
+
+When popping the WHILEM block after a successful or unsuccessful B match,
+restore the previous cur_curlyx.
+
+Here's an example for the pattern (AI* BI)*BO
+I and O refer to inner and outer, C and W refer to CURLYX and WHILEM:
+
+cur_
+curlyx backtrack stack
+------ ---------------
+NULL
+CO <CO prev=NULL> <WO>
+CI <CO prev=NULL> <WO> <CI prev=CO> <WI> ai
+CO <CO prev=NULL> <WO> <CI prev=CO> <WI> ai <WI prev=CI> bi
+NULL <CO prev=NULL> <WO> <CI prev=CO> <WI> ai <WI prev=CI> bi <WO prev=CO> bo
+
+At this point the pattern succeeds, and we work back down the stack to
+clean up, restoring as we go:
+
+CO <CO prev=NULL> <WO> <CI prev=CO> <WI> ai <WI prev=CI> bi
+CI <CO prev=NULL> <WO> <CI prev=CO> <WI> ai
+CO <CO prev=NULL> <WO>
+NULL
+
+*******************************************************************/
+
+#define ST st->u.curlyx
+
+ case CURLYX: /* start of /A*B/ (for complex A) */
+ {
+ /* No need to save/restore up to this paren */
+ I32 parenfloor = scan->flags;
+
+ assert(next); /* keep Coverity happy */
+ if (OP(PREVOPER(next)) == NOTHING) /* LONGJMP */
+ next += ARG(next);
+
+ /* XXXX Probably it is better to teach regpush to support
+ parenfloor > PL_regsize... */
+ if (parenfloor > (I32)*PL_reglastparen)
+ parenfloor = *PL_reglastparen; /* Pessimization... */
+
+ ST.prev_curlyx= cur_curlyx;
+ cur_curlyx = st;
+ ST.cp = PL_savestack_ix;
+
+ /* these fields contain the state of the current curly.
+ * they are accessed by subsequent WHILEMs */
+ ST.parenfloor = parenfloor;
+ ST.min = ARG1(scan);
+ ST.max = ARG2(scan);
+ ST.A = NEXTOPER(scan) + EXTRA_STEP_2ARGS;
+ ST.B = next;
+ ST.minmod = minmod;
+ minmod = 0;
+ ST.count = -1; /* this will be updated by WHILEM */
+ ST.lastloc = NULL; /* this will be updated by WHILEM */
+
+ PL_reginput = locinput;
+ PUSH_YES_STATE_GOTO(CURLYX_end, PREVOPER(next));