Wild Life  2.29
 All Data Structures Files Functions Variables Typedefs Macros
Macros | Functions | Variables
memory.c File Reference

Go to the source code of this file.

Macros

#define LONELY   1
 
#define assert(N)
 
#define UNCHECKED(P)   (! *((GENERIC)(P)+delta))
 

Functions

char * GetStrOption (char *name, char *def)
 
int GetBoolOption (char *name)
 
int GetIntOption (char *name, int def)
 
void pchoices ()
 
void print_undo_stack ()
 
long bounds_undo_stack ()
 
static void check_psi_list ()
 
static void check_resid_list ()
 
static void check_choice ()
 
static void check_undo_stack ()
 
void fail_all ()
 
static void compress ()
 
static long unchecked (GENERIC *p, long len)
 
static void check_string (GENERIC *s)
 
static void check_bytedata (GENERIC *s)
 
static void check_code (ptr_int_list *c)
 
static void check_pair_list (ptr_pair_list *p)
 
static void check_triple_list (ptr_triple_list *p)
 
static void check_kids (ptr_int_list *c)
 
static void check_operator_data (ptr_operator_data *op)
 
static void check_module ()
 
void check_hash_table ()
 
static void check_keyword ()
 
static void check_module_list (ptr_int_list *c)
 
static void check_module_tree (ptr_node *n)
 
static void check_module (ptr_module *m)
 
void check_hash_table (ptr_hash_table table)
 
static void check_keyword (ptr_keyword *k)
 
void check_definition (ptr_definition *d)
 
void check_definition_list ()
 
static void check_def_code (ptr_definition *d)
 
static void check_def_rest (ptr_definition *d)
 
static void check_symbol (ptr_node *n)
 
static void check_type_disj (ptr_int_list *p)
 
static void check_goal_stack (ptr_goal *g)
 
static void check_resid (ptr_residuation *r)
 
void check_resid_block (ptr_resid_block *rb)
 
void check_psi_term (ptr_psi_term *t)
 
void check_attr (ptr_node *n)
 
void check_gamma_code ()
 
static void check_gamma_rest ()
 
static void check_undo_stack (ptr_stack *s)
 
static void check_choice_structs (ptr_choice_point *c)
 
static void check_choice (ptr_choice_point *c)
 
static void check_special_addresses ()
 
static void check_psi_list (ptr_int_list *l)
 
static void check_resid_list (ptr_resid_list *l)
 
static void check_var (ptr_node *n)
 
static void check ()
 
void print_gc_info (long timeflag)
 
void garbage ()
 
GENERIC heap_alloc (long s)
 
GENERIC stack_alloc (long s)
 
void init_memory ()
 
long memory_check ()
 

Variables

static long delta
 
static long pass
 
static struct tms last_garbage_time
 
static float gc_time
 
static float life_time
 

Macro Definition Documentation

#define assert (   N)

Definition at line 104 of file memory.c.

#define LONELY   1

Definition at line 20 of file memory.c.

#define UNCHECKED (   P)    (! *((GENERIC)(P)+delta))

Definition at line 292 of file memory.c.

Function Documentation

long bounds_undo_stack ( )

Definition at line 121 of file memory.c.

References wl_stack::aaaa_3, FALSE, mem_base, mem_limit, wl_stack::next, TRUE, wl_stack::type, undo_action, undo_stack, and VALID_ADDRESS.

124 {
126 
127  while (u) {
128  if ( (GENERIC)u<mem_base
129  || (GENERIC)u>mem_limit
130  || (!VALID_ADDRESS(u->aaaa_3) && !(u->type & undo_action))
131  ) {
132  if ((GENERIC)u<mem_base || (GENERIC)u>mem_limit) {
133  printf("\nUNDO: u=%lx\n",(long)u);
134  }
135  else {
136  printf("\nUNDO: u:%lx type:%ld a:%lx b:%lx next:%lx\n",
137  (unsigned long)u,(unsigned long)u->type,(unsigned long)u->aaaa_3,(unsigned long)u->bbbb_3,(unsigned long)u->next);
138  }
139  (void)fflush(stdout);
140  return FALSE;
141  }
142  u=u->next;
143  }
144 
145  return TRUE;
146 }
#define VALID_ADDRESS(A)
Definition: def_macro.h:132
GENERIC mem_limit
Definition: def_glob.h:13
ptr_stack undo_stack
Definition: def_glob.h:53
type_ptr type
Definition: def_struct.h:216
#define TRUE
Definition: def_const.h:127
#define FALSE
Definition: def_const.h:128
GENERIC mem_base
Definition: def_glob.h:11
GENERIC * aaaa_3
Definition: def_struct.h:217
#define undo_action
Definition: def_const.h:188
unsigned long * GENERIC
Definition: def_struct.h:17
ptr_stack next
Definition: def_struct.h:219
static void check ( )
static

Definition at line 1208 of file memory.c.

References aborthooksym, abortsym, add_module1, add_module2, add_module3, aim, alist, and, apply, assert, bi_module, boolpredsym, bounds_undo_stack(), built_in, call_handlersym, check_choice(), check_choice_structs(), check_definition(), check_definition_list(), check_gamma_code(), check_gamma_rest(), check_goal_stack(), check_module(), check_module_tree(), check_psi_term(), check_resid_list(), check_special_addresses(), check_string(), check_sys_definitions(), check_undo_stack(), check_var(), choice_stack, colonsym, commasym, comment, constant, current_module, cut, day_attr, delay_checksym, disj_nil, disjunction, dynamicsym, encodesym, eof, eqsym, error_psi_term, eval_argsym, final_dot, final_question, funcsym, functor, fx_sym, fy_sym, goal_stack, hour_attr, iff, input_state, inputfilesym, integer, lf_false, lf_true, life_or, listingsym, loadsym, minus_symbol, minute_attr, module_table, month_attr, nil, no_module, nothing, null_psi_term, nullsym, old_saved_psi_term, old_state, one, opsym, pass, predsym, quote, quoted_string, real, resid_aim, resid_vars, saved_psi_term, second_attr, staticsym, stdin_state, stream, succeed, such_that, syntax_module, sys_module, three, timesym, top, tracesym, TRUE, two, typesym, undo_stack, user_module, var_tree, variable, weekday_attr, x_module, xbutton_event, xconfigure_event, xdestroy_event, xdisplay, xdisplaylist, xdrawable, xenter_event, xevent, xevent_existing, xevent_list, xexpose_event, xf_sym, xfx_sym, xfy_sym, xgc, xkeyboard_event, xleave_event, xmisc_event, xmotion_event, xpixmap, xwindow, year_attr, yf_sym, and yfx_sym.

