Wild Life: copy.c File Reference

Wild Life 2.30

- Main Page
- Data Structures
- Files

- File List
- Globals

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 hashbucket * | hashbuckets
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 */
712 push_ptr_value(int_ptr,(GENERIC *)&(t->status));
713 t->status = 4;
714 t->flags=QUOTED_TRUE; /* 14.9 */
715 t->status |= RMASK;
716 bk_mark_quote(t->coref);
717 bk_mark_quote_tree(t->attr_list);
718 t->status &= ~RMASK;
719 }
720 }
push_ptr_value
void push_ptr_value(type_ptr t, GENERIC *p)
push_ptr_value
Definition: login.c:383
heap_pointer
GENERIC heap_pointer
used to allocate from heap - size allocated subtracted - adj for alignment
Definition: def_glob.h:55
bk_mark_quote_tree
void bk_mark_quote_tree(ptr_node t)
bk_mark_quote_tree
Definition: copy.c:728
GENERIC
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
bk_mark_quote
void bk_mark_quote(ptr_psi_term t)
bk_mark_quote
Definition: copy.c:708
RMASK
#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
wl_psi_term::coref
ptr_psi_term coref
Definition: def_struct.h:188
wl_psi_term::status
long status
Definition: def_struct.h:182
wl_psi_term::flags
long flags
Definition: def_struct.h:185
QUOTED_TRUE
#define QUOTED_TRUE
True flags for the flags field of psi-terms.
Definition: def_const.h:254
wl_psi_term::attr_list
ptr_node attr_list
Definition: def_struct.h:187
int_ptr
#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) {
731 bk_mark_quote_tree(t->left);
732 bk_mark_quote((ptr_psi_term) (t->data));
733 bk_mark_quote_tree(t->right);
734 }
735 }
bk_mark_quote_tree
void bk_mark_quote_tree(ptr_node t)
bk_mark_quote_tree
Definition: copy.c:728
wl_psi_term
Definition: def_struct.h:177
wl_node::data
GENERIC data
Definition: def_struct.h:201
wl_node::left
ptr_node left
Definition: def_struct.h:199
bk_mark_quote
void bk_mark_quote(ptr_psi_term t)
bk_mark_quote
Definition: copy.c:708
wl_node::right
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 }
hashfree
static long hashfree
Definition: copy.c:19
hashtime
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 {
277 if (heap_pointer-stack_pointer < COPY_THRESHOLD) {
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) {
341 u->value_3=(GENERIC)choice_stack;
342 traceline("current choice point is %x\n",choice_stack);
343 }
344 }
345 }
346 }
347
348 return u;
349 }
stack_pointer
GENERIC stack_pointer
used to allocate from stack - size allocated added - adj for alignment
Definition: def_glob.h:69
COPY_THRESHOLD
#define COPY_THRESHOLD
Copy threshold (1/8 of GC_THRESHOLD is reasonable)
Definition: def_const.h:125
wl_psi_term::resid
ptr_residuation resid
Definition: def_struct.h:189
function_it
#define function_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1408
translate
ptr_psi_term translate(ptr_psi_term a, long **infoptr)
translate
Definition: copy.c:108
HEAP
#define HEAP
Flag to indicate heap allocation.
Definition: def_const.h:324
heap_pointer
GENERIC heap_pointer
used to allocate from heap - size allocated subtracted - adj for alignment
Definition: def_glob.h:55
wl_definition::evaluate_args
char evaluate_args
Definition: def_struct.h:156
cut
ptr_definition cut
symbol in syntax module
Definition: def_glob.h:242
QUOTE_STUB
#define QUOTE_STUB
flag having to do with copying in copy.c
Definition: def_const.h:1328
wl_definition::type_def
def_type type_def
Definition: def_struct.h:153
wl_psi_term
Definition: def_struct.h:177
insert_translation
void insert_translation(ptr_psi_term a, ptr_psi_term b, long info)
insert_translation
Definition: copy.c:67
global_it
#define global_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1422
NULL
#define NULL
Definition: def_const.h:533
NEW
#define NEW(A, TYPE)
Definition: def_macro.h:284
abort_life
long abort_life(int nlflag)
abort_life
Definition: built_ins.c:2259
traceline
void traceline(char *format,...)
traceline
Definition: error.c:186
type_it
#define type_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1415
EVAL_FLAG
#define EVAL_FLAG
flag to copy function in copy.c to indicate kind of copy
Definition: def_const.h:1320
Errorline
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
GENERIC
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
deref_ptr
#define deref_ptr(P)
Definition: def_macro.h:100
TRUE
#define TRUE
Standard boolean.
Definition: def_const.h:268
copy_tree
static ptr_node copy_tree(ptr_node t, long copy_flag, long heap_flag)
ptr_node copy_tree
Definition: copy.c:148
curr_status
static long curr_status
Definition: copy.c:209
FALSE
#define FALSE
Standard boolean.
Definition: def_const.h:275
wl_psi_term::value_3
GENERIC value_3
Definition: def_struct.h:186
mark_quote_c
void mark_quote_c(ptr_psi_term t, long heap_flag)
mark_quote_c
Definition: copy.c:434
wl_psi_term::status
long status
Definition: def_struct.h:182
wl_psi_term::flags
long flags
Definition: def_struct.h:185
env
jmp_buf env
Definition: def_glob.h:877
global_time_stamp
unsigned long global_time_stamp
Definition: login.c:28
HEAPDONE
#define HEAPDONE(R)
Definition: def_macro.h:296
QUOTE_FLAG
#define QUOTE_FLAG
flag to copy function in copy.c to indicate kind of copy
Definition: def_const.h:1313
wl_psi_term::type
ptr_definition type
Definition: def_struct.h:181
wl_definition::properties
ptr_triple_list properties
Definition: def_struct.h:149
QUOTED_TRUE
#define QUOTED_TRUE
True flags for the flags field of psi-terms.
Definition: def_const.h:254
wl_psi_term::attr_list
ptr_node attr_list
Definition: def_struct.h:187
choice_stack
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 }
wl_psi_term
Definition: def_struct.h:177
ptr_psi_term
struct wl_psi_term * ptr_psi_term
quotedStackCopy
Definition: def_struct.h:62
wl_node::data
GENERIC data
Definition: def_struct.h:201
NULL
#define NULL
Definition: def_const.h:533
NEW
#define NEW(A, TYPE)
Definition: def_macro.h:284
wl_node::left
ptr_node left
Definition: def_struct.h:199
GENERIC
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
wl_node::key
char * key
Definition: def_struct.h:198
copy
ptr_psi_term copy(ptr_psi_term t, long copy_flag, long heap_flag)
copy
Definition: copy.c:248
copy_tree
static ptr_node copy_tree(ptr_node t, long copy_flag, long heap_flag)
ptr_node copy_tree
Definition: copy.c:148
HEAPDONE
#define HEAPDONE(R)
Definition: def_macro.h:296
wl_node
Definition: def_struct.h:197
wl_node::right
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); */
403 res->attr_list=distinct_tree(t->attr_list);
404
405 return res;
406 }
wl_psi_term
Definition: def_struct.h:177
distinct_tree
ptr_node distinct_tree(ptr_node t)
distinct_tree
Definition: copy.c:366
STACK_ALLOC
#define STACK_ALLOC(A)
Definition: def_macro.h:21
global_time_stamp
unsigned long global_time_stamp
Definition: login.c:28
wl_psi_term::attr_list
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 }
wl_node::data
GENERIC data
Definition: def_struct.h:201
NULL
#define NULL
Definition: def_const.h:533
distinct_tree
ptr_node distinct_tree(ptr_node t)
distinct_tree
Definition: copy.c:366
wl_node::left
ptr_node left
Definition: def_struct.h:199
wl_node::key
char * key
Definition: def_struct.h:198
STACK_ALLOC
#define STACK_ALLOC(A)
Definition: def_macro.h:21
wl_node
Definition: def_struct.h:197
wl_node::right
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)); }
EVAL_FLAG
#define EVAL_FLAG
flag to copy function in copy.c to indicate kind of copy
Definition: def_const.h:1320
copy
ptr_psi_term copy(ptr_psi_term t, long copy_flag, long heap_flag)
copy
Definition: copy.c:248
to_heap
long to_heap
Definition: def_glob.h:905
FALSE
#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)); }
EXACT_FLAG
#define EXACT_FLAG
flag to copy function in copy.c to indicate kind of copy
Definition: def_const.h:1306
copy
ptr_psi_term copy(ptr_psi_term t, long copy_flag, long heap_flag)
copy
Definition: copy.c:248
to_heap
long to_heap
Definition: def_glob.h:905
FALSE
#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)); }
EXACT_FLAG
#define EXACT_FLAG
flag to copy function in copy.c to indicate kind of copy
Definition: def_const.h:1306
TRUE
#define TRUE
Standard boolean.
Definition: def_const.h:268
copy
ptr_psi_term copy(ptr_psi_term t, long copy_flag, long heap_flag)
copy
Definition: copy.c:248
to_heap
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;
40 numbuckets = NUMBUCKETS;
41 hashbuckets = (struct hashbucket *)
42 malloc(NUMBUCKETS * sizeof(struct hashbucket));
43 }
hashtable
static struct hashentry hashtable[HASHSIZE]
Definition: copy.c:16
NUMBUCKETS
#define NUMBUCKETS
Total number of buckets in initial hash table;.
Definition: def_const.h:1292
numbuckets
static long numbuckets
Definition: copy.c:20
hashtime
static long hashtime
Definition: copy.c:18
hashbuckets
static struct hashbucket * hashbuckets
Definition: copy.c:17
hashbucket
Definition: def_struct.h:384
HASHSIZE
#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 }
89 hashtable[index].bucketindex = hashfree;
90 hashbuckets[hashfree].old_value = a;
91 hashbuckets[hashfree].new_value = b;
92 hashbuckets[hashfree].info = info;
93 hashbuckets[hashfree].next = lastbucket;
94 hashfree++;
95 }
hashtable
static struct hashentry hashtable[HASHSIZE]
Definition: copy.c:16
hashfree
static long hashfree
Definition: copy.c:19
numbuckets
static long numbuckets
Definition: copy.c:20
HASHEND
#define HASHEND
Tail of hash bucket.
Definition: def_const.h:1299
hashbucket::old_value
ptr_psi_term old_value
Definition: def_struct.h:385
hashtime
static long hashtime
Definition: copy.c:18
traceline
void traceline(char *format,...)
traceline
Definition: error.c:186
hashbucket::new_value
ptr_psi_term new_value
Definition: def_struct.h:386
hashbucket::next
long next
Definition: def_struct.h:388
hashentry::timestamp
long timestamp
Definition: def_struct.h:392
hashbuckets
static struct hashbucket * hashbuckets
Definition: copy.c:17
hashentry::bucketindex
long bucketindex
Definition: def_struct.h:393
hashbucket::info
long info
Definition: def_struct.h:387
HASH
#define HASH(A)
Definition: def_macro.h:278
hashbucket
Definition: def_struct.h:384

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();
501 mark_nonstrict_flag=FALSE;
502 mark_eval_new(t);
503 }
mark_eval_new
void mark_eval_new(ptr_psi_term t)
mark_eval_new
Definition: copy.c:540
clear_copy
void clear_copy()
clear_copy
Definition: copy.c:53
FALSE
#define FALSE
Standard boolean.
Definition: def_const.h:275
mark_nonstrict_flag
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 {
563 insert_translation(t,(ptr_psi_term)TRUE,flag);
564 old_status=curr_status;
565 curr_status=4;
566
567 if (flag) /* 16.9 */
568 mark_eval_tree_new(t->attr_list);
569 else
570 mark_quote_tree_new(t->attr_list);
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 }
function_it
#define function_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1408
translate
ptr_psi_term translate(ptr_psi_term a, long **infoptr)
translate
Definition: copy.c:108
wl_definition::evaluate_args
char evaluate_args
Definition: def_struct.h:156
wl_definition::type_def
def_type type_def
Definition: def_struct.h:153
wl_psi_term
Definition: def_struct.h:177
insert_translation
void insert_translation(ptr_psi_term a, ptr_psi_term b, long info)
insert_translation
Definition: copy.c:67
global_it
#define global_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1422
mark_eval_tree_new
void mark_eval_tree_new(ptr_node n)
mark_eval_tree_new
Definition: copy.c:611
type_it
#define type_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1415
deref_ptr
#define deref_ptr(P)
Definition: def_macro.h:100
TRUE
#define TRUE
Standard boolean.
Definition: def_const.h:268
mark_quote_tree_new
void mark_quote_tree_new(ptr_node n)
mark_quote_tree_new
Definition: copy.c:653
curr_status
static long curr_status
Definition: copy.c:209
FALSE
#define FALSE
Standard boolean.
Definition: def_const.h:275
mark_quote_new
void mark_quote_new(ptr_psi_term t)
mark_quote_new
Definition: copy.c:626
wl_psi_term::status
long status
Definition: def_struct.h:182
wl_psi_term::flags
long flags
Definition: def_struct.h:185
mark_nonstrict_flag
static long mark_nonstrict_flag
Definition: copy.c:479
wl_psi_term::type
ptr_definition type
Definition: def_struct.h:181
wl_definition::properties
ptr_triple_list properties
Definition: def_struct.h:149
QUOTED_TRUE
#define QUOTED_TRUE
True flags for the flags field of psi-terms.
Definition: def_const.h:254
wl_psi_term::attr_list
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) {
614 mark_eval_tree_new(n->left);
615 mark_eval_new((ptr_psi_term) (n->data));
616 mark_eval_tree_new(n->right);
617 }
618 }
mark_eval_new
void mark_eval_new(ptr_psi_term t)
mark_eval_new
Definition: copy.c:540
wl_psi_term
Definition: def_struct.h:177
wl_node::data
GENERIC data
Definition: def_struct.h:201
mark_eval_tree_new
void mark_eval_tree_new(ptr_node n)
mark_eval_tree_new
Definition: copy.c:611
wl_node::left
ptr_node left
Definition: def_struct.h:199
wl_node::right
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();
516 mark_nonstrict_flag=TRUE;
517 mark_eval_new(t);
518 }
mark_eval_new
void mark_eval_new(ptr_psi_term t)
mark_eval_new
Definition: copy.c:540
clear_copy
void clear_copy()
clear_copy
Definition: copy.c:53
TRUE
#define TRUE
Standard boolean.
Definition: def_const.h:268
mark_nonstrict_flag
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);
681 mark_quote_tree(t->attr_list);
682 t->status &= ~RMASK;
683 }
684 }
RMASK
#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
wl_psi_term::coref
ptr_psi_term coref
Definition: def_struct.h:188
mark_quote
void mark_quote(ptr_psi_term t)
mark_quote
Definition: copy.c:674
wl_psi_term::status
long status
Definition: def_struct.h:182
wl_psi_term::flags
long flags
Definition: def_struct.h:185
QUOTED_TRUE
#define QUOTED_TRUE
True flags for the flags field of psi-terms.
Definition: def_const.h:254
wl_psi_term::attr_list
ptr_node attr_list
Definition: def_struct.h:187
mark_quote_tree
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);
455 insert_translation(t,u,QUOTE_STUB);
456 }
457 }
458 }
translate
ptr_psi_term translate(ptr_psi_term a, long **infoptr)
translate
Definition: copy.c:108
mark_quote_tree_c
void mark_quote_tree_c(ptr_node n, long heap_flag)
mark_quote_tree_c
Definition: copy.c:467
QUOTE_STUB
#define QUOTE_STUB
flag having to do with copying in copy.c
Definition: def_const.h:1328
wl_psi_term
Definition: def_struct.h:177
insert_translation
void insert_translation(ptr_psi_term a, ptr_psi_term b, long info)
insert_translation
Definition: copy.c:67
NEW
#define NEW(A, TYPE)
Definition: def_macro.h:284
EVAL_FLAG
#define EVAL_FLAG
flag to copy function in copy.c to indicate kind of copy
Definition: def_const.h:1320
deref_ptr
#define deref_ptr(P)
Definition: def_macro.h:100
wl_psi_term::status
long status
Definition: def_struct.h:182
wl_psi_term::flags
long flags
Definition: def_struct.h:185
QUOTE_FLAG
#define QUOTE_FLAG
flag to copy function in copy.c to indicate kind of copy
Definition: def_const.h:1313
QUOTED_TRUE
#define QUOTED_TRUE
True flags for the flags field of psi-terms.
Definition: def_const.h:254
wl_psi_term::attr_list
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 */
639 if (!u) insert_translation(t,(ptr_psi_term)TRUE,FALSE);
640 else *infoptr = FALSE; /* sanjay */
641 t->status= 4;
642 t->flags=QUOTED_TRUE; /* 14.9 */
643 mark_quote_tree_new(t->attr_list);
644 }
645 }
translate
ptr_psi_term translate(ptr_psi_term a, long **infoptr)
translate
Definition: copy.c:108
wl_psi_term
Definition: def_struct.h:177
insert_translation
void insert_translation(ptr_psi_term a, ptr_psi_term b, long info)
insert_translation
Definition: copy.c:67
deref_ptr
#define deref_ptr(P)
Definition: def_macro.h:100
TRUE
#define TRUE
Standard boolean.
Definition: def_const.h:268
mark_quote_tree_new
void mark_quote_tree_new(ptr_node n)
mark_quote_tree_new
Definition: copy.c:653
FALSE
#define FALSE
Standard boolean.
Definition: def_const.h:275
wl_psi_term::status
long status
Definition: def_struct.h:182
wl_psi_term::flags
long flags
Definition: def_struct.h:185
QUOTED_TRUE
#define QUOTED_TRUE
True flags for the flags field of psi-terms.
Definition: def_const.h:254
wl_psi_term::attr_list
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();
530 mark_nonstrict_flag=FALSE;
531 mark_quote_new(t);
532 }
clear_copy
void clear_copy()
clear_copy
Definition: copy.c:53
FALSE
#define FALSE
Standard boolean.
Definition: def_const.h:275
mark_quote_new
void mark_quote_new(ptr_psi_term t)
mark_quote_new
Definition: copy.c:626
mark_nonstrict_flag
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));
697 mark_quote_tree(t->right);
698 }
699 }
wl_psi_term
Definition: def_struct.h:177
wl_node::data
GENERIC data
Definition: def_struct.h:201
wl_node::left
ptr_node left
Definition: def_struct.h:199
mark_quote
void mark_quote(ptr_psi_term t)
mark_quote
Definition: copy.c:674
mark_quote_tree
void mark_quote_tree()
wl_node::right
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 }
mark_quote_tree_c
void mark_quote_tree_c(ptr_node n, long heap_flag)
mark_quote_tree_c
Definition: copy.c:467
wl_psi_term
Definition: def_struct.h:177
wl_node::data
GENERIC data
Definition: def_struct.h:201
wl_node::left
ptr_node left
Definition: def_struct.h:199
mark_quote_c
void mark_quote_c(ptr_psi_term t, long heap_flag)
mark_quote_c
Definition: copy.c:434
wl_node::right
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) {
656 mark_quote_tree_new(n->left);
657 mark_quote_new((ptr_psi_term) (n->data));
658 mark_quote_tree_new(n->right);
659 }
660 }
wl_psi_term
Definition: def_struct.h:177
wl_node::data
GENERIC data
Definition: def_struct.h:201
wl_node::left
ptr_node left
Definition: def_struct.h:199
mark_quote_tree_new
void mark_quote_tree_new(ptr_node n)
mark_quote_tree_new
Definition: copy.c:653
mark_quote_new
void mark_quote_new(ptr_psi_term t)
mark_quote_new
Definition: copy.c:626
wl_node::right
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)); }
copy
ptr_psi_term copy(ptr_psi_term t, long copy_flag, long heap_flag)
copy
Definition: copy.c:248
to_heap
long to_heap
Definition: def_glob.h:905
FALSE
#define FALSE
Standard boolean.
Definition: def_const.h:275
QUOTE_FLAG
#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 }
hashtable
static struct hashentry hashtable[HASHSIZE]
Definition: copy.c:16
HASHEND
#define HASHEND
Tail of hash bucket.
Definition: def_const.h:1299
NULL
#define NULL
Definition: def_const.h:533
hashbucket::old_value
ptr_psi_term old_value
Definition: def_struct.h:385
hashtime
static long hashtime
Definition: copy.c:18
hashbucket::new_value
ptr_psi_term new_value
Definition: def_struct.h:386
hashbucket::next
long next
Definition: def_struct.h:388
hashbuckets
static struct hashbucket * hashbuckets
Definition: copy.c:17
hashentry::bucketindex
long bucketindex
Definition: def_struct.h:393
hashbucket::info
long info
Definition: def_struct.h:387
HASH
#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.