home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Moscow ML 1.31 / source code / mosml / src / runtime / roots.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-03  |  979 b   |  44 lines  |  [TEXT/R*ch]

  1. /* To walk the memory roots for garbage collection */
  2.  
  3. #include "debugger.h"
  4. #include "memory.h"
  5. #include "misc.h"
  6. #include "mlvalues.h"
  7. #include "stacks.h"
  8.  
  9. void local_roots (copy_fn)
  10.      void (*copy_fn) ();
  11. {
  12.   register value *sp;
  13.   register int i;
  14.  
  15.   /* argument stack */
  16.   for (sp = extern_asp; sp < arg_stack_high; sp++) {
  17.     if (*sp != MARK) copy_fn (sp, *sp);
  18.   }
  19.  
  20.   /* return stack */
  21.   for (sp = extern_rsp; sp < ret_stack_high; ) {
  22.     copy_fn (&((struct return_frame *) sp)->env,
  23.          ((struct return_frame *) sp)->env);
  24.     i = ((struct return_frame *) sp)->cache_size;
  25.     sp = (value *) ((char *) sp + sizeof(struct return_frame));
  26.     while (i > 0) {
  27.       Assert (sp < ret_stack_high);
  28.       copy_fn (sp, *sp);
  29.       sp++;
  30.       i--;
  31.     }
  32.   }
  33.  
  34.   /* C roots */
  35.   {
  36.     value *block;
  37.     for (block = c_roots_head; block != NULL; block = (value *) block [1]){
  38.       for (sp = block - (long) block [0]; sp < block; sp++){
  39.     copy_fn (sp, *sp);
  40.       }
  41.     }
  42.   }
  43. }
  44.