1209 {
1210 #ifdef prlDEBUG
1211  amount_used=0;
1212 #endif
1213 
1214  /* First of all, get all the codes right so that data type-checking remains
1215  coherent.
1216 
1217  Kids and Parents cannot be checked because the built-in types have codes
1218  which might have been moved.
1219  */
1220  /* print_undo_stack(); */
1221 
1222 
1223  check_choice_structs(&choice_stack); /* RM: Oct 28 1993 */
1224 
1226  check_gamma_code();
1227 
1228  /* Now, check the rest of the definitions and all global roots */
1229 
1230  check_gamma_rest();
1231 
1233 
1234  check_definition(&abortsym); /* 26.1 */
1235  check_definition(&aborthooksym); /* 26.1 */
1236 
1237  check_definition(&add_module1); /* RM: Mar 12 1993 */
1240 
1243  check_definition(&boolean);
1249  /* check_definition(&conjunction); 19.8 */
1253  check_definition(&disj_nil); /* RM: Feb 16 1993 */
1262  check_definition(&life_or); /* RM: Apr 6 1993 */
1263  check_definition(&minus_symbol); /* RM: Jun 21 1993 */
1264  check_definition(&nil); /* RM: Dec 9 1992 */
1276  check_definition(&tracesym); /* 26.1 */
1285  /* check_definition(&provesym); */
1298 
1299  /* RM: Jul 7 1993 */
1302 
1304 
1305 #ifdef X11
1322 #endif
1323 
1324  /* check_psi_term(&empty_list); 5.8 */
1325 
1326  check_string(&one);
1327  check_string(&two);
1328  check_string(&three);
1336 
1343  check_psi_term(&old_state); /* RM: Feb 17 1993 */
1344 
1346 #ifdef X11
1349 #endif
1350 
1352  /* check_choice(&prompt_choice_stack); 12.7 */
1353 
1354 
1355  /* RM: Feb 3 1993 */
1356  /* check_symbol(&symbol_table); */
1357  /* check_definition(&first_definition); */
1358  check_definition_list(); /* RM: Feb 15 1993 */
1359 
1360 
1361  /*** MODULES ***/
1362  /* RM: Jan 13 1993 */
1363 
1367  check_module(&user_module); /* RM: Jan 27 1993 */
1372 
1373  /*** End ***/
1374 
1375 
1376 
1377  check_var(&var_tree);
1378 
1380  check_goal_stack(&aim); /* 7.10 */
1381 
1382  if (TRUE /*resid_aim 10.6 */) check_resid_list(&resid_vars); /* 21.9 */
1383 
1385 
1388 
1391 
1393 }
ptr_definition encodesym
Definition: def_glob.h:116
ptr_definition such_that
Definition: def_glob.h:105
ptr_definition boolpredsym
Definition: def_glob.h:74
static void check_undo_stack()
ptr_definition abortsym
Definition: def_glob.h:64
ptr_definition timesym
Definition: def_glob.h:108
static void check_resid_list()
ptr_definition xfy_sym
Definition: def_glob.h:127
ptr_definition staticsym
Definition: def_glob.h:115
ptr_psi_term stdin_state
Definition: def_glob.h:200
ptr_definition loadsym
Definition: def_glob.h:113
ptr_goal goal_stack
Definition: def_glob.h:50
ptr_module current_module
Definition: def_glob.h:161
ptr_definition dynamicsym
Definition: def_glob.h:114
ptr_definition opsym
Definition: def_glob.h:112
ptr_definition comment
Definition: def_glob.h:80
ptr_definition xdisplaylist
Definition: def_glob.h:211
ptr_definition stream
Definition: def_glob.h:103
ptr_psi_term xevent_list
Definition: def_glob.h:208
static void check_goal_stack(ptr_goal *g)
Definition: memory.c:739
ptr_definition xbutton_event
Definition: def_glob.h:211
ptr_definition listingsym
Definition: def_glob.h:117
ptr_psi_term old_state
Definition: def_glob.h:142
char * two
Definition: def_glob.h:251
ptr_definition commasym
Definition: def_glob.h:79
ptr_psi_term null_psi_term
Definition: def_glob.h:140
static void check_string(GENERIC *s)
Definition: memory.c:375
ptr_definition fy_sym
Definition: def_glob.h:125
static void check_special_addresses()
Definition: memory.c:1119
static long pass
Definition: memory.c:17
ptr_definition aborthooksym
Definition: def_glob.h:65
ptr_definition xexpose_event
Definition: def_glob.h:211
ptr_definition constant
Definition: def_glob.h:82
ptr_module user_module
Definition: def_glob.h:156
ptr_definition top
Definition: def_glob.h:106
ptr_node var_tree
Definition: def_glob.h:26
ptr_psi_term input_state
Definition: def_glob.h:199
ptr_definition quote
Definition: def_glob.h:100
static void check_module()
char * three
Definition: def_glob.h:252
ptr_definition apply
Definition: def_glob.h:72
ptr_definition xgc
Definition: def_glob.h:211
ptr_goal resid_aim
Definition: def_glob.h:220
ptr_definition xmotion_event
Definition: def_glob.h:211
ptr_resid_list resid_vars
Definition: def_glob.h:221
ptr_definition xmisc_event
Definition: def_glob.h:211
ptr_definition minus_symbol
Definition: def_glob.h:96
static void check_choice()
ptr_definition xfx_sym
Definition: def_glob.h:126
void check_definition(ptr_definition *d)
Definition: memory.c:612
ptr_definition add_module3
Definition: def_glob.h:69
ptr_stack undo_stack
Definition: def_glob.h:53
ptr_definition yf_sym
Definition: def_glob.h:124
ptr_definition disj_nil
Definition: def_glob.h:85
ptr_definition nullsym
Definition: def_glob.h:129
ptr_definition real
Definition: def_glob.h:102
ptr_definition alist
Definition: def_glob.h:94
static void check_choice_structs(ptr_choice_point *c)
Definition: memory.c:1094
ptr_definition functor
Definition: def_glob.h:91
ptr_definition eqsym
Definition: def_glob.h:87
ptr_definition eof
Definition: def_glob.h:86
ptr_definition xkeyboard_event
Definition: def_glob.h:211
#define TRUE
Definition: def_const.h:127
ptr_definition xwindow
Definition: def_glob.h:211
ptr_psi_term error_psi_term
Definition: def_glob.h:23
ptr_definition built_in
Definition: def_glob.h:75
ptr_definition integer
Definition: def_glob.h:93
ptr_definition lf_true
Definition: def_glob.h:107
ptr_definition iff
Definition: def_glob.h:92
ptr_definition final_dot
Definition: def_glob.h:137
ptr_definition quoted_string
Definition: def_glob.h:101
ptr_definition succeed
Definition: def_glob.h:104
ptr_definition and
Definition: def_glob.h:71
ptr_node module_table
Definition: def_glob.h:160
void check_psi_term(ptr_psi_term *t)
Definition: memory.c:920
ptr_definition lf_false
Definition: def_glob.h:89
ptr_module syntax_module
Definition: def_glob.h:159
ptr_goal aim
Definition: def_glob.h:49
char * weekday_attr
Definition: def_glob.h:259
ptr_definition disjunction
Definition: def_glob.h:84
ptr_definition xpixmap
Definition: def_glob.h:211
char * one
Definition: def_glob.h:250
ptr_definition xenter_event
Definition: def_glob.h:211
ptr_definition xevent
Definition: def_glob.h:211
ptr_definition add_module2
Definition: def_glob.h:68
ptr_definition life_or
Definition: def_glob.h:95
ptr_definition delay_checksym
Definition: def_glob.h:118
void check_definition_list()
Definition: memory.c:648
ptr_definition yfx_sym
Definition: def_glob.h:128
ptr_definition final_question
Definition: def_glob.h:138
ptr_psi_term saved_psi_term
Definition: def_glob.h:194
ptr_module sys_module
Definition: def_glob.h:162
ptr_definition add_module1
Definition: def_glob.h:67
ptr_definition tracesym
Definition: def_glob.h:109
ptr_definition xdisplay
Definition: def_glob.h:211
void check_gamma_code()
Definition: memory.c:1008
static void check_var(ptr_node *n)
Definition: memory.c:1180
ptr_definition fx_sym
Definition: def_glob.h:123
char * minute_attr
Definition: def_glob.h:257
ptr_definition cut
Definition: def_glob.h:83
ptr_module x_module
Definition: def_glob.h:158
ptr_definition xdestroy_event
Definition: def_glob.h:211
static void check_module_tree(ptr_node *n)
Definition: memory.c:539
ptr_definition nothing
Definition: def_glob.h:98
ptr_definition nil
Definition: def_glob.h:97
char * year_attr
Definition: def_glob.h:253
ptr_module no_module
Definition: def_glob.h:157
char * second_attr
Definition: def_glob.h:258
ptr_definition xleave_event
Definition: def_glob.h:211
char * day_attr
Definition: def_glob.h:255
static void check_gamma_rest()
Definition: memory.c:1023
ptr_module bi_module
Definition: def_glob.h:155
ptr_definition predsym
Definition: def_glob.h:99
char * hour_attr
Definition: def_glob.h:256
void check_sys_definitions()
Definition: sys.c:1740
ptr_definition xconfigure_event
Definition: def_glob.h:211
ptr_psi_term xevent_existing
Definition: def_glob.h:208
ptr_definition xf_sym
Definition: def_glob.h:122
long bounds_undo_stack()
Definition: memory.c:121
ptr_definition colonsym
Definition: def_glob.h:78
ptr_definition inputfilesym
Definition: def_glob.h:120
ptr_definition variable
Definition: def_glob.h:111
ptr_definition call_handlersym
Definition: def_glob.h:121
ptr_choice_point choice_stack
Definition: def_glob.h:51
ptr_psi_term old_saved_psi_term
Definition: def_glob.h:195
ptr_definition eval_argsym
Definition: def_glob.h:119
ptr_definition funcsym
Definition: def_glob.h:90
char * month_attr
Definition: def_glob.h:254
ptr_definition typesym
Definition: def_glob.h:110
#define assert(N)
Definition: memory.c:104
ptr_definition xdrawable
Definition: def_glob.h:211
void check_attr ( ptr_node n)

Definition at line 985 of file memory.c.

References check_psi_term(), check_string(), and unchecked().

987 {
988  while (unchecked(n,sizeof(node))) {
989  check_attr(&((*n)->left));
990  check_string(&((*n)->key));
991  check_psi_term((struct wl_psi_term **)&((*n)->data));
992 
993  n = &((*n)->right);
994  /* check_attr(&((*n)->right)); 9.6 */
995  }
996 }
static void check_string(GENERIC *s)
Definition: memory.c:375
static long unchecked(GENERIC *p, long len)
Definition: memory.c:309
void check_psi_term(ptr_psi_term *t)
Definition: memory.c:920
void check_attr(ptr_node *n)
Definition: memory.c:985
static void check_bytedata ( GENERIC s)
static

Definition at line 416 of file memory.c.

References delta, MAX_BUILT_INS, pass, and unchecked().

418 {
419  GENERIC addr;
420  long value;
421  if ((unsigned long) *s > MAX_BUILT_INS) {
422  unsigned long bytes = *((unsigned long *) *s);
423  unsigned long size = bytes + sizeof(bytes);
424  switch (pass) {
425  case 1:
426  (void)unchecked(s,size);
427  break;
428  case 2:
429  addr=(*s+delta);
430  value= *addr;
431  if (value & 1) {
432  value--;
433  *s=(GENERIC) value;
434  *addr=value;
435 #ifdef prlDEBUG
436  amount_used+=size;
437 #endif
438  }
439  *s=(GENERIC)value;
440  break;
441  }
442  }
443 }
static long delta
Definition: memory.c:8
static long pass
Definition: memory.c:17
static long unchecked(GENERIC *p, long len)
Definition: memory.c:309
#define MAX_BUILT_INS
Definition: def_const.h:82
unsigned long * GENERIC
Definition: def_struct.h:17
static void check_choice ( )
static
static void check_choice ( ptr_choice_point c)
static

Definition at line 1102 of file memory.c.

