Wild Life  2.30
 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
t- ptr_psi_term t

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

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

709 {
710  if (t && !(t->status&RMASK)) {
711  if(t->status!=4 && (GENERIC)t<heap_pointer)/* RM: Jul 16 1993 */
713  t->status = 4;
714  t->flags=QUOTED_TRUE; /* 14.9 */
715  t->status |= RMASK;
716  bk_mark_quote(t->coref);
718  t->status &= ~RMASK;
719  }
720 }
void push_ptr_value(type_ptr t, GENERIC *p)
push_ptr_value
Definition: login.c:383
GENERIC heap_pointer
used to allocate from heap - size allocated subtracted - adj for alignment
Definition: def_glob.h:55
void bk_mark_quote_tree(ptr_node t)
bk_mark_quote_tree
Definition: copy.c:728
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
void bk_mark_quote(ptr_psi_term t)
bk_mark_quote
Definition: copy.c:708
#define RMASK
Bit mask for status field of psi-terms: RMASK is used as a flag to avoid infinite loops when tracing ...
Definition: def_const.h:359
ptr_psi_term coref
Definition: def_struct.h:188
#define QUOTED_TRUE
True flags for the flags field of psi-terms.
Definition: def_const.h:254
ptr_node attr_list
Definition: def_struct.h:187
#define int_ptr
values of type_ptr
Definition: def_const.h:397
void bk_mark_quote_tree ( ptr_node  t)

bk_mark_quote_tree

Parameters
t- ptr_node t

Definition at line 728 of file copy.c.

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

