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

memory management More...

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

Variables

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

Detailed Description

memory management

Definition in file memory.c.

Macro Definition Documentation

#define assert (   N)

Definition at line 114 of file memory.c.

#define LONELY   1

Definition at line 24 of file memory.c.

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

Definition at line 318 of file memory.c.

Function Documentation

long bounds_undo_stack ( )

bounds_undo_stack

Address field in undo_stack is within range The only valid address outside this range is that of xevent_state

Definition at line 143 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.

144 {
146 
147  while (u) {
148  if ( (GENERIC)u<mem_base
149  || (GENERIC)u>mem_limit
150  || (!VALID_ADDRESS(u->aaaa_3) && !(u->type & undo_action))
151  ) {
152  if ((GENERIC)u<mem_base || (GENERIC)u>mem_limit) {
153  printf("\nUNDO: u=%lx\n",(long)u);
154  }
155  else {
156  printf("\nUNDO: u:%lx type:%ld a:%lx b:%lx next:%lx\n",
157  (unsigned long)u,(unsigned long)u->type,(unsigned long)u->aaaa_3,(unsigned long)u->bbbb_3,(unsigned long)u->next);
158  }
159  (void)fflush(stdout);
160  return FALSE;
161  }
162  u=u->next;
163  }
164 
165  return TRUE;
166 }
#define VALID_ADDRESS(A)
Definition: def_macro.h:137
GENERIC mem_limit
starting point of heap - mem_base aligned
Definition: def_glob.h:62
ptr_stack undo_stack
Definition: def_glob.h:1027
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
type_ptr type
Definition: def_struct.h:231
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
GENERIC * aaaa_3
Definition: def_struct.h:232
#define undo_action
Fast checking for an undo action.
Definition: def_const.h:484
GENERIC mem_base
mem_size memory allocated in init_memory by malloc
Definition: def_glob.h:48
ptr_stack next
Definition: def_struct.h:234
static void check ( )
static

check

CHECK This routine checks all pointers and psi_terms to find out which memory cells must be preserved and which can be discarded.

This routine explores all known structures. It is vital that it should visit them all exactly once. It thus creates a map of what is used in memory, which COMPRESS uses to compact the memory and recalculate the addresses. Exploration of these structures should be done in exactly the same order in both passes. If it is the second pass, pointers are assigned their new values.

A crucial property of this routine: In pass 2, a global variable (i.e. a root for GC) must be updated before it is accessed. E.g. don't use the variable goal_stack before updating it.

Definition at line 1300 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.

1301 {
1302 #ifdef prlDEBUG
1303  amount_used=0;
1304 #endif
1305 
1306  /* First of all, get all the codes right so that data type-checking remains
1307  coherent.
1308 
1309  Kids and Parents cannot be checked because the built-in types have codes
1310  which might have been moved.
1311  */
1312  /* print_undo_stack(); */
1313 
1314 
1315  check_choice_structs(&choice_stack); /* RM: Oct 28 1993 */
1316 
1318  check_gamma_code();
1319 
1320  /* Now, check the rest of the definitions and all global roots */
1321 
1322  check_gamma_rest();
1323 
1325 
1326  check_definition(&abortsym); /* 26.1 */
1327  check_definition(&aborthooksym); /* 26.1 */
1328 
1329  check_definition(&add_module1); /* RM: Mar 12 1993 */
1332 
1335  check_definition(&boolean);
1341  /* check_definition(&conjunction); 19.8 */
1345  check_definition(&disj_nil); /* RM: Feb 16 1993 */
1354  check_definition(&life_or); /* RM: Apr 6 1993 */
1355  check_definition(&minus_symbol); /* RM: Jun 21 1993 */
1356  check_definition(&nil); /* RM: Dec 9 1992 */
1368  check_definition(&tracesym); /* 26.1 */
1377  /* check_definition(&provesym); */
1390 
1391  /* RM: Jul 7 1993 */
1394 
1396 
1397 #ifdef X11
1414 #endif
1415 
1416  /* check_psi_term(&empty_list); 5.8 */
1417 
1418  check_string((GENERIC *)&one); // added cast DJD 12/8/2016
1419  check_string((GENERIC *)&two); // added cast DJD 12/8/2016
1420  check_string((GENERIC *)&three); // added cast DJD 12/8/2016
1421  check_string((GENERIC *)&year_attr); // added cast DJD 12/8/2016
1422  check_string((GENERIC *)&month_attr); // added cast DJD 12/8/2016
1423  check_string((GENERIC *)&day_attr); // added cast DJD 12/8/2016
1424  check_string((GENERIC *)&hour_attr); // added cast DJD 12/8/2016
1425  check_string((GENERIC *)&minute_attr); // added cast DJD 12/8/2016
1426  check_string((GENERIC *)&second_attr); // added cast DJD 12/8/2016
1427  check_string((GENERIC *)&weekday_attr); // added cast DJD 12/8/2016
1428 
1435  check_psi_term(&old_state); /* RM: Feb 17 1993 */
1436 
1438 #ifdef X11
1441 #endif
1442 
1444  /* check_choice(&prompt_choice_stack); 12.7 */
1445 
1446 
1447  /* RM: Feb 3 1993 */
1448  /* check_symbol(&symbol_table); */
1449  /* check_definition(&first_definition); */
1450  check_definition_list(); /* RM: Feb 15 1993 */
1451 
1452 
1453  /*** MODULES ***/
1454  /* RM: Jan 13 1993 */
1455 
1459  check_module(&user_module); /* RM: Jan 27 1993 */
1464 
1465  /*** End ***/
1466 
1467 
1468 
1469  check_var(&var_tree);
1470 
1471  check_goal_stack((ptr_goal *)&goal_stack); // added cast DJD 12/8/2016
1472  check_goal_stack((ptr_goal *)&aim); /* 7.10 */ // added cast DJD 12/8/2016
1473 
1474  if (TRUE /*resid_aim 10.6 */) check_resid_list(&resid_vars); /* 21.9 */
1475 
1476  check_goal_stack((ptr_goal *)&resid_aim); // added cast DJD 12/8/2016
1477 
1480 
1483 
1485 }
ptr_definition disjunction
symbol in bi module
Definition: def_glob.h:249
static void check_undo_stack()
ptr_definition alist
symbol in bi module
Definition: def_glob.h:319
ptr_definition succeed
symbol in bi module
Definition: def_glob.h:389
static void check_resid_list()
ptr_definition xf_sym
symbol in bi module
Definition: def_glob.h:515
ptr_psi_term stdin_state
Definition: def_glob.h:857
ptr_definition apply
symbol in bi module
Definition: def_glob.h:178
ptr_definition lf_false
symbol in bi module
Definition: def_glob.h:284
ptr_definition nothing
symbol in bi module
Definition: def_glob.h:347
ptr_definition integer
symbol in bi module
Definition: def_glob.h:312
ptr_definition eqsym
symbol in syntax module
Definition: def_glob.h:270
ptr_definition functor
symbol in bi module
Definition: def_glob.h:298
ptr_definition quote
symbol in syntax module
Definition: def_glob.h:361
ptr_module user_module
Default module for user input.
Definition: def_glob.h:694
ptr_definition final_question
symbol in syntax module
Definition: def_glob.h:615
ptr_goal goal_stack
Definition: def_glob.h:1025
ptr_definition xdisplaylist
Definition: def_glob.h:1040
ptr_psi_term xevent_list
Definition: def_glob.h:1037
static void check_goal_stack(ptr_goal *g)
check_goal_stack
Definition: memory.c:801
ptr_definition xbutton_event
Definition: def_glob.h:1040
ptr_module current_module
The current module for the tokenizer.
Definition: def_glob.h:729
ptr_definition delay_checksym
symbol in bi module
Definition: def_glob.h:487
ptr_definition cut
symbol in syntax module
Definition: def_glob.h:242
char * two
Definition: def_glob.h:892
ptr_definition iff
symbol in bi module
Definition: def_glob.h:305
ptr_definition timesym
symbol in bi module
Definition: def_glob.h:417
ptr_module syntax_module
Module for minimal Prolog syntax.
Definition: def_glob.h:715
static void check_string(GENERIC *s)
check_string
Definition: memory.c:406
ptr_definition comment
symbol in bi module
Definition: def_glob.h:227
ptr_definition listingsym
symbol in bi module
Definition: def_glob.h:480
static void check_special_addresses()
check_special_addresses
Definition: memory.c:1203
ptr_definition fx_sym
symbol in bi module
Definition: def_glob.h:522
static long pass
Definition: memory.c:21
ptr_definition stream
symbol in bi module
Definition: def_glob.h:382
ptr_definition xexpose_event
Definition: def_glob.h:1040
ptr_definition call_handlersym
symbol in bi module
Definition: def_glob.h:508
ptr_definition dynamicsym
symbol in bi module
Definition: def_glob.h:459
ptr_definition opsym
symbol in bi module
Definition: def_glob.h:445
ptr_node var_tree
Definition: def_glob.h:1005
ptr_definition add_module3
symbol in bi module for feature_values
Definition: def_glob.h:157
ptr_psi_term input_state
Definition: def_glob.h:856
ptr_definition add_module2
symbol in bi module for str2psi
Definition: def_glob.h:150
static void check_module()
char * three
Definition: def_glob.h:893
ptr_definition funcsym
symbol in syntax module
Definition: def_glob.h:291
ptr_definition xgc
Definition: def_glob.h:1040
ptr_goal resid_aim
Definition: def_glob.h:865
ptr_definition eval_argsym
symbol in bi module
Definition: def_glob.h:494
ptr_definition xmotion_event
Definition: def_glob.h:1040
ptr_definition and
symbol in syntax module
Definition: def_glob.h:171
ptr_resid_list resid_vars
Definition: def_glob.h:866
ptr_definition xmisc_event
Definition: def_glob.h:1040
ptr_psi_term null_psi_term
Used to represent an empty parse token.
Definition: def_glob.h:656
static void check_choice()
ptr_definition built_in
symbol in bi module
Definition: def_glob.h:199
ptr_psi_term old_state
used in token.c to save state to restore it later
Definition: def_glob.h:663
void check_definition(ptr_definition *d)
check_definition
Definition: memory.c:663
ptr_definition real
symbol in bi module
Definition: def_glob.h:375
ptr_definition inputfilesym
symbol in bi module
Definition: def_glob.h:501
ptr_definition yf_sym
symbol in bi module
Definition: def_glob.h:529
ptr_stack undo_stack
Definition: def_glob.h:1027
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
ptr_definition variable
symbol in bi module
Definition: def_glob.h:438
static void check_choice_structs(ptr_choice_point *c)
check_choice_structs
Definition: memory.c:1170
ptr_definition final_dot
symbol in syntax module
Definition: def_glob.h:608
ptr_definition colonsym
symbol in syntax module
Definition: def_glob.h:213
ptr_definition xkeyboard_event
Definition: def_glob.h:1040
#define TRUE
Standard boolean.
Definition: def_const.h:268
ptr_definition xwindow
Definition: def_glob.h:1040
ptr_definition minus_symbol
symbol in syntax module
Definition: def_glob.h:333
ptr_definition eof
symbol in syntax module
Definition: def_glob.h:263
ptr_definition constant
symbol in bi module
Definition: def_glob.h:235
ptr_definition abortsym
symbol in bi module
Definition: def_glob.h:126
ptr_definition add_module1
symbol in bi module for features
Definition: def_glob.h:143
ptr_definition staticsym
symbol in bi module
Definition: def_glob.h:466
ptr_definition such_that
symbol in syntax module
Definition: def_glob.h:396
ptr_definition typesym
symbol in syntax module
Definition: def_glob.h:431
ptr_definition nil
symbol in bi module
Definition: def_glob.h:340
void check_psi_term(ptr_psi_term *t)
check_psi_term
Definition: memory.c:988
ptr_definition xfy_sym
symbol in bi module
Definition: def_glob.h:550
ptr_goal aim
Definition: def_glob.h:1024
ptr_definition disj_nil
symbol in syntax module
Definition: def_glob.h:256
char * weekday_attr
Definition: def_glob.h:900
ptr_definition xpixmap
Definition: def_glob.h:1040
char * one
Definition: def_glob.h:891
ptr_definition xenter_event
Definition: def_glob.h:1040
ptr_definition xevent
Definition: def_glob.h:1040
ptr_definition commasym
symbol in syntax module
Definition: def_glob.h:220
void check_definition_list()
check_definition_list
Definition: memory.c:700
ptr_module bi_module
Module for public built-ins.
Definition: def_glob.h:687
ptr_psi_term saved_psi_term
Definition: def_glob.h:851
ptr_module sys_module
Definition: def_glob.h:735
ptr_psi_term error_psi_term
symbol in bi module
Definition: def_glob.h:118
ptr_definition top
symbol in syntax module
Definition: def_glob.h:403
ptr_definition yfx_sym
symbol in bi module
Definition: def_glob.h:557
ptr_definition xdisplay
Definition: def_glob.h:1040
void check_gamma_code()
check_gamma_code
Definition: memory.c:1079
static void check_var(ptr_node *n)
check_var
Definition: memory.c:1271
ptr_node module_table
The table of modules.
Definition: def_glob.h:722
ptr_definition loadsym
symbol in bi module
Definition: def_glob.h:452
char * minute_attr
Definition: def_glob.h:898
ptr_definition nullsym
symbol in bi module
Definition: def_glob.h:564
ptr_definition xdestroy_event
Definition: def_glob.h:1040
ptr_module no_module
???
Definition: def_glob.h:701
static void check_module_tree(ptr_node *n)
check_module_tree
Definition: memory.c:588
char * year_attr
Definition: def_glob.h:894
ptr_definition encodesym
symbol in bi module
Definition: def_glob.h:473
ptr_definition fy_sym
symbol in bi module
Definition: def_glob.h:536
char * second_attr
Definition: def_glob.h:899
ptr_definition xleave_event
Definition: def_glob.h:1040
char * day_attr
Definition: def_glob.h:896
static void check_gamma_rest()
check_gamma_rest
Definition: memory.c:1096
ptr_definition lf_true
symbol in bi module
Definition: def_glob.h:410
char * hour_attr
Definition: def_glob.h:897
ptr_definition aborthooksym
symbol in bi module
Definition: def_glob.h:133
void check_sys_definitions()
check_sys_definitions
Definition: sys.c:2186
ptr_definition xconfigure_event
Definition: def_glob.h:1040
ptr_psi_term xevent_existing
Definition: def_glob.h:1037
ptr_definition boolpredsym
symbol in bi module
Definition: def_glob.h:192
long bounds_undo_stack()
bounds_undo_stack
Definition: memory.c:143
ptr_definition xfx_sym
symbol in bi module
Definition: def_glob.h:543
ptr_module x_module
'ifdef X11' unnecessary
Definition: def_glob.h:708
ptr_definition quoted_string
symbol in bi module
Definition: def_glob.h:368
ptr_choice_point choice_stack
Definition: def_glob.h:1026
ptr_psi_term old_saved_psi_term
Definition: def_glob.h:852
ptr_definition predsym
symbol in syntax module
Definition: def_glob.h:354
char * month_attr
Definition: def_glob.h:895
#define assert(N)
Definition: memory.c:114
ptr_definition xdrawable
Definition: def_glob.h:1040
ptr_definition tracesym
symbol in bi module
Definition: def_glob.h:424
ptr_definition life_or
symbol in syntax module
Definition: def_glob.h:326
void check_attr ( ptr_node n)