References check_goal_stack(), and check_undo_stack().

1104 {
1105  while(*c) {
1106  check_undo_stack(&((*c)->undo_point)); /* 17.7 */
1107  check_goal_stack(&((*c)->goal_stack));
1108  c= &((*c)->next);
1109  }
1110 }
static void check_undo_stack()
static void check_goal_stack(ptr_goal *g)
Definition: memory.c:739
static void check_choice_structs ( ptr_choice_point c)
static

Definition at line 1094 of file memory.c.

References unchecked().

1096 {
1097  while(unchecked(c,sizeof(choice_point))) {
1098  c= &((*c)->next);
1099  }
1100 }
static long unchecked(GENERIC *p, long len)
Definition: memory.c:309
static void check_code ( ptr_int_list c)
static

Definition at line 448 of file memory.c.

References unchecked().

450 {
451  while (unchecked(c,sizeof(int_list)))
452  c= &((*c)->next);
453 }
static long unchecked(GENERIC *p, long len)
Definition: memory.c:309
static void check_def_code ( ptr_definition d)
static

Definition at line 667 of file memory.c.

References check_code(), and unchecked().

669 {
670  if (unchecked(d,sizeof(definition)))
671  check_code(&((*d)->code));
672  /* p = &((*d)->properties); */
673  /* check_def_prop(p); */
674 }
static long unchecked(GENERIC *p, long len)
Definition: memory.c:309
static void check_code(ptr_int_list *c)
Definition: memory.c:448
static void check_def_rest ( ptr_definition d)
static

Definition at line 682 of file memory.c.

References check_keyword(), check_kids(), check_operator_data(), check_pair_list(), check_triple_list(), and type_it.

684 {
685  if (*d) {
686  check_keyword(&((*d)->keyword)); /* RM: Jan 12 1993 */
687  check_pair_list(&((*d)->rule));
688  check_triple_list(&((*d)->properties));
689 
690  if ((*d)->type_def==(def_type)type_it) {
691  check_kids(&((*d)->parents));
692  check_kids(&((*d)->children));
693  }
694  check_operator_data(&((*d)->op_data)); /* PVR 5.6 */
695 #ifdef CLIFE
696  check_block_def(&((*d)->block_def)); /*CB 25/01/93 */
697 #endif /* CLIFE */
698  }
699 }
static void check_operator_data(ptr_operator_data *op)
Definition: memory.c:506
static void check_pair_list(ptr_pair_list *p)
Definition: memory.c:460
#define type_it
Definition: def_const.h:363
static void check_kids(ptr_int_list *c)
Definition: memory.c:492
static void check_triple_list(ptr_triple_list *p)
Definition: memory.c:476
static void check_keyword()
void check_definition ( ptr_definition d)

Definition at line 612 of file memory.c.

References check_code(), check_keyword(), check_kids(), check_operator_data(), check_pair_list(), check_psi_term(), check_triple_list(), type_it, and unchecked().

614 {
615  if(unchecked(d,sizeof(definition))) {
616 
617  check_keyword(&((*d)->keyword)); /* RM: Jan 12 1993 */
618 
619 #ifdef prlDEBUG
620  printf("%lx %20s %ld\n",*d,(*d)->keyword->symbol,amount_used);
621 #endif
622 
623  check_code(&((*d)->code));
624  check_pair_list(&((*d)->rule));
625  check_triple_list(&((*d)->properties));
626 
627  if ((*d)->type_def==(def_type)type_it) {
628  check_kids(&((*d)->parents));
629  check_kids(&((*d)->children));
630  }
631 
632  check_psi_term(&((*d)->global_value)); /* RM: Feb 9 1993 */
633  check_psi_term(&((*d)->init_value)); /* RM: Mar 23 1993 */
634 
635  check_operator_data(&((*d)->op_data)); /* PVR 5.6 */
636 
637 #ifdef CLIFE
638  check_block_def(&((*d)->block_def)); /* RM: Jan 27 1993 */
639 #endif /* CLIFE */
640  }
641 }
static void check_operator_data(ptr_operator_data *op)
Definition: memory.c:506
ptr_keyword keyword
Definition: def_struct.h:124
static void check_pair_list(ptr_pair_list *p)
Definition: memory.c:460
char * symbol
Definition: def_struct.h:91
static long unchecked(GENERIC *p, long len)
Definition: memory.c:309
#define type_it
Definition: def_const.h:363
static void check_kids(ptr_int_list *c)
Definition: memory.c:492
static void check_triple_list(ptr_triple_list *p)
Definition: memory.c:476
void check_psi_term(ptr_psi_term *t)
Definition: memory.c:920
static void check_code(ptr_int_list *c)
Definition: memory.c:448
static void check_keyword()
void check_definition_list ( )

Definition at line 648 of file memory.c.

References check_definition(), and first_definition.

650 {
651  ptr_definition *d;
652 
653  d= &first_definition;
654 
655  while(*d) {
656  check_definition(d);
657  d= &((*d)->next);
658  }
659 }
void check_definition(ptr_definition *d)
Definition: memory.c:612
ptr_definition first_definition
Definition: def_glob.h:3
void check_gamma_code ( )

Definition at line 1008 of file memory.c.

References check_def_code(), gamma_table, type_count, and unchecked().

1009 {
1010  long i;
1011 
1013  for (i=0;i<type_count;i++)
1014  check_def_code(&(gamma_table[i]));
1015  }
1016 }
long type_count
Definition: def_glob.h:46
static long unchecked(GENERIC *p, long len)
Definition: memory.c:309
static void check_def_code(ptr_definition *d)
Definition: memory.c:667
ptr_definition * gamma_table
Definition: def_glob.h:309
static void check_gamma_rest ( )
static

Definition at line 1023 of file memory.c.

References check_def_rest(), gamma_table, and type_count.

1024 {
1025  long i;
1026 
1027  for (i=0;i<type_count;i++)
1028  check_def_rest(&(gamma_table[i]));
1029 }
long type_count
Definition: def_glob.h:46
ptr_definition * gamma_table
Definition: def_glob.h:309
static void check_def_rest(ptr_definition *d)
Definition: memory.c:682
static void check_goal_stack ( ptr_goal g)
static

Definition at line 739 of file memory.c.

References check_pair_list(), check_psi_term(), check_resid_block(), check_string(), check_type_disj(), choice_stack, clause, DEFRULES, del_clause, disj, Errorline(), eval, eval_cut, fail, freeze_cut, general_cut, implies_cut, load, LONELY, match, pass, prove, retract, type_disj, unchecked(), unify, unify_noeval, and what_next.

