Cyclone Scheme  0.28.0
types.h
Go to the documentation of this file.
1 /*
2  * Cyclone Scheme
3  * Copyright (c) 2014, Justin Ethier
4  * All rights reserved.
5  *
6  * This file contains C types used by compiled programs.
7  */
8 
9 #ifndef CYCLONE_TYPES_H
10 #define CYCLONE_TYPES_H
11 
12 #include <math.h>
13 #include <complex.h>
14 #include <setjmp.h>
15 #include <stdarg.h>
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <time.h>
20 #include <pthread.h>
21 #include <stdint.h>
22 #include <dlfcn.h>
23 #include "cyclone/bignum.h"
24 
25 #ifdef CYC_HIGH_RES_TIMERS
26 
30 long long hrt_get_current();
31 long long hrt_cmp_current(long long tstamp);
32 void hrt_log_delta(const char *label, long long tstamp);
34 #endif
35 
40 typedef void *object;
41 
48 enum object_tag {
52  , macro_tag = 3 // Keep closures here for quick type checking
57  , cvar_tag = 8
58  , double_tag = 9
59  , eof_tag = 10
60  , forward_tag = 11
61  , integer_tag = 12
62  , bignum_tag = 13
63  , mutex_tag = 14
64  , pair_tag = 15
65  , port_tag = 16
67  , string_tag = 18
68  , symbol_tag = 19
69  , vector_tag = 20
71  , atomic_tag = 22
72  , void_tag = 23
73  , record_tag = 24
74 };
75 
79 #define obj_is_not_closure(obj) \
80  ((obj == NULL) || is_value_type(obj) || (type_of(obj) > macro_tag))
81 
86 typedef unsigned char tag_type;
87 
92 #define type_of(obj) (((pair_type *) obj)->tag)
93 
112 // Parameters for size of a "page" on the heap (the second generation GC), in bytes.
114 
116 #define GROW_HEAP_BY_SIZE (2 * 1024 * 1024)
117 
119 #define INITIAL_HEAP_SIZE (3 * 1024 * 1024)
120 
122 #define HEAP_SIZE (8 * 1024 * 1024)
123 
124 // End heap page size parameters
126 
128 // Major GC tuning parameters
129 
131 #define GC_COLLECTION_THRESHOLD 0.0125 //0.05
132 
134 #define GC_COLLECT_UNDER_UNSWEPT_HEAP_COUNT 3
135 
137 #define GC_FREE_THRESHOLD 0.40
138 // END GC tuning
140 
142 #define MAX_STACK_TRACES 10
143 
145 #define DEBUG_SHOW_DIAG 0
146 
148 #define GC_DEBUG_SHOW_SWEEP_DIAG 0
149 
151 #define GC_DEBUG_TRACE 0
152 
154 #define GC_DEBUG_VERBOSE 0
155 
161 #define GC_SAFETY_CHECKS 0
162 
164 #define NANOSECONDS_PER_MILLISECOND 1000000
165 
166 /* GC data structures */
167 
186 typedef enum {
187  HEAP_SM = 0 // 32 byte objects (min gc_heap_align)
190  , HEAP_REST // Everything else
191  , HEAP_HUGE // Huge objects, 1 per page
192 } gc_heap_type;
193 
195 #if INTPTR_MAX == INT64_MAX
196 #define LAST_FIXED_SIZE_HEAP_TYPE HEAP_96
197 #else
198 #define LAST_FIXED_SIZE_HEAP_TYPE HEAP_64
199 #endif
200 
202 #define NUM_HEAP_TYPES (HEAP_HUGE + 1)
203 
209  unsigned int size;
211 };
212 
222 typedef struct gc_heap_t gc_heap;
223 struct gc_heap_t {
226  unsigned int size;
228  unsigned int ttl;
230  unsigned int remaining;
232  unsigned block_size;
234  unsigned int free_size;
236  unsigned char is_full;
238  unsigned char is_unswept;
242  unsigned int last_alloc_size;
248  gc_heap *next; // TBD, linked list is not very efficient, but easy to work with as a start
250  char *data;
252  char *data_end;
253 };
254 
261 };
262 
268  unsigned char mark; // mark bits
269  unsigned char grayed:1; // stack object to be grayed when moved to heap
270  unsigned char immutable:1; // Flag normally mutable obj (EG: pair) as read-only
271 };
272 
274 #define mark(x) (((list) x)->hdr.mark)
275 
277 #define grayed(x) (((list) x)->hdr.grayed)
278 
279 //** Access an object's "immutable" field */
280 #define immutable(x) (((list) x)->hdr.immutable)
281 
285 
288  //, STAGE_REF_PROCESSING
290 } gc_stage_type;
291 
292 // Constant colors are defined here.
293 // The mark/clear colors are defined in the gc module because
294 // the collector swaps their values as an optimization.
295 
297 #define gc_color_red 0
298 
300 #define gc_color_blue 2
301 
303 typedef struct mark_buffer_t mark_buffer;
305  void **buf;
306  unsigned buf_len;
308 };
309 
315 
324  char **stack_traces;
332  char *stack_start;
334  char *stack_limit;
336  void **mutations;
342  unsigned char globals_changed;
344  void **moveBuf;
348  unsigned char gc_alloc_color;
350  unsigned char gc_trace_color;
371  pthread_mutex_t lock;
373  pthread_t thread_id;
387  object param_objs;
389  jmp_buf *jmp_start;
391  object gc_cont;
393  object *gc_args;
395  short gc_num_args;
398 };
399 
400 /* GC prototypes */
401 void gc_initialize(void);
403 void gc_add_mutator(gc_thread_data * thd);
407 void gc_sleep_ms(int ms);
408 gc_heap *gc_heap_create(int heap_type, size_t size, gc_thread_data *thd);
409 gc_heap *gc_heap_free(gc_heap *page, gc_heap *prev_page);
410 void gc_heap_merge(gc_heap *hdest, gc_heap *hsrc);
412 void gc_print_stats(gc_heap * h);
413 gc_heap *gc_grow_heap(gc_heap * h, size_t size, gc_thread_data *thd);
414 char *gc_copy_obj(object hp, char *obj, gc_thread_data * thd);
415 void *gc_try_alloc(gc_heap * h, size_t size, char *obj,
416  gc_thread_data * thd);
417 void *gc_try_alloc_slow(gc_heap *h_passed, gc_heap *h, size_t size, char *obj, gc_thread_data *thd);
418 void *gc_alloc(gc_heap_root * h, size_t size, char *obj, gc_thread_data * thd,
419  int *heap_grown);
420 void *gc_alloc_bignum(gc_thread_data *data);
421 size_t gc_allocated_bytes(object obj, gc_free_list * q, gc_free_list * r);
423 
425 void *gc_try_alloc_rest(gc_heap * h, size_t size, char *obj, gc_thread_data * thd);
426 void *gc_alloc_rest(gc_heap_root * hrt, size_t size, char *obj, gc_thread_data * thd, int *heap_grown);
428 
429 //size_t gc_heap_total_size(gc_heap * h);
430 //size_t gc_heap_total_free_size(gc_heap *h);
431 //size_t gc_collect(gc_heap *h, size_t *sum_freed);
432 //void gc_mark(gc_heap *h, object obj);
433 void gc_request_mark_globals(void);
434 void gc_mark_globals(object globals, object global_table);
435 //size_t gc_sweep(gc_heap * h, size_t * sum_freed_ptr, gc_thread_data *thd);
438 void gc_thread_data_init(gc_thread_data * thd, int mut_num, char *stack_base,
439  long stack_size);
441 // Prototypes for mutator/collector:
449 #define gc_is_stack_obj(low_limit, thd, obj) \
450  (stack_overflow(((object)low_limit), ((object)obj)) && \
451  stack_overflow(((object)obj), ((object)((gc_thread_data *)thd)->stack_start)))
452 void gc_mut_update(gc_thread_data * thd, object old_obj, object value);
453 void gc_mut_cooperate(gc_thread_data * thd, int buf_len);
454 void gc_mark_gray(gc_thread_data * thd, object obj);
455 void gc_mark_gray2(gc_thread_data * thd, object obj);
456 void gc_collector_trace();
460 void gc_wait_handshake();
461 void gc_start_collector();
462 void gc_mutator_thread_blocked(gc_thread_data * thd, object cont);
463 void gc_mutator_thread_runnable(gc_thread_data * thd, object result, object maybe_copied);
464 void Cyc_make_shared_object(void *data, object k, object obj);
465 #define set_thread_blocked(d, c) \
466  gc_mutator_thread_blocked(((gc_thread_data *)d), (c))
467 
470 #define return_thread_runnable(d, r) \
471  gc_mutator_thread_runnable(((gc_thread_data *)d), (r), NULL)
472 
476 #define return_thread_runnable_with_obj(d, r, maybe_copied) \
477  gc_mutator_thread_runnable(((gc_thread_data *)d), (r), maybe_copied)
478 /*
479 //#define do_with_blocked_thread(data, cont, result, body) \
480 // set_thread_blocked((data), (cont)); \
481 // body \
482 // return_thread_runnable((data), (result));
483 */
484 
497 #define NUM_GC_ARGS 128
498 
502 #define STACK_GROWTH_IS_DOWNWARD 1
503 
508 #define STACK_SIZE 500000
509 
513 #define MAX_STACK_OBJ (STACK_SIZE * 2)
514 
516 #if STACK_GROWTH_IS_DOWNWARD
517 #define stack_overflow(x,y) ((x) < (y))
518 #else
519 #define stack_overflow(x,y) ((x) > (y))
520 #endif
521 
528 #define forward(obj) (((pair_type *) obj)->pair_car)
529 
530 
536 void add_mutation(void *data, object var, int index, object value);
537 void clear_mutations(void *data);
545 object transport_stack_value(gc_thread_data *data, object var, object value, int *run_gc);
550 // END GC section
557 object Cyc_scm_call(gc_thread_data *parent_thd, object fnc, int argc, object *args);
558 object Cyc_scm_call_no_gc(gc_thread_data *parent_thd, object fnc, object arg);
593 #define CYC_FIXNUM_MAX 1073741823
594 
596 #define CYC_FIXNUM_MIN -1073741824
597 
602 typedef uint32_t char_type;
603 
607 #define obj_is_int(x) ((unsigned long)(x) & (unsigned long)1)
608 
612 //#define obj_obj2int(n) (((long)((ulong)(n) & ~1))/(long)(1uL<<1))
613 #define obj_obj2int(x) ((long)((uintptr_t)x)>>1)
614 
618 //#define obj_int2obj(n) ((void *) ((((long)(n))*(long)(1uL<<1)) | 1))
619 #define obj_int2obj(c) ((void *)((((long)c)*2) | 1))
620 
624 #define obj_is_char(x) (((unsigned long)(x) & (unsigned long)3) == 2)
625 
629 #define obj_obj2char(x) (char_type)((uintptr_t)(x)>>2)
630 
634 #define obj_char2obj(c) ((void *)((((uintptr_t)c)<<2) | 2))
635 
639 #define is_value_type(x) ((unsigned long)(x) & (unsigned long)3)
640 
644 #define is_object_type(x) ((x != NULL) && !is_value_type(x))
645 
666 typedef void (*function_type) (void *data, object clo, int argc, object *args);
667 
669 typedef void (*primitive_function_type)(void *data, object cont, object args);
670 
673 
677 typedef struct {
681  object *pvar;
682 } cvar_type;
683 typedef cvar_type *cvar;
684 
688 #define make_cvar(n,v) \
689  cvar_type n; \
690  n.hdr.mark = gc_color_red; \
691  n.hdr.grayed = 0; \
692  n.hdr.immutable = 0; \
693  n.tag = cvar_tag; \
694  n.pvar = v;
695 
702 typedef struct {
705  unsigned char collect_ptr;
708  void *ptr;
709 } c_opaque_type;
711 
713 #define make_c_opaque(var, p) \
714  c_opaque_type var; \
715  var.hdr.mark = gc_color_red; \
716  var.hdr.grayed = 0; \
717  var.hdr.immutable = 0; \
718  var.tag = c_opaque_tag; \
719  var.collect_ptr = 0; \
720  var.ptr = p;
721 
723 #define opaque_ptr(x) (((c_opaque)x)->ptr)
724 
726 #define opaque_collect_ptr(x) (((c_opaque)x)->collect_ptr)
727 
733 typedef struct {
736  pthread_mutex_t lock;
737 } mutex_type;
738 typedef mutex_type *mutex;
739 
745 typedef struct {
748  pthread_cond_t cond;
749 } cond_var_type;
751 
757 typedef struct {
760  object obj;
761 } atomic_type;
763 
770 typedef struct {
772  const tag_type tag;
773  const char *desc;
774 } boolean_type;
776 
777 #define boolean_desc(x) (((boolean_type *) x)->desc)
778 
779 #define make_boolean(x) (x ? boolean_t : boolean_f)
780 
788 typedef struct {
790  const tag_type tag;
791  const char *desc;
792 } symbol_type;
794 
795 #define symbol_desc(x) (((symbol_type *) x)->desc)
796 
797 #define defsymbol(name) \
798 static object quote_##name = NULL;
799 
800 /* Define numeric types */
801 
808 typedef struct {
811  int value;
812  int padding; // Prevent mem corruption if sizeof(int) < sizeof(ptr)
813 } integer_type;
814 
823 typedef struct {
826  mp_int bn;
827 } bignum_type;
828 
830 #define alloc_bignum(data, p) \
831  bignum_type *p = gc_alloc_bignum((gc_thread_data *)data);
832 
834 #define BIGNUM_CALL(x) { \
835  int __bn_mp_rv; \
836  if ((__bn_mp_rv = (x)) != MP_OKAY) { \
837  fprintf(stderr, "Error calling bignum function: %s\n", \
838  mp_error_to_string(__bn_mp_rv)); \
839  exit(1); \
840  } \
841 }
842 
846 typedef struct {
849  double complex value;
851 
853 #define make_complex_num(n,r,i) \
854  complex_num_type n; \
855  n.hdr.mark = gc_color_red; \
856  n.hdr.grayed = 0; \
857  n.tag = complex_num_tag; \
858  n.value = (r + (i * I));
859 
860 #define alloca_complex_num(n,r,i) \
861  complex_num_type *n = alloca(sizeof(complex_num_type)); \
862  n->hdr.mark = gc_color_red; \
863  n->hdr.grayed = 0; \
864  n->tag = complex_num_tag; \
865  n->value = (r + (i * I));
866 
868 #define assign_complex_num(pobj,v) \
869  ((complex_num_type *)pobj)->hdr.mark = gc_color_red; \
870  ((complex_num_type *)pobj)->hdr.grayed = 0; \
871  ((complex_num_type *)pobj)->tag = complex_num_tag; \
872  complex_num_value(pobj) = v;
873 
877 typedef struct {
880  double value;
881 } double_type;
882 
884 #define make_double(n,v) \
885  double_type n; \
886  n.hdr.mark = gc_color_red; \
887  n.hdr.grayed = 0; \
888  n.tag = double_tag; \
889  n.value = v;
890 
892 #define alloca_double(n,v) \
893  double_type *n = alloca(sizeof(double_type)); \
894  n->hdr.mark = gc_color_red; \
895  n->hdr.grayed = 0; \
896  n->tag = double_tag; \
897  n->value = v;
898 
900 #define assign_double(pobj,v) \
901  ((double_type *)pobj)->hdr.mark = gc_color_red; \
902  ((double_type *)pobj)->hdr.grayed = 0; \
903  ((double_type *)pobj)->tag = double_tag; \
904  double_value(pobj) = v;
905 
907 #define integer_value(x) (((integer_type *) x)->value)
908 
910 #define double_value(x) (((double_type *) x)->value)
911 
913 #define bignum_value(x) (((bignum_type *) x)->bn)
914 
916 #define complex_num_value(x) (((complex_num_type *) x)->value)
917 
922 typedef enum {
924  , CYC_BN_LT = MP_LT
925  , CYC_BN_EQ = MP_EQ
926  , CYC_BN_GT = MP_GT
928 } bn_cmp_type;
929 
933 typedef struct {
936  int num_cp;
937  int len;
938  char *str;
939 } string_type;
940 
941 // TODO: below macros are obsolete, need new ones that populate num_cp and
942 // raise an error if an invalid UTF-8 char is detected
943 
945 #define make_string(cs, s) string_type cs; \
946 { int len = strlen(s); \
947  cs.hdr.mark = gc_color_red; \
948  cs.hdr.grayed = 0; \
949  cs.hdr.immutable = 0; \
950  cs.tag = string_tag; \
951  cs.num_cp = len; \
952  cs.len = len; \
953  cs.str = alloca(sizeof(char) * (len + 1)); \
954  memcpy(cs.str, s, len + 1);}
955 
960 #define make_string_with_len(cs, s, length) string_type cs; \
961 { int len = length; \
962  cs.hdr.mark = gc_color_red; \
963  cs.hdr.grayed = 0; \
964  cs.hdr.immutable = 0; \
965  cs.tag = string_tag; cs.len = len; \
966  cs.num_cp = len; \
967  cs.str = alloca(sizeof(char) * (len + 1)); \
968  memcpy(cs.str, s, len); \
969  cs.str[len] = '\0';}
970 
975 #define make_string_noalloc(cs, s, length) string_type cs; \
976 { cs.hdr.mark = gc_color_red; cs.hdr.grayed = 0; cs.hdr.immutable = 0; \
977  cs.tag = string_tag; cs.len = length; \
978  cs.num_cp = length; \
979  cs.str = s; }
980 
982 #define make_utf8_string(data, cs, s) string_type cs; \
983 { int len = strlen(s); \
984  cs.hdr.mark = gc_color_red; \
985  cs.hdr.grayed = 0; \
986  cs.hdr.immutable = 0; \
987  cs.tag = string_tag; \
988  cs.num_cp = Cyc_utf8_count_code_points((uint8_t *)s); \
989  if (cs.num_cp < 0) { \
990  Cyc_rt_raise_msg(data, "Invalid UTF-8 characters in string"); \
991  } \
992  cs.len = len; \
993  cs.str = alloca(sizeof(char) * (len + 1)); \
994  memcpy(cs.str, s, len + 1);}
995 
1000 #define make_utf8_string_with_len(cs, s, length, num_code_points) string_type cs; \
1001 { int len = length; \
1002  cs.hdr.mark = gc_color_red; \
1003  cs.hdr.grayed = 0; \
1004  cs.hdr.immutable = 0; \
1005  cs.tag = string_tag; cs.len = len; \
1006  cs.num_cp = num_code_points; \
1007  cs.str = alloca(sizeof(char) * (len + 1)); \
1008  memcpy(cs.str, s, len); \
1009  cs.str[len] = '\0';}
1010 
1015 #define make_utf8_string_noalloc(cs, s, length) string_type cs; \
1016 { cs.hdr.mark = gc_color_red; cs.hdr.grayed = 0; cs.hdr.immutable = 0; \
1017  cs.tag = string_tag; cs.len = length; \
1018  cs.num_cp = length; \
1019  cs.str = s; }
1020 
1024 #define alloc_string(_data, _s, _len, _num_cp) \
1025  if (_len >= MAX_STACK_OBJ) { \
1026  int heap_grown; \
1027  _s = gc_alloc(((gc_thread_data *)data)->heap, \
1028  sizeof(string_type) + _len + 1, \
1029  boolean_f, /* OK to populate manually over here */ \
1030  (gc_thread_data *)data, \
1031  &heap_grown); \
1032  ((string_type *) _s)->hdr.mark = ((gc_thread_data *)data)->gc_alloc_color; \
1033  ((string_type *) _s)->hdr.grayed = 0; \
1034  ((string_type *) _s)->hdr.immutable = 0; \
1035  ((string_type *) _s)->tag = string_tag; \
1036  ((string_type *) _s)->len = _len; \
1037  ((string_type *) _s)->num_cp = _num_cp; \
1038  ((string_type *) _s)->str = (((char *)_s) + sizeof(string_type)); \
1039  } else { \
1040  _s = alloca(sizeof(string_type)); \
1041  ((string_type *)_s)->hdr.mark = gc_color_red; \
1042  ((string_type *)_s)->hdr.grayed = 0; \
1043  ((string_type *)_s)->hdr.immutable = 0; \
1044  ((string_type *)_s)->tag = string_tag; \
1045  ((string_type *)_s)->len = _len; \
1046  ((string_type *)_s)->num_cp = _num_cp; \
1047  ((string_type *)_s)->str = alloca(sizeof(char) * (_len + 1)); \
1048  }
1049 
1053 #define alloc_bytevector(_data, _bv, _len) \
1054  if (_len >= MAX_STACK_OBJ) { \
1055  int heap_grown; \
1056  _bv = gc_alloc(((gc_thread_data *)data)->heap, \
1057  sizeof(bytevector_type) + _len, \
1058  boolean_f, /* OK to populate manually over here */ \
1059  (gc_thread_data *)data, \
1060  &heap_grown); \
1061  ((bytevector) _bv)->hdr.mark = ((gc_thread_data *)data)->gc_alloc_color; \
1062  ((bytevector) _bv)->hdr.grayed = 0; \
1063  ((bytevector) _bv)->hdr.immutable = 0; \
1064  ((bytevector) _bv)->tag = bytevector_tag; \
1065  ((bytevector) _bv)->len = _len; \
1066  ((bytevector) _bv)->data = (char *)(((char *)_bv) + sizeof(bytevector_type)); \
1067  } else { \
1068  _bv = alloca(sizeof(bytevector_type)); \
1069  ((bytevector) _bv)->hdr.mark = gc_color_red; \
1070  ((bytevector) _bv)->hdr.grayed = 0; \
1071  ((bytevector) _bv)->hdr.immutable = 0; \
1072  ((bytevector) _bv)->tag = bytevector_tag; \
1073  ((bytevector) _bv)->len = _len; \
1074  ((bytevector) _bv)->data = alloca(sizeof(char) * _len); \
1075  }
1076 
1078 #define string_num_cp(x) (((string_type *) x)->num_cp)
1079 
1081 #define string_len(x) (((string_type *) x)->len)
1082 
1084 #define string_str(x) (((string_type *) x)->str)
1085 
1086 /* I/O types */
1087 
1088 // TODO: FILE* may not be good enough
1089 // consider http://stackoverflow.com/questions/6206893/how-to-implement-char-ready-in-c
1090 // TODO: a simple wrapper around FILE may not be good enough long-term
1091 // TODO: how exactly mode will be used. need to know r/w, bin/txt
1092 
1096 typedef struct {
1099  void *unused; // Protect against forwarding pointer, ideally would not be needed.
1100  FILE *fp;
1101  int mode;
1102  unsigned char flags;
1103  unsigned int line_num;
1104  unsigned int col_num;
1105  unsigned int buf_idx;
1106  unsigned int tok_start; // Start of token in mem_buf (end is unknown yet)
1107  unsigned int tok_end; // End of token in tok_buf (start is tok_buf[0])
1108  char *tok_buf; // Alternative buffer for tokens
1109  size_t tok_buf_len;
1110  char *mem_buf;
1111  size_t mem_buf_len;
1112  unsigned short read_len;
1115 } port_type;
1116 
1117 #define CYC_BINARY_PORT_FLAG 0x10
1118 
1119 #define CYC_IO_BUF_LEN 1024
1120 
1122 #define make_port(p,f,m) \
1123  port_type p; \
1124  p.hdr.mark = gc_color_red; \
1125  p.hdr.grayed = 0; \
1126  p.hdr.immutable = 0; \
1127  p.tag = port_tag; \
1128  p.fp = f; \
1129  p.mode = m; \
1130  p.flags = 0; \
1131  p.line_num = 1; \
1132  p.col_num = 1; \
1133  p.buf_idx = 0; \
1134  p.tok_start = 0; \
1135  p.tok_end = 0; \
1136  p.tok_buf = NULL; \
1137  p.tok_buf_len = 0; \
1138  p.mem_buf = NULL; \
1139  p.mem_buf_len = 0; \
1140  p.str_bv_in_mem_buf = NULL; \
1141  p.str_bv_in_mem_buf_len = 0; \
1142  p.read_len = 1;
1143 
1145 #define make_input_port(p,f,rl) \
1146  port_type p; \
1147  p.hdr.mark = gc_color_red; \
1148  p.hdr.grayed = 0; \
1149  p.hdr.immutable = 0; \
1150  p.tag = port_tag; \
1151  p.fp = f; \
1152  p.mode = 1; \
1153  p.flags = 1; \
1154  p.line_num = 1; \
1155  p.col_num = 1; \
1156  p.buf_idx = 0; \
1157  p.tok_start = 0; \
1158  p.tok_end = 0; \
1159  p.tok_buf = malloc(CYC_IO_BUF_LEN); \
1160  p.tok_buf_len = CYC_IO_BUF_LEN; \
1161  p.mem_buf = malloc(CYC_IO_BUF_LEN); \
1162  p.mem_buf_len = 0; \
1163  p.str_bv_in_mem_buf = NULL; \
1164  p.str_bv_in_mem_buf_len = 0; \
1165  p.read_len = rl;
1166 
1170 typedef struct {
1174  object *elements;
1175 } vector_type;
1177 
1178 typedef struct { vector_type v; object arr[2]; } vector_2_type;
1179 typedef struct { vector_type v; object arr[3]; } vector_3_type;
1180 typedef struct { vector_type v; object arr[4]; } vector_4_type;
1181 typedef struct { vector_type v; object arr[5]; } vector_5_type;
1182 
1184 #define make_empty_vector(v) \
1185  vector_type v; \
1186  v.hdr.mark = gc_color_red; \
1187  v.hdr.grayed = 0; \
1188  v.hdr.immutable = 0; \
1189  v.tag = vector_tag; \
1190  v.num_elements = 0; \
1191  v.elements = NULL;
1192 
1194 #define alloca_empty_vector(v) \
1195  vector_type *v = alloca(sizeof(vector_type)); \
1196  v->hdr.mark = gc_color_red; \
1197  v->hdr.grayed = 0; \
1198  v->hdr.immutable = 0; \
1199  v->tag = vector_tag; \
1200  v->num_elements = 0; \
1201  v->elements = NULL;
1202 
1209 typedef struct {
1212  int len;
1213  char *data;
1214 } bytevector_type;
1216 
1218 #define make_empty_bytevector(v) \
1219  bytevector_type v; \
1220  v.hdr.mark = gc_color_red; \
1221  v.hdr.grayed = 0; \
1222  v.hdr.immutable = 0; \
1223  v.tag = bytevector_tag; \
1224  v.len = 0; \
1225  v.data = NULL;
1226 
1228 #define alloca_empty_bytevector(v) \
1229  bytevector_type *v = alloca(sizeof(bytevector_type)); \
1230  v->hdr.mark = gc_color_red; \
1231  v->hdr.grayed = 0; \
1232  v->hdr.immutable = 0; \
1233  v->tag = bytevector_tag; \
1234  v->len = 0; \
1235  v->data = NULL;
1236 
1247 typedef struct {
1250  object pair_car;
1251  object pair_cdr;
1252 } pair_type;
1253 typedef pair_type *list;
1254 typedef pair_type *pair;
1255 
1257 #define make_pair(n,a,d) \
1258  pair_type n; \
1259  n.hdr.mark = gc_color_red; \
1260  n.hdr.grayed = 0; \
1261  n.hdr.immutable = 0; \
1262  n.tag = pair_tag; \
1263  n.pair_car = a; \
1264  n.pair_cdr = d;
1265 
1267 #define alloca_pair(n,a,d) \
1268  pair_type *n = alloca(sizeof(pair_type)); \
1269  n->hdr.mark = gc_color_red; \
1270  n->hdr.grayed = 0; \
1271  n->hdr.immutable = 0; \
1272  n->tag = pair_tag; \
1273  n->pair_car = a; \
1274  n->pair_cdr = d;
1275 
1282 #define set_pair(n,a,d) \
1283  n->hdr.mark = gc_color_red; \
1284  n->hdr.grayed = 0; \
1285  n->hdr.immutable = 0; \
1286  n->tag = pair_tag; \
1287  n->pair_car = a; \
1288  n->pair_cdr = d;
1289 
1296 #define set_pair_as_expr(n,a,d) \
1297  (((pair)(n))->hdr.mark = gc_color_red, \
1298  ((pair)(n))->hdr.grayed = 0, \
1299  ((pair)(n))->hdr.immutable = 0, \
1300  ((pair)(n))->tag = pair_tag, \
1301  ((pair)(n))->pair_car = a, \
1302  ((pair)(n))->pair_cdr = d, \
1303  (n))
1304 
1305 //typedef list_1_type pair_type;
1306 typedef struct { pair_type a; pair_type b; } list_2_type;
1307 typedef struct { pair_type a; pair_type b; pair_type c;} list_3_type;
1308 typedef struct { pair_type a; pair_type b; pair_type c; pair_type d;} list_4_type;
1309 
1314 #define make_cell(n,a) make_pair(n,a,NULL)
1315 #define alloca_cell(n,a) alloca_pair(n,a,NULL)
1316 #define set_cell_as_expr(n,a) set_pair_as_expr(n,a,NULL)
1317 
1325 #define car(x) (((pair_type *) x)->pair_car)
1326 
1327 #define cdr(x) (((pair_type *) x)->pair_cdr)
1328 #define caar(x) (car(car(x)))
1329 #define cadr(x) (car(cdr(x)))
1330 #define cdar(x) (cdr(car(x)))
1331 #define cddr(x) (cdr(cdr(x)))
1332 #define caaar(x) (car(car(car(x))))
1333 #define caadr(x) (car(car(cdr(x))))
1334 #define cadar(x) (car(cdr(car(x))))
1335 #define caddr(x) (car(cdr(cdr(x))))
1336 #define cdaar(x) (cdr(car(car(x))))
1337 #define cdadr(x) (cdr(car(cdr(x))))
1338 #define cddar(x) (cdr(cdr(car(x))))
1339 #define cdddr(x) (cdr(cdr(cdr(x))))
1340 #define caaaar(x) (car(car(car(car(x)))))
1341 #define caaadr(x) (car(car(car(cdr(x)))))
1342 #define caadar(x) (car(car(cdr(car(x)))))
1343 #define caaddr(x) (car(car(cdr(cdr(x)))))
1344 #define cadaar(x) (car(cdr(car(car(x)))))
1345 #define cadadr(x) (car(cdr(car(cdr(x)))))
1346 #define caddar(x) (car(cdr(cdr(car(x)))))
1347 #define cadddr(x) (car(cdr(cdr(cdr(x)))))
1348 #define cdaaar(x) (cdr(car(car(car(x)))))
1349 #define cdaadr(x) (cdr(car(car(cdr(x)))))
1350 #define cdadar(x) (cdr(car(cdr(car(x)))))
1351 #define cdaddr(x) (cdr(car(cdr(cdr(x)))))
1352 #define cddaar(x) (cdr(cdr(car(car(x)))))
1353 #define cddadr(x) (cdr(cdr(car(cdr(x)))))
1354 #define cdddar(x) (cdr(cdr(cdr(car(x)))))
1355 #define cddddr(x) (cdr(cdr(cdr(cdr(x)))))
1356 
1364 #define Cyc_caar(d, x) (Cyc_car(d, Cyc_car(d, x)))
1365 #define Cyc_cadr(d, x) (Cyc_car(d, Cyc_cdr(d, x)))
1366 #define Cyc_cdar(d, x) (Cyc_cdr(d, Cyc_car(d, x)))
1367 #define Cyc_cddr(d, x) (Cyc_cdr(d, Cyc_cdr(d, x)))
1368 #define Cyc_caaar(d, x) (Cyc_car(d, Cyc_car(d, Cyc_car(d, x))))
1369 #define Cyc_caadr(d, x) (Cyc_car(d, Cyc_car(d, Cyc_cdr(d, x))))
1370 #define Cyc_cadar(d, x) (Cyc_car(d, Cyc_cdr(d, Cyc_car(d, x))))
1371 #define Cyc_caddr(d, x) (Cyc_car(d, Cyc_cdr(d, Cyc_cdr(d, x))))
1372 #define Cyc_cdaar(d, x) (Cyc_cdr(d, Cyc_car(d, Cyc_car(d, x))))
1373 #define Cyc_cdadr(d, x) (Cyc_cdr(d, Cyc_car(d, Cyc_cdr(d, x))))
1374 #define Cyc_cddar(d, x) (Cyc_cdr(d, Cyc_cdr(d, Cyc_car(d, x))))
1375 #define Cyc_cdddr(d, x) (Cyc_cdr(d, Cyc_cdr(d, Cyc_cdr(d, x))))
1376 #define Cyc_caaaar(d, x) (Cyc_car(d, Cyc_car(d, Cyc_car(d, Cyc_car(d, x)))))
1377 #define Cyc_caaadr(d, x) (Cyc_car(d, Cyc_car(d, Cyc_car(d, Cyc_cdr(d, x)))))
1378 #define Cyc_caadar(d, x) (Cyc_car(d, Cyc_car(d, Cyc_cdr(d, Cyc_car(d, x)))))
1379 #define Cyc_caaddr(d, x) (Cyc_car(d, Cyc_car(d, Cyc_cdr(d, Cyc_cdr(d, x)))))
1380 #define Cyc_cadaar(d, x) (Cyc_car(d, Cyc_cdr(d, Cyc_car(d, Cyc_car(d, x)))))
1381 #define Cyc_cadadr(d, x) (Cyc_car(d, Cyc_cdr(d, Cyc_car(d, Cyc_cdr(d, x)))))
1382 #define Cyc_caddar(d, x) (Cyc_car(d, Cyc_cdr(d, Cyc_cdr(d, Cyc_car(d, x)))))
1383 #define Cyc_cadddr(d, x) (Cyc_car(d, Cyc_cdr(d, Cyc_cdr(d, Cyc_cdr(d, x)))))
1384 #define Cyc_cdaaar(d, x) (Cyc_cdr(d, Cyc_car(d, Cyc_car(d, Cyc_car(d, x)))))
1385 #define Cyc_cdaadr(d, x) (Cyc_cdr(d, Cyc_car(d, Cyc_car(d, Cyc_cdr(d, x)))))
1386 #define Cyc_cdadar(d, x) (Cyc_cdr(d, Cyc_car(d, Cyc_cdr(d, Cyc_car(d, x)))))
1387 #define Cyc_cdaddr(d, x) (Cyc_cdr(d, Cyc_car(d, Cyc_cdr(d, Cyc_cdr(d, x)))))
1388 #define Cyc_cddaar(d, x) (Cyc_cdr(d, Cyc_cdr(d, Cyc_car(d, Cyc_car(d, x)))))
1389 #define Cyc_cddadr(d, x) (Cyc_cdr(d, Cyc_cdr(d, Cyc_car(d, Cyc_cdr(d, x)))))
1390 #define Cyc_cdddar(d, x) (Cyc_cdr(d, Cyc_cdr(d, Cyc_cdr(d, Cyc_car(d, x)))))
1391 #define Cyc_cddddr(d, x) (Cyc_cdr(d, Cyc_cdr(d, Cyc_cdr(d, Cyc_cdr(d, x)))))
1392 
1394 /* Closure types */
1395 
1397 typedef struct {
1402 } macro_type;
1403 
1405 typedef struct {
1410 } closure0_type;
1412 typedef struct {
1417  object element;
1418 } closure1_type;
1420 typedef struct {
1426  object *elements;
1427 } closureN_type;
1428 
1434 
1435 #define mmacro(c,f) \
1436  macro_type c; \
1437  c.hdr.mark = gc_color_red; \
1438  c.hdr.grayed = 0; \
1439  c.tag = macro_tag; \
1440  c.fn = f; \
1441  c.num_args = -1;
1442 
1447 #define mclosure0(c, f) \
1448  static closure0_type c = { .hdr.mark = gc_color_red, .hdr.grayed = 0, .tag = closure0_tag, .fn = f, .num_args = -1 }; /* TODO: need a new macro that initializes num_args */
1449 
1450 #define maclosure0(c,f,na) \
1451  closure0_type c; \
1452  c.hdr.mark = gc_color_red; \
1453  c.hdr.grayed = 0; \
1454  c.tag = closure0_tag; \
1455  c.fn = f; \
1456  c.num_args = na;
1457 
1461 #define mclosure1(c,f,a) \
1462  closure1_type c; \
1463  c.hdr.mark = gc_color_red; \
1464  c.hdr.grayed = 0; \
1465  c.tag = closure1_tag; \
1466  c.fn = f; \
1467  c.num_args = -1; \
1468  c.element = a;
1469 
1473 typedef struct {
1476  const char *desc;
1478 } primitive_type;
1480 
1481 #define defprimitive(name, desc, fnc) \
1482 static primitive_type name##_primitive = {primitive_tag, #desc, fnc}; \
1483 static const object primitive_##name = &name##_primitive
1484 
1486 #define prim(x) (x && ((primitive)x)->tag == primitive_tag)
1487 
1489 #define prim_name(x) (((primitive_type *) x)->desc)
1490 
1497 typedef union {
1506 } common_type;
1507 
1508 #define return_copy(ptr, o) \
1509 { \
1510  tag_type t; \
1511  object obj = o; \
1512  if (!is_object_type(obj)) \
1513  return obj; \
1514  t = type_of(obj); \
1515  if (t == double_tag) { \
1516  ((common_type *)ptr)->double_t.hdr.mark = gc_color_red; \
1517  ((common_type *)ptr)->double_t.hdr.grayed = 0; \
1518  ((common_type *)ptr)->double_t.tag = double_tag; \
1519  ((common_type *)ptr)->double_t.value = double_value(obj); \
1520  return ptr; \
1521  } else { \
1522  return obj; \
1523  } \
1524 }
1525 
1529 typedef struct vpbuffer_t vpbuffer;
1530 struct vpbuffer_t {
1531  void **buf;
1532  int len;
1533  int count;
1534 };
1535 
1536 vpbuffer *vp_create(void);
1537 void vp_add(vpbuffer *v, void *obj);
1538 
1539 /* Utility functions */
1540 void **vpbuffer_realloc(void **buf, int *len);
1541 void **vpbuffer_add(void **buf, int *len, int i, void *obj);
1542 void vpbuffer_free(void **buf);
1543 
1544 /* Bignum utility functions */
1545 int Cyc_bignum_cmp(bn_cmp_type type, object x, int tx, object y, int ty);
1546 void Cyc_int2bignum(int n, mp_int *bn);
1547 
1548 /* Remaining GC prototypes that require objects to be defined */
1550 
1555 int gc_minor(void *data, object low_limit, object high_limit, closure cont,
1556  object * args, int num_args);
1557 
1558 void Cyc_import_shared_object(void *data, object cont, object filename, object entry_pt_fnc);
1559 #endif /* CYCLONE_TYPES_H */
primitive_type::tag
tag_type tag
Definition: types.h:1475
gc_status_type
gc_status_type
Definition: types.h:283
forward_tag
@ forward_tag
Definition: types.h:60
primitive_function_type
void(* primitive_function_type)(void *data, object cont, object args)
Definition: types.h:669
gc_alloc
void * gc_alloc(gc_heap_root *h, size_t size, char *obj, gc_thread_data *thd, int *heap_grown)
Allocate memory on the heap for an object.
Definition: gc.c:1360
port_type::read_len
unsigned short read_len
Definition: types.h:1112
bytevector
bytevector_type * bytevector
Definition: types.h:1215
cond_var_type::tag
tag_type tag
Definition: types.h:747
string_type::tag
tag_type tag
Definition: types.h:935
mark_buffer_t
Definition: types.h:304
boolean_type::tag
const tag_type tag
Definition: types.h:772
bignum_type::tag
tag_type tag
Definition: types.h:825
vector_tag
@ vector_tag
Definition: types.h:69
closure1_type::num_args
int num_args
Definition: types.h:1416
gc_mutator_thread_runnable
void gc_mutator_thread_runnable(gc_thread_data *thd, object result, object maybe_copied)
Called explicitly from a mutator thread to let the collector know that it has finished blocking.
Definition: gc.c:2880
c_opaque_type::ptr
void * ptr
Definition: types.h:708
CYC_BN_GTE
@ CYC_BN_GTE
Definition: types.h:927
closure1_type::tag
tag_type tag
Definition: types.h:1414
common_type::complex_num_t
complex_num_type complex_num_t
Definition: types.h:1505
closure0_type
A closed-over function with no variables.
Definition: types.h:1405
vector_type::num_elements
int num_elements
Definition: types.h:1173
complex_num_type
Complex number.
Definition: types.h:846
integer_tag
@ integer_tag
Definition: types.h:61
closureN_type::fn
function_type fn
Definition: types.h:1423
gc_heap_root_t
Definition: types.h:259
gc_try_alloc_rest
void * gc_try_alloc_rest(gc_heap *h, size_t size, char *obj, gc_thread_data *thd)
closure1_type::hdr
gc_header_type hdr
Definition: types.h:1413
gc_thread_data_t::last_write
int last_write
Definition: types.h:356
gc_thread_data_t::moveBuf
void ** moveBuf
Definition: types.h:344
port_type::tok_end
unsigned int tok_end
Definition: types.h:1107
closure1_type::fn
function_type fn
Definition: types.h:1415
port_type::mem_buf
char * mem_buf
Definition: types.h:1110
gc_heap_t::is_unswept
unsigned char is_unswept
Definition: types.h:238
gc_post_handshake
void gc_post_handshake(gc_status_type s)
Change GC status to the given type.
Definition: gc.c:2415
gc_thread_data_t::stack_trace_idx
int stack_trace_idx
Definition: types.h:326
complex_num_type::tag
tag_type tag
Definition: types.h:848
gc_heap_type
gc_heap_type
Definition: types.h:186
gc_mut_cooperate
void gc_mut_cooperate(gc_thread_data *thd, int buf_len)
Called by a mutator to cooperate with the collector thread.
Definition: gc.c:1914
Cyc_int2bignum
void Cyc_int2bignum(int n, mp_int *bn)
Definition: runtime.c:1723
primitive_tag
@ primitive_tag
Definition: types.h:66
gc_thread_data_t::lock
pthread_mutex_t lock
Definition: types.h:371
mutex_type::lock
pthread_mutex_t lock
Definition: types.h:736
primitive_type::hdr
gc_header_type hdr
Definition: types.h:1474
string_type::num_cp
int num_cp
Definition: types.h:936
cyc_thread_state_type
cyc_thread_state_type
Definition: types.h:311
cond_var
cond_var_type * cond_var
Definition: types.h:750
closure1_type::element
object element
Definition: types.h:1417
macro_type::hdr
gc_header_type hdr
Definition: types.h:1398
record_tag
@ record_tag
Definition: types.h:73
vector_3_type::v
vector_type v
Definition: types.h:1179
list
pair_type * list
Definition: types.h:1253
cond_var_type
The condition variable thread synchronization type.
Definition: types.h:745
gc_thread_data_t::globals_changed
unsigned char globals_changed
Definition: types.h:342
gc_collector_trace
void gc_collector_trace()
The collector's tracing algorithm.
Definition: gc.c:2328
mutex_type::tag
tag_type tag
Definition: types.h:735
gc_heap_t::is_full
unsigned char is_full
Definition: types.h:236
gc_start_collector
void gc_start_collector()
Spawn the collector thread.
Definition: gc.c:2618
cvar
cvar_type * cvar
Definition: types.h:683
vector_3_type
Definition: types.h:1179
closure1_type
A closed-over function with one variable.
Definition: types.h:1412
list_4_type::d
pair_type d
Definition: types.h:1308
bn_cmp_type
bn_cmp_type
Definition: types.h:922
gc_initialize
void gc_initialize(void)
Perform one-time initialization before mutators can be executed.
Definition: gc.c:213
void_tag
@ void_tag
Definition: types.h:72
gc_thread_data_t::gc_done_tracing
uint8_t gc_done_tracing
Definition: types.h:352
common_type::bignum_t
bignum_type bignum_t
Definition: types.h:1504
primitive_type
A function built into the runtime.
Definition: types.h:1473
port_type
The port object type.
Definition: types.h:1096
c_opaque_type
C Opaque type - a wrapper around a pointer of any type.
Definition: types.h:702
pair_type::pair_car
object pair_car
Definition: types.h:1250
gc_thread_data_t::num_minor_gcs
int num_minor_gcs
Definition: types.h:383
double_type::tag
tag_type tag
Definition: types.h:879
CYC_THREAD_STATE_BLOCKED_COOPERATING
@ CYC_THREAD_STATE_BLOCKED_COOPERATING
Definition: types.h:312
primitive
primitive_type * primitive
Definition: types.h:1479
vector_type
Vector type.
Definition: types.h:1170
HEAP_REST
@ HEAP_REST
Definition: types.h:190
common_type::boolean_t
boolean_type boolean_t
Definition: types.h:1498
gc_stage_type
gc_stage_type
Definition: types.h:287
mark_buffer_t::buf
void ** buf
Definition: types.h:305
closure0_type::num_args
int num_args
Definition: types.h:1409
vector_2_type
Definition: types.h:1178
common_type::double_t
double_type double_t
Definition: types.h:1503
gc_header_type_t::immutable
unsigned char immutable
Definition: types.h:270
gc_header_type_t::grayed
unsigned char grayed
Definition: types.h:269
vector_4_type
Definition: types.h:1180
port_type::flags
unsigned char flags
Definition: types.h:1102
gc_try_alloc_slow
void * gc_try_alloc_slow(gc_heap *h_passed, gc_heap *h, size_t size, char *obj, gc_thread_data *thd)
Definition: gc.c:1139
boolean_type
The boolean type: True or False.
Definition: types.h:770
gc_heap_merge
void gc_heap_merge(gc_heap *hdest, gc_heap *hsrc)
Merge one heap into another.
Definition: gc.c:2789
CYC_THREAD_STATE_NEW
@ CYC_THREAD_STATE_NEW
Definition: types.h:311
gc_thr_grow_move_buffer
void gc_thr_grow_move_buffer(gc_thread_data *d)
Increase the size of the mutator's move buffer.
Definition: gc.c:1769
string_type::len
int len
Definition: types.h:937
bignum_type::hdr
gc_header_type hdr
Definition: types.h:824
closureN_type::elements
object * elements
Definition: types.h:1426
string_type::str
char * str
Definition: types.h:938
macro
closure0_type * macro
Definition: types.h:1433
STAGE_TRACING
@ STAGE_TRACING
Definition: types.h:287
pair_type
The pair (cons) type.
Definition: types.h:1247
common_type::pair_t
pair_type pair_t
Definition: types.h:1499
gc_thread_data_t
Definition: types.h:322
boolean
boolean_type * boolean
Definition: types.h:775
atomic_tag
@ atomic_tag
Definition: types.h:71
atomic_type
The atomic thread synchronization type.
Definition: types.h:757
gc_thread_data_t::gc_num_args
short gc_num_args
Definition: types.h:395
closureN_type::num_elements
int num_elements
Definition: types.h:1425
bytevector_type::len
int len
Definition: types.h:1212
double_type::hdr
gc_header_type hdr
Definition: types.h:878
cond_var_tag
@ cond_var_tag
Definition: types.h:56
integer_type::padding
int padding
Definition: types.h:812
gc_mark_globals
void gc_mark_globals(object globals, object global_table)
Mark globals as part of the tracing collector.
Definition: gc.c:2634
gc_thread_data_t::mutation_buflen
int mutation_buflen
Definition: types.h:338
gc_thread_data_t::stack_limit
char * stack_limit
Definition: types.h:334
closure1
closure1_type * closure1
Definition: types.h:1430
port_type::str_bv_in_mem_buf_len
size_t str_bv_in_mem_buf_len
Definition: types.h:1114
HEAP_96
@ HEAP_96
Definition: types.h:189
vp_add
void vp_add(vpbuffer *v, void *obj)
Definition: runtime.c:6902
c_opaque_type::hdr
gc_header_type hdr
Definition: types.h:703
vpbuffer_t
Definition: types.h:1530
c_opaque
c_opaque_type * c_opaque
Definition: types.h:710
gc_thread_data_t::mutation_count
int mutation_count
Definition: types.h:340
transport_stack_value
object transport_stack_value(gc_thread_data *data, object var, object value, int *run_gc)
Definition: runtime.c:566
vpbuffer_add
void ** vpbuffer_add(void **buf, int *len, int i, void *obj)
Definition: runtime.c:6877
Cyc_make_shared_object
void Cyc_make_shared_object(void *data, object k, object obj)
Definition: runtime.c:6204
gc_mark_gray2
void gc_mark_gray2(gc_thread_data *thd, object obj)
Add a pending write to the mark buffer.
Definition: gc.c:2170
Cyc_bignum_cmp
int Cyc_bignum_cmp(bn_cmp_type type, object x, int tx, object y, int ty)
Definition: runtime.c:1731
port_type::fp
FILE * fp
Definition: types.h:1100
gc_thread_data_t::stack_prev_frame
char * stack_prev_frame
Definition: types.h:328
mutex
mutex_type * mutex
Definition: types.h:738
gc_mark_gray
void gc_mark_gray(gc_thread_data *thd, object obj)
Mark the given object gray if it is on the heap.
Definition: gc.c:2137
vector
vector_type * vector
Definition: types.h:1176
cvar_type::hdr
gc_header_type hdr
Definition: types.h:678
gc_heap_t::size
unsigned int size
Definition: types.h:226
gc_heap_t::next
gc_heap * next
Definition: types.h:248
integer_type::tag
tag_type tag
Definition: types.h:810
gc_thread_data_free
void gc_thread_data_free(gc_thread_data *thd)
Free all data for the given mutator.
Definition: gc.c:2739
cvar_type
C-variable integration type - wrapper around a Cyclone object pointer.
Definition: types.h:677
gc_thread_data_t::stack_traces
char ** stack_traces
Definition: types.h:324
closureN_type::hdr
gc_header_type hdr
Definition: types.h:1421
bytevector_type
Bytevector type.
Definition: types.h:1209
common_type::primitive_t
primitive_type primitive_t
Definition: types.h:1501
integer_type
Deprecated - boxed integers.
Definition: types.h:808
gc_header_type_t::mark
unsigned char mark
Definition: types.h:268
closureN_tag
@ closureN_tag
Definition: types.h:51
gc_print_stats
void gc_print_stats(gc_heap *h)
Print heap usage information. Before calling this function the current thread must have the heap lock...
Definition: gc.c:776
primitive_type::fn
primitive_function_type fn
Definition: types.h:1477
clear_mutations
void clear_mutations(void *data)
Definition: runtime.c:660
complex_num_type::hdr
gc_header_type hdr
Definition: types.h:847
gc_heap_free
gc_heap * gc_heap_free(gc_heap *page, gc_heap *prev_page)
Free a page of the heap.
Definition: gc.c:733
closureN_type::num_args
int num_args
Definition: types.h:1424
gc_alloc_bignum
void * gc_alloc_bignum(gc_thread_data *data)
A convenience function for allocating bignums.
Definition: gc.c:1315
atomic_type::hdr
gc_header_type hdr
Definition: types.h:758
HEAP_SM
@ HEAP_SM
Definition: types.h:187
macro_type::fn
function_type fn
Definition: types.h:1400
macro_type
Closure for a macro.
Definition: types.h:1397
gc_thread_data_t::moveBufLen
int moveBufLen
Definition: types.h:346
vector_5_type
Definition: types.h:1181
gc_heap_t::block_size
unsigned block_size
Definition: types.h:232
closureN_type::tag
tag_type tag
Definition: types.h:1422
port_type::mode
int mode
Definition: types.h:1101
double_tag
@ double_tag
Definition: types.h:58
gc_free_list_t
Definition: types.h:208
boolean_type::desc
const char * desc
Definition: types.h:773
gc_thread_data_t::gc_cont
object gc_cont
Definition: types.h:391
HEAP_64
@ HEAP_64
Definition: types.h:188
Cyc_scm_call_no_gc
object Cyc_scm_call_no_gc(gc_thread_data *parent_thd, object fnc, object arg)
Definition: ffi.c:137
closure0
closure0_type * closure0
Definition: types.h:1429
closure0_type::fn
function_type fn
Definition: types.h:1408
gc_heap_create
gc_heap * gc_heap_create(int heap_type, size_t size, gc_thread_data *thd)
Create a new heap page. The caller must hold the necessary locks.
Definition: gc.c:394
pair_type::pair_cdr
object pair_cdr
Definition: types.h:1251
gc_thread_data_t::gc_trace_color
unsigned char gc_trace_color
Definition: types.h:350
gc_thread_data_t::heap_num_huge_allocations
int heap_num_huge_allocations
Definition: types.h:381
port_tag
@ port_tag
Definition: types.h:65
gc_thread_data_t::mark_buffer
mark_buffer * mark_buffer
Definition: types.h:367
gc_heap_t::ttl
unsigned int ttl
Definition: types.h:228
cvar_type::pvar
object * pvar
Definition: types.h:681
common_type::integer_t
integer_type integer_t
Definition: types.h:1502
gc_header_type_t
Definition: types.h:267
closure0_type::tag
tag_type tag
Definition: types.h:1407
gc_thread_data_t::exception_handler_stack
object exception_handler_stack
Definition: types.h:385
Cyc_scm_call
object Cyc_scm_call(gc_thread_data *parent_thd, object fnc, int argc, object *args)
Definition: ffi.c:61
gc_mut_update
void gc_mut_update(gc_thread_data *thd, object old_obj, object value)
Write barrier for updates to heap-allocated objects.
Definition: gc.c:1879
string_type::hdr
gc_header_type hdr
Definition: types.h:934
gc_thread_data_t::param_objs
object param_objs
Definition: types.h:387
complex_num_type::value
double complex value
Definition: types.h:849
add_mutation
void add_mutation(void *data, object var, int index, object value)
Definition: runtime.c:625
atomic_type::obj
object obj
Definition: types.h:760
gc_merge_all_heaps
void gc_merge_all_heaps(gc_thread_data *dest, gc_thread_data *src)
Merge all thread heaps into another.
Definition: gc.c:2802
STAGE_CLEAR_OR_MARKING
@ STAGE_CLEAR_OR_MARKING
Definition: types.h:287
CYC_THREAD_STATE_TERMINATED
@ CYC_THREAD_STATE_TERMINATED
Definition: types.h:313
STAGE_RESTING
@ STAGE_RESTING
Definition: types.h:289
gc_free_list_t::next
gc_free_list * next
Definition: types.h:210
mutex_type::hdr
gc_header_type hdr
Definition: types.h:734
gc_sleep_ms
void gc_sleep_ms(int ms)
A high-resolution sleep function.
Definition: gc.c:2605
gc_try_alloc
void * gc_try_alloc(gc_heap *h, size_t size, char *obj, gc_thread_data *thd)
Attempt to allocate a new heap slot for the given object.
Definition: gc.c:1076
symbol_type
Symbols are similar to strings, but only one instance of each unique symbol is created,...
Definition: types.h:788
closureN_type
A closed-over function with zero or more closed-over variables.
Definition: types.h:1420
gc_request_mark_globals
void gc_request_mark_globals(void)
A helper function for calling gc_mark_globals.
Definition: runtime.c:5854
gc_thread_data_t::cached_heap_free_sizes
uintptr_t * cached_heap_free_sizes
Definition: types.h:377
port_type::unused
void * unused
Definition: types.h:1099
mark_buffer_t::buf_len
unsigned buf_len
Definition: types.h:306
pair
pair_type * pair
Definition: types.h:1254
STATUS_ASYNC
@ STATUS_ASYNC
Definition: types.h:283
string_type
The string type.
Definition: types.h:933
gc_heap_t::remaining
unsigned int remaining
Definition: types.h:230
gc_thread_data_t::scm_thread_obj
object scm_thread_obj
Definition: types.h:397
port_type::tok_buf_len
size_t tok_buf_len
Definition: types.h:1109
gc_heap_t::type
gc_heap_type type
Definition: types.h:224
CYC_BN_GT
@ CYC_BN_GT
Definition: types.h:926
gc_thread_data_t::thread_id
pthread_t thread_id
Definition: types.h:373
cond_var_type::hdr
gc_header_type hdr
Definition: types.h:746
list_3_type::c
pair_type c
Definition: types.h:1307
inline_function_type
object(* inline_function_type)()
Definition: types.h:672
c_opaque_type::collect_ptr
unsigned char collect_ptr
Definition: types.h:705
bignum_type::bn
mp_int bn
Definition: types.h:826
STATUS_SYNC1
@ STATUS_SYNC1
Definition: types.h:283
Cyc_import_shared_object
void Cyc_import_shared_object(void *data, object cont, object filename, object entry_pt_fnc)
Definition: runtime.c:6994
port_type::buf_idx
unsigned int buf_idx
Definition: types.h:1105
gc_heap_t
Definition: types.h:223
gc_thread_data_t::heap
gc_heap_root * heap
Definition: types.h:375
c_opaque_tag
@ c_opaque_tag
Definition: types.h:55
object_tag
object_tag
Definition: types.h:48
boolean_tag
@ boolean_tag
Definition: types.h:53
list_3_type
Definition: types.h:1307
CYC_BN_LTE
@ CYC_BN_LTE
Definition: types.h:923
gc_thread_data_t::stack_start
char * stack_start
Definition: types.h:332
symbol
symbol_type * symbol
Definition: types.h:793
gc_add_mutator
void gc_add_mutator(gc_thread_data *thd)
Add data for a new mutator that is starting to run.
Definition: gc.c:261
closure0_type::hdr
gc_header_type hdr
Definition: types.h:1406
cvar_tag
@ cvar_tag
Definition: types.h:57
vpbuffer_t::count
int count
Definition: types.h:1533
closure
closure0_type * closure
Definition: types.h:1432
bignum_tag
@ bignum_tag
Definition: types.h:62
gc_thread_data_t::gc_status
int gc_status
Definition: types.h:354
gc_heap_t::next_free
gc_heap * next_free
Definition: types.h:244
gc_thread_data_t::cached_heap_total_sizes
uintptr_t * cached_heap_total_sizes
Definition: types.h:379
atomic
atomic_type * atomic
Definition: types.h:762
gc_is_mutator_new
int gc_is_mutator_new(gc_thread_data *thd)
Determine if the given mutator is in the list of new threads.
Definition: gc.c:329
string_tag
@ string_tag
Definition: types.h:67
list_2_type::b
pair_type b
Definition: types.h:1306
bignum_type
Exact integer of unlimited precision.
Definition: types.h:823
gc_grow_heap
gc_heap * gc_grow_heap(gc_heap *h, size_t size, gc_thread_data *thd)
Grow a heap by allocating a new page.
Definition: gc.c:1012
symbol_type::tag
const tag_type tag
Definition: types.h:790
bytevector_type::hdr
gc_header_type hdr
Definition: types.h:1210
pair_type::tag
tag_type tag
Definition: types.h:1249
vp_create
vpbuffer * vp_create(void)
Definition: runtime.c:6892
gc_thread_data_t::thread_state
cyc_thread_state_type thread_state
Definition: types.h:330
bytevector_type::data
char * data
Definition: types.h:1213
common_type
A union of all the constant-size objects.
Definition: types.h:1497
port_type::hdr
gc_header_type hdr
Definition: types.h:1097
gc_copy_obj
char * gc_copy_obj(object hp, char *obj, gc_thread_data *thd)
Copy given object into given heap object.
Definition: gc.c:814
gc_allocated_bytes
size_t gc_allocated_bytes(object obj, gc_free_list *q, gc_free_list *r)
Get the number of bytes that will be allocated for obj.
Definition: gc.c:1485
eof_tag
@ eof_tag
Definition: types.h:59
gc_heap_t::free_size
unsigned int free_size
Definition: types.h:234
CYC_THREAD_STATE_RUNNABLE
@ CYC_THREAD_STATE_RUNNABLE
Definition: types.h:311
primitive_type::desc
const char * desc
Definition: types.h:1476
gc_heap_t::data
char * data
Definition: types.h:250
vector_5_type::v
vector_type v
Definition: types.h:1181
vpbuffer_t::buf
void ** buf
Definition: types.h:1531
vector_type::elements
object * elements
Definition: types.h:1174
symbol_type::desc
const char * desc
Definition: types.h:791
port_type::tok_buf
char * tok_buf
Definition: types.h:1108
gc_alloc_rest
void * gc_alloc_rest(gc_heap_root *hrt, size_t size, char *obj, gc_thread_data *thd, int *heap_grown)
pair_type::hdr
gc_header_type hdr
Definition: types.h:1248
gc_wait_handshake
void gc_wait_handshake()
Wait for all mutators to handshake.
Definition: gc.c:2430
symbol_tag
@ symbol_tag
Definition: types.h:68
gc_remove_mutator
void gc_remove_mutator(gc_thread_data *thd)
Remove selected mutator from the mutator list. This is done for terminated threads....
Definition: gc.c:290
tag_type
unsigned char tag_type
Definition: types.h:86
gc_init_fixed_size_free_list
void gc_init_fixed_size_free_list(gc_heap *h)
Initialize free lists within a single heap page. Assumes that there is no data currently on the heap ...
Definition: gc.c:458
gc_heap_create_rest
void gc_heap_create_rest(gc_heap *h, gc_thread_data *thd)
port_type::col_num
unsigned int col_num
Definition: types.h:1104
gc_add_new_unrunning_mutator
void gc_add_new_unrunning_mutator(gc_thread_data *thd)
Add data for a new mutator that is not yet scheduled to run. This is done so there is a record in the...
Definition: gc.c:246
closureN
closureN_type * closureN
Definition: types.h:1431
mark_buffer_t::next
mark_buffer * next
Definition: types.h:307
gc_is_mutator_active
int gc_is_mutator_active(gc_thread_data *thd)
Determine if the given mutator is in the list of active threads.
Definition: gc.c:312
gc_mutator_thread_blocked
void gc_mutator_thread_blocked(gc_thread_data *thd, object cont)
Called explicitly from a mutator thread to let the collector know it (may) block for an unknown perio...
Definition: gc.c:2831
gc_heap_last
gc_heap * gc_heap_last(gc_heap *h)
Get the heap's last page.
Definition: gc.c:1554
gc_thread_data_init
void gc_thread_data_init(gc_thread_data *thd, int mut_num, char *stack_base, long stack_size)
Initialize runtime data structures for a thread.
Definition: gc.c:2673
gc_thread_data_t::gc_alloc_color
unsigned char gc_alloc_color
Definition: types.h:348
list_2_type
Definition: types.h:1306
CYC_BN_LT
@ CYC_BN_LT
Definition: types.h:924
port_type::line_num
unsigned int line_num
Definition: types.h:1103
vpbuffer_realloc
void ** vpbuffer_realloc(void **buf, int *len)
Definition: runtime.c:6872
HEAP_HUGE
@ HEAP_HUGE
Definition: types.h:191
gc_thread_data_t::mark_buffer_len
int mark_buffer_len
Definition: types.h:369
double_type::value
double value
Definition: types.h:880
port_type::tag
tag_type tag
Definition: types.h:1098
gc_thread_data_t::last_read
int last_read
Definition: types.h:358
port_type::tok_start
unsigned int tok_start
Definition: types.h:1106
c_opaque_type::tag
tag_type tag
Definition: types.h:704
mutex_type
The mutex thread synchronization type.
Definition: types.h:733
vector_type::tag
tag_type tag
Definition: types.h:1172
vpbuffer_free
void vpbuffer_free(void **buf)
Definition: runtime.c:6887
macro_tag
@ macro_tag
Definition: types.h:52
gc_thread_data_t::mutations
void ** mutations
Definition: types.h:336
object
void * object
Definition: types.h:40
cond_var_type::cond
pthread_cond_t cond
Definition: types.h:748
double_type
Double-precision floating point type, also known as a flonum.
Definition: types.h:877
gc_thread_data_t::pending_writes
int pending_writes
Definition: types.h:365
STATUS_SYNC2
@ STATUS_SYNC2
Definition: types.h:283
gc_heap_t::data_end
char * data_end
Definition: types.h:252
list_4_type
Definition: types.h:1308
integer_type::value
int value
Definition: types.h:811
integer_type::hdr
gc_header_type hdr
Definition: types.h:809
function_type
void(* function_type)(void *data, object clo, int argc, object *args)
Definition: types.h:666
global_table
list global_table
Definition: runtime.c:519
cvar_type::tag
tag_type tag
Definition: types.h:679
closure1_tag
@ closure1_tag
Definition: types.h:50
boolean_type::hdr
gc_header_type hdr
Definition: types.h:771
gc_thread_data_t::gc_args
object * gc_args
Definition: types.h:393
gc_minor
int gc_minor(void *data, object low_limit, object high_limit, closure cont, object *args, int num_args)
Definition: runtime.c:6031
gc_sweep
gc_heap * gc_sweep(gc_heap *h, gc_thread_data *thd)
Sweep portion of the GC algorithm.
Definition: gc.c:1589
vector_type::hdr
gc_header_type hdr
Definition: types.h:1171
STAGE_SWEEPING
@ STAGE_SWEEPING
Definition: types.h:289
mutex_tag
@ mutex_tag
Definition: types.h:63
symbol_type::hdr
gc_header_type hdr
Definition: types.h:789
port_type::mem_buf_len
size_t mem_buf_len
Definition: types.h:1111
gc_empty_collector_stack
void gc_empty_collector_stack()
Empty the collector's mark stack.
Definition: gc.c:2385
pair_tag
@ pair_tag
Definition: types.h:64
gc_handshake
void gc_handshake(gc_status_type s)
Called by the collector thread to perform a handshake with all of the mutators.
Definition: gc.c:2405
gc_heap_t::last_alloc_size
unsigned int last_alloc_size
Definition: types.h:242
vector_4_type::v
vector_type v
Definition: types.h:1180
common_type::symbol_t
symbol_type symbol_t
Definition: types.h:1500
vector_2_type::v
vector_type v
Definition: types.h:1178
gc_thread_data_t::jmp_start
jmp_buf * jmp_start
Definition: types.h:389
atomic_type::tag
tag_type tag
Definition: types.h:759
vpbuffer_t::len
int len
Definition: types.h:1532
bytevector_type::tag
tag_type tag
Definition: types.h:1211
CYC_BN_EQ
@ CYC_BN_EQ
Definition: types.h:925
gc_alloc_from_bignum
void * gc_alloc_from_bignum(gc_thread_data *data, bignum_type *src)
A helper function to create a heap-allocated copy of a bignum.
Definition: gc.c:1340
gc_heap_t::num_unswept_children
int num_unswept_children
Definition: types.h:240
port_type::str_bv_in_mem_buf
char * str_bv_in_mem_buf
Definition: types.h:1113
gc_heap_root_t::heap
gc_heap ** heap
Definition: types.h:260
macro_type::tag
tag_type tag
Definition: types.h:1399
gc_heap_t::free_list
gc_free_list * free_list
Definition: types.h:246
CYC_THREAD_STATE_BLOCKED
@ CYC_THREAD_STATE_BLOCKED
Definition: types.h:312
closure0_tag
@ closure0_tag
Definition: types.h:49
macro_type::num_args
int num_args
Definition: types.h:1401
bytevector_tag
@ bytevector_tag
Definition: types.h:54
char_type
uint32_t char_type
Definition: types.h:602
gc_free_list_t::size
unsigned int size
Definition: types.h:209
complex_num_tag
@ complex_num_tag
Definition: types.h:70