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

New translation routines for Wild_Life. More...

Go to the source code of this file.

Functions

void init_copy ()
 init_copy More...
 
void clear_copy ()
 clear_copy More...
 
void insert_translation (ptr_psi_term a, ptr_psi_term b, long info)
 insert_translation More...
 
ptr_psi_term translate (ptr_psi_term a, long **infoptr)
 translate More...
 
static ptr_node copy_tree (ptr_node t, long copy_flag, long heap_flag)
 ptr_node copy_tree More...
 
ptr_psi_term exact_copy (ptr_psi_term t, long heap_flag)
 exact_copy More...
 
ptr_psi_term quote_copy (ptr_psi_term t, long heap_flag)
 quote_copy More...
 
ptr_psi_term eval_copy (ptr_psi_term t, long heap_flag)
 eval_copy More...
 
ptr_psi_term inc_heap_copy (ptr_psi_term t)
 inc_heap_copy More...
 
ptr_psi_term copy (ptr_psi_term t, long copy_flag, long heap_flag)
 copy More...
 
ptr_node distinct_tree (ptr_node t)
 distinct_tree More...
 
ptr_psi_term distinct_copy (ptr_psi_term t)
 distinct_copy More...
 
void mark_quote_c (ptr_psi_term t, long heap_flag)
 mark_quote_c More...
 
void mark_quote_tree_c (ptr_node n, long heap_flag)
 mark_quote_tree_c More...
 
void mark_eval (ptr_psi_term t)
 mark_eval More...
 
void mark_nonstrict (ptr_psi_term t)
 mark_nonstrict More...
 
void mark_quote_new2 (ptr_psi_term t)
 mark_quote_new2 More...
 
void mark_eval_new (ptr_psi_term t)
 mark_eval_new More...
 
void mark_eval_tree_new (ptr_node n)
 mark_eval_tree_new More...
 
void mark_quote_new (ptr_psi_term t)
 mark_quote_new More...
 
void mark_quote_tree_new (ptr_node n)
 mark_quote_tree_new More...
 
void mark_quote_tree ()
 
void mark_quote (ptr_psi_term t)
 mark_quote More...
 
void mark_quote_tree (ptr_node t)
 mark_quote_tree More...
 
void bk_mark_quote (ptr_psi_term t)
 bk_mark_quote More...
 
void bk_mark_quote_tree (ptr_node t)
 bk_mark_quote_tree More...
 

Variables

static struct hashentry hashtable [HASHSIZE]
 
static struct hashbuckethashbuckets
 
static long hashtime
 
static long hashfree
 
static long numbuckets
 
static long curr_status
 
static long mark_nonstrict_flag
 

Detailed Description

New translation routines for Wild_Life.

These routines work for any size structure. They are based on a hash table with buckets and timestamp. This allows fast clearing of the table and fast insertion and lookup.

Definition in file copy.c.

Function Documentation

void bk_mark_quote ( ptr_psi_term  t)

bk_mark_quote

Parameters
ptr_psi_termt

Back-trackably mark a psi-term as completely evaluated.

Definition at line 709 of file copy.c.

References wl_psi_term::attr_list, bk_mark_quote(), bk_mark_quote_tree(), wl_psi_term::coref, wl_psi_term::flags, heap_pointer, int_ptr, push_ptr_value(), QUOTED_TRUE, RMASK, and wl_psi_term::status.

710 {
711  if (t && !(t->status&RMASK)) {
712  if(t->status!=4 && (GENERIC)t<heap_pointer)/* RM: Jul 16 1993 */
714  t->status = 4;
715  t->flags=QUOTED_TRUE; /* 14.9 */
716  t->status |= RMASK;
717  bk_mark_quote(t->coref);
719  t->status &= ~RMASK;
720  }
721 }
void push_ptr_value(type_ptr t, GENERIC *p)
push_ptr_value
Definition: login.c:383
void bk_mark_quote_tree(ptr_node t)
bk_mark_quote_tree
Definition: copy.c:729
void bk_mark_quote(ptr_psi_term t)
bk_mark_quote
Definition: copy.c:709
#define RMASK
Definition: def_const.h:159
ptr_psi_term coref
Definition: def_struct.h:172
GENERIC heap_pointer
Definition: def_glob.h:12
unsigned long * GENERIC
Definition: def_struct.h:17
#define QUOTED_TRUE
Definition: def_const.h:123
ptr_node attr_list
Definition: def_struct.h:171
#define int_ptr
Definition: def_const.h:172
void bk_mark_quote_tree ( ptr_node  t)

bk_mark_quote_tree

Parameters
ptr_nodet

Definition at line 729 of file copy.c.

References bk_mark_quote(), bk_mark_quote_tree(), wl_node::data, wl_node::left, and wl_node::right.

730 {
731  if (t) {
735  }
736 }
void bk_mark_quote_tree(ptr_node t)
bk_mark_quote_tree
Definition: copy.c:729
GENERIC data
Definition: def_struct.h:185
ptr_node left
Definition: def_struct.h:183
void bk_mark_quote(ptr_psi_term t)
bk_mark_quote
Definition: copy.c:709
ptr_node right
Definition: def_struct.h:184
void clear_copy ( )