741 {
742  while (unchecked(g,sizeof(goal))) {
743 
744  switch ((*g)->type) {
745 
746  case fail:
747  break;
748 
749  case unify:
750  case unify_noeval: /* PVR 5.6 */
751  check_psi_term(&((*g)->aaaa_1));
752  check_psi_term(&((*g)->bbbb_1));
753  break;
754 
755  case prove:
756  check_psi_term(&((*g)->aaaa_1));
757  if ((unsigned long)(*g)->bbbb_1!=DEFRULES) check_pair_list(&((*g)->bbbb_1));
758  check_pair_list(&((*g)->cccc_1));
759  break;
760 
761  case disj:
762  check_psi_term(&((*g)->aaaa_1));
763  check_psi_term(&((*g)->bbbb_1));
764  break;
765 
766  case what_next:
767  /* check_choice(&((*g)->bbbb_1)); */
768  break;
769 
770  case eval:
771  check_psi_term(&((*g)->aaaa_1));
772  check_psi_term(&((*g)->bbbb_1));
773  check_pair_list(&((*g)->cccc_1));
774  break;
775 
776  case load:
777  check_psi_term(&((*g)->aaaa_1));
778  check_string(&((*g)->cccc_1));
779  break;
780 
781  case match:
782  check_psi_term(&((*g)->aaaa_1));
783  check_psi_term(&((*g)->bbbb_1));
784  check_resid_block((struct wl_resid_block **)&((*g)->cccc_1));
785  break;
786 
787  case general_cut:
788  /* assert((GENERIC)(*g)->aaaa_3 <= (GENERIC)choice_stack); 12.7 17.7 */
789  if (pass==1 && (ptr_choice_point)(*g)->aaaa_1>choice_stack)
790  (*g)->aaaa_1=(ptr_psi_term)choice_stack;
791  (void)unchecked(&((*g)->aaaa_1),LONELY);
792  break;
793 
794  case eval_cut:
795  check_psi_term(&((*g)->aaaa_1));
796  /* assert((GENERIC)(*g)->bbbb_1 <= (GENERIC)choice_stack); 12.7 17.7 */
797  if (pass==1 && (ptr_choice_point)(*g)->bbbb_1>choice_stack)
798  (*g)->bbbb_1=(ptr_psi_term)choice_stack;
799  (void)unchecked(&((*g)->bbbb_1),LONELY);
800  check_resid_block((struct wl_resid_block **)&((*g)->cccc_1));
801  break;
802 
803  case freeze_cut:
804  case implies_cut:
805  check_psi_term(&((*g)->aaaa_1));
806  /* assert((GENERIC)(*g)->bbbb_1 <= (GENERIC)choice_stack); 12.7 17.7 */
807  if (pass==1 && (ptr_choice_point)(*g)->bbbb_1>choice_stack)
808  (*g)->bbbb_1=(ptr_psi_term)choice_stack;
809  (void)unchecked(&((*g)->bbbb_1),LONELY);
810  check_resid_block((struct wl_resid_block **)&((*g)->cccc_1));
811  break;
812 
813  case type_disj:
814  check_psi_term(&((*g)->aaaa_1));
815  check_type_disj(&((*g)->bbbb_1));
816  break;
817 
818  case clause:
819  check_psi_term(&((*g)->aaaa_1));
820  check_psi_term(&((*g)->bbbb_1));
821  (void)unchecked(&((*g)->cccc_1),LONELY);
822  /* check_pair_list((*g)->cccc_1); */ /* 6.8 */
823  break;
824 
825  case del_clause:
826  check_psi_term(&((*g)->aaaa_1));
827  check_psi_term(&((*g)->bbbb_1));
828  (void)unchecked(&((*g)->cccc_1),LONELY);
829  /* check_pair_list((*g)->cccc_1); */ /* 6.8 */
830  break;
831 
832  case retract:
833  (void)unchecked(&((*g)->aaaa_1),LONELY);
834  /* check_pair_list((*g)->aaaa_1); */ /* 6.8 */
835  /*PVR*/ /* check_choice(&((*g)->bbbb_1)); 9.6 */
836  break;
837 
838  default:
839  Errorline("in garbage collection, bad goal on stack.\n");
840  }
841 
842  g= &((*g)->next);
843  }
844 }
#define prove
Definition: def_const.h:273
static void check_type_disj(ptr_int_list *p)
Definition: memory.c:723
#define general_cut
Definition: def_const.h:282
static void check_string(GENERIC *s)
Definition: memory.c:375
#define implies_cut
Definition: def_const.h:281
#define DEFRULES
Definition: def_const.h:138
static long pass
Definition: memory.c:17
static void check_pair_list(ptr_pair_list *p)
Definition: memory.c:460
static long unchecked(GENERIC *p, long len)
Definition: memory.c:309
#define eval
Definition: def_const.h:278
void Errorline(char *format,...)
Definition: error.c:414
void check_resid_block(ptr_resid_block *rb)
Definition: memory.c:900
#define freeze_cut
Definition: def_const.h:280
#define what_next
Definition: def_const.h:277
#define match
Definition: def_const.h:283
#define clause
Definition: def_const.h:285
void check_psi_term(ptr_psi_term *t)
Definition: memory.c:920
#define fail
Definition: def_const.h:272
#define retract
Definition: def_const.h:287
#define unify
Definition: def_const.h:274
#define load
Definition: def_const.h:288
#define unify_noeval
Definition: def_const.h:275
#define del_clause
Definition: def_const.h:286
#define eval_cut
Definition: def_const.h:279
struct wl_psi_term * ptr_psi_term
Definition: def_struct.h:34
#define disj
Definition: def_const.h:276
#define type_disj
Definition: def_const.h:284
#define LONELY
Definition: memory.c:20
ptr_choice_point choice_stack
Definition: def_glob.h:51
void check_hash_table ( )
void check_hash_table ( ptr_hash_table  table)

Definition at line 576 of file memory.c.

References check_keyword().

579 {
580  long i;
581 
582  for(i=0;i<table->size;i++)
583  if(table->data[i])
584  check_keyword(&(table->data[i]));
585 }
ptr_keyword * data
Definition: def_struct.h:114
static void check_keyword()
static void check_keyword ( )
static
static void check_keyword ( ptr_keyword k)
static

Definition at line 593 of file memory.c.

References check_definition(), check_module(), check_string(), and unchecked().

596 {
597  if(unchecked(k,sizeof(struct wl_keyword))) {
598  check_module(&((*k)->module));
599  check_string(&((*k)->symbol));
600  check_string(&((*k)->combined_name));
601  check_definition(&((*k)->definition));
602  }
603 }
static void check_string(GENERIC *s)
Definition: memory.c:375
static void check_module()
static long unchecked(GENERIC *p, long len)
Definition: memory.c:309
void check_definition(ptr_definition *d)
Definition: memory.c:612
static void check_kids ( ptr_int_list c)
static

Definition at line 492 of file memory.c.

References check_definition(), and unchecked().

494 {
495  while (unchecked(c,sizeof(int_list))) {
496  check_definition((ptr_definition *)&((*c)->value_1));
497  c= &((*c)->next);
498  }
499 }
static long unchecked(GENERIC *p, long len)
Definition: memory.c:309
void check_definition(ptr_definition *d)
Definition: memory.c:612
static void check_module ( )
static
static void check_module ( ptr_module m)
static

Definition at line 556 of file memory.c.

References check_hash_table(), check_module_list(), check_string(), and unchecked().

559 {
560  if(unchecked(m,sizeof(struct wl_module))) {
561  check_string(&((*m)->module_name));
562  check_string(&((*m)->source_file));
563  check_module_list(&((*m)->open_modules));
564  check_module_list(&((*m)->inherited_modules));
565  check_hash_table((*m)->symbol_table);
566  }
567 }
void check_hash_table()
static void check_string(GENERIC *s)
Definition: memory.c:375
static long unchecked(GENERIC *p, long len)
Definition: memory.c:309
static void check_module_list(ptr_int_list *c)
Definition: memory.c:525
static void check_module_list ( ptr_int_list c)
static

Definition at line 525 of file memory.c.

References check_module(), and unchecked().

528 {
529  while (unchecked(c,sizeof(int_list))) {
530  check_module(&((*c)->value_1));
531  c= &((*c)->next);
532  }
533 }
static void check_module()
static long unchecked(GENERIC *p, long len)
Definition: memory.c:309
static void check_module_tree ( ptr_node n)
static

Definition at line 539 of file memory.c.

References check_module(), check_string(), and unchecked().

541 {
542  if (unchecked(n,sizeof(node))) {
543  check_module_tree(&((*n)->left));
544  check_string(&((*n)->key));
545  check_module(&((*n)->data));
546  check_module_tree(&((*n)->right));
547  }
548 }
static void check_string(GENERIC *s)
Definition: memory.c:375
static void check_module()
static long unchecked(GENERIC *p, long len)
Definition: memory.c:309
static void check_module_tree(ptr_node *n)
Definition: memory.c:539
static void check_operator_data ( ptr_operator_data op)
static

Definition at line 506 of file memory.c.

References unchecked().

508 {
509  while (unchecked(op,sizeof(operator_data))) {
510  op = &((*op)->next);
511  }
512 }
static long unchecked(GENERIC *p, long len)
Definition: memory.c:309
static void check_pair_list ( ptr_pair_list p)
static

Definition at line 460 of file memory.c.

References check_psi_term(), and unchecked().

462 {
463  while (unchecked(p,sizeof(pair_list))) {
464  check_psi_term(&((*p)->aaaa_2));
465  check_psi_term(&((*p)->bbbb_2));
466  p= &((*p)->next);
467  }
468 }
static long unchecked(GENERIC *p, long len)
Definition: memory.c:309
void check_psi_term(ptr_psi_term *t)
Definition: memory.c:920
static void check_psi_list ( )
static
static void check_psi_list ( ptr_int_list l)
static

Definition at line 1149 of file memory.c.

References check_psi_term(), and unchecked().

1151 {
1152  while(unchecked(l,sizeof(int_list))) {
1153  check_psi_term((struct wl_psi_term **)&((*l)->value_1));
1154  l= &((*l)->next);
1155  }
1156 }
static long unchecked(GENERIC *p, long len)
Definition: memory.c:309
void check_psi_term(ptr_psi_term *t)
Definition: memory.c:920
void check_psi_term ( ptr_psi_term t)

Definition at line 920 of file memory.c.

References alist, assert, check_attr(), check_bytedata(), check_definition(), check_resid(), check_string(), choice_stack, cut, Errorline(), heap_pointer, LONELY, mem_limit, NULL, pass, quoted_string, REAL, real, stream, sub_type(), sys_bytedata, unchecked(), and variable.