729 {
730  if (t) {
734  }
735 }
void bk_mark_quote_tree(ptr_node t)
bk_mark_quote_tree
Definition: copy.c:728
GENERIC data
Definition: def_struct.h:201
ptr_node left
Definition: def_struct.h:199
void bk_mark_quote(ptr_psi_term t)
bk_mark_quote
Definition: copy.c:708
ptr_node right
Definition: def_struct.h:200
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
t- ptr_psi_term t
copy_flag- long copy_flag
heap_flag- long heap_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_it, 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_it: /* 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 }
GENERIC stack_pointer
used to allocate from stack - size allocated added - adj for alignment
Definition: def_glob.h:69
#define COPY_THRESHOLD
Copy threshold (1/8 of GC_THRESHOLD is reasonable)
Definition: def_const.h:125
ptr_residuation resid
Definition: def_struct.h:189
#define function_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1408
ptr_psi_term translate(ptr_psi_term a, long **infoptr)
translate
Definition: copy.c:108
#define HEAP
Flag to indicate heap allocation.
Definition: def_const.h:324
GENERIC heap_pointer
used to allocate from heap - size allocated subtracted - adj for alignment
Definition: def_glob.h:55
char evaluate_args
Definition: def_struct.h:156
ptr_definition cut
symbol in syntax module
Definition: def_glob.h:242
#define QUOTE_STUB
flag having to do with copying in copy.c
Definition: def_const.h:1328
def_type type_def
Definition: def_struct.h:153
void insert_translation(ptr_psi_term a, ptr_psi_term b, long info)
insert_translation
Definition: copy.c:67
#define global_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1422
#define NULL
Definition: def_const.h:533
#define NEW(A, TYPE)
Definition: def_macro.h:284
long abort_life(int nlflag)
abort_life
Definition: built_ins.c:2259
void traceline(char *format,...)
traceline
Definition: error.c:186
#define type_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1415
#define EVAL_FLAG
flag to copy function in copy.c to indicate kind of copy
Definition: def_const.h:1320
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
#define deref_ptr(P)
Definition: def_macro.h:100
#define TRUE
Standard boolean.
Definition: def_const.h:268
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
Standard boolean.
Definition: def_const.h:275
GENERIC value_3
Definition: def_struct.h:186
void mark_quote_c(ptr_psi_term t, long heap_flag)
mark_quote_c
Definition: copy.c:434
jmp_buf env
Definition: def_glob.h:877
unsigned long global_time_stamp
Definition: login.c:28
#define HEAPDONE(R)
Definition: def_macro.h:296
#define QUOTE_FLAG
flag to copy function in copy.c to indicate kind of copy
Definition: def_const.h:1313
ptr_definition type
Definition: def_struct.h:181
ptr_triple_list properties
Definition: def_struct.h:149
#define QUOTED_TRUE
True flags for the flags field of psi-terms.
Definition: def_const.h:254
ptr_node attr_list
Definition: def_struct.h:187
ptr_choice_point choice_stack
Definition: def_glob.h:1026
static ptr_node copy_tree ( ptr_node  t,
long  copy_flag,
long  heap_flag 
)
static

ptr_node copy_tree

Parameters
t- ptr_node t
copy_flag- long copy_flag
heap_flag- long heap_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 }
struct wl_psi_term * ptr_psi_term
quotedStackCopy
Definition: def_struct.h:62
GENERIC data
Definition: def_struct.h:201
#define NULL
Definition: def_const.h:533
#define NEW(A, TYPE)
Definition: def_macro.h:284
ptr_node left
Definition: def_struct.h:199
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
char * key
Definition: def_struct.h:198
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
#define HEAPDONE(R)
Definition: def_macro.h:296
ptr_node right
Definition: def_struct.h:200
ptr_psi_term distinct_copy ( ptr_psi_term  t)

distinct_copy

Parameters
t- ptr_psi_term t

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:21
unsigned long global_time_stamp
Definition: login.c:28
ptr_node attr_list
Definition: def_struct.h:187
ptr_node distinct_tree ( ptr_node  t)

distinct_tree

Parameters
t- ptr_node t

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:201
#define NULL
Definition: def_const.h:533
ptr_node distinct_tree(ptr_node t)
distinct_tree
Definition: copy.c:366
ptr_node left
Definition: def_struct.h:199
char * key
Definition: def_struct.h:198
#define STACK_ALLOC(A)
Definition: def_macro.h:21
ptr_node right
Definition: def_struct.h:200
ptr_psi_term eval_copy ( ptr_psi_term  t,
long  heap_flag 
)

eval_copy

Parameters
t- ptr_psi_term t
heap_flag- long heap_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
flag to copy function in copy.c to indicate kind of copy
Definition: def_const.h:1320
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:905
#define FALSE
Standard boolean.
Definition: def_const.h:275
ptr_psi_term exact_copy ( ptr_psi_term  t,
long  heap_flag 
)

exact_copy

Parameters
t- ptr_psi_term t
heap_flag- long heap_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
flag to copy function in copy.c to indicate kind of copy
Definition: def_const.h:1306
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:905
#define FALSE
Standard boolean.
Definition: def_const.h:275
ptr_psi_term inc_heap_copy ( ptr_psi_term  t)

inc_heap_copy

Parameters
t- ptr_psi_term t

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
flag to copy function in copy.c to indicate kind of copy
Definition: def_const.h:1306
#define TRUE
Standard boolean.
Definition: def_const.h:268
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:905
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
Total number of buckets in initial hash table;.
Definition: def_const.h:1292
static long numbuckets
Definition: copy.c:20
static long hashtime
Definition: copy.c:18
static struct hashbucket * hashbuckets
Definition: copy.c:17
#define HASHSIZE
Size of hash table; must be a power of 2.
Definition: def_const.h:1284
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
Tail of hash bucket.
Definition: def_const.h:1299
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:278
void mark_eval ( ptr_psi_term  t)

mark_eval

Parameters
t- ptr_psi_term t

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:540
void clear_copy()
clear_copy
Definition: copy.c:53
#define FALSE
Standard boolean.
Definition: def_const.h:275
static long mark_nonstrict_flag
Definition: copy.c:479
void mark_eval_new ( ptr_psi_term  t)

mark_eval_new

Parameters
t- ptr_psi_term t

Definition at line 540 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_it, 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.

541 {
542  long *infoptr,flag;
543  ptr_psi_term u;
544  long old_status;
545 
546  if (t) {
547  deref_ptr(t);
548  flag = t->type->evaluate_args;
549  u=translate(t,&infoptr);
550  if (u) {
551  /* Quote the subgraph if it was already copied as to be evaluated. */
552  if (!flag && *infoptr) {
553  mark_quote_new(t);
554  *infoptr=FALSE;
555  }
556  /* If any subterm has zero curr_status (i.e., if t->status==0),
557  then so does the whole term: PVR 14.2.94 */
558  old_status=curr_status;
559  curr_status=(long)t->status;
560  if (curr_status) curr_status=old_status;
561  }
562  else {
564  old_status=curr_status;
565  curr_status=4;
566 
567  if (flag) /* 16.9 */
569  else
571 
572  switch((long)t->type->type_def) {
573  case type_it:
574  if (t->type->properties)
575  curr_status=0;
576  break;
577 
578  case function_it:
579  curr_status=0;
580  break;
581 
582  case global_it: /* RM: Feb 8 1993 */
583  curr_status=0;
584  break;
585 
586  default:
587  break;
588  }
589  if (mark_nonstrict_flag) { /* 25.8 */
590  if (curr_status) {
591  /* Only increase the status, never decrease it: */
592  t->status=curr_status;
593  }
594  }
595  else {
596  t->status=curr_status;
597  t->flags=curr_status?QUOTED_TRUE:FALSE; /* 14.9 */
598  }
599  /* If any subterm has zero curr_status, then so does the whole term: */
600  if (curr_status) curr_status=old_status;
601  }
602  }
603 }
#define function_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1408
ptr_psi_term translate(ptr_psi_term a, long **infoptr)
translate
Definition: copy.c:108
char evaluate_args
Definition: def_struct.h:156
def_type type_def
Definition: def_struct.h:153
void insert_translation(ptr_psi_term a, ptr_psi_term b, long info)
insert_translation
Definition: copy.c:67
#define global_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1422
void mark_eval_tree_new(ptr_node n)
mark_eval_tree_new
Definition: copy.c:611
#define type_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1415
#define deref_ptr(P)
Definition: def_macro.h:100
#define TRUE
Standard boolean.
Definition: def_const.h:268
void mark_quote_tree_new(ptr_node n)
mark_quote_tree_new
Definition: copy.c:653
static long curr_status
Definition: copy.c:209
#define FALSE
Standard boolean.
Definition: def_const.h:275
void mark_quote_new(ptr_psi_term t)
mark_quote_new
Definition: copy.c:626
static long mark_nonstrict_flag
Definition: copy.c:479
ptr_definition type
Definition: def_struct.h:181
ptr_triple_list properties
Definition: def_struct.h:149
#define QUOTED_TRUE
True flags for the flags field of psi-terms.
Definition: def_const.h:254
ptr_node attr_list
Definition: def_struct.h:187
void mark_eval_tree_new ( ptr_node  n)