check_attr

Parameters
n- ptr_node *n

CHECK_ATTR(attribute-tree) Check an attribute tree. (Could improve this by randomly picking left or right subtree for last call optimization. This would never overflow, even on very skewed attribute trees.)

Definition at line 1055 of file memory.c.

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

1056 {
1057  while (unchecked((GENERIC *)n,sizeof(node))) { // added cast DJD 12/8/2016
1058  check_attr(&((*n)->left));
1059  check_string((GENERIC *)&((*n)->key)); // added cast DJD 12/8/2016
1060  check_psi_term((struct wl_psi_term **)&((*n)->data));
1061 
1062  n = &((*n)->right);
1063  /* check_attr(&((*n)->right)); 9.6 */
1064  }
1065 }
static void check_string(GENERIC *s)
check_string
Definition: memory.c:406
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:339
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
void check_psi_term(ptr_psi_term *t)
check_psi_term
Definition: memory.c:988
void check_attr(ptr_node *n)
check_attr
Definition: memory.c:1055
static void check_bytedata ( GENERIC s)
static

check_bytedata

Parameters
s- GENERIC *s

CHECK_BYTEDATA(s) Claim the memory used by a block of bytes

Definition at line 451 of file memory.c.

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

452 {
453  GENERIC addr;
454  long value;
455  if ((unsigned long) *s > MAX_BUILT_INS) {
456  unsigned long bytes = *((unsigned long *) *s);
457  unsigned long size = bytes + sizeof(bytes);
458  switch (pass) {
459  case 1:
460  (void)unchecked((GENERIC *)s,size);
461  break;
462  case 2:
463  addr=(*s+delta);
464  value= *addr;
465  if (value & 1) {
466  value--;
467  *s=(GENERIC) value;
468  *addr=value;
469 #ifdef prlDEBUG
470  amount_used+=size;
471 #endif
472  }
473  *s=(GENERIC)value;
474  break;
475  }
476  }
477 }
static long delta
Definition: memory.c:12
static long pass
Definition: memory.c:21
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:339
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
#define MAX_BUILT_INS
Maximum number of built_ins.
Definition: def_const.h:154
static void check_choice ( )
static
static void check_choice ( ptr_choice_point c)
static

check_choice

Parameters
c- ptr_choice_point *c

CHECK_CHOICE(c) This routine checks all choice points.

Definition at line 1185 of file memory.c.

References check_goal_stack(), and check_undo_stack().

1186 {
1187  while(*c) {
1188  check_undo_stack(&((*c)->undo_point)); /* 17.7 */
1189  check_goal_stack((ptr_goal *)&((*c)->goal_stack)); // added cast DJD 12/8/2016
1190  c= &((*c)->next);
1191  }
1192 }
static void check_undo_stack()
static void check_goal_stack(ptr_goal *g)
check_goal_stack
Definition: memory.c:801
static void check_choice_structs ( ptr_choice_point c)
static

check_choice_structs

Parameters
c- ptr_choice_point *c

Definition at line 1170 of file memory.c.

References unchecked().

1171 {
1172  while(unchecked((GENERIC *)c,sizeof(choice_point))) { // added cast DJD 12/8/2016
1173  c= &((*c)->next);
1174  }
1175 }
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:339
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
static void check_code ( ptr_int_list c)
static

check_code

Parameters
c- ptr_int_list *c

CHECK_CODE(c) Claim the memory used by a type code (=list of integers).

Definition at line 487 of file memory.c.

References unchecked().

488 {
489  while (unchecked((GENERIC *)c,sizeof(int_list))) // added cast DJD 12/8/2016
490  c= &((*c)->next);
491 }
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:339
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
static void check_def_code ( ptr_definition d)
static

check_def_code

Parameters
d- ptr_definition *d

CHECK_DEF_CODE(d) This routine checks the CODE field in a definition. It may only be invoked by CHECK_GAMMA.

Definition at line 721 of file memory.c.

References check_code(), and unchecked().

722 {
723  if (unchecked((GENERIC *)d,sizeof(definition))) // added cast DJD 12/8/2016
724  check_code((ptr_int_list *)&((*d)->code)); // added cast DJD 12/8/2016
725  /* p = &((*d)->properties); */
726  /* check_def_prop(p); */
727 }
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:339
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
static void check_code(ptr_int_list *c)
check_code
Definition: memory.c:487
static void check_def_rest ( ptr_definition d)
static

check_def_rest

Parameters
d- ptr_definition *d

CHECK_DEF_REST(d) This routine checks the other fields in a definition. It may only be invoked by CHECK_GAMMA_REST.

Definition at line 738 of file memory.c.

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