922 {
923  ptr_list *l;
924 
925  while (unchecked(t,sizeof(psi_term))) {
926 
927  /* A psi-term on the heap has no residuation list. */
928  if (pass==1 && (GENERIC)(*t)>=heap_pointer && (GENERIC)(*t)<mem_limit) {
929  assert((*t)->resid==NULL);
930  }
931  check_definition(&((*t)->type));
932  check_attr(&((*t)->attr_list));
933 
934  if ((*t)->value_3) {
935 
936  if ((*t)->type==alist) { /* RM: Dec 15 1992 Should be removed */
937  l=(ptr_list *) &((*t)->value_3);
938  if (l)
939  printf("Found an old list!\n");
940  }
941  else
942 
943  if (sub_type((*t)->type,real))
944  (void)unchecked(&((*t)->value_3),sizeof(REAL));
945  else if (sub_type((*t)->type,quoted_string))
946  check_string(&((*t)->value_3));
947  /* DENYS: BYTEDATA */
948  else if (sub_type((*t)->type,sys_bytedata))
949  check_bytedata(&((*t)->value_3));
950 #ifdef CLIFE
951  else if ((*t)->type->type==block) { /* RM: Jan 27 1993 */
952  check_block_value(&((*t)->value_3));
953  }
954 #endif /* CLIFE */
955  else if ((*t)->type==cut) { /* RM: Oct 28 1993 */
956  /* assert((*t)->value_3 <= (GENERIC)choice_stack); 12.7 17.7 */
957  if (pass==1 && (*t)->value_3>(GENERIC)choice_stack)
958  (*t)->value_3=(GENERIC)choice_stack;
959  (void)unchecked(&((*t)->value_3),LONELY);
960  }
961  else if (sub_type((*t)->type,variable)) /* 8.8 */
962  check_string(&((*t)->value_3));
963  else if ((*t)->type!=stream)
964  Errorline("non-NULL value field in garbage collector, type='%s', value=%d.\n",
965  (*t)->type->keyword->combined_name,
966  (*t)->value_3);
967  }
968 
969  /* check_psi_term(&((*t)->coref)); 9.6 */
970  if ((*t)->resid)
971  check_resid(&((*t)->resid));
972 
973  t = &((*t)->coref);
974  }
975 }
static void check_bytedata(GENERIC *s)
Definition: memory.c:416
static void check_resid(ptr_residuation *r)
Definition: memory.c:851
GENERIC mem_limit
Definition: def_glob.h:13
ptr_definition stream
Definition: def_glob.h:103
static void check_string(GENERIC *s)
Definition: memory.c:375
static long pass
Definition: memory.c:17
#define NULL
Definition: def_const.h:203
#define REAL
Definition: def_const.h:72
static long unchecked(GENERIC *p, long len)
Definition: memory.c:309
struct wl_list * ptr_list
Definition: def_struct.h:38
long sub_type(ptr_definition t1, ptr_definition t2)
Definition: types.c:1544
void check_definition(ptr_definition *d)
Definition: memory.c:612
void Errorline(char *format,...)
Definition: error.c:414
ptr_definition real
Definition: def_glob.h:102
ptr_definition alist
Definition: def_glob.h:94
ptr_definition quoted_string
Definition: def_glob.h:101
GENERIC heap_pointer
Definition: def_glob.h:12
ptr_definition sys_bytedata
Definition: def_glob.h:336
ptr_definition cut
Definition: def_glob.h:83
#define LONELY
Definition: memory.c:20
unsigned long * GENERIC
Definition: def_struct.h:17
void check_attr(ptr_node *n)
Definition: memory.c:985
ptr_definition variable
Definition: def_glob.h:111
ptr_choice_point choice_stack
Definition: def_glob.h:51
#define assert(N)
Definition: memory.c:104
static void check_resid ( ptr_residuation r)
static

Definition at line 851 of file memory.c.

References alist, check_bytedata(), check_code(), check_definition(), check_goal_stack(), check_string(), choice_stack, wl_definition::code, cut, LONELY, pass, quoted_string, REAL, real, sub_CodeType(), sys_bytedata, unchecked(), and variable.

853 {
854  ptr_int_list code;
855  ptr_list *l;
856 
857  while (unchecked(r,sizeof(residuation))) {
858 
859  if ((*r)->sortflag) /* 22.9 */
860  check_definition((struct wl_definition **)&((*r)->bestsort));
861  else
862  check_code(&((*r)->bestsort)); /* 21.9 */
863 
864  /* Handling of the value field (6.10) */
865  code = (*r)->sortflag ? ((ptr_definition)((*r)->bestsort))->code
866  : (ptr_int_list)(*r)->bestsort;
867  /* Copied (almost) verbatim from check_psi_term: */
868  if ((*r)->value_2) {
869  if (code==alist->code) { /* RM: Dec 15 1992 Will be removed */
870  l=(ptr_list *) &((*r)->value_2);
871  if (l)
872  printf("Found an old list!!\n");
873  }
874  else if (sub_CodeType(code,real->code))
875  (void)unchecked(&((*r)->value_2),sizeof(REAL));
876  else if (sub_CodeType(code,quoted_string->code))
877  check_string(&((*r)->value_2));
878  /* DENYS: BYTEDATA */
879  else if (sub_CodeType(code,sys_bytedata->code))
880  check_bytedata(&((*r)->value_2));
881  else if (sub_CodeType(code,cut->code)) {
882  if (pass==1 && (*r)->value_2>(GENERIC)choice_stack)
883  (*r)->value_2=(GENERIC)choice_stack;
884  (void)unchecked(&((*r)->value_2),LONELY);
885  }
886  else if (sub_CodeType(code,variable->code)) /* 8.8 */
887  check_string(&((*r)->value_2));
888  }
889 
890  check_goal_stack(&((*r)->goal));
891  r= &((*r)->next);
892  }
893 }
static void check_bytedata(GENERIC *s)
Definition: memory.c:416
static void check_goal_stack(ptr_goal *g)
Definition: memory.c:739
static void check_string(GENERIC *s)
Definition: memory.c:375
static long pass
Definition: memory.c:17
#define REAL
Definition: def_const.h:72
static long unchecked(GENERIC *p, long len)
Definition: memory.c:309
struct wl_list * ptr_list
Definition: def_struct.h:38
void check_definition(ptr_definition *d)
Definition: memory.c:612
ptr_definition real
Definition: def_glob.h:102
ptr_definition alist
Definition: def_glob.h:94
ptr_definition quoted_string
Definition: def_glob.h:101
struct wl_definition * ptr_definition
Definition: def_struct.h:31
static void check_code(ptr_int_list *c)
Definition: memory.c:448
ptr_definition sys_bytedata
Definition: def_glob.h:336
long sub_CodeType(ptr_int_list c1, ptr_int_list c2)
Definition: types.c:1522
ptr_definition cut
Definition: def_glob.h:83
ptr_int_list code
Definition: def_struct.h:129
#define LONELY
Definition: memory.c:20
unsigned long * GENERIC
Definition: def_struct.h:17
ptr_definition variable
Definition: def_glob.h:111
ptr_choice_point choice_stack
Definition: def_glob.h:51
void check_resid_block ( ptr_resid_block rb)

Definition at line 900 of file memory.c.

References check_goal_stack(), check_resid_list(), LONELY, and unchecked().

902 {
903  if (*rb) {
904  if (unchecked(rb,sizeof(resid_block))) {
905  check_goal_stack(&((*rb)->ra));
906  check_resid_list(&((*rb)->rv)); /* 21.9 */
907  /* unchecked(&((*rb)->rl),LONELY); 12.6 */ /* 10.6 */
908  (void)unchecked(&((*rb)->md),LONELY); /* 10.6 */
909  /* check_goal_stack(&((*rb)->rl)); 10.6 */
910  /* check_psi_term(&((*rb)->md)); 10.6 */
911  }
912  }
913 }
static void check_resid_list()
static void check_goal_stack(ptr_goal *g)
Definition: memory.c:739
static long unchecked(GENERIC *p, long len)
Definition: memory.c:309
#define LONELY
Definition: memory.c:20
static void check_resid_list ( )
static
static void check_resid_list ( ptr_resid_list l)
static

Definition at line 1164 of file memory.c.

References check_psi_term(), and unchecked().

1166 {
1167  while(unchecked(l,sizeof(resid_list))) {
1168  check_psi_term(&((*l)->var));
1169  check_psi_term(&((*l)->othervar));
1170  l= &((*l)->next);
1171  }
1172 }
static long unchecked(GENERIC *p, long len)
Definition: memory.c:309
void check_psi_term(ptr_psi_term *t)
Definition: memory.c:920
static void check_special_addresses ( )
static

Definition at line 1119 of file memory.c.

References wl_stack::aaaa_3, wl_stack::bbbb_3, choice_stack, cut_ptr, LONELY, wl_stack::next, wl_choice_point::next, wl_choice_point::stack_top, wl_stack::type, unchecked(), undo_action, undo_stack, and VALID_RANGE.

1120 {
1121  ptr_choice_point c;
1122  ptr_stack p;
1123  // ptr_goal g;
1124 
1125  c=choice_stack;
1126  while(c) {
1127  /* unchecked(&(c->undo_point),LONELY); 17.7 */
1128  (void)unchecked(&(c->stack_top),LONELY);
1129  c=c->next;
1130  }
1131 
1132  p=undo_stack;
1133  while (p) {
1134  if (!(p->type & undo_action)) {
1135  /* Only update an address if it's within the Life data space! */
1136  if (VALID_RANGE(p->aaaa_3)) (void)unchecked(&(p->aaaa_3),LONELY);
1137  if (p->type==cut_ptr) (void)unchecked(&(p->bbbb_3),LONELY); /* 22.9 */
1138  }
1139  p=p->next;
1140  }
1141 }
#define VALID_RANGE(A)
Definition: def_macro.h:122
GENERIC * bbbb_3
Definition: def_struct.h:218
GENERIC stack_top
Definition: def_struct.h:236
#define cut_ptr
Definition: def_const.h:176
ptr_choice_point next
Definition: def_struct.h:235
static long unchecked(GENERIC *p, long len)
Definition: memory.c:309
ptr_stack undo_stack
Definition: def_glob.h:53
type_ptr type
Definition: def_struct.h:216
GENERIC * aaaa_3
Definition: def_struct.h:217
#define undo_action
Definition: def_const.h:188
#define LONELY
Definition: memory.c:20
ptr_stack next
Definition: def_struct.h:219
ptr_choice_point choice_stack
Definition: def_glob.h:51
static void check_string ( GENERIC s)
static

Definition at line 375 of file memory.c.

References delta, LONELY, MAX_BUILT_INS, pass, and unchecked().