mark_eval_tree_new

Parameters
n- ptr_node n

Definition at line 611 of file copy.c.

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

612 {
613  if (n) {
617  }
618 }
void mark_eval_new(ptr_psi_term t)
mark_eval_new
Definition: copy.c:540
GENERIC data
Definition: def_struct.h:201
void mark_eval_tree_new(ptr_node n)
mark_eval_tree_new
Definition: copy.c:611
ptr_node left
Definition: def_struct.h:199
ptr_node right
Definition: def_struct.h:200
void mark_nonstrict ( ptr_psi_term  t)

mark_nonstrict

Parameters
t- ptr_psi_term t

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 513 of file copy.c.

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

514 {
515  clear_copy();
517  mark_eval_new(t);
518 }
void mark_eval_new(ptr_psi_term t)
mark_eval_new
Definition: copy.c:540
void clear_copy()
clear_copy
Definition: copy.c:53
#define TRUE
Standard boolean.
Definition: def_const.h:268
static long mark_nonstrict_flag
Definition: copy.c:479
void mark_quote ( ptr_psi_term  t)

mark_quote

Parameters
t- ptr_psi_term t

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 674 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.

675 {
676  if (t && !(t->status&RMASK)) {
677  t->status = 4;
678  t->flags=QUOTED_TRUE; /* 14.9 */
679  t->status |= RMASK;
680  mark_quote(t->coref);
682  t->status &= ~RMASK;
683  }
684 }
#define RMASK
Bit mask for status field of psi-terms: RMASK is used as a flag to avoid infinite loops when tracing ...
Definition: def_const.h:359
ptr_psi_term coref
Definition: def_struct.h:188
void mark_quote(ptr_psi_term t)
mark_quote
Definition: copy.c:674
#define QUOTED_TRUE
True flags for the flags field of psi-terms.
Definition: def_const.h:254
ptr_node attr_list
Definition: def_struct.h:187
void mark_quote_tree()
void mark_quote_c ( ptr_psi_term  t,
long  heap_flag 
)

mark_quote_c

