On Fri, Oct 25, 2002 at 01:01:16PM +0100, Nicholas Clark wrote:

> What is wrong with any of
> 
> 1: Duplicating the above loop (which isn't large), one for upwards stack,
>    the other for downwards stack, and switching (outside) between the two
>    based on an if statement on a global stack direction variable.

Here is what I suggested in a previous email. Always walk the stack in the same
direction, regardless of the direction in which it grows. PARROT_STACK_DIR is
not used.

Non-contiguous stack systems will have to use an entirely different version of
the stack walking function. This is left as an exercise for the reader.

-- 
Jason
Index: dod.c
===================================================================
RCS file: /cvs/public/parrot/dod.c,v
retrieving revision 1.24
diff -u -r1.24 dod.c
--- dod.c       23 Oct 2002 05:27:01 -0000      1.24
+++ dod.c       25 Oct 2002 21:55:24 -0000
@@ -460,7 +460,7 @@
 {
     size_t lo_var_ptr = (size_t)interpreter->lo_var_ptr;
     size_t hi_var_ptr = (size_t)&lo_var_ptr;
-    size_t prefix;
+    size_t prefix, tmp_ptr;
     ptrdiff_t cur_var_ptr;
 
     size_t buffer_min = get_min_buffer_address(interpreter);
@@ -471,6 +471,12 @@
     size_t mask = find_common_mask(buffer_min < pmc_min ? buffer_min: pmc_min,
                 buffer_max > pmc_max ? buffer_max : pmc_max);
 
+    if(lo_var_ptr > hi_var_ptr){
+        tmp_ptr = hi_var_ptr;
+        hi_var_ptr = lo_var_ptr;
+        lo_var_ptr = tmp_ptr;
+    }
+
     /* Get the expected prefix */
     prefix = mask & buffer_min;
 
@@ -478,10 +484,8 @@
         return last;
     
     for (cur_var_ptr = lo_var_ptr;
-        (ptrdiff_t)(cur_var_ptr * PARROT_STACK_DIR) < 
-            (ptrdiff_t)(hi_var_ptr * PARROT_STACK_DIR);
-        cur_var_ptr = (size_t)( (ptrdiff_t)cur_var_ptr + 
-            PARROT_STACK_DIR * PARROT_PTR_ALIGNMENT )
+        cur_var_ptr < hi_var_ptr;
+        cur_var_ptr = (size_t)((ptrdiff_t)cur_var_ptr + PARROT_PTR_ALIGNMENT)
          ) {
         size_t ptr = *(size_t *)cur_var_ptr;
 

Reply via email to