377 {
378  GENERIC addr;
379  long value;
380  long bytes;
381 
382  if ((unsigned long) *s > MAX_BUILT_INS) {
383  switch (pass) {
384  case 1:
385  bytes=strlen((char *)*s)+1;
386  /* if (bytes==LONELY) {
387  fprintf(stderr,"Caught an empty string!\n");
388  fflush(stderr);
389  } */
390  /* Make sure there's no conflict with LONELY (this occurs for an */
391  /* empty string, which still needs a single byte of storage). */
392  /* This does occasionally happen. */
393  (void)unchecked(s, (bytes==LONELY)?bytes+1:bytes);
394  break;
395  case 2:
396  addr=(*s+delta);
397  value= *addr;
398  if (value & 1) { /* If low bit set */
399  value--;
400  *s=(GENERIC)value;
401  *addr=value;
402 #ifdef prlDEBUG
403  amount_used+=strlen(*s)+1;
404 #endif
405  }
406  *s=(GENERIC)value;
407  break;
408  }
409  }
410 }
static long delta
Definition: memory.c:8
static long pass
Definition: memory.c:17
static long unchecked(GENERIC *p, long len)
Definition: memory.c:309
#define MAX_BUILT_INS
Definition: def_const.h:82
#define LONELY
Definition: memory.c:20
unsigned long * GENERIC
Definition: def_struct.h:17
static void check_symbol ( ptr_node n)
static

Definition at line 707 of file memory.c.

References check_keyword(), check_string(), and unchecked().

709 {
710  if (unchecked(n,sizeof(node))) {
711  check_symbol(&((*n)->left));
712  check_string(&((*n)->key));
713  check_keyword(&((*n)->data)); /* RM: Jan 12 1993 */
714  check_symbol(&((*n)->right));
715  }
716 }
static void check_string(GENERIC *s)
Definition: memory.c:375
static long unchecked(GENERIC *p, long len)
Definition: memory.c:309
static void check_symbol(ptr_node *n)
Definition: memory.c:707
static void check_keyword()
static void check_triple_list ( ptr_triple_list p)
static

Definition at line 476 of file memory.c.

References check_definition(), check_psi_term(), and unchecked().

478 {
479  while (unchecked(p,sizeof(triple_list))) {
480  check_psi_term(&((*p)->aaaa_4));
481  check_psi_term(&((*p)->bbbb_4));
482  check_definition(&((*p)->cccc_4));
483  p= &((*p)->next);
484  }
485 }
static long unchecked(GENERIC *p, long len)
Definition: memory.c:309
void check_definition(ptr_definition *d)
Definition: memory.c:612
void check_psi_term(ptr_psi_term *t)
Definition: memory.c:920
static void check_type_disj ( ptr_int_list p)
static

Definition at line 723 of file memory.c.

References check_definition(), and unchecked().

725 {
726  while (unchecked(p,sizeof(int_list))) {
727  check_definition((struct wl_definition **)&((*p)->value_1));
728  p= &((*p)->next);
729  }
730 }
static long unchecked(GENERIC *p, long len)
Definition: memory.c:309
void check_definition(ptr_definition *d)
Definition: memory.c:612
static void check_undo_stack ( )
static
static void check_undo_stack ( ptr_stack s)
static

Definition at line 1038 of file memory.c.

References check_code(), check_definition(), check_goal_stack(), check_psi_term(), check_resid(), code_ptr, cut_ptr, def_ptr, destroy_window, goal_ptr, hide_window, int_ptr, psi_term_ptr, resid_ptr, show_window, and unchecked().

1040 {
1041  while (unchecked(s,sizeof(stack))) {
1042 
1043  switch((*s)->type) {
1044 
1045  case psi_term_ptr:
1046  check_psi_term((struct wl_psi_term **)&((*s)->bbbb_3));
1047  break;
1048 
1049  case resid_ptr:
1050  check_resid(&((*s)->bbbb_3));
1051  break;
1052 
1053  case int_ptr:
1054  /* int_ptr's are used to trail time_stamps, so they can get large. */
1055  break;
1056 
1057  case def_ptr:
1058  check_definition((struct wl_definition **)&((*s)->bbbb_3));
1059  break;
1060 
1061  case code_ptr:
1062  check_code(&((*s)->bbbb_3));
1063  break;
1064 
1065  case goal_ptr:
1066  check_goal_stack(&((*s)->bbbb_3));
1067  break;
1068 
1069  case cut_ptr: /* 22.9 */
1070  break;
1071 #ifdef CLIFE
1072  case block_ptr: /* CB: Jan 28 1993 */
1073  check_block_value(&((*s)->bbbb_3));
1074  break;
1075 
1076 #endif /* CLIFE */
1077  /* All undo actions here */
1078  case destroy_window:
1079  case show_window:
1080  case hide_window:
1081  /* No pointers to follow */
1082  break;
1083  }
1084 
1085  s= &((*s)->next);
1086  }
1087 }
static void check_resid(ptr_residuation *r)
Definition: memory.c:851
#define show_window
Definition: def_const.h:184
#define def_ptr
Definition: def_const.h:173
static void check_goal_stack(ptr_goal *g)
Definition: memory.c:739
#define destroy_window
Definition: def_const.h:183
#define cut_ptr
Definition: def_const.h:176
static long unchecked(GENERIC *p, long len)
Definition: memory.c:309
void check_definition(ptr_definition *d)
Definition: memory.c:612
#define hide_window
Definition: def_const.h:185
#define code_ptr
Definition: def_const.h:174
void check_psi_term(ptr_psi_term *t)
Definition: memory.c:920
static void check_code(ptr_int_list *c)
Definition: memory.c:448
#define resid_ptr
Definition: def_const.h:171
#define goal_ptr
Definition: def_const.h:175
#define psi_term_ptr
Definition: def_const.h:170
#define int_ptr
Definition: def_const.h:172
static void check_var ( ptr_node n)
static

Definition at line 1180 of file memory.c.

References check_psi_term(), check_string(), and unchecked().

1182 {
1183  if (unchecked(n,sizeof(node))) {
1184  check_var(&((*n)->left));
1185  check_string(&((*n)->key));
1186  check_psi_term((struct wl_psi_term **)&((*n)->data));
1187  check_var(&((*n)->right));
1188  }
1189 }
static void check_string(GENERIC *s)
Definition: memory.c:375
static long unchecked(GENERIC *p, long len)
Definition: memory.c:309
void check_psi_term(ptr_psi_term *t)
Definition: memory.c:920
static void check_var(ptr_node *n)
Definition: memory.c:1180
static void compress ( )
static

Definition at line 195 of file memory.c.

References ALIGN, assert, delta, heap_pointer, LONELY, mem_base, mem_limit, other_pointer, stack_pointer, TRUE, and VALID_ADDRESS.

196 {
197  GENERIC addr, new_addr;
198  long len, i;
199 
200  /* Compressing the stack: */
201 
202  addr=new_addr=mem_base;
203  while (addr<=stack_pointer) {
204  len = *(addr+delta);
205  if (len) {
206  /* There are lots of these: */
207  /* if (len==LONELY) printf("Isolated LONELY at %lx\n",addr); */
208  if (len==LONELY) len=ALIGN;
209  else if (len & (ALIGN-1)) len=len-(len & (ALIGN-1))+ALIGN;
210  /* if (len & (ALIGN-1)) len=len-(len & (ALIGN-1))+ALIGN; 12.6 */
211  assert((len & (ALIGN-1))==0);
212  len /= sizeof(*addr);
213  assert(len>0);
214 
215  for (i=0; i<len; i++) {
216  *new_addr = *addr;
217  if (i>0) {
218  if (*(addr+delta)>=len)
219  assert(i>0 ? *(addr+delta)<len : TRUE);
220  }
221  assert(VALID_ADDRESS(new_addr));
222  *(addr+delta) = (long)new_addr + 1; /* Set low bit */
223 #ifdef prlDEBUG
224  if (*(addr+delta) & 1 == 0)
225  printf ("compress: could be a bug ...\n");
226 #endif
227  addr++;
228  new_addr++;
229  }
230  }
231  else
232  addr++;
233  }
234  other_pointer=stack_pointer; /* 10.6 this var. is unused */
235  stack_pointer=new_addr;
236 
237  /* Compressing the heap: */
238 
239  addr=new_addr=mem_limit;
240  addr--; /* PVR fix: adding this statement avoids accessing beyond */
241  /* the memory's edge, which causes a segmentation fault on*/
242  /* SPARC. */
243  while (addr>=heap_pointer) {
244  skip_addr:
245  len= *(addr+delta);
246  if (len) {
247  if (len!=LONELY) {
248 
249  if (len & (ALIGN-1)) len=len-(len & (ALIGN-1))+ALIGN;
250  assert((len & (ALIGN-1))==0);
251  len /= sizeof (*addr);
252  assert(len>0);
253 
254  } else { /* len==LONELY */
255  GENERIC a;
256 
257  if (len & (ALIGN-1)) len=len-(len & (ALIGN-1))+ALIGN;
258  assert((len & (ALIGN-1))==0);
259  len /= sizeof (*addr);
260  assert(len==1);
261 
262  /* Check if the LONELY field is actually part of a block. */
263  /* If so, skip to the beginning of the block. */
264  a=addr;
265  do {
266  a--;
267  } while (a>=heap_pointer &&
268  (*(a+delta)==0 || *(a+delta)==LONELY));
269  if (a>=heap_pointer && *(a+delta)/sizeof(*a)+a>addr) {
270  addr=a;
271  goto skip_addr;
272  }
273  }
274 
275  /* Move a block or an isolated LONELY field. */
276  addr += len;
277  for (i=0; i<len; i++) {
278  addr--;
279  new_addr--;
280  *new_addr = *addr;
281  assert(VALID_ADDRESS(new_addr));
282  *(addr+delta) = (long)new_addr + 1;
283  }
284  }
285  addr--;
286  }
287  heap_pointer=new_addr;
288 }
#define VALID_ADDRESS(A)
Definition: def_macro.h:132
GENERIC mem_limit
Definition: def_glob.h:13
static long delta
Definition: memory.c:8
GENERIC other_pointer
Definition: def_glob.h:21
#define TRUE
Definition: def_const.h:127
GENERIC mem_base
Definition: def_glob.h:11
GENERIC heap_pointer
Definition: def_glob.h:12
GENERIC stack_pointer
Definition: def_glob.h:14
#define LONELY
Definition: memory.c:20
unsigned long * GENERIC
Definition: def_struct.h:17
#define ALIGN
Definition: def_const.h:31
#define assert(N)
Definition: memory.c:104
void fail_all ( )