Parameters
t- ptr_psi_term t
heap_flag- long heap_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
flag having to do with copying in copy.c
Definition: def_const.h:1328
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:284
#define EVAL_FLAG
flag to copy function in copy.c to indicate kind of copy
Definition: def_const.h:1320
#define deref_ptr(P)
Definition: def_macro.h:100
#define QUOTE_FLAG
flag to copy function in copy.c to indicate kind of copy
Definition: def_const.h:1313
#define QUOTED_TRUE
True flags for the flags field of psi-terms.
Definition: def_const.h:254
ptr_node attr_list
Definition: def_struct.h:187
void mark_quote_new ( ptr_psi_term  t)

mark_quote_new

Parameters
t- ptr_psi_term t

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

627 {
628  long *infoptr;
629  ptr_psi_term u;
630 
631  if (t) {
632  deref_ptr(t);
633  u=translate(t,&infoptr);
634 
635  /* Return if the subgraph is already quoted. */
636  if (u && !*infoptr) return;
637 
638  /* Otherwise quote the subgraph */
640  else *infoptr = FALSE; /* sanjay */
641  t->status= 4;
642  t->flags=QUOTED_TRUE; /* 14.9 */
644  }
645 }
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:100
#define TRUE
Standard boolean.
Definition: def_const.h:268
void mark_quote_tree_new(ptr_node n)
mark_quote_tree_new
Definition: copy.c:653
#define FALSE
Standard boolean.
Definition: def_const.h:275
#define QUOTED_TRUE
True flags for the flags field of psi-terms.
Definition: def_const.h:254
ptr_node attr_list
Definition: def_struct.h:187
void mark_quote_new2 ( ptr_psi_term  t)

mark_quote_new2

Parameters
t- ptr_psi_term t

Mark a term as quoted.

Definition at line 527 of file copy.c.

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

528 {
529  clear_copy();
531  mark_quote_new(t);
532 }
void clear_copy()
clear_copy
Definition: copy.c:53
#define FALSE
Standard boolean.
Definition: def_const.h:275
void mark_quote_new(ptr_psi_term t)
mark_quote_new
Definition: copy.c:626
static long mark_nonstrict_flag
Definition: copy.c:479
void mark_quote_tree ( )
void mark_quote_tree ( ptr_node  t)

mark_quote_tree

Parameters
t- ptr_node t

Definition at line 692 of file copy.c.

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

693 {
694  if (t) {
695  mark_quote_tree(t->left);
696  mark_quote((ptr_psi_term) (t->data));
698  }
699 }
GENERIC data
Definition: def_struct.h:201
ptr_node left
Definition: def_struct.h:199
void mark_quote(ptr_psi_term t)
mark_quote
Definition: copy.c:674
void mark_quote_tree()
ptr_node right
Definition: def_struct.h:200
void mark_quote_tree_c ( ptr_node  n,
long  heap_flag 
)

mark_quote_tree_c

Parameters
n- ptr_node n
heap_flag- long heap_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:201
ptr_node left
Definition: def_struct.h:199
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:200
void mark_quote_tree_new ( ptr_node  n)

mark_quote_tree_new

void mark_quote_tree_new(ptr_node n)

Parameters
n- ptr_node n

Definition at line 653 of file copy.c.

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

654 {
655  if (n) {
659  }
660 }
GENERIC data
Definition: def_struct.h:201
ptr_node left
Definition: def_struct.h:199
void mark_quote_tree_new(ptr_node n)
mark_quote_tree_new
Definition: copy.c:653
void mark_quote_new(ptr_psi_term t)
mark_quote_new
Definition: copy.c:626
ptr_node right
Definition: def_struct.h:200
ptr_psi_term quote_copy ( ptr_psi_term  t,
long  heap_flag 
)

quote_copy

Parameters
t- ptr_psi_term t
heap_flag- long heap_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:905
#define FALSE
Standard boolean.
Definition: def_const.h:275
#define QUOTE_FLAG
flag to copy function in copy.c to indicate kind of copy
Definition: def_const.h:1313
ptr_psi_term translate ( ptr_psi_term  a,
long **  infoptr 
)

translate

Parameters
a- ptr_psi_term a
infoptr- 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
Tail of hash bucket.
Definition: def_const.h:1299
#define NULL
Definition: def_const.h:533
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:278

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.