cvsuser     03/06/24 01:35:18

  Modified:    include/parrot stacks.h
               .        interpreter.c stacks.c sub.c
  Log:
  stack-limit
  
  Revision  Changes    Path
  1.29      +7 -2      parrot/include/parrot/stacks.h
  
  Index: stacks.h
  ===================================================================
  RCS file: /cvs/public/parrot/include/parrot/stacks.h,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -w -r1.28 -r1.29
  --- stacks.h  21 Jun 2003 09:22:43 -0000      1.28
  +++ stacks.h  24 Jun 2003 08:35:16 -0000      1.29
  @@ -1,7 +1,7 @@
   /* stacks.h
    *  Copyright: (When this is determined...it will go here)
    *  CVS Info
  - *     $Id: stacks.h,v 1.28 2003/06/21 09:22:43 leo Exp $
  + *     $Id: stacks.h,v 1.29 2003/06/24 08:35:16 leo Exp $
    *  Overview:
    *     Stack handling routines for Parrot
    *  Data Structure and Algorithms:
  @@ -16,6 +16,7 @@
   #include "parrot/parrot.h"
   
   #define STACK_CHUNK_DEPTH 256
  +#define STACK_CHUNK_LIMIT 100
   
   typedef struct Stack_Entry {
       union {
  @@ -34,12 +35,16 @@
       Stack_chunk_flags   flags;
       struct Stack_Chunk *next;
       struct Stack_Chunk *prev;
  +    struct Stack       *stack;
       Buffer *buffer;
   } Stack_Chunk_t;
   
   typedef struct Stack {
       Stack_Chunk_t * base;
       Stack_Chunk_t * top;
  +    int n_chunks;
  +    int chunk_limit;
  +    const char * name;
   } Stack_t;
   
   
  @@ -47,7 +52,7 @@
   
   #define STACK_CLEANUP_NULL ((Stack_cleanup_method)NULLfunc)
   
  -Stack_Chunk_t * new_stack(Interp *interpreter);
  +Stack_Chunk_t * new_stack(Interp *interpreter, const char *name);
   void stack_destroy(Stack_Chunk_t * top);
   
   Stack_Chunk_t * stack_copy(Interp *interpreter, Stack_Chunk_t *old_stack);
  
  
  
  1.161     +4 -4      parrot/interpreter.c
  
  Index: interpreter.c
  ===================================================================
  RCS file: /cvs/public/parrot/interpreter.c,v
  retrieving revision 1.160
  retrieving revision 1.161
  diff -u -w -r1.160 -r1.161
  --- interpreter.c     21 Jun 2003 09:22:40 -0000      1.160
  +++ interpreter.c     24 Jun 2003 08:35:18 -0000      1.161
  @@ -1,7 +1,7 @@
   /* interpreter.c
    *  Copyright: (When this is determined...it will go here)
    *  CVS Info
  - *     $Id: interpreter.c,v 1.160 2003/06/21 09:22:40 leo Exp $
  + *     $Id: interpreter.c,v 1.161 2003/06/24 08:35:18 leo Exp $
    *  Overview:
    *     The interpreter api handles running the operations
    *  Data Structure and Algorithms:
  @@ -543,15 +543,15 @@
       Parrot_clear_p(interpreter);
   
       /* Stack for lexical pads */
  -    interpreter->ctx.pad_stack = new_stack(interpreter);
  +    interpreter->ctx.pad_stack = new_stack(interpreter, "Pad");
   
       /* Need a user stack */
  -    interpreter->ctx.user_stack = new_stack(interpreter);
  +    interpreter->ctx.user_stack = new_stack(interpreter, "User");
       assert(interpreter->ctx.user_stack->buffer !=
               interpreter->ctx.pad_stack->buffer);
   
       /* And a control stack */
  -    interpreter->ctx.control_stack = new_stack(interpreter);
  +    interpreter->ctx.control_stack = new_stack(interpreter, "Control");
       assert(interpreter->ctx.control_stack->buffer !=
               interpreter->ctx.user_stack->buffer);
   
  
  
  
  1.55      +40 -22    parrot/stacks.c
  
  Index: stacks.c
  ===================================================================
  RCS file: /cvs/public/parrot/stacks.c,v
  retrieving revision 1.54
  retrieving revision 1.55
  diff -u -w -r1.54 -r1.55
  --- stacks.c  21 Jun 2003 09:22:40 -0000      1.54
  +++ stacks.c  24 Jun 2003 08:35:18 -0000      1.55
  @@ -1,7 +1,7 @@
   /* stacks.c
    *  Copyright: (When this is determined...it will go here)
    *  CVS Info
  - *     $Id: stacks.c,v 1.54 2003/06/21 09:22:40 leo Exp $
  + *     $Id: stacks.c,v 1.55 2003/06/24 08:35:18 leo Exp $
    *  Overview:
    *     Stack handling routines for Parrot
    *  Data Structure and Algorithms:
  @@ -15,40 +15,40 @@
    * References: */
   
   #include "parrot/parrot.h"
  +#include <assert.h>
   
   Stack_Chunk_t *
  -new_stack(Interp *interpreter)
  +new_stack(Interp *interpreter, const char *name)
   {
  -#ifdef TIDY
  -    int i;
  -    Stack_Entry_t *entry;
  -#endif
   
  -    Stack_Chunk_t *stack = mem_sys_allocate_zeroed(sizeof(Stack_Chunk_t));
  +    Stack_Chunk_t *chunk = mem_sys_allocate_zeroed(sizeof(Stack_Chunk_t));
  +    Stack_t *stack = mem_sys_allocate_zeroed(sizeof(Stack_t));
  +
  +    chunk->flags = NO_STACK_CHUNK_FLAGS;
  +    SET_NULL(chunk->next);
  +    SET_NULL(chunk->prev);
  +    SET_NULL(chunk->buffer);
  +    chunk->stack = stack;
  +    stack->top = stack->base = chunk;
  +    stack->n_chunks = 1;
  +    stack->chunk_limit = STACK_CHUNK_LIMIT;
  +    stack->name = name;
   
  -    stack->flags = NO_STACK_CHUNK_FLAGS;
  -    SET_NULL(stack->next);
  -    SET_NULL(stack->prev);
  -    SET_NULL(stack->buffer);
  -    stack->buffer = new_buffer_header(interpreter);
  +    chunk->buffer = new_buffer_header(interpreter);
   
       /* Block DOD from murdering our newly allocated stack->buffer. */
       Parrot_block_DOD(interpreter);
  -    Parrot_allocate(interpreter, stack->buffer,
  +    Parrot_allocate(interpreter, chunk->buffer,
                       sizeof(Stack_Entry_t) * STACK_CHUNK_DEPTH);
       Parrot_unblock_DOD(interpreter);
   
  -#ifdef TIDY
  -    entry = (Stack_Entry_t *)stack->buffer->bufstart;
  -    for (i = 0; i < STACK_CHUNK_DEPTH; i++)
  -        entry[i].flags = NO_STACK_ENTRY_FLAGS;
  -#endif
  -    return stack;
  +    return chunk;
   }
   
   void
   stack_destroy(Stack_Chunk_t * top)
   {
  +    mem_sys_free(top->stack);
       while (top->next)
           top = top->next;
       while(top) {
  @@ -73,13 +73,15 @@
   
   /* Returns the height of the stack.  The maximum "depth" is height - 1 */
   size_t
  -stack_height(Interp *interpreter, Stack_Chunk_t *stack)
  +stack_height(Interp *interpreter, Stack_Chunk_t *top)
   {
       Stack_Chunk_t *chunk;
  -    size_t height = stack->used;
  +    size_t height = top->used;
   
  -    for (chunk = stack->prev; chunk; chunk = chunk->prev)
  +    for (chunk = top->prev; chunk; chunk = chunk->prev)
           height += chunk->used;
  +    assert(height == (top->stack->n_chunks - 1) * STACK_CHUNK_DEPTH +
  +            top->used);
   
       return height;
   }
  @@ -95,6 +97,9 @@
       Stack_Chunk_t *new_chunk;
       Stack_Chunk_t *new_top = NULL;
       Stack_Chunk_t *last = NULL;
  +    Stack_t *stack = mem_sys_allocate_zeroed(sizeof(Stack_t));
  +    stack->n_chunks = 0;
  +    stack->name = old_top->stack->name;
       do {
           new_chunk = mem_sys_allocate(sizeof(Stack_Chunk_t));
           if (new_top == NULL) {
  @@ -123,8 +128,12 @@
           memcpy(new_chunk->buffer->bufstart, old_chunk->buffer->bufstart,
                  old_chunk->buffer->buflen);
           old_chunk = old_chunk->prev;
  +        stack->n_chunks++;
  +        stack->base = new_chunk;
       }
       while (old_chunk);
  +    new_top->stack = stack;
  +    stack->top = new_top;
       return new_top;
   }
   
  @@ -246,6 +255,11 @@
               SET_NULL(new_chunk->next);
               new_chunk->prev = chunk;
               chunk->next = new_chunk;
  +            new_chunk->stack = chunk->stack;
  +            new_chunk->stack->n_chunks++;
  +            if (new_chunk->stack->n_chunks == new_chunk->stack->chunk_limit)
  +                internal_exception(1, "Stack '%s' too deep\n",
  +                        chunk->stack->name);
               *stack_p = chunk = new_chunk;
               SET_NULL(new_chunk->buffer);
               new_chunk->buffer = new_buffer_header(interpreter);
  @@ -257,7 +271,9 @@
               /* Reuse the spare chunk we kept */
               chunk = chunk->next;
               *stack_p = chunk;
  +            chunk->stack->n_chunks++;
           }
  +        chunk->stack->top = chunk;
       }
   
       entry = (Stack_Entry_t *)(chunk->buffer->bufstart) + chunk->used;
  @@ -329,6 +345,8 @@
            * just emptied around for now in case we need it again. */
           chunk = chunk->prev;
           *stack_p = chunk;
  +        chunk->stack->top = chunk;
  +        chunk->stack->n_chunks--;
       }
   
       /* Quick sanity check */
  
  
  
  1.23      +5 -5      parrot/sub.c
  
  Index: sub.c
  ===================================================================
  RCS file: /cvs/public/parrot/sub.c,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -w -r1.22 -r1.23
  --- sub.c     21 Jun 2003 10:41:09 -0000      1.22
  +++ sub.c     24 Jun 2003 08:35:18 -0000      1.23
  @@ -1,7 +1,7 @@
   /*  sub.c
    *  Copyright: (When this is determined...it will go here)
    *  CVS Info
  - *     $Id: sub.c,v 1.22 2003/06/21 10:41:09 leo Exp $
  + *     $Id: sub.c,v 1.23 2003/06/24 08:35:18 leo Exp $
    *  Overview:
    *     Sub-routines, co-routines and other fun stuff...
    *  Data Structure and Algorithms:
  @@ -59,7 +59,7 @@
       struct Parrot_Closure *newsub =
           mem_sys_allocate(sizeof(struct Parrot_Closure));
       PMC * pad = scratchpad_get_current(interp);
  -    newsub->ctx.pad_stack = new_stack(interp);
  +    newsub->ctx.pad_stack = new_stack(interp, "Pad");
       if (pad) {
           /* put the correct pad in place */
           stack_push(interp, &newsub->ctx.pad_stack, pad,
  @@ -75,9 +75,9 @@
       PMC * pad = NULL;
       struct Parrot_Coroutine *newco =
           mem_sys_allocate(sizeof(struct Parrot_Coroutine));
  -    newco->ctx.user_stack = new_stack(interp);
  -    newco->ctx.control_stack = new_stack(interp);
  -    newco->ctx.pad_stack = new_stack(interp);
  +    newco->ctx.user_stack = new_stack(interp, "User");
  +    newco->ctx.control_stack = new_stack(interp, "Control");
  +    newco->ctx.pad_stack = new_stack(interp, "Pad");
   
       pad = scratchpad_get_current(interp);
   
  
  
  

Reply via email to