clear_copy

CLEAR_COPY() Erase the hash table. This must be done as a prelude to any copying operation.

Definition at line 53 of file copy.c.

References hashfree, and hashtime.

54 {
55  hashtime++;
56  hashfree=0;
57 }
static long hashfree
Definition: copy.c:19
static long hashtime
Definition: copy.c:18
ptr_psi_term copy ( ptr_psi_term  t,
long  copy_flag,
long  heap_flag 
)

copy

Parameters
ptr_psi_termt
longcopy_flag
longheap_flag

COPY(t) This is the workhorse of the interpreter (alas!). All copy-related routines are non-interruptible by the garbage collector.

Make a copy in the STACK or in the HEAP of psi_term t, which is located in the HEAP. A copy is done whenever invoking a rule, so it had better be fast. This routine uses hash tables with buckets and partial inlining for speed.

The following three versions of copy all rename their variables and return a completely dereferenced object:

u=exact_copy(t,hf) u is an exact copy of t. u=quote_copy(t,hf) u is a copy of t that is recursively marked evaluated. u=eval_copy(t,hf) u is a copy of t that is recursively marked unevaluated.

This version of copy is an incremental copy to the heap. It copies only those parts of a psi_term that are on the stack, leaving the others unchanged:

u=inc_heap_copy(t) u is an exact copy of t, on the heap. This is like hf==HEAP, except that objects already on the heap are untouched. Relies on no pointers from heap to stack.

hf = heap_flag. hf = HEAP or STACK means allocate in the HEAP or STACK. Marking eval/uneval is done by modifying the STATUS field of the copied psi_term. In eval_copy, a term's status is set to 0 if the term or any subterm needs evaluation. Terms are dereferenced when copying them to the heap.

Definition at line 248 of file copy.c.

References abort_life(), wl_psi_term::attr_list, choice_stack, COPY_THRESHOLD, copy_tree(), curr_status, cut, deref_ptr, env, Errorline(), EVAL_FLAG, wl_definition::evaluate_args, FALSE, wl_psi_term::flags, function_it, global, global_time_stamp, HEAP, heap_pointer, HEAPDONE, insert_translation(), mark_quote_c(), NEW, NULL, wl_definition::properties, QUOTE_FLAG, QUOTE_STUB, QUOTED_TRUE, wl_psi_term::resid, stack_pointer, wl_psi_term::status, traceline(), translate(), TRUE, wl_psi_term::type, wl_definition::type_def, type_it, and wl_psi_term::value_3.