Definition at line 165 of file memory.c.

References abort_life(), choice_stack, goal_stack, NULL, open_input_file(), output_stream, stdin_cleareof(), TRUE, and undo_stack.

166 {
167  output_stream=stdout;
171  (void)abort_life(TRUE);
172  /* printf("\n*** Abort\n"); */
173  stdin_cleareof();
174  (void)open_input_file("stdin");
175 }
ptr_goal goal_stack
Definition: def_glob.h:50
#define NULL
Definition: def_const.h:203
long abort_life(int nlflag)
Definition: built_ins.c:2124
ptr_stack undo_stack
Definition: def_glob.h:53
#define TRUE
Definition: def_const.h:127
FILE * output_stream
Definition: def_glob.h:41
void stdin_cleareof()
Definition: token.c:42
long open_input_file(char *file)
Definition: token.c:504
ptr_choice_point choice_stack
Definition: def_glob.h:51
void garbage ( )

Definition at line 1430 of file memory.c.

References assert, bounds_undo_stack(), check(), clear_copy(), compress(), FALSE, garbage_time, gc_time, heap_pointer, ignore_eff, last_garbage_time, life_time, mem_base, mem_limit, NULL, other_base, other_limit, pass, pointer_names, print_gc_info(), printed_pointers, stack_info(), stack_pointer, TRUE, and verbose.

1431 {
1432  GENERIC addr;
1433  struct tms garbage_start_time,garbage_end_time;
1434  long start_number_cells, end_number_cells;
1435 
1436  start_number_cells = (stack_pointer-mem_base) + (mem_limit-heap_pointer);
1437 
1438  (void)times(&garbage_start_time);
1439 
1440  /* Time elapsed since last garbage collection */
1441  life_time=(garbage_start_time.tms_utime - last_garbage_time.tms_utime)/60.0;
1442 
1443 
1444  if (verbose) {
1445  fprintf(stderr,"*** Garbage Collect "); /* RM: Jan 26 1993 */
1446  fprintf(stderr,"\n*** Begin");
1448  (void)fflush(stderr);
1449  }
1450 
1451 
1452  /* reset the other base */
1453  for (addr = other_base; addr < other_limit; addr ++)
1454  *addr = 0;
1455 
1456  pass=1;
1457 
1458  check();
1459 #ifdef GCVERBOSE
1460  fprintf(stderr,"- Done pass 1 ");
1461 #endif
1462 
1464  compress();
1465 #ifdef GCVERBOSE
1466  fprintf(stderr,"- Done compress ");
1467 #endif
1468 
1469  pass=2;
1470 
1471  check();
1473 #ifdef GCVERBOSE
1474  fprintf(stderr,"- Done pass 2\n");
1475 #endif
1476 
1477  clear_copy();
1478 
1481 
1482  (void)times(&garbage_end_time);
1483  gc_time=(garbage_end_time.tms_utime - garbage_start_time.tms_utime)/60.0;
1485 
1486  if (verbose) {
1487  fprintf(stderr,"*** End ");
1488  print_gc_info(TRUE); /* RM: Jan 26 1993 */
1489  stack_info(stderr);
1490  (void)fflush(stderr);
1491  }
1492 
1493  last_garbage_time=garbage_end_time;
1494 
1495  end_number_cells = (stack_pointer-mem_base) + (mem_limit-heap_pointer);
1496  assert(end_number_cells<=start_number_cells);
1497 
1498  ignore_eff=FALSE;
1499 
1500 }
ptr_node printed_pointers
Definition: def_glob.h:28
static void check()
Definition: memory.c:1208
void clear_copy()
Definition: copy.c:52
GENERIC mem_limit
Definition: def_glob.h:13
static float gc_time
Definition: memory.c:23
long verbose
Definition: def_glob.h:273
static long pass
Definition: memory.c:17
GENERIC other_base
Definition: def_glob.h:19
#define NULL
Definition: def_const.h:203
long ignore_eff
Definition: def_glob.h:151
ptr_node pointer_names
Definition: def_glob.h:29
void print_gc_info(long timeflag)
Definition: memory.c:1396
#define TRUE
Definition: def_const.h:127
static float life_time
Definition: memory.c:23
#define FALSE
Definition: def_const.h:128
GENERIC mem_base
Definition: def_glob.h:11
GENERIC heap_pointer
Definition: def_glob.h:12
static void compress()
Definition: memory.c:195
void stack_info(FILE *outfile)
Definition: error.c:58
GENERIC other_limit
Definition: def_glob.h:20
GENERIC stack_pointer
Definition: def_glob.h:14
float garbage_time
Definition: def_glob.h:16
unsigned long * GENERIC
Definition: def_struct.h:17
long bounds_undo_stack()
Definition: memory.c:121
static struct tms last_garbage_time
Definition: memory.c:22
#define assert(N)
Definition: memory.c:104
int GetBoolOption ( char *  name)

Definition at line 54 of file memory.c.

References GetStrOption().

56 {
57  char *s;
58  s=GetStrOption(name,"off");
59  return strcmp(s,"off");
60 }
char * name
Definition: def_glob.h:325
char * GetStrOption(char *name, char *def)
Definition: memory.c:33
int GetIntOption ( char *  name,
int  def 
)

Definition at line 64 of file memory.c.

References GetStrOption().

67 {
68  char *s;
69  char buffer_loc[40];
70  (void)snprintf(buffer_loc,40,"%d",def);
71  s=GetStrOption(name,buffer_loc);
72  return atof(s);
73 }
char * name
Definition: def_glob.h:325
char * GetStrOption(char *name, char *def)
Definition: memory.c:33
char* GetStrOption ( char *  name,
char *  def 
)

Definition at line 33 of file memory.c.

References arg_c, and arg_v.

36 {
37  int i;
38  char *result=def;
39  int l=strlen(name);
40 
41  for(i=1;i<arg_c;i++)
42  if(arg_v[i][0]=='-' && (int)strlen(arg_v[i])>=l+1)
43  if(!strncmp(arg_v[i]+1,name,l))
44  if(arg_v[i][l+1]=='=')
45  result=arg_v[i]+l+2;
46  else
47  result=arg_v[i]+l+1;
48 
49  return result;
50 }
char * name
Definition: def_glob.h:325
int arg_c
Definition: def_glob.h:5
char * arg_v[10]
Definition: def_glob.h:6
GENERIC heap_alloc ( long  s)

Definition at line 1518 of file memory.c.

References ALIGN, Errorline(), heap_pointer, and stack_pointer.

1520 {
1521  if (s & (ALIGN-1))
1522  s = s - (s & (ALIGN-1))+ALIGN;
1523  /* assert(s % sizeof(*heap_pointer) == 0); */
1524  s /= sizeof (*heap_pointer);
1525 
1526  heap_pointer -= s;
1527 
1529  Errorline("the heap overflowed into the stack.\n");
1530 
1531  return heap_pointer;
1532 }
void Errorline(char *format,...)
Definition: error.c:414
GENERIC heap_pointer
Definition: def_glob.h:12
GENERIC stack_pointer
Definition: def_glob.h:14
#define ALIGN
Definition: def_const.h:31
void init_memory ( )

Definition at line 1572 of file memory.c.

References ALIGNUP, alloc_words, buffer, delta, Errorline(), GetIntOption(), heap_pointer, mem_base, mem_limit, mem_size, other_base, other_limit, other_pointer, PRINT_BUFFER, and stack_pointer.

