# New Ticket Created by "Sean O'Rourke"
# Please include the string: [perl #16935]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=16935 >
This adds the following two regex ops:
rx_stackdepth Ix -- Store the size of the regex stack in Ix
rx_stackchop Ix -- shorten the regex stack to have Ix entries
I found these useful in implementing explicit backtracking control, and
much better than the alternative, a bytecode loop popping entries and
counting marks.
Steve, others: do you find these useful?
/s
-- attachment 1 ------------------------------------------------------
url: http://rt.perl.org/rt2/attach/36335/29365/24afcb/stacks.patch
Index: rx.ops
===================================================================
RCS file: /cvs/public/parrot/rx.ops,v
retrieving revision 1.30
diff -p -u -w -r1.30 rx.ops
--- rx.ops 25 Aug 2002 00:20:22 -0000 1.30
+++ rx.ops 2 Sep 2002 15:51:14 -0000
@@ -209,6 +209,17 @@ op rx_clearstack () {
intstack_free(interpreter, interpreter->ctx.intstack);
goto NEXT();
}
+
+op rx_stackdepth (out int) {
+ $1 = intstack_depth(interpreter, interpreter->ctx.intstack);
+ goto NEXT();
+}
+
+op rx_stackchop (in int) {
+ intstack_chop(interpreter, interpreter->ctx.intstack, $1);
+ goto NEXT();
+}
+
########################################
=item C<rx_pushmark>(in pmc)
Index: rxstacks.c
===================================================================
RCS file: /cvs/public/parrot/rxstacks.c,v
retrieving revision 1.8
diff -p -u -w -r1.8 rxstacks.c
--- rxstacks.c 22 Aug 2002 20:08:24 -0000 1.8
+++ rxstacks.c 2 Sep 2002 15:51:14 -0000
@@ -101,6 +101,27 @@ intstack_pop(struct Parrot_Interp *inter
return entry->value;
}
+void intstack_chop (struct Parrot_Interp *interpreter, IntStack stack,
+ INTVAL n)
+{
+ INTVAL depth = intstack_depth(interpreter, stack);
+ IntStack_Chunk chunk = stack->prev;
+ IntStack_Entry entry;
+
+ if (depth < n) {
+ internal_exception(ERROR_STACK_EMPTY, "popn: stack underflow\n");
+ }
+ while (depth - chunk->used > n) {
+ depth -= chunk->used;
+ if (chunk->next != stack) {
+ chunk->next = stack;
+ }
+
+ chunk = chunk->prev;
+ stack->prev = chunk;
+ }
+ chunk->used -= depth - n;
+}
void intstack_free (struct Parrot_Interp *interpreter, IntStack stack)
{
Index: include/parrot/rxstacks.h
===================================================================
RCS file: /cvs/public/parrot/include/parrot/rxstacks.h,v
retrieving revision 1.4
diff -p -u -w -r1.4 rxstacks.h
--- include/parrot/rxstacks.h 22 Aug 2002 20:08:59 -0000 1.4
+++ include/parrot/rxstacks.h 2 Sep 2002 15:51:14 -0000
@@ -37,6 +37,8 @@ INTVAL intstack_depth(struct Parrot_Inte
void intstack_push(struct Parrot_Interp *, IntStack, INTVAL);
INTVAL intstack_pop(struct Parrot_Interp *, IntStack);
+void intstack_chop(struct Parrot_Interp *interpreter, IntStack stack,
+ INTVAL n);
void intstack_free(struct Parrot_Interp *, IntStack);