249 {
250  ptr_psi_term u;
251  long old_status;
252  long local_copy_flag;
253  long *infoptr;
254 
255 
256  if ((u=t)) {
257  deref_ptr(t); /* Always dereference when copying */
258 
259  if (HEAPDONE(t)) return t;
260  u = translate(t,&infoptr);
261 
262  if (u && *infoptr!=QUOTE_STUB) { /* 24.8 */
263  /* If it was eval-copied before, then quote it now. */
264  if (*infoptr==EVAL_FLAG && copy_flag==QUOTE_FLAG) { /* 24.8 25.8 */
265  mark_quote_c(t,heap_flag);
266  *infoptr=QUOTE_FLAG; /* I.e. don't touch this term any more */
267  }
268  if (copy_flag==EVAL_FLAG) { /* PVR 14.2.94 */
269  /* If any subterm has zero curr_status (i.e., if u->status==0),
270  then so does the whole term: */
271  old_status=curr_status;
272  curr_status=u->status;
273  if (curr_status) curr_status=old_status;
274  }
275  }
276  else {
278  Errorline("psi-term too large -- get a bigger Life!\n");
279  (void)abort_life(TRUE);
280  longjmp(env,FALSE); /* Back to main loop */ /* RM: Feb 15 1993 */
281  }
282  if (copy_flag==EVAL_FLAG && !t->type->evaluate_args) /* 24.8 25.8 */
283  local_copy_flag=QUOTE_FLAG; /* All arguments will be quoted 24.8 */
284  else /* 24.8 */
285  local_copy_flag=copy_flag;
286  if (copy_flag==EVAL_FLAG) {
287  old_status = curr_status;
288  curr_status = 4;
289  }
290  if (u) { /* 15.9 */
291  *infoptr=QUOTE_FLAG;
292  local_copy_flag=QUOTE_FLAG;
293  copy_flag=QUOTE_FLAG;
294  }
295  else {
296  u=NEW(t,psi_term);
297  insert_translation(t,u,local_copy_flag); /* 24.8 */
298  }
299  *u = *t;
300  u->resid=NULL; /* 24.8 Don't copy residuations */
301 #ifdef TS
302  u->time_stamp=global_time_stamp; /* 9.6 */
303 #endif
304 
305  if (t->attr_list)
306  u->attr_list=copy_tree(t->attr_list, local_copy_flag, heap_flag);
307 
308  if (copy_flag==EVAL_FLAG) {
309  switch((long)t->type->type_def) {
310  case (long)type_it:
311  if (t->type->properties)
312  curr_status=0;
313  break;
314 
315  case (long)function_it:
316  curr_status=0;
317  break;
318 
319  case (long)global: /* RM: Feb 8 1993 */
320  curr_status=0;
321  break;
322 
323  default:
324  break;
325  }
326  u->status=curr_status;
327  u->flags=curr_status?QUOTED_TRUE:FALSE; /* 14.9 */
328  /* If any subterm has zero curr_status,
329  then so does the whole term: */
330  if (curr_status) curr_status=old_status;
331  } else if (copy_flag==QUOTE_FLAG) {
332  u->status=4;
333  u->flags=QUOTED_TRUE; /* 14.9 */
334  }
335  /* else copy_flag==EXACT_FLAG & u->status=t->status */
336 
337  if (heap_flag==HEAP) {
338  if (t->type==cut) u->value_3=NULL;
339  } else {
340  if (t->type==cut) {
342  traceline("current choice point is %x\n",choice_stack);
343  }
344  }
345  }
346  }
347 
348  return u;
349 }
#define COPY_THRESHOLD
Definition: def_const.h:68
ptr_residuation resid
Definition: def_struct.h:173
#define function_it
Definition: def_const.h:362
ptr_psi_term translate(ptr_psi_term a, long **infoptr)
translate
Definition: copy.c:108
#define HEAP
Definition: def_const.h:147
char evaluate_args
Definition: def_struct.h:136
#define global
Definition: def_const.h:364
#define QUOTE_STUB
Definition: def_const.h:329
def_type type_def
Definition: def_struct.h:133
void insert_translation(ptr_psi_term a, ptr_psi_term b, long info)
insert_translation
Definition: copy.c:67
#define NULL
Definition: def_const.h:203
#define NEW(A, TYPE)
Definition: def_macro.h:279
long abort_life(int nlflag)
abort_life
Definition: built_ins.c:2260
void traceline(char *format,...)
traceline
Definition: error.c:186
#define type_it
Definition: def_const.h:363
#define EVAL_FLAG
Definition: def_const.h:327
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
#define deref_ptr(P)
Definition: def_macro.h:95
#define TRUE
Definition: def_const.h:127
static ptr_node copy_tree(ptr_node t, long copy_flag, long heap_flag)
ptr_node copy_tree
Definition: copy.c:148
static long curr_status
Definition: copy.c:209
#define FALSE
Definition: def_const.h:128
GENERIC value_3
Definition: def_struct.h:170
void mark_quote_c(ptr_psi_term t, long heap_flag)
mark_quote_c
Definition: copy.c:434
GENERIC heap_pointer
Definition: def_glob.h:12
jmp_buf env
Definition: def_glob.h:236
ptr_definition cut
Definition: def_glob.h:83
unsigned long global_time_stamp
Definition: login.c:28
#define HEAPDONE(R)
Definition: def_macro.h:291
GENERIC stack_pointer
Definition: def_glob.h:14
#define QUOTE_FLAG
Definition: def_const.h:326
ptr_definition type
Definition: def_struct.h:165
unsigned long * GENERIC
Definition: def_struct.h:17
ptr_triple_list properties
Definition: def_struct.h:127
#define QUOTED_TRUE
Definition: def_const.h:123
ptr_node attr_list
Definition: def_struct.h:171
ptr_choice_point choice_stack
Definition: def_glob.h:51
static ptr_node copy_tree ( ptr_node  t,
long  copy_flag,
long  heap_flag 
)
static

ptr_node copy_tree

Parameters
ptr_nodet
longcopy_flag
longheap_flag

COPY_TREE(t) Return a pointer to a copy of the binary tree t. Structure sharing between trees is not preserved by this routine, this is not a problem seeing that coreferences in the nodes will ensure coherence.

Definition at line 148 of file copy.c.

References copy(), wl_node::data, HEAPDONE, wl_node::key, wl_node::left, NEW, NULL, and wl_node::right.

149 {
150  ptr_node r;
151  ptr_psi_term t1,t2;
152 
153  /* if (t) { RM: Dec 15 1992 this test is useless */
154 
155  if (HEAPDONE(t)) return t;
156  r=NEW(t,node);
157  r->key = t->key;
158  r->left = (t->left) ? copy_tree(t->left,copy_flag,heap_flag) : NULL;
159  t1 = (ptr_psi_term)(t->data);
160  t2 = copy(t1,copy_flag,heap_flag);
161  r->data = (GENERIC) t2;
162  r->right = (t->right) ? copy_tree(t->right,copy_flag,heap_flag) : NULL;
163 
164  /* } else r=NULL; */
165 
166  return r;
167 }
GENERIC data
Definition: def_struct.h:185
#define NULL
Definition: def_const.h:203
#define NEW(A, TYPE)
Definition: def_macro.h:279
ptr_node left
Definition: def_struct.h:183
char * key
Definition: def_struct.h:182
ptr_psi_term copy(ptr_psi_term t, long copy_flag, long heap_flag)
copy
Definition: copy.c:248
static ptr_node copy_tree(ptr_node t, long copy_flag, long heap_flag)
ptr_node copy_tree
Definition: copy.c:148
struct wl_psi_term * ptr_psi_term
Definition: def_struct.h:34
#define HEAPDONE(R)
Definition: def_macro.h:291
unsigned long * GENERIC
Definition: def_struct.h:17
ptr_node right
Definition: def_struct.h:184
ptr_psi_term distinct_copy ( ptr_psi_term  t)