739 {
740  if (*d) {
741  check_keyword((ptr_keyword *)&((*d)->keyword)); /* RM: Jan 12 1993 */ // added cast DJD 12/8/2016
742  check_pair_list((ptr_pair_list *)&((*d)->rule)); // added cast DJD 12/8/2016
743  check_triple_list(&((*d)->properties));
744 
745  if ((*d)->type_def==(def_type)type_it) {
746  check_kids(&((*d)->parents));
747  check_kids(&((*d)->children));
748  }
749  check_operator_data(&((*d)->op_data)); /* PVR 5.6 */
750 #ifdef CLIFE
751  check_block_def(&((*d)->block_def)); /*CB 25/01/93 */
752 #endif /* CLIFE */
753  }
754 }
static void check_operator_data(ptr_operator_data *op)
check_operator_data
Definition: memory.c:552
static void check_pair_list(ptr_pair_list *p)
check_pair_list
Definition: memory.c:501
#define type_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1415
static void check_kids(ptr_int_list *c)
check_kids
Definition: memory.c:536
static void check_triple_list(ptr_triple_list *p)
check_triple_list
Definition: memory.c:518
static void check_keyword()
void check_definition ( ptr_definition d)

check_definition

Parameters
d- ptr_definition *d

CHECK_DEFINITION This goes through the type tree which contains the parents and children lists for all types, and the attributed code. The code field is not checked as this has been done separately by CHECK_GAMMA.

Definition at line 663 of file memory.c.

References check_code(), check_keyword(), check_kids(), check_operator_data(), check_pair_list(), check_psi_term(), check_triple_list(), wl_definition::keyword, wl_keyword::symbol, type_it, and unchecked().

664 {
665  if(unchecked((GENERIC *)d,sizeof(definition))) { // added cast DJD 12/8/2016
666 
667  check_keyword((ptr_keyword *)&((*d)->keyword)); /* RM: Jan 12 1993 */ // added cast DJD 12/8/2016
668 
669 #ifdef prlDEBUG
670  printf("%lx %20s %ld\n",*d,(*d)->keyword->symbol,amount_used);
671 #endif
672 
673  check_code((ptr_int_list *)&((*d)->code)); // added cast DJD 12/8/2016
674  check_pair_list((ptr_pair_list *)&((*d)->rule)); // added cast DJD 12/8/2016
675  check_triple_list(&((*d)->properties));
676 
677  if ((*d)->type_def==(def_type)type_it) {
678  check_kids(&((*d)->parents));
679  check_kids(&((*d)->children));
680  }
681 
682  check_psi_term(&((*d)->global_value)); /* RM: Feb 9 1993 */
683  check_psi_term(&((*d)->init_value)); /* RM: Mar 23 1993 */
684 
685  check_operator_data(&((*d)->op_data)); /* PVR 5.6 */
686 
687 #ifdef CLIFE
688  check_block_def(&((*d)->block_def)); /* RM: Jan 27 1993 */
689 #endif /* CLIFE */
690  }
691 }
static void check_operator_data(ptr_operator_data *op)
check_operator_data
Definition: memory.c:552
ptr_keyword keyword
Definition: def_struct.h:147
static void check_pair_list(ptr_pair_list *p)
check_pair_list
Definition: memory.c:501
char * symbol
Definition: def_struct.h:118
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:339
#define type_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1415
static void check_kids(ptr_int_list *c)
check_kids
Definition: memory.c:536
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
static void check_triple_list(ptr_triple_list *p)
check_triple_list
Definition: memory.c:518
void check_psi_term(ptr_psi_term *t)
check_psi_term
Definition: memory.c:988
static void check_code(ptr_int_list *c)
check_code
Definition: memory.c:487
static void check_keyword()
void check_definition_list ( )

check_definition_list

CHECK_DEFINITION_LIST This checks the entire list of definitions.

Definition at line 700 of file memory.c.

References check_definition(), and first_definition.

701 {
702  ptr_definition *d;
703 
704  d= &first_definition;
705 
706  while(*d) {
707  check_definition(d);
708  d= &((*d)->next);
709  }
710 }
ptr_definition first_definition
All definition are stores in a linked list starting at first_definition.
Definition: def_glob.h:13
void check_definition(ptr_definition *d)
check_definition
Definition: memory.c:663
void check_gamma_code ( )

check_gamma_code

CHECK_GAMMA_CODE() Check and update the code reversing table. In this part, only the codes are checked in the definitions, this is vital because these codes are used later to distinguish between the various data types and to determine the type of the VALUE field in psi_terms. Misunderstanding this caused a lot of bugs in the GC.

Definition at line 1079 of file memory.c.

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

1080 {
1081  long i;
1082 
1083  if (unchecked((GENERIC *)&gamma_table,type_count*sizeof(ptr_definition))) { // added cast DJD 12/8/2016
1084  for (i=0;i<type_count;i++)
1085  check_def_code(&(gamma_table[i]));
1086  }
1087 }
long type_count
Definition: def_glob.h:1021
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:339
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
static void check_def_code(ptr_definition *d)
check_def_code
Definition: memory.c:721
ptr_definition * gamma_table
Definition: def_glob.h:950
static void check_gamma_rest ( )
static

check_gamma_rest

CHECK_GAMMA_REST() Check and update the code reversing table.

Definition at line 1096 of file memory.c.

References check_def_rest(), gamma_table, and type_count.

1097 {
1098  long i;
1099 
1100  for (i=0;i<type_count;i++)
1101  check_def_rest(&(gamma_table[i]));
1102 }
long type_count
Definition: def_glob.h:1021
ptr_definition * gamma_table
Definition: def_glob.h:950
static void check_def_rest(ptr_definition *d)
check_def_rest
Definition: memory.c:738
static void check_goal_stack ( ptr_goal g)
static

check_goal_stack

Parameters
g- ptr_goal *g

CHECK_GOAL_STACK Check the goal_stack. This is quite complicated as each type of goal (prove, unify, eval, eval_cut etc...) gives its own meanings to the three other fields (A,B and C) present in each goal.

Definition at line 801 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.

802 {
803  while (unchecked((GENERIC *)g,sizeof(goal))) { // added cast DJD 12/8/2016
804 
805  switch ((*g)->type) {
806 
807  case fail:
808  break;
809 
810  case unify:
811  case unify_noeval: /* PVR 5.6 */
812  check_psi_term(&((*g)->aaaa_1));
813  check_psi_term(&((*g)->bbbb_1));
814  break;
815 
816  case prove:
817  check_psi_term(&((*g)->aaaa_1));
818  if ((unsigned long)(*g)->bbbb_1!=DEFRULES) check_pair_list((ptr_pair_list *)&((*g)->bbbb_1)); // added cast DJD 12/8/2016
819  check_pair_list((ptr_pair_list *)&((*g)->cccc_1)); // added cast DJD 12/8/2016
820  break;
821 
822  case disj:
823  check_psi_term(&((*g)->aaaa_1));
824  check_psi_term(&((*g)->bbbb_1));
825  break;
826 
827  case what_next:
828  /* check_choice(&((*g)->bbbb_1)); */
829  break;
830 
831  case eval:
832  check_psi_term(&((*g)->aaaa_1));
833  check_psi_term(&((*g)->bbbb_1));
834  check_pair_list((ptr_pair_list *)&((*g)->cccc_1)); // added cast DJD 12/8/2016
835  break;
836 
837  case load:
838  check_psi_term(&((*g)->aaaa_1));
839  check_string((GENERIC *)&((*g)->cccc_1)); // added cast DJD 12/8/2016
840  break;
841 
842  case match:
843  check_psi_term(&((*g)->aaaa_1));
844  check_psi_term(&((*g)->bbbb_1));
845  check_resid_block((struct wl_resid_block **)&((*g)->cccc_1));
846  break;
847 
848  case general_cut:
849  /* assert((GENERIC)(*g)->aaaa_3 <= (GENERIC)choice_stack); 12.7 17.7 */
850  if (pass==1 && (ptr_choice_point)(*g)->aaaa_1>choice_stack)
851  (*g)->aaaa_1=(ptr_psi_term)choice_stack;
852  (void)unchecked((GENERIC *)&((*g)->aaaa_1),LONELY); // added cast DJD 12/8/2016
853  break;
854 
855  case eval_cut:
856  check_psi_term(&((*g)->aaaa_1));
857  /* assert((GENERIC)(*g)->bbbb_1 <= (GENERIC)choice_stack); 12.7 17.7 */
858  if (pass==1 && (ptr_choice_point)(*g)->bbbb_1>choice_stack)
859  (*g)->bbbb_1=(ptr_psi_term)choice_stack;
860  (void)unchecked((GENERIC *)&((*g)->bbbb_1),LONELY); // added cast DJD 12/8/2016
861  check_resid_block((struct wl_resid_block **)&((*g)->cccc_1));
862  break;
863 
864  case freeze_cut:
865  case implies_cut:
866  check_psi_term(&((*g)->aaaa_1));
867  /* assert((GENERIC)(*g)->bbbb_1 <= (GENERIC)choice_stack); 12.7 17.7 */
868  if (pass==1 && (ptr_choice_point)(*g)->bbbb_1>choice_stack)
869  (*g)->bbbb_1=(ptr_psi_term)choice_stack;
870  (void)unchecked((GENERIC *)&((*g)->bbbb_1),LONELY); // added cast DJD 12/8/2016
871  check_resid_block((struct wl_resid_block **)&((*g)->cccc_1));
872  break;
873 
874  case type_disj:
875  check_psi_term(&((*g)->aaaa_1));
876  check_type_disj((ptr_int_list *)&((*g)->bbbb_1)); // added cast DJD 12/8/2016
877  break;
878 
879  case clause:
880  check_psi_term(&((*g)->aaaa_1));
881  check_psi_term(&((*g)->bbbb_1));
882  (void)unchecked((GENERIC *)&((*g)->cccc_1),LONELY); // added cast DJD 12/8/2016
883  /* check_pair_list((*g)->cccc_1); */ /* 6.8 */
884  break;
885 
886  case del_clause:
887  check_psi_term(&((*g)->aaaa_1));
888  check_psi_term(&((*g)->bbbb_1));
889  (void)unchecked((GENERIC *)&((*g)->cccc_1),LONELY); // added cast DJD 12/8/2016
890  /* check_pair_list((*g)->cccc_1); */ /* 6.8 */
891  break;
892 
893  case retract:
894  (void)unchecked((GENERIC *)&((*g)->aaaa_1),LONELY); // added cast DJD 12/8/2016
895  /* check_pair_list((*g)->aaaa_1); */ /* 6.8 */
896  /*PVR*/ /* check_choice(&((*g)->bbbb_1)); 9.6 */
897  break;
898 
899  default:
900  Errorline("in garbage collection, bad goal on stack.\n");
901  }
902 
903  g= &((*g)->next);
904  }
905 }
#define prove
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1051
static void check_type_disj(ptr_int_list *p)
check_type_disj
Definition: memory.c:783
#define general_cut
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1114
static void check_string(GENERIC *s)
check_string
Definition: memory.c:406
#define implies_cut
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1107
#define DEFRULES
Must be different from NULL, a built-in index, and a pointer Used to indicate that the rules of the d...
Definition: def_const.h:302
static long pass
Definition: memory.c:21
static void check_pair_list(ptr_pair_list *p)
check_pair_list
Definition: memory.c:501
struct wl_psi_term * ptr_psi_term
quotedStackCopy
Definition: def_struct.h:62
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:339
#define eval
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1086
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
void check_resid_block(ptr_resid_block *rb)
check_resid_block
Definition: memory.c:966
#define freeze_cut
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1100
#define what_next
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1079
#define match
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1121
#define clause
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1135
void check_psi_term(ptr_psi_term *t)
check_psi_term
Definition: memory.c:988
#define fail
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1044
#define retract
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1149
#define unify
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1058
#define load
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1156
#define unify_noeval
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1065
#define del_clause
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1142
#define eval_cut
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1093
#define disj
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1072
#define type_disj
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1128
#define LONELY
Definition: memory.c:24
ptr_choice_point choice_stack
Definition: def_glob.h:1026
void check_hash_table ( ptr_hash_table  table)

