Hello,

our team is working on a large compiler project using ghc and hugs. In the
recent months we have not been able to run our compiler with the standard
hugs on larger input files due to the limited control stack.

As far as we know there is no possibility to set the size of the control
stack when calling hugs. Therefore, one member of our team modified hugs
in a way that the size of the control stack is doubled dynamically when
needed.

We feel that it is not good if such changes have to be made
individually and therefore suggest that hugs can be given an additional
parameter to change the size of the control stack, or maybe, even a
parameter to allow for a dynamic increase of the control stack.

In the appendix, I send you his changes to the new hugs release.

Sincerely
Christoph
----------------------------------------------------------------------
 Christoph Herrmann
 E-mail:  [EMAIL PROTECTED]
 WWW:     http://brahms.fmi.uni-passau.de/cl/staff/herrmann.html
----------------------------------------------------------------------
We have changed our local hugs-1.4-June-distribution to

 - give a control-stack-size (-c<Num>) at start-up
   like the heap-size (-h<Num>)
 - dynamically increase the control-stack,
   if the given (or default) value was too optimistic

We want to present a "diff -rcs" to the original
June-distribution, so that a "patch <thisDiff" in the src-directory
will restore the changes, we have made.
---------------------------------------------------------------------

------------------ patch <contents of the following -----------------
diff -rcs ./hugs.c ../b/hugs.c
*** ./hugs.c    Mon Jul 13 12:28:02 1998
--- ../b/hugs.c Fri Jul 10 11:33:36 1998
***************
*** 98,103 ****
--- 98,106 ----
  static Bool   chaseImports = TRUE;      /* TRUE => chase imports on
load   */
  static Bool   useDots      = RISCOS;    /* TRUE => use dots in
progress    */
  static Bool   quiet        = FALSE;     /* TRUE => don't show
progress     */
+ #if EXTENSION
+ int         NumStack     = NUM_STACK;
+ #endif
  
  static String scriptName[NUM_SCRIPTS];  /* Script file
names               */
  static Time   lastChange[NUM_SCRIPTS];  /* Time of last change to
script   */
***************
*** 225,230 ****
--- 228,236 ----
              addScriptName(argv[i],TRUE);
        }
      }
+ #if EXTENSION
+     printf("Control stack has %d cells.\n\n",NumStack);
+ #endif
      scriptName[0] = strCopy(findMPathname(NULL,STD_PRELUDE));
      if (!scriptName[0]) {
          Printf("Prelude not found on current path: \"%s\"\n",
***************
*** 468,473 ****
--- 474,486 ----
  
              case 'h' : setHeapSize(s+1);
                       return TRUE;
+ 
+ #if EXTENSION
+           case 'c' : NumStack = argToInt(s+1);
+                      if( NumStack < 2048 )
+                          NumStack = 2048;
+                      return TRUE;
+ #endif
  
              default  : toggleSet(*s,state);
                         break;
diff -rcs ./prelude.h ../b/prelude.h
*** ./prelude.h Mon Jul 13 12:27:57 1998
--- ../b/prelude.h      Fri Jul 10 11:35:21 1998
***************
*** 122,127 ****
--- 122,129 ----
  
  #define SHORT_CIRCUIT_COERCIONS 1
  
+ #define EXTENSION       1
/*                                               */
+ 
 
/*---------------------------------------------------------------------------
   * Platform-dependent settings:
  
*-------------------------------------------------------------------------*/
diff -rcs ./storage.c ../b/storage.c
*** ./storage.c Mon Jul 13 12:27:49 1998
--- ../b/storage.c      Fri Jul 10 11:42:52 1998
***************
*** 992,998 ****
   * operations are defined as macros, expanded inline.
   *
------------------------------------------------------------------------*/
  
! Cell DEFTABLE(cellStack,NUM_STACK); /* Storage for cells on
stack          */
  #ifndef  GLOBALsp
  StackPtr sp;                        /* stack
pointer                       */
  #endif
--- 992,1002 ----
   * operations are defined as macros, expanded inline.
   *
------------------------------------------------------------------------*/
  
! #if EXTENSION
! Cell    *cellStack = NULL;
! #else
! Cell     DEFTABLE(cellStack,NUM_STACK);/* Storage for cells on
stack       */
! #endif
  #ifndef  GLOBALsp
  StackPtr sp;                        /* stack
pointer                       */
  #endif
***************
*** 2802,2808 ****
   * storage control:
   *
------------------------------------------------------------------------*/
  
! #if DYN_TABLES
  static void far* safeFarCalloc Args((Int,Int));
  static void far* safeFarCalloc(n,s)     /* allocate table storage and
check*/
  Int n, s; {                             /* for non-null
return             */
--- 2806,2812 ----
   * storage control:
   *
------------------------------------------------------------------------*/
  
! #if (DYN_TABLES || EXTENSION)
  static void far* safeFarCalloc Args((Int,Int));
  static void far* safeFarCalloc(n,s)     /* allocate table storage and
check*/
  Int n, s; {                             /* for non-null
return             */
***************
*** 2813,2818 ****
--- 2817,2824 ----
      }
      return tab;
  }
+ #endif
+ #if DYN_TABLES
  #define TABALLOC(v,t,n)                 v=(t
far*)safeFarCalloc(n,sizeof(t));
  #else
  #define TABALLOC(v,t,n)
***************
*** 3005,3011 ****
--- 3011,3021 ----
                       TABALLOC(nameHash,  Name,             NAMEHSZ)
                       TABALLOC(tabName,   struct strName,   NUM_NAME)
                       TABALLOC(tabClass,  struct strClass, 
NUM_CLASSES)
+ #if EXTENSION
+                        cellStack = (Cell *)safeFarCalloc(NumStack,
sizeof(Cell
)       );
+ #else
                       TABALLOC(cellStack, Cell,             NUM_STACK)
+ #endif
                       TABALLOC(tabModule, struct Module,   
NUM_SCRIPTS)
  #if TREX
                       TABALLOC(tabExt,    Text,             NUM_EXT)
***************
*** 3077,3079 ****
--- 3087,3117 ----
  }
  
 