distinct_copy

Parameters
ptr_psi_termt

DISTINCT_COPY(t) Make a distinct copy of T and T's attribute tree, which are identical to T, only located elsewhere in memory. This is used by apply to build the calling psi-term which is used for matching. Note that this routine is not recursive, i.e. it only copies the main functor & the attribute tree.

Definition at line 393 of file copy.c.

References wl_psi_term::attr_list, distinct_tree(), global_time_stamp, and STACK_ALLOC.

394 {
395  ptr_psi_term res;
396 
397  res=STACK_ALLOC(psi_term);
398  *res= *t;
399 #ifdef TS
400  res->time_stamp=global_time_stamp; /* 9.6 */
401 #endif
402  /* res->coref=distinct_copy(t->coref); */
404 
405  return res;
406 }
ptr_node distinct_tree(ptr_node t)
distinct_tree
Definition: copy.c:366
#define STACK_ALLOC(A)
Definition: def_macro.h:16
unsigned long global_time_stamp
Definition: login.c:28
ptr_node attr_list
Definition: def_struct.h:171
ptr_node distinct_tree ( ptr_node  t)

distinct_tree

Parameters
ptr_nodet

DISTINCT_TREE(t) Return an exact copy of an attribute tree. This is used by APPLY in order to build the calling psi-term which is used for matching.

Definition at line 366 of file copy.c.

References wl_node::data, distinct_tree(), wl_node::key, wl_node::left, NULL, wl_node::right, and STACK_ALLOC.

367 {
368  ptr_node n;
369 
370  n=NULL;
371  if (t) {
372  n=STACK_ALLOC(node);
373  n->key=t->key;
374  n->data=t->data;
375  n->left=distinct_tree(t->left);
376  n->right=distinct_tree(t->right);
377  }
378 
379  return n;
380 }
GENERIC data
Definition: def_struct.h:185
#define NULL
Definition: def_const.h:203
ptr_node distinct_tree(ptr_node t)
distinct_tree
Definition: copy.c:366
ptr_node left
Definition: def_struct.h:183
char * key
Definition: def_struct.h:182
#define STACK_ALLOC(A)
Definition: def_macro.h:16
ptr_node right
Definition: def_struct.h:184
ptr_psi_term eval_copy ( ptr_psi_term  t,
long  heap_flag 
)

eval_copy

Parameters
ptr_psi_termt
longheap_flag

Definition at line 196 of file copy.c.

References copy(), EVAL_FLAG, FALSE, and to_heap.

197 { to_heap=FALSE; return (copy(t, EVAL_FLAG, heap_flag)); }
#define EVAL_FLAG
Definition: def_const.h:327
ptr_psi_term copy(ptr_psi_term t, long copy_flag, long heap_flag)
copy
Definition: copy.c:248
long to_heap
Definition: def_glob.h:264
#define FALSE
Definition: def_const.h:128
ptr_psi_term exact_copy ( ptr_psi_term  t,
long  heap_flag 
)

exact_copy

Parameters
ptr_psi_termt
longheap_flag

Definition at line 176 of file copy.c.

References copy(), EXACT_FLAG, FALSE, and to_heap.

177 { to_heap=FALSE; return (copy(t, EXACT_FLAG, heap_flag)); }
#define EXACT_FLAG
Definition: def_const.h:325
ptr_psi_term copy(ptr_psi_term t, long copy_flag, long heap_flag)
copy
Definition: copy.c:248
long to_heap
Definition: def_glob.h:264
#define FALSE
Definition: def_const.h:128
ptr_psi_term inc_heap_copy ( ptr_psi_term  t)

inc_heap_copy

Parameters
ptr_psi_termt

There is a bug in inc_heap_copy

Definition at line 206 of file copy.c.

References copy(), EXACT_FLAG, to_heap, and TRUE.

207 { to_heap=TRUE; return (copy(t, EXACT_FLAG, TRUE)); }
#define EXACT_FLAG
Definition: def_const.h:325
#define TRUE
Definition: def_const.h:127
ptr_psi_term copy(ptr_psi_term t, long copy_flag, long heap_flag)
copy
Definition: copy.c:248
long to_heap
Definition: def_glob.h:264
void init_copy ( )

init_copy

INIT_COPY() Execute once upon startup of Wild_Life.

Definition at line 32 of file copy.c.

References HASHSIZE, hashtable, hashtime, numbuckets, and NUMBUCKETS.