check_hash_table

Parameters
table- ptr_hash_table table

CHECK_HASH_TABLE(table) Check a hash table of keywords. The actual table is not stored within LIFE memory.

Definition at line 626 of file memory.c.

References check_keyword(), wl_hash_table::data, and wl_hash_table::size.

627 {
628  long i;
629 
630  for(i=0;i<table->size;i++)
631  if(table->data[i])
632  check_keyword((ptr_keyword *)&(table->data[i]));
633 }
ptr_keyword * data
Definition: def_struct.h:139
static void check_keyword()
static void check_keyword ( )
static
check_keyword ( ptr_keyword k)
static

check_keyword

Parameters
k- ptr_keyword *k

CHECK_KEYWORD(k) Checks a keyword.

Definition at line 643 of file memory.c.

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

644 {
645  if(unchecked((GENERIC *)k,sizeof(struct wl_keyword))) { // added cast DJD 12/8/2016
646  check_module(&((*k)->module));
647  check_string((GENERIC *)&((*k)->symbol)); // added cast DJD 12/8/2016
648  check_string((GENERIC *)&((*k)->combined_name)); // added cast DJD 12/8/2016
649  check_definition(&((*k)->definition));
650  }
651 }
static void check_string(GENERIC *s)
check_string
Definition: memory.c:406
static void check_module()
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:339
void check_definition(ptr_definition *d)
check_definition
Definition: memory.c:663
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
static void check_kids ( ptr_int_list c)
static

check_kids

Parameters
c- ptr_int_list *c

CHECK_KIDS(c) Check a list of parents or children of a given type.

Definition at line 536 of file memory.c.

References check_definition(), and unchecked().

537 {
538  while (unchecked((GENERIC *) c,sizeof(int_list))) { // added cast DJD 12/8/2016
539  check_definition((ptr_definition *)&((*c)->value_1));
540  c= &((*c)->next);
541  }
542 }
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:339
void check_definition(ptr_definition *d)
check_definition
Definition: memory.c:663
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
static void check_module ( )
static
static void check_module ( ptr_module m)
static

check_module

Parameters
m- ptr_module *m

CHECK_MODULE(m) Checks a module.

Definition at line 606 of file memory.c.

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

607 {
608  if(unchecked((GENERIC *)m,sizeof(struct wl_module))) { // added cast DJD 12/8/2016
609  check_string((GENERIC *)&((*m)->module_name)); // added cast DJD 12/8/2016
610  check_string((GENERIC *)&((*m)->source_file)); // added cast DJD 12/8/2016
611  check_module_list(&((*m)->open_modules));
612  check_module_list(&((*m)->inherited_modules));
613  check_hash_table((*m)->symbol_table);
614  }
615 }
static void check_string(GENERIC *s)
check_string
Definition: memory.c:406
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:339
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
static void check_module_list(ptr_int_list *c)
check_module_list
Definition: memory.c:571
void check_hash_table(ptr_hash_table table)
check_hash_table
Definition: memory.c:626
static void check_module_list ( ptr_int_list c)
static

check_module_list

Parameters
c- ptr_int_list *c

CHECK_MODULE_LIST(c) Check a list of modules.

Definition at line 571 of file memory.c.

References check_module(), and unchecked().

572 {
573  while (unchecked((GENERIC *)c,sizeof(int_list))) { // added cast DJD 12/8/2016
574  check_module(&((*c)->value_1));
575  c= &((*c)->next);
576  }
577 }
static void check_module()
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:339
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
static void check_module_tree ( ptr_node n)
static

check_module_tree

Parameters
n- ptr_node *n

CHECK_MODULE_TREE This goes through the module table, checking all nodes.

Definition at line 588 of file memory.c.

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

589 {
590  if (unchecked((GENERIC *)n,sizeof(node))) { // added cast DJD 12/8/2016
591  check_module_tree(&((*n)->left));
592  check_string((GENERIC *)&((*n)->key)); // added cast DJD 12/8/2016
593  check_module(&((*n)->data));
594  check_module_tree(&((*n)->right));
595  }
596 }
static void check_string(GENERIC *s)
check_string
Definition: memory.c:406
static void check_module()
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:339
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
static void check_module_tree(ptr_node *n)
check_module_tree
Definition: memory.c:588
static void check_operator_data ( ptr_operator_data op)
static

check_operator_data

Parameters
op- ptr_operator_data *op

CHECK_OPERATOR_DATA(op) Explore a list of operator declarations.

Definition at line 552 of file memory.c.

References unchecked().

553 {
554  while (unchecked((GENERIC *) op,sizeof(operator_data))) { // added cast DJD 12/8/2016
555  op = &((*op)->next);
556  }
557 }
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:339
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
static void check_pair_list ( ptr_pair_list p)
static

check_pair_list

ptr_pair_list *p

CHECK_PAIR_LIST Checks a list of <GOAL,BODY> pairs.

Definition at line 501 of file memory.c.

References check_psi_term(), and unchecked().

502 {
503  while (unchecked((GENERIC *)p,sizeof(pair_list))) { // added cast DJD 12/8/2016
504  check_psi_term(&((*p)->aaaa_2));
505  check_psi_term(&((*p)->bbbb_2));
506  p= &((*p)->next);
507  }
508 }
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:339
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
void check_psi_term(ptr_psi_term *t)
check_psi_term
Definition: memory.c:988
static void check_psi_list ( )
static
static void check_psi_list ( ptr_int_list l)
static

check_psi_list

Parameters
l- ptr_int_list *l

CHECK_PSI_LIST Update all the values in the list of residuation variables, which is a list of psi_terms.

Definition at line 1236 of file memory.c.

References check_psi_term(), and unchecked().

1237 {
1238  while(unchecked((GENERIC *)l,sizeof(int_list))) { // added cast DJD 12/8/2016
1239  check_psi_term((struct wl_psi_term **)&((*l)->value_1));
1240  l= &((*l)->next);
1241  }
1242 }
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:339
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
void check_psi_term(ptr_psi_term *t)
check_psi_term
Definition: memory.c:988
void check_psi_term ( ptr_psi_term t)

check_psi_term

Parameters
t- ptr_psi_term *t

CHECK_PSI_TERM(t) Explore a psi_term.

Definition at line 988 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.

989 {
990  ptr_list *l;
991 
992  while (unchecked((GENERIC *)t,sizeof(psi_term))) { // added cast DJD 12/8/2016
993 
994  /* A psi-term on the heap has no residuation list. */
995  if (pass==1 && (GENERIC)(*t)>=heap_pointer && (GENERIC)(*t)<mem_limit) {
996  assert((*t)->resid==NULL);
997  }
998  check_definition(&((*t)->type));
999  check_attr(&((*t)->attr_list));
1000 
1001  if ((*t)->value_3) {
1002 
1003  if ((*t)->type==alist) { /* RM: Dec 15 1992 Should be removed */
1004  l=(ptr_list *) &((*t)->value_3);
1005  if (l)
1006  printf("Found an old list!\n");
1007  }
1008  else
1009 
1010  if (sub_type((*t)->type,real))
1011  (void)unchecked((GENERIC *)&((*t)->value_3),sizeof(REAL)); // added cast DJD 12/8/2016
1012  else if (sub_type((*t)->type,quoted_string))
1013  check_string((GENERIC *)&((*t)->value_3)); // added cast DJD 12/8/2016
1014  /* DENYS: BYTEDATA */
1015  else if (sub_type((*t)->type,sys_bytedata))
1016  check_bytedata(&((*t)->value_3));
1017 #ifdef CLIFE
1018  else if ((*t)->type->type==block) { /* RM: Jan 27 1993 */
1019  check_block_value(&((*t)->value_3));
1020  }
1021 #endif /* CLIFE */
1022  else if ((*t)->type==cut) { /* RM: Oct 28 1993 */
1023  /* assert((*t)->value_3 <= (GENERIC)choice_stack); 12.7 17.7 */
1024  if (pass==1 && (*t)->value_3>(GENERIC)choice_stack)
1025  (*t)->value_3=(GENERIC)choice_stack;
1026  (void)unchecked((GENERIC *)&((*t)->value_3),LONELY); // added cast DJD 12/8/2016
1027  }
1028  else if (sub_type((*t)->type,variable)) /* 8.8 */
1029  check_string((GENERIC *)&((*t)->value_3)); // added cast DJD 12/8/2016
1030  else if ((*t)->type!=stream)
1031  Errorline("non-NULL value field in garbage collector, type='%s', value=%d.\n",
1032  (*t)->type->keyword->combined_name,
1033  (*t)->value_3);
1034  }
1035 
1036  /* check_psi_term(&((*t)->coref)); 9.6 */
1037  if ((*t)->resid)
1038  check_resid((ptr_residuation *)&((*t)->resid)); // added cast DJD 12/8/2016
1039 
1040  t = &((*t)->coref);
1041  }
1042 }
ptr_definition alist
symbol in bi module
Definition: def_glob.h:319
static void check_bytedata(GENERIC *s)
check_bytedata
Definition: memory.c:451
GENERIC heap_pointer
used to allocate from heap - size allocated subtracted - adj for alignment
Definition: def_glob.h:55
static void check_resid(ptr_residuation *r)
check_resid
Definition: memory.c:915
GENERIC mem_limit
starting point of heap - mem_base aligned
Definition: def_glob.h:62
ptr_definition cut
symbol in syntax module
Definition: def_glob.h:242
static void check_string(GENERIC *s)
check_string
Definition: memory.c:406
static long pass
Definition: memory.c:21
ptr_definition stream
symbol in bi module
Definition: def_glob.h:382
#define NULL
Definition: def_const.h:533
#define REAL
Which C type to use to represent reals and integers in Wild_Life.
Definition: def_const.h:132
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:339
struct wl_list * ptr_list
Definition: def_struct.h:66
ptr_definition sys_bytedata
symbol in sys module
Definition: def_glob.h:983
long sub_type(ptr_definition t1, ptr_definition t2)
sub_type
Definition: types.c:1642
void check_definition(ptr_definition *d)
check_definition
Definition: memory.c:663
ptr_definition real
symbol in bi module
Definition: def_glob.h:375
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
ptr_definition variable
symbol in bi module
Definition: def_glob.h:438
#define LONELY
Definition: memory.c:24
void check_attr(ptr_node *n)
check_attr
Definition: memory.c:1055
ptr_definition quoted_string
symbol in bi module
Definition: def_glob.h:368
ptr_choice_point choice_stack
Definition: def_glob.h:1026
#define assert(N)
Definition: memory.c:114
static void check_resid ( ptr_residuation r)
static