/*-------------------------------------------------------------------------*/
+ 
+ #if EXTENSION
+ void chkStack(Int n)
+ {
+   if( sp>=NumStack-n )
+   {
+     Cell *tmp_cellStack;
+     int   new_size    = 2*NumStack;
+     Cell *del_cellStack = cellStack;
+ 
+     if( MAX_STACK_SIZE && NumStack >= MAX_STACK_SIZE )
+       stackOverflow();
+ 
+     if( MAX_STACK_SIZE && new_size  > MAX_STACK_SIZE )
+       new_size  = MAX_STACK_SIZE;
+ 
+     printf("\nIncreasing control stack to %d cells.\n", new_size);
+     fflush(stdout);
+ 
+     tmp_cellStack = (Cell *)safeFarCalloc( new_size, sizeof(Cell) );
+ 
+     cellStack = (Cell *) memcpy(tmp_cellStack, cellStack,
NumStack*sizeof(Cell
) 
+ );
+     free(del_cellStack);
+     NumStack = new_size;
+   }
+ }
+ #endif
diff -rcs ./storage.h ../b/storage.h
*** ./storage.h Mon Jul 13 12:27:49 1998
--- ../b/storage.h      Fri Jul 10 11:46:32 1998
***************
*** 787,793 ****
   *     For example, "push(1+pop());" doesn't increment TOS.
   *
------------------------------------------------------------------------*/
  
! extern  Cell DECTABLE(cellStack);
  #ifdef  GLOBALsp
  register StackPtr    sp GLOBALsp;
  #else
--- 787,801 ----
   *     For example, "push(1+pop());" doesn't increment TOS.
   *
------------------------------------------------------------------------*/
  
! #if EXTENSION
! extern  int   NumStack;
! extern  Cell *cellStack;
! void    chkStack();
! #define MAX_STACK_SIZE 128000
! #else
! extern        Cell         DECTABLE(cellStack);
! #define chkStack(n)  if (sp>=NUM_STACK-(n)) stackOverflow()
! #endif
  #ifdef  GLOBALsp
  register StackPtr    sp GLOBALsp;
  #else
***************
*** 797,803 ****
  #define clearStack() sp=(-1)
  #define stackEmpty() (sp==(-1))
  #define stack(p)     cellStack[p]
- #define chkStack(n)  if (sp>=NUM_STACK-(n)) stackOverflow()
  #define push(c)      \
    do {               \
      chkStack(1);     \
--- 805,810 ----

Reply via email to