1573 {
1574  alloc_words=GetIntOption("memory",ALLOC_WORDS);
1575  mem_size=alloc_words*sizeof(long);
1576 
1577  mem_base = (GENERIC) malloc(mem_size);
1578  other_base = (GENERIC) malloc(mem_size);
1579 
1580  if (mem_base && other_base) {
1581  /* Rewrote some rather poor code... RM: Mar 1 1994 */
1582  ALIGNUP(mem_base);
1584 
1585  mem_limit=mem_base+alloc_words-2;
1586  ALIGNUP(mem_limit);
1588 
1591 
1592  other_limit=other_base+alloc_words-2;
1594 
1596  buffer = (char *) malloc (PRINT_BUFFER); /* The printing buffer */
1597 
1598  /* RM: Oct 22 1993 */
1599  /* Fill the memory with rubbish data */
1600  /*
1601  {
1602  int i;
1603 
1604  for(i=0;i<alloc_words;i++) {
1605  mem_base[i]= -1234;
1606  other_base[i]= -1234;
1607  }
1608  }
1609  */
1610  }
1611  else
1612  Errorline("Wild_life could not allocate sufficient memory to run.\n\n");
1613 }
GENERIC mem_limit
Definition: def_glob.h:13
int alloc_words
Definition: def_glob.h:10
static long delta
Definition: memory.c:8
int mem_size
Definition: def_glob.h:9
GENERIC other_base
Definition: def_glob.h:19
GENERIC other_pointer
Definition: def_glob.h:21
void Errorline(char *format,...)
Definition: error.c:414
char * buffer
Definition: def_glob.h:175
#define ALIGNUP(X)
Definition: def_macro.h:294
#define PRINT_BUFFER
Definition: def_const.h:106
GENERIC mem_base
Definition: def_glob.h:11
GENERIC heap_pointer
Definition: def_glob.h:12
GENERIC other_limit
Definition: def_glob.h:20
GENERIC stack_pointer
Definition: def_glob.h:14
int GetIntOption(char *name, int def)
Definition: memory.c:64
unsigned long * GENERIC
Definition: def_struct.h:17
long memory_check ( )

Definition at line 1622 of file memory.c.

References fail_all(), FALSE, garbage(), GC_THRESHOLD, heap_pointer, stack_pointer, TRUE, and verbose.

1623 {
1624  long success=TRUE;
1625 
1627  if(verbose) fprintf(stderr,"\n"); /* RM: Feb 1 1993 */
1628  garbage();
1629  /* Abort if didn't recover at least GC_THRESHOLD/10 of memory */
1631  fprintf(stderr,"*********************\n");
1632  fprintf(stderr,"*** OUT OF MEMORY ***\n");
1633  fprintf(stderr,"*********************\n");
1634  fail_all();
1635  success=FALSE;
1636  }
1637  }
1638  return success;
1639 }
void fail_all()
Definition: memory.c:165
long verbose
Definition: def_glob.h:273
#define TRUE
Definition: def_const.h:127
#define FALSE
Definition: def_const.h:128
GENERIC heap_pointer
Definition: def_glob.h:12
void garbage()
Definition: memory.c:1430
#define GC_THRESHOLD
Definition: def_const.h:65
GENERIC stack_pointer
Definition: def_glob.h:14
void pchoices ( )

Definition at line 81 of file memory.c.

References choice_stack, wl_choice_point::next, stack_pointer, and wl_choice_point::stack_top.

82 {
84  printf("stack pointer is: %lx\n",(unsigned long)stack_pointer);
85  for(c=choice_stack;c;c=c->next)
86  printf("\tc=%lx\ts=%lx\tg=%lx\tu=%lx\n",(unsigned long)c,(unsigned long)c->stack_top,(unsigned long)c->goal_stack,(unsigned long)c->undo_point);
87 }
GENERIC stack_top
Definition: def_struct.h:236
ptr_choice_point next
Definition: def_struct.h:235
GENERIC stack_pointer
Definition: def_glob.h:14
ptr_choice_point choice_stack
Definition: def_glob.h:51
void print_gc_info ( long  timeflag)

Definition at line 1396 of file memory.c.

References gc_time, heap_pointer, life_time, mem_base, mem_limit, mem_size, and stack_pointer.

1398 {
1399  fprintf(stderr," [%ld%% free (%ldK), %ld%% heap, %ld%% stack",
1400  (100*((unsigned long)heap_pointer-(unsigned long)stack_pointer)+mem_size/2)/mem_size,
1401  ((unsigned long)heap_pointer-(unsigned long)stack_pointer+512)/1024,
1402  (100*((unsigned long)mem_limit-(unsigned long)heap_pointer)+mem_size/2)/mem_size,
1403  (100*((unsigned long)stack_pointer-(unsigned long)mem_base)+mem_size/2)/mem_size);
1404  if (timeflag) {
1405  fprintf(stderr,", %1.3fs cpu (%ld%%)",
1406  gc_time,
1407  (unsigned long)(0.5+100*gc_time/(life_time+gc_time)));
1408  }
1409  fprintf(stderr,"]\n");
1410 }
GENERIC mem_limit
Definition: def_glob.h:13
static float gc_time
Definition: memory.c:23
int mem_size
Definition: def_glob.h:9
static float life_time
Definition: memory.c:23
GENERIC mem_base
Definition: def_glob.h:11
GENERIC heap_pointer
Definition: def_glob.h:12
GENERIC stack_pointer
Definition: def_glob.h:14
void print_undo_stack ( )

Definition at line 107 of file memory.c.

References wl_stack::aaaa_3, wl_stack::bbbb_3, mem_base, mem_limit, wl_stack::next, wl_stack::type, and undo_stack.

108 {
110 
111  while (u) {
112  if ((GENERIC)u->aaaa_3<mem_base || (GENERIC)u->aaaa_3>mem_limit ||
113  (GENERIC)u->next<mem_base || (GENERIC)u->next>mem_limit) {
114  printf("UNDO: type:%ld a:%lx b:%lx next:%lx\n",u->type,(unsigned long)u->aaaa_3,(unsigned long)u->bbbb_3,(unsigned long)u->next);
115  (void)fflush(stdout);
116  }
117  u=u->next;
118  }
119 }
GENERIC mem_limit
Definition: def_glob.h:13
GENERIC * bbbb_3
Definition: def_struct.h:218
ptr_stack undo_stack
Definition: def_glob.h:53
type_ptr type
Definition: def_struct.h:216
GENERIC mem_base
Definition: def_glob.h:11
GENERIC * aaaa_3
Definition: def_struct.h:217
unsigned long * GENERIC
Definition: def_struct.h:17
ptr_stack next
Definition: def_struct.h:219
GENERIC stack_alloc ( long  s)

Definition at line 1542 of file memory.c.

References ALIGN, Errorline(), heap_pointer, and stack_pointer.

1544 {
1545  GENERIC r;
1546 
1547  r = stack_pointer;
1548 
1549  if (s & (ALIGN-1))
1550  s = s - (s & (ALIGN-1)) + ALIGN;
1551  /* assert(s % sizeof(*stack_pointer) == 0); */
1552  s /= sizeof (*stack_pointer);
1553 
1554  stack_pointer += s;
1555 
1557  Errorline("the stack overflowed into the heap.\n");
1558 
1559  return r;
1560 }
void Errorline(char *format,...)
Definition: error.c:414
GENERIC heap_pointer
Definition: def_glob.h:12
GENERIC stack_pointer
Definition: def_glob.h:14
unsigned long * GENERIC
Definition: def_struct.h:17
#define ALIGN
Definition: def_const.h:31
static long unchecked ( GENERIC p,
long  len 
)
static

Definition at line 309 of file memory.c.

References assert, delta, Errorline(), FALSE, LONELY, MAX_BUILT_INS, pass, TRUE, and VALID_ADDRESS.

313 {
314  GENERIC addr;
315  long result=FALSE, value;
316 
317  assert(len>0);
318  if ((unsigned long)*p>MAX_BUILT_INS) {
319 #ifdef GCTEST
320  if (!VALID_ADDRESS(*p)) {
321  printf("p=%lx,*p=%lx\n",p,*p);
322  }
323 #endif
324  assert(VALID_ADDRESS(*p));
325  addr = *p + delta;
326  value = *addr;
327  switch (pass) {
328  case 1:
329 #ifdef GCTEST
330  if (FALSE /* len>100 || value>100 13.8 */) {
331  /* This does in fact happen */
332  printf("len=%ld,value=%ld\n",len,value);
333  fflush(stdout);
334  }
335 #endif
336  /* if (!value) */
337  if (!value || value==LONELY) {
338  /* Pointer not yet explored */
339  result=TRUE;
340  *addr=len;
341 #ifdef prlDEBUG
342  amount_used+=len;
343 #endif
344  }
345  else if (value < len && len != LONELY) {
346  Errorline("in garbage collection, %d < %d.\n", value, len);
347  }
348  else if (value > len && len != LONELY) {
349  Errorline("in garbage collection, %d > %d.\n", value, len);
350  }
351  break;
352  case 2:
353  if (value & 1) { /* If low bit set */
354  value--; /* Reset low bit */
355  *addr=value;
356 #ifdef prlDEBUG
357  amount_used+=len;
358 #endif
359  result=TRUE;
360  }
361  if (!VALID_ADDRESS(value))
362  assert(VALID_ADDRESS(value));
363  *p = (GENERIC) value;
364  break;
365  }
366  }
367  return result;
368 }
#define VALID_ADDRESS(A)
Definition: def_macro.h:132
static long delta
Definition: memory.c:8
static long pass
Definition: memory.c:17
void Errorline(char *format,...)
Definition: error.c:414
#define TRUE
Definition: def_const.h:127
#define FALSE
Definition: def_const.h:128
#define MAX_BUILT_INS
Definition: def_const.h:82
#define LONELY
Definition: memory.c:20
unsigned long * GENERIC
Definition: def_struct.h:17
#define assert(N)
Definition: memory.c:104

Variable Documentation

long delta
static

Definition at line 8 of file memory.c.

float gc_time
static

Definition at line 23 of file memory.c.

struct tms last_garbage_time
static

Definition at line 22 of file memory.c.

float life_time
static

Definition at line 23 of file memory.c.

long pass
static

Definition at line 17 of file memory.c.