check_resid

Parameters
r- ptr_residuation *r

CHECK_RESID(r) Explore a list of residuations.

Definition at line 915 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.

916 {
917  ptr_int_list code;
918  ptr_list *l;
919 
920  while (unchecked((GENERIC *)r,sizeof(residuation))) { // added cast DJD 12/8/2016
921 
922  if ((*r)->sortflag) /* 22.9 */
923  check_definition((struct wl_definition **)&((*r)->bestsort));
924  else
925  check_code((ptr_int_list *)&((*r)->bestsort)); /* 21.9 */ // added cast DJD 12/8/2016
926 
927  /* Handling of the value field (6.10) */
928  code = (*r)->sortflag ? ((ptr_definition)((*r)->bestsort))->code
929  : (ptr_int_list)(*r)->bestsort;
930  /* Copied (almost) verbatim from check_psi_term: */
931  if ((*r)->value_2) {
932  if (code==alist->code) { /* RM: Dec 15 1992 Will be removed */
933  l=(ptr_list *) &((*r)->value_2);
934  if (l)
935  printf("Found an old list!!\n");
936  }
937  else if (sub_CodeType(code,real->code))
938  (void)unchecked((GENERIC *)&((*r)->value_2),sizeof(REAL)); // added cast DJD 12/8/2016
939  else if (sub_CodeType(code,quoted_string->code))
940  check_string((GENERIC *)&((*r)->value_2)); // added cast DJD 12/8/2016
941  /* DENYS: BYTEDATA */
942  else if (sub_CodeType(code,sys_bytedata->code))
943  check_bytedata(&((*r)->value_2));
944  else if (sub_CodeType(code,cut->code)) {
945  if (pass==1 && (*r)->value_2>(GENERIC)choice_stack)
946  (*r)->value_2=(GENERIC)choice_stack;
947  (void)unchecked((GENERIC *)&((*r)->value_2),LONELY); // added cast DJD 12/8/2016
948  }
949  else if (sub_CodeType(code,variable->code)) /* 8.8 */
950  check_string((GENERIC *)&((*r)->value_2)); // added cast DJD 12/8/2016
951  }
952 
953  check_goal_stack((ptr_goal *)&((*r)->goal)); // added cast DJD 12/8/2016
954  r= &((*r)->next);
955  }
956 }
ptr_definition alist
symbol in bi module
Definition: def_glob.h:319
static void check_bytedata(GENERIC *s)
check_bytedata
Definition: memory.c:451
static void check_goal_stack(ptr_goal *g)
check_goal_stack
Definition: memory.c:801
ptr_definition cut
symbol in syntax module
Definition: def_glob.h:242
static void check_string(GENERIC *s)
check_string
Definition: memory.c:406
static long pass
Definition: memory.c:21
#define REAL
Which C type to use to represent reals and integers in Wild_Life.
Definition: def_const.h:132
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:339
struct wl_list * ptr_list
Definition: def_struct.h:66
ptr_definition sys_bytedata
symbol in sys module
Definition: def_glob.h:983
void check_definition(ptr_definition *d)
check_definition
Definition: memory.c:663
ptr_definition real
symbol in bi module
Definition: def_glob.h:375
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
ptr_definition variable
symbol in bi module
Definition: def_glob.h:438
struct wl_definition * ptr_definition
Definition: def_struct.h:59
static void check_code(ptr_int_list *c)
check_code
Definition: memory.c:487
long sub_CodeType(ptr_int_list c1, ptr_int_list c2)
sub_CodeType
Definition: types.c:1618
ptr_int_list code
Definition: def_struct.h:150
#define LONELY
Definition: memory.c:24
ptr_definition quoted_string
symbol in bi module
Definition: def_glob.h:368
ptr_choice_point choice_stack
Definition: def_glob.h:1026
void check_resid_block ( ptr_resid_block rb)

check_resid_block

Parameters
rb- ptr_resid_block *rb

CHECK_RESID_BLOCK(rb) Explore a residuation block.

Definition at line 966 of file memory.c.

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

967 {
968  if (*rb) {
969  if (unchecked((GENERIC *)rb,sizeof(resid_block))) { // added cast DJD 12/8/2016
970  check_goal_stack((ptr_goal *)&((*rb)->ra)); // added cast DJD 12/8/2016
971  check_resid_list(&((*rb)->rv)); /* 21.9 */
972  /* unchecked(&((*rb)->rl),LONELY); 12.6 */ /* 10.6 */
973  (void)unchecked((GENERIC *)&((*rb)->md),LONELY); /* 10.6 */ // added cast DJD 12/8/2016
974  /* check_goal_stack(&((*rb)->rl)); 10.6 */
975  /* check_psi_term(&((*rb)->md)); 10.6 */
976  }
977  }
978 }
static void check_resid_list()
static void check_goal_stack(ptr_goal *g)
check_goal_stack
Definition: memory.c:801
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:339
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
#define LONELY
Definition: memory.c:24
static void check_resid_list ( )
static
static void check_resid_list ( ptr_resid_list l)
static

check_resid_list

Parameters
l- ptr_resid_list *l

CHECK_RESID_LIST Update all the values in the list of residuation variables, which is a list of pairs of psi_terms.

Definition at line 1253 of file memory.c.

References check_psi_term(), and unchecked().

1254 {
1255  while(unchecked((GENERIC *)l,sizeof(resid_list))) { // added cast DJD 12/8/2016
1256  check_psi_term(&((*l)->var));
1257  check_psi_term(&((*l)->othervar));
1258  l= &((*l)->next);
1259  }
1260 }
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:339
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
void check_psi_term(ptr_psi_term *t)
check_psi_term
Definition: memory.c:988
static void check_special_addresses ( )
static

check_special_addresses

CHECK_SPECIAL_ADDRESSES Here we check all the addresses which do not point to a whole data structure, but to something within, for example a field such as VALUE which might have been modified in a PSI_TERM structure. These are the LONELY addresses.

Definition at line 1203 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.

1204 {
1205  ptr_choice_point c;
1206  ptr_stack p;
1207  // ptr_goal g;
1208 
1209  c=choice_stack;
1210  while(c) {
1211  /* unchecked(&(c->undo_point),LONELY); 17.7 */
1212  (void)unchecked((GENERIC *)&(c->stack_top),LONELY); // added cast DJD 12/8/2016
1213  c=c->next;
1214  }
1215 
1216  p=undo_stack;
1217  while (p) {
1218  if (!(p->type & undo_action)) {
1219  /* Only update an address if it's within the Life data space! */
1220  if (VALID_RANGE(p->aaaa_3)) (void)unchecked((GENERIC *)&(p->aaaa_3),LONELY); // added cast DJD 12/8/2016
1221  if (p->type==cut_ptr) (void)unchecked((GENERIC *)&(p->bbbb_3),LONELY); /* 22.9 */ // added cast DJD 12/8/2016
1222  }
1223  p=p->next;
1224  }
1225 }
#define VALID_RANGE(A)
Definition: def_macro.h:127
GENERIC * bbbb_3
Definition: def_struct.h:233
GENERIC stack_top
Definition: def_struct.h:251
#define cut_ptr
values of type_ptr 22.9
Definition: def_const.h:425
ptr_choice_point next
Definition: def_struct.h:250
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:339
ptr_stack undo_stack
Definition: def_glob.h:1027
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
type_ptr type
Definition: def_struct.h:231
GENERIC * aaaa_3
Definition: def_struct.h:232
#define undo_action
Fast checking for an undo action.
Definition: def_const.h:484
#define LONELY
Definition: memory.c:24
ptr_stack next
Definition: def_struct.h:234
ptr_choice_point choice_stack
Definition: def_glob.h:1026
static void check_string ( GENERIC s)
static

check_string

Parameters
s- GENERIC *s

CHECK_STRING(s) Claim the memory used by the string S.

Definition at line 406 of file memory.c.

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

