About two weeks ago, Dan asked me to modify Parrot so that the regex
engine's high-speed integer stacks could be used by anyone.  Since then
I've been busy with all sorts of school-related nonsense, but I finally
got a break tonight long enough to implement this.

The attached patch adds three new opcodes: intsave, intrestore, and
intdepth.  It also adds a new test.

Though the files are still rxstacks.c and rxstacks.h, the data structure
is IntStack and the functions are prefixed with intstack_.  I would have
renamed the files, but CVS doesn't handle that situation very well.

Share and enjoy.

--Brent Dax <[EMAIL PROTECTED]>
@roles=map {"Parrot $_"} qw(embedding regexen Configure)

blink:  Text blinks (alternates between visible and invisible).
Conforming user agents are not required to support this value.
    --The W3C CSS-2 Specification
Index: core.ops
===================================================================
RCS file: /home/perlcvs/parrot/core.ops,v
retrieving revision 1.135
diff -u -r1.135 core.ops
--- core.ops    12 May 2002 04:37:57 -0000      1.135
+++ core.ops    14 May 2002 07:34:41 -0000
@@ -2657,11 +2657,48 @@
   goto NEXT();
 }
 
+########################################
 
-=back
+=item B<intsave>(in INT)
+
+Save register or constant $1 onto the high-speed int stack.
+
+=cut
+
+inline op intsave(in INT) {
+  intstack_push(interpreter, interpreter->intstack, $1);
+  goto NEXT();
+}
+
+########################################
+
+=item B<intrestore>(out INT)
+
+Restore register $1 from the high-speed int stack.
+
+=cut
+
+inline op intrestore(out INT) {
+  $1=intstack_pop(interpreter, interpreter->intstack);
+  goto NEXT();
+}
+
+########################################
+
+=item B<intdepth>(out INT)
+
+Puts the depth of the high-speed int stack in $1.
 
 =cut
 
+inline op intdepth(out INT) {
+  $1=intstack_depth(interpreter, interpreter->intstack);
+  goto NEXT();
+}
+
+=back
+
+=cut
 
 ###############################################################################
 
Index: interpreter.c
===================================================================
RCS file: /home/perlcvs/parrot/interpreter.c,v
retrieving revision 1.85
diff -u -r1.85 interpreter.c
--- interpreter.c       11 May 2002 20:20:05 -0000      1.85
+++ interpreter.c       14 May 2002 07:34:42 -0000
@@ -581,6 +581,9 @@
     /* And a control stack */
     interpreter->control_stack = new_stack(interpreter);
 
+    /* A regex stack would be nice too. */
+    interpreter->intstack = intstack_new(interpreter);
+
     /* Load the core op func and info tables */
     interpreter->op_lib = PARROT_CORE_OPLIB_INIT();
     interpreter->op_count = interpreter->op_lib->op_count;
Index: rx.c
===================================================================
RCS file: /home/perlcvs/parrot/rx.c,v
retrieving revision 1.13
diff -u -r1.13 rx.c
--- rx.c        28 Mar 2002 08:02:02 -0000      1.13
+++ rx.c        14 May 2002 07:34:43 -0000
@@ -41,7 +41,7 @@
     rx->groupstart = pmc_new(interpreter, enum_class_PerlArray);
     rx->groupend = pmc_new(interpreter, enum_class_PerlArray);
 
-    rx->stack = rxstack_new(interpreter);
+    rx->stack = intstack_new(interpreter);
 
     string_transcode(interpreter, rx->string, encoding_lookup("utf32"),
                      rx->string->type, &rx->string);
Index: rx.ops
===================================================================
RCS file: /home/perlcvs/parrot/rx.ops,v
retrieving revision 1.18
diff -u -r1.18 rx.ops
--- rx.ops      19 Apr 2002 01:32:40 -0000      1.18
+++ rx.ops      14 May 2002 07:34:44 -0000
@@ -225,8 +225,8 @@
        rx->minlength=0;
        rx->whichway=enum_rxdirection_forwards;
        
