home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / src / !runtime / memory.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-18  |  2.8 KB  |  83 lines  |  [TEXT/R*ch]

  1. /* Allocation macros and functions */
  2.  
  3. #ifndef _memory_
  4. #define _memory_
  5.  
  6.  
  7. #include "config.h"
  8. #include "gc.h"
  9. #include "major_gc.h"
  10. #include "minor_gc.h"
  11. #include "misc.h"
  12. #include "mlvalues.h"
  13.  
  14. extern value *c_roots_head;
  15.  
  16. void init_c_roots P((void));
  17. value alloc_shr P((mlsize_t, tag_t));
  18. void adjust_gc_speed P((mlsize_t, mlsize_t));
  19. void modify P((value *, value));
  20. void initialize P((value *, value));
  21. char * stat_alloc P((asize_t));                 /* Size in bytes. */
  22. void stat_free P((char *));
  23. char * stat_resize P((char *, asize_t));     /* Size in bytes. */
  24.  
  25.  
  26. #define Alloc_small(result, wosize, tag) {                      \
  27.   char *_res_ = young_ptr;                              \
  28.   young_ptr += Bhsize_wosize (wosize);                          \
  29.   if (young_ptr > young_end){                              \
  30.     Setup_for_gc;                                  \
  31.     minor_collection ();                              \
  32.     Restore_after_gc;                                  \
  33.     _res_ = young_ptr;                                  \
  34.     young_ptr += Bhsize_wosize (wosize);                      \
  35.   }                                          \
  36.   Hd_hp (_res_) = Make_header ((wosize), (tag), Black);                  \
  37.   (result) = Val_hp (_res_);                              \
  38. }
  39.  
  40. /* You must use [Modify] to change a field of an existing shared block,
  41.    unless you are sure the value being overwritten is not a shared block and
  42.    the value being written is not a young block. */
  43. /* [Modify] never calls the GC. */
  44. #define Modify(fp, val) {                              \
  45.   value _old_ = *(fp);                                  \
  46.   *(fp) = (val);                                  \
  47.   if (Is_in_heap (fp)){                                  \
  48.     if (gc_phase == Phase_mark) darken (_old_);                      \
  49.     if (Is_block (val) && Is_young (val)                      \
  50.     && ! (Is_block (_old_) && Is_young (_old_))){                  \
  51.       *ref_table_ptr++ = (fp);                              \
  52.       if (ref_table_ptr >= ref_table_limit){                      \
  53.         Assert (ref_table_ptr == ref_table_limit);                  \
  54.     realloc_ref_table ();                              \
  55.       }                                          \
  56.     }                                          \
  57.   }                                          \
  58. }
  59.  
  60. /* [Push_roots] and [Pop_roots] are used for C variables that are GC roots.
  61.  * It must contain all values in C local variables at the time the minor GC is
  62.  * called.
  63.  * Usage:
  64.  * At the end of the declarations of your C local variables, add
  65.  * [ Push_roots (variable_name, size); ]
  66.  * The size is the number of declared roots.  They are accessed as
  67.  * [ variable_name [0] ... variable_name [size - 1] ].
  68.  * The [variable_name] and the [size] must not be [ _ ].
  69.  * Just before the function return, add a call to [Pop_roots].
  70.  */
  71.  
  72. #define Push_roots(name, size)                              \
  73.    value name [(size) + 2];                              \
  74.    { long _; for (_ = 0; _ < (size); name [_++] = Val_long (0)); }          \
  75.    name [(size)] = (value) (size);                          \
  76.    name [(size) + 1] = (value) c_roots_head;                      \
  77.    c_roots_head = &(name [(size)]);
  78.  
  79. #define Pop_roots() {c_roots_head = (value *) c_roots_head [1]; }
  80.  
  81.  
  82. #endif /* _memory_ */
  83.