33 {
34  long i;
35 
36  /* for(i=0; i<HASHSTATS; i++) hashstats[i]=0; 20.8 */
37 
38  for(i=0; i<HASHSIZE; i++) hashtable[i].timestamp = 0;
39  hashtime = 0;
41  hashbuckets = (struct hashbucket *)
42  malloc(NUMBUCKETS * sizeof(struct hashbucket));
43 }
static struct hashentry hashtable[HASHSIZE]
Definition: copy.c:16
#define NUMBUCKETS
Definition: def_const.h:319
static long numbuckets
Definition: copy.c:20
static long hashtime
Definition: copy.c:18
static struct hashbucket * hashbuckets
Definition: copy.c:17
#define HASHSIZE
Definition: def_const.h:315
void insert_translation ( ptr_psi_term  a,
ptr_psi_term  b,
long  info 
)

insert_translation

void insert_translation(ptr_psi_term a,ptr_psi_term b,long info) INSERT_TRANSLATION(a,b,info) Add the translation of address A to address B in the translation table. Also add an info field.

Definition at line 67 of file copy.c.

References hashentry::bucketindex, HASH, hashbuckets, HASHEND, hashfree, hashtable, hashtime, hashbucket::info, hashbucket::new_value, hashbucket::next, numbuckets, hashbucket::old_value, hashentry::timestamp, and traceline().

68 {
69  long index;
70  long lastbucket;
71 
72  /* Ensure there are free buckets by doubling their number if necessary */
73  if (hashfree >= numbuckets) {
74  numbuckets *= 2;
75  hashbuckets = (struct hashbucket *)
76  realloc((void *) hashbuckets, numbuckets * sizeof(struct hashbucket));
77  /* *** Do error handling here *** */
78  traceline("doubled the number of hashbuckets to %d\n", numbuckets);
79  }
80 
81  /* Add a bucket to the beginning of the list */
82  index = HASH(a);
83  if (hashtable[index].timestamp == hashtime)
84  lastbucket = hashtable[index].bucketindex;
85  else {
86  lastbucket = HASHEND;
87  hashtable[index].timestamp = hashtime;
88  }
93  hashbuckets[hashfree].next = lastbucket;
94  hashfree++;
95 }
static struct hashentry hashtable[HASHSIZE]
Definition: copy.c:16
static long hashfree
Definition: copy.c:19
static long numbuckets
Definition: copy.c:20
#define HASHEND
Definition: def_const.h:322
ptr_psi_term old_value
Definition: def_struct.h:385
static long hashtime
Definition: copy.c:18
void traceline(char *format,...)
traceline
Definition: error.c:186
ptr_psi_term new_value
Definition: def_struct.h:386
long timestamp
Definition: def_struct.h:392
static struct hashbucket * hashbuckets
Definition: copy.c:17
long bucketindex
Definition: def_struct.h:393
#define HASH(A)
Definition: def_macro.h:273
void mark_eval ( ptr_psi_term  t)

mark_eval

Parameters
ptr_psi_termt

A (possibly) correct mark_eval and its companion mark_quote.

The translation table is used to record whether a subgraph has already been quoted or not. Mark a psi-term as to be evaluated (i.e. strict), except for arguments of a nonstrict term, which are marked quoted. Set status correctly and propagate zero status upwards. Avoid doing superfluous work: non-shared terms are traversed once; shared terms are traversed at most twice (this only occurs if the first occurrence encountered is strict and a later occurrence is nonstrict). The translation table is used to indicate (1) whether a term has already been traversed, and if so, (2) whether there was a nonstrict traversal (in that case, the info field is FALSE).

Definition at line 498 of file copy.c.

References clear_copy(), FALSE, mark_eval_new(), and mark_nonstrict_flag.

499 {
500  clear_copy();
502  mark_eval_new(t);
503 }
void mark_eval_new(ptr_psi_term t)
mark_eval_new
Definition: copy.c:541
void clear_copy()
clear_copy
Definition: copy.c:53
#define FALSE
Definition: def_const.h:128
static long mark_nonstrict_flag
Definition: copy.c:479
void mark_eval_new ( ptr_psi_term  t)

mark_eval_new

Parameters
ptr_psi_termt

Definition at line 541 of file copy.c.

References wl_psi_term::attr_list, curr_status, deref_ptr, wl_definition::evaluate_args, FALSE, wl_psi_term::flags, function_it, global, insert_translation(), mark_eval_tree_new(), mark_nonstrict_flag, mark_quote_new(), mark_quote_tree_new(), wl_definition::properties, QUOTED_TRUE, wl_psi_term::status, translate(), TRUE, wl_psi_term::type, wl_definition::type_def, and type_it.