407 {
408  GENERIC addr;
409  long value;
410  long bytes;
411 
412  if ((unsigned long) *s > MAX_BUILT_INS) {
413  switch (pass) {
414  case 1:
415  bytes=strlen((char *)*s)+1;
416  /* if (bytes==LONELY) {
417  fprintf(stderr,"Caught an empty string!\n");
418  fflush(stderr);
419  } */
420  /* Make sure there's no conflict with LONELY (this occurs for an */
421  /* empty string, which still needs a single byte of storage). */
422  /* This does occasionally happen. */
423  (void)unchecked((GENERIC *)s, (bytes==LONELY)?bytes+1:bytes); // added cast DJD 12/8/2016
424  break;
425  case 2:
426  addr=(*s+delta);
427  value= *addr;
428  if (value & 1) { /* If low bit set */
429  value--;
430  *s=(GENERIC)value;
431  *addr=value;
432 #ifdef prlDEBUG
433  amount_used+=strlen(*s)+1;
434 #endif
435  }
436  *s=(GENERIC)value;
437  break;
438  }
439  }
440 }
static long delta
Definition: memory.c:12
static long pass
Definition: memory.c:21
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:339
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
#define MAX_BUILT_INS
Maximum number of built_ins.
Definition: def_const.h:154
#define LONELY
Definition: memory.c:24
static void check_symbol ( ptr_node n)
static

check_symbol

Parameters
n- ptr_node *n

CHECK_SYMBOL This goes through the symbol table, checking all nodes, symbols, strings and definitions not contained in the type table.

Definition at line 765 of file memory.c.

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

766 {
767  if (unchecked((GENERIC *)n,sizeof(node))) { // added cast DJD 12/8/2016
768  check_symbol(&((*n)->left));
769  check_string((GENERIC *)&((*n)->key)); // added cast DJD 12/8/2016
770  check_keyword((ptr_keyword *)&((*n)->data)); /* RM: Jan 12 1993 */ // added cast DJD 12/8/2016
771  check_symbol(&((*n)->right));
772  }
773 }
static void check_string(GENERIC *s)
check_string
Definition: memory.c:406
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:339
static void check_symbol(ptr_node *n)
check_symbol
Definition: memory.c:765
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
static void check_keyword()
static void check_triple_list ( ptr_triple_list p)
static

check_triple_list

Parameters
p- ptr_triple_list *p

CHECK_TRIPLE_LIST Checks a list of <GOAL,BODY,DEF> triples.

Definition at line 518 of file memory.c.

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

519 {
520  while (unchecked((GENERIC *)p,sizeof(triple_list))) { // added cast DJD 12/8/2016
521  check_psi_term(&((*p)->aaaa_4));
522  check_psi_term(&((*p)->bbbb_4));
523  check_definition(&((*p)->cccc_4));
524  p= &((*p)->next);
525  }
526 }
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:339
void check_definition(ptr_definition *d)
check_definition
Definition: memory.c:663
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
void check_psi_term(ptr_psi_term *t)
check_psi_term
Definition: memory.c:988
static void check_type_disj ( ptr_int_list p)
static

check_type_disj

Parameters
p- ptr_int_list *p

CHECK_TYPE_DISJ Checks the list of definitions appearing in a type disjunction.

Definition at line 783 of file memory.c.

References check_definition(), and unchecked().

784 {
785  while (unchecked((GENERIC *)p,sizeof(int_list))) { // added cast DJD 12/8/2016
786  check_definition((struct wl_definition **)&((*p)->value_1));
787  p= &((*p)->next);
788  }
789 }
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:339
void check_definition(ptr_definition *d)
check_definition
Definition: memory.c:663
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
static void check_undo_stack ( )
static
static void check_undo_stack ( ptr_stack s)
static

check_undo_stack

Parameters
s- ptr_stack *s

CHECK_UNDO_STACK() This looks after checking the addresses of objects pointed to in the trail. The type of the pointer to be restored on backtracking is known, which allows the structure it is referring to to be accordingly checked.

Definition at line 1114 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().

1115 {
1116  while (unchecked((GENERIC *)s,sizeof(stack))) { // added cast DJD 12/8/2016
1117 
1118  switch((*s)->type) {
1119 
1120  case psi_term_ptr:
1121  check_psi_term((struct wl_psi_term **)&((*s)->bbbb_3));
1122  break;
1123 
1124  case resid_ptr:
1125  check_resid((ptr_residuation *)&((*s)->bbbb_3)); // added cast DJD 12/8/2016
1126  break;
1127 
1128  case int_ptr:
1129  /* int_ptr's are used to trail time_stamps, so they can get large. */
1130  break;
1131 
1132  case def_ptr:
1133  check_definition((struct wl_definition **)&((*s)->bbbb_3));
1134  break;
1135 
1136  case code_ptr:
1137  check_code((ptr_int_list *)&((*s)->bbbb_3)); // added cast DJD 12/8/2016
1138  break;
1139 
1140  case goal_ptr:
1141  check_goal_stack((ptr_goal *)&((*s)->bbbb_3)); // added cast DJD 12/8/2016
1142  break;
1143 
1144  case cut_ptr: /* 22.9 */
1145  break;
1146 #ifdef CLIFE
1147  case block_ptr: /* CB: Jan 28 1993 */
1148  check_block_value(&((*s)->bbbb_3));
1149  break;
1150 
1151 #endif /* CLIFE */
1152  /* All undo actions here */
1153  case destroy_window:
1154  case show_window:
1155  case hide_window:
1156  /* No pointers to follow */
1157  break;
1158  }
1159 
1160  s= &((*s)->next);
1161  }
1162 }
static void check_resid(ptr_residuation *r)
check_resid
Definition: memory.c:915
#define show_window
To backtrack on show window.
Definition: def_const.h:456
#define def_ptr
values of type_ptr
Definition: def_const.h:404
static void check_goal_stack(ptr_goal *g)
check_goal_stack
Definition: memory.c:801
#define destroy_window
To backtrack on window creation.
Definition: def_const.h:449
#define cut_ptr
values of type_ptr 22.9
Definition: def_const.h:425
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:339
void check_definition(ptr_definition *d)
check_definition
Definition: memory.c:663
#define hide_window
To backtrack on hide window.
Definition: def_const.h:463
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
#define code_ptr
values of type_ptr
Definition: def_const.h:411
void check_psi_term(ptr_psi_term *t)
check_psi_term
Definition: memory.c:988
static void check_code(ptr_int_list *c)
check_code
Definition: memory.c:487
#define resid_ptr
values of type_ptr
Definition: def_const.h:390
#define goal_ptr
values of type_ptr
Definition: def_const.h:418
#define psi_term_ptr
values of type_ptr
Definition: def_const.h:383
#define int_ptr
values of type_ptr
Definition: def_const.h:397
static void check_var ( ptr_node n)
static

check_var

Parameters
n- ptr_node *n

CHECK_VAR(t) Go through the VARiable tree. (This could be made tail recursive.)

Definition at line 1271 of file memory.c.

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

1272 {
1273  if (unchecked((GENERIC *)n,sizeof(node))) { // added cast DJD 12/8/2016
1274  check_var(&((*n)->left));
1275  check_string((GENERIC *)&((*n)->key)); // added cast DJD 12/8/2016
1276  check_psi_term((struct wl_psi_term **)&((*n)->data));
1277  check_var(&((*n)->right));
1278  }
1279 }
static void check_string(GENERIC *s)
check_string
Definition: memory.c:406
static long unchecked(GENERIC *p, long len)
unchecked
Definition: memory.c:339
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
void check_psi_term(ptr_psi_term *t)
check_psi_term
Definition: memory.c:988
static void check_var(ptr_node *n)
check_var
Definition: memory.c:1271
static void compress ( )
static

compress

COMPRESS() This routine compresses the memory contents and calculates the new addresses. First the Stack is compressed, bottom up. Secondly the Heap is compressed, top down.

Definition at line 223 of file memory.c.

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

224 {
225  GENERIC addr, new_addr;
226  long len, i;
227 
228  /* Compressing the stack: */
229 
230  addr=new_addr=mem_base;
231  while (addr<=stack_pointer) {
232  len = *(addr+delta);
233  if (len) {
234  /* There are lots of these: */
235  /* if (len==LONELY) printf("Isolated LONELY at %lx\n",addr); */
236  if (len==LONELY) len=ALIGN;
237  else if (len & (ALIGN-1)) len=len-(len & (ALIGN-1))+ALIGN;
238  /* if (len & (ALIGN-1)) len=len-(len & (ALIGN-1))+ALIGN; 12.6 */
239  assert((len & (ALIGN-1))==0);
240  len /= sizeof(*addr);
241  assert(len>0);
242 
243  for (i=0; i<len; i++) {
244  *new_addr = *addr;
245  if (i>0) {
246  if (*(addr+delta)>=len)
247  assert(i>0 ? *(addr+delta)<len : TRUE);
248  }
249  assert(VALID_ADDRESS(new_addr));
250  *(addr+delta) = (long)new_addr + 1; /* Set low bit */
251 #ifdef prlDEBUG
252  if (*(addr+delta) & 1 == 0)
253  printf ("compress: could be a bug ...\n");
254 #endif
255  addr++;
256  new_addr++;
257  }
258  }
259  else
260  addr++;
261  }
262  other_pointer=stack_pointer; /* 10.6 this var. is unused */
263  stack_pointer=new_addr;
264 
265  /* Compressing the heap: */
266 
267  addr=new_addr=mem_limit;
268  addr--; /* PVR fix: adding this statement avoids accessing beyond */
269  /* the memory's edge, which causes a segmentation fault on*/
270  /* SPARC. */
271  while (addr>=heap_pointer) {
272  skip_addr:
273  len= *(addr+delta);
274  if (len) {
275  if (len!=LONELY) {
276 
277  if (len & (ALIGN-1)) len=len-(len & (ALIGN-1))+ALIGN;
278  assert((len & (ALIGN-1))==0);
279  len /= sizeof (*addr);
280  assert(len>0);
281 
282  } else { /* len==LONELY */
283  GENERIC a;
284 
285  if (len & (ALIGN-1)) len=len-(len & (ALIGN-1))+ALIGN;
286  assert((len & (ALIGN-1))==0);
287  len /= sizeof (*addr);
288  assert(len==1);
289 
290  /* Check if the LONELY field is actually part of a block. */
291  /* If so, skip to the beginning of the block. */
292  a=addr;
293  do {
294  a--;
295  } while (a>=heap_pointer &&
296  (*(a+delta)==0 || *(a+delta)==LONELY));
297  if (a>=heap_pointer && *(a+delta)/sizeof(*a)+a>addr) {
298  addr=a;
299  goto skip_addr;
300  }
301  }
302 
303  /* Move a block or an isolated LONELY field. */
304  addr += len;
305  for (i=0; i<len; i++) {
306  addr--;
307  new_addr--;
308  *new_addr = *addr;
309  assert(VALID_ADDRESS(new_addr));
310  *(addr+delta) = (long)new_addr + 1;
311  }
312  }
313  addr--;
314  }
315  heap_pointer=new_addr;
316 }
GENERIC stack_pointer
used to allocate from stack - size allocated added - adj for alignment
Definition: def_glob.h:69
#define VALID_ADDRESS(A)
Definition: def_macro.h:137
GENERIC heap_pointer
used to allocate from heap - size allocated subtracted - adj for alignment
Definition: def_glob.h:55
GENERIC mem_limit
starting point of heap - mem_base aligned
Definition: def_glob.h:62
static long delta
Definition: memory.c:12
GENERIC other_pointer
NOT USED - according to comment.
Definition: def_glob.h:111
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
#define TRUE
Standard boolean.
Definition: def_const.h:268
GENERIC mem_base
mem_size memory allocated in init_memory by malloc
Definition: def_glob.h:48
#define LONELY
Definition: memory.c:24
#define ALIGN
Definition: def_const.h:66
#define assert(N)
Definition: memory.c:114
void fail_all ( )