-       while(rxstack_depth(interpreter, rx->stack)) {
-               (void)rxstack_pop(interpreter, rx->stack);
+       while(intstack_depth(interpreter, rx->stack)) {
+               (void)intstack_pop(interpreter, rx->stack);
        }
        
        rx->string=$2;
@@ -274,7 +274,7 @@
        rx2=mem_sys_allocate(sizeof(rxinfo));
        *rx2=*rx;
        
-       rx2->stack=rxstack_new(interpreter);
+       rx2->stack=intstack_new(interpreter);
 
        $1=pmc_new(interpreter, enum_class_ParrotPointer);
        $1->data=rx2;
@@ -404,7 +404,7 @@
 op rx_pushindex(in pmc) {
        RX_dUNPACK($1);
 
-       rxstack_push(interpreter, rx->stack, rx->index);
+       intstack_push(interpreter, rx->stack, rx->index);
        
        goto NEXT();
 }
@@ -421,7 +421,7 @@
 op rx_pushmark(in pmc) {
        RX_dUNPACK($1);
 
-       rxstack_push(interpreter, rx->stack, RX_MARK);
+       intstack_push(interpreter, rx->stack, RX_MARK);
        
        goto NEXT();
 }
@@ -439,7 +439,7 @@
        RX_dUNPACK($1);
        INTVAL i;
        
-       i=rxstack_pop(interpreter, rx->stack);
+       i=intstack_pop(interpreter, rx->stack);
 
        if(i==RX_MARK) {
                goto OFFSET($2);
@@ -530,8 +530,8 @@
 
        rx->index=rx->startindex;
        
-       while(rxstack_depth(interpreter, rx->stack)) {
-               (void)rxstack_pop(interpreter, rx->stack);
+       while(intstack_depth(interpreter, rx->stack)) {
+               (void)intstack_pop(interpreter, rx->stack);
        }
        
        goto NEXT();
Index: rxstacks.c
===================================================================
RCS file: /home/perlcvs/parrot/rxstacks.c,v
retrieving revision 1.3
diff -u -r1.3 rxstacks.c
--- rxstacks.c  1 Apr 2002 04:35:14 -0000       1.3
+++ rxstacks.c  14 May 2002 07:34:44 -0000
@@ -16,10 +16,10 @@
 
 #define STACK_CHUNK_BASE(x) (void *)(MASK_STACK_CHUNK_LOW_BITS & (ptrcast_t)x)
 
-rxStack
-rxstack_new(struct Parrot_Interp *interpreter)
+IntStack
+intstack_new(struct Parrot_Interp *interpreter)
 {
-    rxStack stack = mem_allocate_aligned(sizeof(struct rxStack_chunk_t));
+    IntStack stack = mem_allocate_aligned(sizeof(struct IntStack_chunk_t));
     stack->used = 0;
     stack->next = stack;
     stack->prev = stack;
@@ -27,9 +27,9 @@
 }
 
 INTVAL
-rxstack_depth(struct Parrot_Interp *interpreter, rxStack stack)
+intstack_depth(struct Parrot_Interp *interpreter, IntStack stack)
 {
-    rxStack_Chunk chunk;
+    IntStack_Chunk chunk;
     INTVAL depth = stack->used;
 
     for (chunk = stack->next; chunk != stack; chunk = chunk->next)
@@ -39,17 +39,17 @@
 }
 
 void
-rxstack_push(struct Parrot_Interp *interpreter, rxStack stack, INTVAL data)
+intstack_push(struct Parrot_Interp *interpreter, IntStack stack, INTVAL data)
 {
-    rxStack_Chunk chunk = stack->prev;
-    rxStack_Entry entry = &chunk->entry[chunk->used];
+    IntStack_Chunk chunk = stack->prev;
+    IntStack_Entry entry = &chunk->entry[chunk->used];
 
     entry->value = data;
 
     /* Register the new entry */
     if (++chunk->used == STACK_CHUNK_DEPTH) {
         /* Need to add a new chunk */
-        rxStack_Chunk new_chunk = mem_allocate_aligned(sizeof(*new_chunk));
+        IntStack_Chunk new_chunk = mem_allocate_aligned(sizeof(*new_chunk));
         new_chunk->used = 0;
         new_chunk->next = stack;
         new_chunk->prev = chunk;
@@ -59,10 +59,10 @@
 }
 
 INTVAL
-rxstack_pop(struct Parrot_Interp *interpreter, rxStack stack)
+intstack_pop(struct Parrot_Interp *interpreter, IntStack stack)
 {
-    rxStack_Chunk chunk = stack->prev;
-    rxStack_Entry entry;
+    IntStack_Chunk chunk = stack->prev;
+    IntStack_Entry entry;
 
     /* We may have an empty chunk at the end of the list */
     if (chunk->used == 0 && chunk != stack) {
Index: include/parrot/interpreter.h
===================================================================
RCS file: /home/perlcvs/parrot/include/parrot/interpreter.h,v
retrieving revision 1.42
diff -u -r1.42 interpreter.h
--- include/parrot/interpreter.h        11 May 2002 20:19:52 -0000      1.42
+++ include/parrot/interpreter.h        14 May 2002 07:34:48 -0000
@@ -40,6 +40,8 @@
 #include "parrot/op.h"
 #include "parrot/oplib.h"
 
+#include "parrot/rxstacks.h"
+
 typedef struct warnings_t {
     Warnings_classes classes;
 } *Warnings;
@@ -71,8 +73,11 @@
     struct NRegChunk *num_reg_base;     /* Base of the float reg stack */
     struct SRegChunk *string_reg_base;  /* Base of the string stack */
     struct PRegChunk *pmc_reg_base;     /* Base of the PMC stack */
+
     struct stack_chunk *user_stack;     /* Base of the scratch stack */
     struct stack_chunk *control_stack;  /* Base of the flow control stack */
+    IntStack intstack;                  /* Base of the regex stack */
+
     struct Stash *perl_stash;           /* Pointer to the global variable
                                          * area */
     struct Scratchpad *cur_pad;         /* The current scratchpad */
Index: include/parrot/rx.h
===================================================================
RCS file: /home/perlcvs/parrot/include/parrot/rx.h,v
retrieving revision 1.16
diff -u -r1.16 rx.h
--- include/parrot/rx.h 4 Mar 2002 03:38:23 -0000       1.16
+++ include/parrot/rx.h 14 May 2002 07:34:48 -0000
@@ -63,7 +63,7 @@
 
     opcode_t *substfunc;
 
-    rxStack stack;
+    IntStack stack;
 } rxinfo;
 
 
Index: include/parrot/rxstacks.h
===================================================================
RCS file: /home/perlcvs/parrot/include/parrot/rxstacks.h,v
retrieving revision 1.2
diff -u -r1.2 rxstacks.h
--- include/parrot/rxstacks.h   4 Mar 2002 03:17:21 -0000       1.2
+++ include/parrot/rxstacks.h   14 May 2002 07:34:48 -0000
@@ -17,26 +17,26 @@
 
 #define STACK_CHUNK_DEPTH 256
 
-typedef struct rxStack_entry_t {
+typedef struct IntStack_entry_t {
     INTVAL value;
-} *rxStack_Entry;
+} *IntStack_Entry;
 
-typedef struct rxStack_chunk_t {
+typedef struct IntStack_chunk_t {
     INTVAL used;
-    struct rxStack_chunk_t *next;
-    struct rxStack_chunk_t *prev;
-    struct rxStack_entry_t entry[STACK_CHUNK_DEPTH];
-} *rxStack_Chunk;
+    struct IntStack_chunk_t *next;
+    struct IntStack_chunk_t *prev;
+    struct IntStack_entry_t entry[STACK_CHUNK_DEPTH];
+} *IntStack_Chunk;
 
-typedef rxStack_Chunk rxStack;
+typedef IntStack_Chunk IntStack;
 
-rxStack rxstack_new(struct Parrot_Interp *);
+IntStack intstack_new(struct Parrot_Interp *);
 
-INTVAL rxstack_depth(struct Parrot_Interp *, rxStack);
+INTVAL intstack_depth(struct Parrot_Interp *, IntStack);
 
-void rxstack_push(struct Parrot_Interp *, rxStack, INTVAL);
+void intstack_push(struct Parrot_Interp *, IntStack, INTVAL);
 
-INTVAL rxstack_pop(struct Parrot_Interp *, rxStack);
+INTVAL intstack_pop(struct Parrot_Interp *, IntStack);
 
 #endif
 
Index: t/op/stacks.t
===================================================================
RCS file: /home/perlcvs/parrot/t/op/stacks.t,v
retrieving revision 1.14
diff -u -r1.14 stacks.t
--- t/op/stacks.t       17 Apr 2002 21:19:16 -0000      1.14
+++ t/op/stacks.t       14 May 2002 07:34:54 -0000
@@ -1,6 +1,6 @@
 #! perl -w
 
-use Parrot::Test tests => 28;
+use Parrot::Test tests => 29;
 use Test::More;
 
 # Tests for stack operations, currently push*, push_*_c and pop*
@@ -588,6 +588,38 @@
 Stack Depth Wrong
 OUTPUT
 }
+
+output_is(<<'CODE', <<'OUTPUT', "intstack");
+       intsave -1
+       intsave 0
+       intsave 1
+       intsave 2
+       intsave 3
+       set I0, 4
+       intsave I0
+       
+       intrestore I1
+       print I1
+       
+       intrestore I1
+       print I1
+       
+       intrestore I1
+       print I1
+       
+       intrestore I1
+       print I1
+       
+       intrestore I1
+       print I1
+       
+       intrestore I1
+       print I1
+
+       print "\n"
+CODE
+43210-1
+OUTPUT
 
 ##############################
 

Reply via email to