542 {
543  long *infoptr,flag;
544  ptr_psi_term u;
545  long old_status;
546 
547  if (t) {
548  deref_ptr(t);
549  flag = t->type->evaluate_args;
550  u=translate(t,&infoptr);
551  if (u) {
552  /* Quote the subgraph if it was already copied as to be evaluated. */
553  if (!flag && *infoptr) {
554  mark_quote_new(t);
555  *infoptr=FALSE;
556  }
557  /* If any subterm has zero curr_status (i.e., if t->status==0),
558  then so does the whole term: PVR 14.2.94 */
559  old_status=curr_status;
560  curr_status=(long)t->status;
561  if (curr_status) curr_status=old_status;
562  }
563  else {
565  old_status=curr_status;
566  curr_status=4;
567 
568  if (flag) /* 16.9 */
570  else
572 
573  switch((long)t->type->type_def) {
574  case type_it:
575  if (t->type->properties)
576  curr_status=0;
577  break;
578 
579  case function_it:
580  curr_status=0;
581  break;
582 
583  case global: /* RM: Feb 8 1993 */
584  curr_status=0;
585  break;
586 
587  default:
588  break;
589  }
590  if (mark_nonstrict_flag) { /* 25.8 */
591  if (curr_status) {
592  /* Only increase the status, never decrease it: */
593  t->status=curr_status;
594  }
595  }
596  else {
597  t->status=curr_status;
598  t->flags=curr_status?QUOTED_TRUE:FALSE; /* 14.9 */
599  }
600  /* If any subterm has zero curr_status, then so does the whole term: */
601  if (curr_status) curr_status=old_status;
602  }
603  }
604 }
#define function_it
Definition: def_const.h:362
ptr_psi_term translate(ptr_psi_term a, long **infoptr)
translate
Definition: copy.c:108
char evaluate_args
Definition: def_struct.h:136
#define global
Definition: def_const.h:364
def_type type_def
Definition: def_struct.h:133
void insert_translation(ptr_psi_term a, ptr_psi_term b, long info)
insert_translation
Definition: copy.c:67
void mark_eval_tree_new(ptr_node n)
mark_eval_tree_new
Definition: copy.c:612
#define type_it
Definition: def_const.h:363
#define deref_ptr(P)
Definition: def_macro.h:95
#define TRUE
Definition: def_const.h:127
void mark_quote_tree_new(ptr_node n)
mark_quote_tree_new
Definition: copy.c:654
static long curr_status
Definition: copy.c:209
#define FALSE
Definition: def_const.h:128
void mark_quote_new(ptr_psi_term t)
mark_quote_new
Definition: copy.c:627
static long mark_nonstrict_flag
Definition: copy.c:479
ptr_definition type
Definition: def_struct.h:165
ptr_triple_list properties
Definition: def_struct.h:127
#define QUOTED_TRUE
Definition: def_const.h:123
ptr_node attr_list
Definition: def_struct.h:171
void mark_eval_tree_new ( ptr_node  n)

mark_eval_tree_new

Parameters
ptr_noden

Definition at line 612 of file copy.c.

References wl_node::data, wl_node::left, mark_eval_new(), mark_eval_tree_new(), and wl_node::right.

613 {
614  if (n) {
618  }
619 }
void mark_eval_new(ptr_psi_term t)
mark_eval_new
Definition: copy.c:541
GENERIC data
Definition: def_struct.h:185
void mark_eval_tree_new(ptr_node n)
mark_eval_tree_new
Definition: copy.c:612
ptr_node left
Definition: def_struct.h:183
ptr_node right
Definition: def_struct.h:184
void mark_nonstrict ( ptr_psi_term  t)

mark_nonstrict

ptr_psi_term t

Parameters
ptr_psi_termt

Same as above, except that the status is only changed from 0 to 4 when needed; it is never changed from 4 to 0.

Definition at line 514 of file copy.c.

References clear_copy(), mark_eval_new(), mark_nonstrict_flag, and TRUE.

515 {
516  clear_copy();
518  mark_eval_new(t);
519 }
void mark_eval_new(ptr_psi_term t)
mark_eval_new
Definition: copy.c:541
void clear_copy()
clear_copy
Definition: copy.c:53
#define TRUE
Definition: def_const.h:127
static long mark_nonstrict_flag
Definition: copy.c:479
void mark_quote ( ptr_psi_term  t)

mark_quote

Parameters
ptr_psi_termt

A more efficient version of mark_quote This version avoids using the translation table by setting a 'visited' in the status field. Mark a psi-term as completely evaluated.

Definition at line 675 of file copy.c.

References wl_psi_term::attr_list, wl_psi_term::coref, wl_psi_term::flags, mark_quote(), mark_quote_tree(), QUOTED_TRUE, RMASK, and wl_psi_term::status.

676 {
677  if (t && !(t->status&RMASK)) {
678  t->status = 4;
679  t->flags=QUOTED_TRUE; /* 14.9 */
680  t->status |= RMASK;
681  mark_quote(t->coref);
683  t->status &= ~RMASK;
684  }
685 }
#define RMASK
Definition: def_const.h:159
ptr_psi_term coref
Definition: def_struct.h:172
void mark_quote(ptr_psi_term t)
mark_quote
Definition: copy.c:675
#define QUOTED_TRUE
Definition: def_const.h:123
ptr_node attr_list
Definition: def_struct.h:171
void mark_quote_tree()
void mark_quote_c ( ptr_psi_term  t,
long  heap_flag 
)

mark_quote_c