fail_all

FAIL_ALL() This routines provokes a total failure, in case of a bad error (out of memory, abort, etc...). All goals are abandoned.

Definition at line 189 of file memory.c.

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

190 {
191  output_stream=stdout;
195  (void)abort_life(TRUE);
196  /* printf("\n*** Abort\n"); */
197  stdin_cleareof();
198  (void)open_input_file("stdin");
199 }
ptr_goal goal_stack
Definition: def_glob.h:1025
#define NULL
Definition: def_const.h:533
long abort_life(int nlflag)
abort_life
Definition: built_ins.c:2259
ptr_stack undo_stack
Definition: def_glob.h:1027
#define TRUE
Standard boolean.
Definition: def_const.h:268
FILE * output_stream
Definition: def_glob.h:1017
void stdin_cleareof()
stdin_cleareof
Definition: token.c:51
long open_input_file(char *file)
open_input_file
Definition: token.c:594
ptr_choice_point choice_stack
Definition: def_glob.h:1026
void garbage ( )

garbage

GARBAGE() The garbage collector. This routine is called whenever memory is getting low. It returns TRUE if insufficient memory was freed to allow the interpreter to carry on working.

This is a half-space GC, it first explores all known structures, then compresses the heap and the stack, then during the second pass assigns all the new addresses.

Bugs will appear if the collector is called during parsing or other such routines which are 'unsafe'. In order to avoid this problem, before one of these routines is invoked the program will check to see whether there is enough memory available to work, and will call the GC if not (this is a fix, because it is not possible to determine in advance what the size of a psi_term read by the parser will be).

Definition at line 1530 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.

1531 {
1532  GENERIC addr;
1533  struct tms garbage_start_time,garbage_end_time;
1534  long start_number_cells, end_number_cells;
1535 
1536  start_number_cells = (stack_pointer-mem_base) + (mem_limit-heap_pointer);
1537 
1538  (void)times(&garbage_start_time);
1539 
1540  /* Time elapsed since last garbage collection */
1541  life_time=(garbage_start_time.tms_utime - last_garbage_time.tms_utime)/60.0;
1542 
1543 
1544  if (verbose) {
1545  fprintf(stderr,"*** Garbage Collect "); /* RM: Jan 26 1993 */
1546  fprintf(stderr,"\n*** Begin");
1548  (void)fflush(stderr);
1549  }
1550 
1551  /* reset the other base */
1552  for (addr = other_base; addr < other_limit; addr ++)
1553  *addr = 0;
1554 
1555  pass=1;
1556 
1557  check();
1558 #ifdef GCVERBOSE
1559  fprintf(stderr,"- Done pass 1 ");
1560 #endif
1561 
1563  compress();
1564 #ifdef GCVERBOSE
1565  fprintf(stderr,"- Done compress ");
1566 #endif
1567 
1568  pass=2;
1569 
1570  check();
1572 #ifdef GCVERBOSE
1573  fprintf(stderr,"- Done pass 2\n");
1574 #endif
1575 
1576  clear_copy();
1577 
1580 
1581  (void)times(&garbage_end_time);
1582  gc_time=(garbage_end_time.tms_utime - garbage_start_time.tms_utime)/60.0;
1584 
1585  if (verbose) {
1586  fprintf(stderr,"*** End ");
1587  print_gc_info(TRUE); /* RM: Jan 26 1993 */
1588  stack_info(stderr);
1589  (void)fflush(stderr);
1590  }
1591 
1592  last_garbage_time=garbage_end_time;
1593 
1594  end_number_cells = (stack_pointer-mem_base) + (mem_limit-heap_pointer);
1595  assert(end_number_cells<=start_number_cells);
1596 
1597  ignore_eff=FALSE;
1598 
1599 }
GENERIC stack_pointer
used to allocate from stack - size allocated added - adj for alignment
Definition: def_glob.h:69
ptr_node printed_pointers
Definition: def_glob.h:1007
float garbage_time
total time on garbage collections - seconds
Definition: def_glob.h:76
static void check()
check
Definition: memory.c:1300
void clear_copy()
clear_copy
Definition: copy.c:53
GENERIC heap_pointer
used to allocate from heap - size allocated subtracted - adj for alignment
Definition: def_glob.h:55
GENERIC mem_limit
starting point of heap - mem_base aligned
Definition: def_glob.h:62
static float gc_time
Definition: memory.c:27
long verbose
Definition: def_glob.h:914
static long pass
Definition: memory.c:21
#define NULL
Definition: def_const.h:533
long ignore_eff
Definition: def_glob.h:677
GENERIC other_limit
only used for the half-space garbage collector
Definition: def_glob.h:104
ptr_node pointer_names
Definition: def_glob.h:1008
void print_gc_info(long timeflag)
print_gc_info
Definition: memory.c:1493
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
#define TRUE
Standard boolean.
Definition: def_const.h:268
GENERIC other_base
mem_size memory allocated in init_memory by malloc
Definition: def_glob.h:98
static float life_time
Definition: memory.c:27
#define FALSE
Standard boolean.
Definition: def_const.h:275
static void compress()
compress
Definition: memory.c:223
void stack_info(FILE *outfile)
stack_info
Definition: error.c:77
GENERIC mem_base
mem_size memory allocated in init_memory by malloc
Definition: def_glob.h:48
long bounds_undo_stack()
bounds_undo_stack
Definition: memory.c:143
static struct tms last_garbage_time
Definition: memory.c:26
#define assert(N)
Definition: memory.c:114
int GetBoolOption ( char *  name)

GetBoolOption.

Parameters
name- char *name

Definition at line 64 of file memory.c.

References GetStrOption().

65 {
66  char *s;
67  s=GetStrOption(name,"off");
68  return strcmp(s,"off");
69 }
char * name
Definition: def_glob.h:966
char * GetStrOption(char *name, char *def)
GetStrOption.
Definition: memory.c:41
int GetIntOption ( char *  name,
int  def 
)

GetIntOption.

Parameters
name- char *name
def- int def

Definition at line 78 of file memory.c.

References GetStrOption().

79 {
80  char *s;
81  char buffer_loc[40];
82 
83  (void)snprintf(buffer_loc,40,"%d",def);
84  s=GetStrOption(name,buffer_loc);
85  return atof(s);
86 }
char * name
Definition: def_glob.h:966
char * GetStrOption(char *name, char *def)
GetStrOption.
Definition: memory.c:41
char* GetStrOption ( char *  name,
char *  def 
)

GetStrOption.

Parameters
name- char *name
def- char *def

STUFF FOR PARSING COMMAND LINE ARGS

Definition at line 41 of file memory.c.

References arg_c, and arg_v.

42 {
43  int i;
44  char *result=def;
45  int l=strlen(name);
46 
47  for(i=1; i<arg_c; i++)
48  if(arg_v[i][0]=='-' && (int)strlen(arg_v[i])>=l+1)
49  if(!strncmp(arg_v[i]+1,name,l))
50  if(arg_v[i][l+1]=='=')
51  result=arg_v[i]+l+2;
52  else
53  result=arg_v[i]+l+1;
54 
55  return result;
56 }
int arg_c
set from argc in either life.c or lib.c
Definition: def_glob.h:20
char * name
Definition: def_glob.h:966
char * arg_v[ARGNN]
set from argv in either life.c or lib.c
Definition: def_glob.h:27
GENERIC heap_alloc ( long  s)

heap_alloc

Parameters
s- long s

HEAP_ALLOC(s) This returns a pointer to S bytes of memory in the heap. Alignment is taken into account in the following manner: the macro ALIGN is supposed to be a power of 2 and the pointer returned is a multiple of ALIGN.

Definition at line 1616 of file memory.c.

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

1617 {
1618  if (s & (ALIGN-1))
1619  s = s - (s & (ALIGN-1))+ALIGN;
1620  /* assert(s % sizeof(*heap_pointer) == 0); */
1621  s /= sizeof (*heap_pointer);
1622 
1623  heap_pointer -= s;
1624 
1626  Errorline("the heap overflowed into the stack.\n");
1627 
1628  return heap_pointer;
1629 }
GENERIC stack_pointer
used to allocate from stack - size allocated added - adj for alignment
Definition: def_glob.h:69
GENERIC heap_pointer
used to allocate from heap - size allocated subtracted - adj for alignment
Definition: def_glob.h:55
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
#define ALIGN
Definition: def_const.h:66
void init_memory ( )

init_memory ()

INIT_MEMORY() Get two big blocks of memory to work in. The second is only used for the half-space garbage collector. The start and end addresses of the blocks are re-aligned correctly. to allocate.

Definition at line 1671 of file memory.c.

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