Parameters
ptr_psi_termt
longheap_flag

The new mark_quote to be used from copy.

Meaning of the info field in the translation table: With u=translate(t,&infoptr): If infoptr==QUOTE_FLAG then the whole subgraph from u is quoted. If infoptr==EVAL_FLAG then anything is possible. If infoptr==QUOTE_STUB then the term does not exist yet, e.g., there is a cycle in the term & copy(...) has not created it yet, for example X:s(L,t(X),R), where non_strict(t), in which R does not exist when the call to mark_quote_c is done. When the term is later created, it must be created as quoted.

Mark a psi-term u (which is a copy of t) as completely evaluated. Only t is given as the argument. Assumes the psi-term is a copy of another psi-term t, which is made through eval_copy. Therefore the copy is accessible through the translation table. Assumes all translation table entries already exist. The infoptr field is updated so that each subgraph is only traversed once. This routine is called only from the main copy routine.

Definition at line 434 of file copy.c.

References wl_psi_term::attr_list, deref_ptr, EVAL_FLAG, wl_psi_term::flags, insert_translation(), mark_quote_tree_c(), NEW, QUOTE_FLAG, QUOTE_STUB, QUOTED_TRUE, wl_psi_term::status, and translate().

435 {
436  // ptr_list l;
437  long *infoptr;
438  ptr_psi_term u;
439 
440  if (t) {
441  deref_ptr(t);
442  u=translate(t,&infoptr);
443  /* assert(u!=NULL); 15.9 */
444  if (u) {
445  if (*infoptr==EVAL_FLAG) {
446  *infoptr=QUOTE_FLAG;
447  u->status=4;
448  u->flags=QUOTED_TRUE; /* 14.9 */
449  mark_quote_tree_c(t->attr_list,heap_flag);
450  }
451  }
452  else { /* u does not exist yet */ /* 15.9 */
453  /* Create a stub & mark it as to-be-quoted. */
454  u=NEW(t,psi_term);
456  }
457  }
458 }
ptr_psi_term translate(ptr_psi_term a, long **infoptr)
translate
Definition: copy.c:108
void mark_quote_tree_c(ptr_node n, long heap_flag)
mark_quote_tree_c
Definition: copy.c:467
#define QUOTE_STUB
Definition: def_const.h:329
void insert_translation(ptr_psi_term a, ptr_psi_term b, long info)
insert_translation
Definition: copy.c:67
#define NEW(A, TYPE)
Definition: def_macro.h:279
#define EVAL_FLAG
Definition: def_const.h:327
#define deref_ptr(P)
Definition: def_macro.h:95
#define QUOTE_FLAG
Definition: def_const.h:326
#define QUOTED_TRUE
Definition: def_const.h:123
ptr_node attr_list
Definition: def_struct.h:171
void mark_quote_new ( ptr_psi_term  t)

mark_quote_new

Parameters
ptr_psi_termt

Definition at line 627 of file copy.c.

References wl_psi_term::attr_list, deref_ptr, FALSE, wl_psi_term::flags, insert_translation(), mark_quote_tree_new(), QUOTED_TRUE, wl_psi_term::status, translate(), and TRUE.

628 {
629  long *infoptr;
630  ptr_psi_term u;
631 
632  if (t) {
633  deref_ptr(t);
634  u=translate(t,&infoptr);
635 
636  /* Return if the subgraph is already quoted. */
637  if (u && !*infoptr) return;
638 
639  /* Otherwise quote the subgraph */
641  else *infoptr = FALSE; /* sanjay */
642  t->status= 4;
643  t->flags=QUOTED_TRUE; /* 14.9 */
645  }
646 }
ptr_psi_term translate(ptr_psi_term a, long **infoptr)
translate
Definition: copy.c:108
void insert_translation(ptr_psi_term a, ptr_psi_term b, long info)
insert_translation
Definition: copy.c:67
#define deref_ptr(P)
Definition: def_macro.h:95
#define TRUE
Definition: def_const.h:127
void mark_quote_tree_new(ptr_node n)
mark_quote_tree_new
Definition: copy.c:654
#define FALSE
Definition: def_const.h:128
#define QUOTED_TRUE
Definition: def_const.h:123
ptr_node attr_list
Definition: def_struct.h:171
void mark_quote_new2 ( ptr_psi_term  t)

mark_quote_new2

Parameters
ptr_psi_termt

Mark a term as quoted.

Definition at line 528 of file copy.c.

References clear_copy(), FALSE, mark_nonstrict_flag, and mark_quote_new().

529 {
530  clear_copy();
532  mark_quote_new(t);
533 }
void clear_copy()
clear_copy
Definition: copy.c:53
#define FALSE
Definition: def_const.h:128
void mark_quote_new(ptr_psi_term t)
mark_quote_new
Definition: copy.c:627
static long mark_nonstrict_flag
Definition: copy.c:479
void mark_quote_tree ( )
void mark_quote_tree ( ptr_node  t)

mark_quote_tree

Parameters
ptr_nodet

Definition at line 693 of file copy.c.

References wl_node::data, wl_node::left, mark_quote(), mark_quote_tree(), and wl_node::right.

694 {
695  if (t) {
696  mark_quote_tree(t->left);
697  mark_quote((ptr_psi_term) (t->data));
699  }
700 }
GENERIC data
Definition: def_struct.h:185
ptr_node left
Definition: def_struct.h:183
void mark_quote(ptr_psi_term t)
mark_quote
Definition: copy.c:675
void mark_quote_tree()
ptr_node right
Definition: def_struct.h:184
void mark_quote_tree_c ( ptr_node  n,
long  heap_flag 
)

mark_quote_tree_c

Parameters
ptr_noden
longheap_flag

Definition at line 467 of file copy.c.

References wl_node::data, wl_node::left, mark_quote_c(), mark_quote_tree_c(), and wl_node::right.

468 {
469  if (n) {
470  mark_quote_tree_c(n->left,heap_flag);
471  mark_quote_c((ptr_psi_term) (n->data),heap_flag);
472  mark_quote_tree_c(n->right,heap_flag);
473  }
474 }
void mark_quote_tree_c(ptr_node n, long heap_flag)
mark_quote_tree_c
Definition: copy.c:467
GENERIC data
Definition: def_struct.h:185
ptr_node left
Definition: def_struct.h:183
void mark_quote_c(ptr_psi_term t, long heap_flag)
mark_quote_c
Definition: copy.c:434
ptr_node right
Definition: def_struct.h:184
void mark_quote_tree_new ( ptr_node  n)

mark_quote_tree_new

void mark_quote_tree_new(ptr_node n)

Parameters
ptr_noden

Definition at line 654 of file copy.c.

References wl_node::data, wl_node::left, mark_quote_new(), mark_quote_tree_new(), and wl_node::right.

655 {
656  if (n) {
660  }
661 }
GENERIC data
Definition: def_struct.h:185
ptr_node left
Definition: def_struct.h:183
void mark_quote_tree_new(ptr_node n)
mark_quote_tree_new
Definition: copy.c:654
void mark_quote_new(ptr_psi_term t)
mark_quote_new
Definition: copy.c:627
ptr_node right
Definition: def_struct.h:184
ptr_psi_term quote_copy ( ptr_psi_term  t,
long  heap_flag 
)

quote_copy

Parameters
ptr_psi_termt
longheap_flag

Definition at line 186 of file copy.c.

References copy(), FALSE, QUOTE_FLAG, and to_heap.

187 { to_heap=FALSE; return (copy(t, QUOTE_FLAG, heap_flag)); }
ptr_psi_term copy(ptr_psi_term t, long copy_flag, long heap_flag)
copy
Definition: copy.c:248
long to_heap
Definition: def_glob.h:264
#define FALSE
Definition: def_const.h:128
#define QUOTE_FLAG
Definition: def_const.h:326
ptr_psi_term translate ( ptr_psi_term  a,
long **  infoptr 
)

translate

Parameters
ptr_psi_terma
long**infoptr)

TRANSLATE(a,info) Get the translation of address A and the info field stored with it. Return NULL if none is found.

Definition at line 108 of file copy.c.

References hashentry::bucketindex, HASH, HASHEND, hashtable, hashtime, hashbucket::info, hashbucket::new_value, hashbucket::next, NULL, and hashbucket::old_value.

109 {
110  long index;
111  /* long i; 20.8 */
112  long bucket;
113 
114  index = HASH(a);
115  if (hashtable[index].timestamp != hashtime) return NULL;
116  bucket = hashtable[index].bucketindex;
117  /* i=0; 20.8 */
118  while (bucket != HASHEND && hashbuckets[bucket].old_value != a) {
119  /* i++; 20.8 */
120  bucket = hashbuckets[bucket].next;
121  }
122  /* hashstats[i]++; 20.8 */
123  if (bucket != HASHEND) {
124  *infoptr = &hashbuckets[bucket].info;
125  return (hashbuckets[bucket].new_value);
126  }
127  else
128  return NULL;
129 }
static struct hashentry hashtable[HASHSIZE]
Definition: copy.c:16
#define HASHEND
Definition: def_const.h:322
#define NULL
Definition: def_const.h:203
ptr_psi_term old_value
Definition: def_struct.h:385
static long hashtime
Definition: copy.c:18
ptr_psi_term new_value
Definition: def_struct.h:386
static struct hashbucket * hashbuckets
Definition: copy.c:17
long bucketindex
Definition: def_struct.h:393
#define HASH(A)
Definition: def_macro.h:273

Variable Documentation

long curr_status
static

Definition at line 209 of file copy.c.

struct hashbucket* hashbuckets
static

Definition at line 17 of file copy.c.

long hashfree
static

Definition at line 19 of file copy.c.

struct hashentry hashtable[HASHSIZE]
static

Definition at line 16 of file copy.c.

long hashtime
static

Definition at line 18 of file copy.c.

long mark_nonstrict_flag
static

Definition at line 479 of file copy.c.

long numbuckets
static

Definition at line 20 of file copy.c.