1672 {
1675 
1676  mem_base = (GENERIC) malloc(mem_size);
1677  other_base = (GENERIC) malloc(mem_size);
1678 
1679  if (mem_base && other_base) {
1680  /* Rewrote some rather poor code... RM: Mar 1 1994 */
1681  ALIGNUP(mem_base);
1683 
1685  ALIGNUP(mem_limit);
1687 
1690 
1691  other_limit=other_base+alloc_words-2;
1693 
1695  buffer = (char *) malloc (PRINT_BUFFER); /* The printing buffer */
1696 
1697  /* RM: Oct 22 1993 */
1698  /* Fill the memory with rubbish data */
1699  /*
1700  {
1701  int i;
1702 
1703  for(i=0;i<alloc_words;i++) {
1704  mem_base[i]= -1234;
1705  other_base[i]= -1234;
1706  }
1707  }
1708  */
1709  }
1710  else
1711  Errorline("Wild_life could not allocate sufficient memory to run.\n\n");
1712 }
GENERIC stack_pointer
used to allocate from stack - size allocated added - adj for alignment
Definition: def_glob.h:69
#define WORD
Memory Word Size.
Definition: def_const.h:63
#define ALLOC_WORDS
number of words to allocate if -memory=nnnnn not on command line
Definition: def_config.h:26
GENERIC heap_pointer
used to allocate from heap - size allocated subtracted - adj for alignment
Definition: def_glob.h:55
GENERIC mem_limit
starting point of heap - mem_base aligned
Definition: def_glob.h:62
int alloc_words
number of words to allocate - from either command lind or ALLOC_WORDS define
Definition: def_glob.h:34
static long delta
Definition: memory.c:12
GENERIC other_limit
only used for the half-space garbage collector
Definition: def_glob.h:104
GENERIC other_pointer
NOT USED - according to comment.
Definition: def_glob.h:111
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
char * buffer
buffer used only in print.c - there is local with same name in xpred.c
Definition: def_glob.h:781
#define ALIGNUP(X)
Definition: def_macro.h:299
#define PRINT_BUFFER
Size of print buffer.
Definition: def_const.h:211
GENERIC other_base
mem_size memory allocated in init_memory by malloc
Definition: def_glob.h:98
GENERIC mem_base
mem_size memory allocated in init_memory by malloc
Definition: def_glob.h:48
int mem_size
number of words from memory = alloc_words * sizeof word
Definition: def_glob.h:41
int GetIntOption(char *name, int def)
GetIntOption.
Definition: memory.c:78
long memory_check ( )

memory_check

MEMORY_CHECK() This function tests to see whether enough memory is available to allow execution to continue. It causes a garbage collection if not, and if that fails to release enough memory it returns FALSE.

Definition at line 1723 of file memory.c.

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

1724 {
1725  long success=TRUE;
1726 
1728  if(verbose) fprintf(stderr,"\n"); /* RM: Feb 1 1993 */
1729  garbage();
1730  /* Abort if didn't recover at least GC_THRESHOLD/10 of memory */
1732  fprintf(stderr,"*********************\n");
1733  fprintf(stderr,"*** OUT OF MEMORY ***\n");
1734  fprintf(stderr,"*********************\n");
1735  fail_all();
1736  success=FALSE;
1737  }
1738  }
1739  return success;
1740 }
GENERIC stack_pointer
used to allocate from stack - size allocated added - adj for alignment
Definition: def_glob.h:69
GENERIC heap_pointer
used to allocate from heap - size allocated subtracted - adj for alignment
Definition: def_glob.h:55
void fail_all()
fail_all
Definition: memory.c:189
long verbose
Definition: def_glob.h:914
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
void garbage()
garbage
Definition: memory.c:1530
#define GC_THRESHOLD
Garbage collection threshold (1/8 of MEM_SIZE is reasonable).
Definition: def_const.h:117
void pchoices ( )

pchoices

for debugging

Definition at line 94 of file memory.c.

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

95 {
97  printf("stack pointer is: %lx\n",(unsigned long)stack_pointer);
98  for(c=choice_stack;c;c=c->next)
99  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);
100 }
GENERIC stack_pointer
used to allocate from stack - size allocated added - adj for alignment
Definition: def_glob.h:69
GENERIC stack_top
Definition: def_struct.h:251
ptr_choice_point next
Definition: def_struct.h:250
ptr_choice_point choice_stack
Definition: def_glob.h:1026
void print_gc_info ( long  timeflag)

print_gc_info

Parameters
timeflag- long timeflag

Definition at line 1493 of file memory.c.

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

1494 {
1495  fprintf(stderr," [%ld%% free (%ldK), %ld%% heap, %ld%% stack",
1496  (100*((unsigned long)heap_pointer-(unsigned long)stack_pointer)+mem_size/2)/mem_size,
1497  ((unsigned long)heap_pointer-(unsigned long)stack_pointer+512)/1024,
1498  (100*((unsigned long)mem_limit-(unsigned long)heap_pointer)+mem_size/2)/mem_size,
1499  (100*((unsigned long)stack_pointer-(unsigned long)mem_base)+mem_size/2)/mem_size);
1500  if (timeflag) {
1501  fprintf(stderr,", %1.3fs cpu (%ld%%)",
1502  gc_time,
1503  (unsigned long)(0.5+100*gc_time/(life_time+gc_time)));
1504  }
1505  fprintf(stderr,"]\n");
1506 }
GENERIC stack_pointer
used to allocate from stack - size allocated added - adj for alignment
Definition: def_glob.h:69
GENERIC heap_pointer
used to allocate from heap - size allocated subtracted - adj for alignment
Definition: def_glob.h:55
GENERIC mem_limit
starting point of heap - mem_base aligned
Definition: def_glob.h:62
static float gc_time
Definition: memory.c:27
static float life_time
Definition: memory.c:27
GENERIC mem_base
mem_size memory allocated in init_memory by malloc
Definition: def_glob.h:48
int mem_size
number of words from memory = alloc_words * sizeof word
Definition: def_glob.h:41
void print_undo_stack ( )

print_undo_stack

Definition at line 122 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.

123 {
125 
126  while (u) {
127  if ((GENERIC)u->aaaa_3<mem_base || (GENERIC)u->aaaa_3>mem_limit ||
128  (GENERIC)u->next<mem_base || (GENERIC)u->next>mem_limit) {
129  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);
130  (void)fflush(stdout);
131  }
132  u=u->next;
133  }
134 }
GENERIC mem_limit
starting point of heap - mem_base aligned
Definition: def_glob.h:62
GENERIC * bbbb_3
Definition: def_struct.h:233
ptr_stack undo_stack
Definition: def_glob.h:1027
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
type_ptr type
Definition: def_struct.h:231
GENERIC * aaaa_3
Definition: def_struct.h:232
GENERIC mem_base
mem_size memory allocated in init_memory by malloc
Definition: def_glob.h:48
ptr_stack next
Definition: def_struct.h:234
GENERIC stack_alloc ( long  s)

stack_alloc

Parameters
s- long s

STACK_ALLOC(s) This returns a pointer to S bytes of memory in the stack. Alignment is taken into account in the following manner: the macro ALIGN is supposed to be a power of 2 and the pointer returned is a multiple of ALIGN.

Definition at line 1642 of file memory.c.

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

1643 {
1644  GENERIC r;
1645 
1646  r = stack_pointer;
1647 
1648  if (s & (ALIGN-1))
1649  s = s - (s & (ALIGN-1)) + ALIGN;
1650  /* assert(s % sizeof(*stack_pointer) == 0); */
1651  s /= sizeof (*stack_pointer);
1652 
1653  stack_pointer += s;
1654 
1656  Errorline("the stack overflowed into the heap.\n");
1657 
1658  return r;
1659 }
GENERIC stack_pointer
used to allocate from stack - size allocated added - adj for alignment
Definition: def_glob.h:69
GENERIC heap_pointer
used to allocate from heap - size allocated subtracted - adj for alignment
Definition: def_glob.h:55
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
#define ALIGN
Definition: def_const.h:66
static long unchecked ( GENERIC p,
long  len 
)
static

unchecked

Parameters
p- GENERIC *p
len- long len

UNCHECKED(p,l) P is a pointer to a structure L bytes in length. If L=LONELY then that means that P is a pointer to a sub-field of a structure. The function returns TRUE if the structure has not been yet thoroughly explored, otherwise FALSE. If this is the second pass then it translates P to its new value (as calculated by COMPRESS).

Definition at line 339 of file memory.c.

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

341 {
342  GENERIC addr;
343  long result=FALSE, value;
344 
345  assert(len>0);
346  if ((unsigned long)*p>MAX_BUILT_INS) {
347 #ifdef GCTEST
348  if (!VALID_ADDRESS(*p)) {
349  printf("p=%lx,*p=%lx\n",p,*p);
350  }
351 #endif
352  assert(VALID_ADDRESS(*p));
353  addr = *p + delta;
354  value = *addr;
355  switch (pass) {
356  case 1:
357 #ifdef GCTEST
358  if (FALSE /* len>100 || value>100 13.8 */) {
359  /* This does in fact happen */
360  printf("len=%ld,value=%ld\n",len,value);
361  fflush(stdout);
362  }
363 #endif
364  /* if (!value) */
365  if (!value || value==LONELY) {
366  /* Pointer not yet explored */
367  result=TRUE;
368  *addr=len;
369 #ifdef prlDEBUG
370  amount_used+=len;
371 #endif
372  }
373  else if (value < len && len != LONELY) {
374  Errorline("in garbage collection, %d < %d.\n", value, len);
375  }
376  else if (value > len && len != LONELY) {
377  Errorline("in garbage collection, %d > %d.\n", value, len);
378  }
379  break;
380  case 2:
381  if (value & 1) { /* If low bit set */
382  value--; /* Reset low bit */
383  *addr=value;
384 #ifdef prlDEBUG
385  amount_used+=len;
386 #endif
387  result=TRUE;
388  }
389  if (!VALID_ADDRESS(value))
390  assert(VALID_ADDRESS(value));
391  *p = (GENERIC) value;
392  break;
393  }
394  }
395  return result;
396 }
#define VALID_ADDRESS(A)
Definition: def_macro.h:137
static long delta
Definition: memory.c:12
static long pass
Definition: memory.c:21
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
#define MAX_BUILT_INS
Maximum number of built_ins.
Definition: def_const.h:154
#define LONELY
Definition: memory.c:24
#define assert(N)
Definition: memory.c:114

Variable Documentation

long delta
static

Definition at line 12 of file memory.c.

float gc_time
static

Definition at line 27 of file memory.c.

struct tms last_garbage_time
static

Definition at line 26 of file memory.c.

float life_time
static

Definition at line 27 of file memory.c.

long pass
static

Definition at line 21 of file memory.c.