New translation routines for Wild_Life. More...
Go to the source code of this file.
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 |
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.
void bk_mark_quote | ( | ptr_psi_term | t | ) |
bk_mark_quote
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.
void bk_mark_quote_tree | ( | ptr_node | t | ) |
bk_mark_quote_tree
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.
void clear_copy | ( | ) |
ptr_psi_term copy | ( | ptr_psi_term | t, |
long | copy_flag, | ||
long | heap_flag | ||
) |
copy
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.
ptr_node copy_tree
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.
ptr_psi_term distinct_copy | ( | ptr_psi_term | t | ) |
distinct_copy
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.
distinct_tree
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.
ptr_psi_term eval_copy | ( | ptr_psi_term | t, |
long | heap_flag | ||
) |
ptr_psi_term exact_copy | ( | ptr_psi_term | t, |
long | heap_flag | ||
) |
exact_copy
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.
ptr_psi_term inc_heap_copy | ( | ptr_psi_term | t | ) |
inc_heap_copy
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.
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.
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().
void mark_eval | ( | ptr_psi_term | t | ) |
mark_eval
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.
void mark_eval_new | ( | ptr_psi_term | t | ) |
mark_eval_new
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.
void mark_eval_tree_new | ( | ptr_node | n | ) |
mark_eval_tree_new
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.
void mark_nonstrict | ( | ptr_psi_term | t | ) |
mark_nonstrict
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.
void mark_quote | ( | ptr_psi_term | t | ) |
mark_quote
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.
void mark_quote_c | ( | ptr_psi_term | t, |
long | heap_flag | ||
) |
mark_quote_c
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().
void mark_quote_new | ( | ptr_psi_term | t | ) |
mark_quote_new
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.
void mark_quote_new2 | ( | ptr_psi_term | t | ) |
mark_quote_new2
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().
void mark_quote_tree | ( | ) |
void mark_quote_tree | ( | ptr_node | t | ) |
mark_quote_tree
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.
void mark_quote_tree_c | ( | ptr_node | n, |
long | heap_flag | ||
) |
mark_quote_tree_c
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.
void mark_quote_tree_new | ( | ptr_node | n | ) |
mark_quote_tree_new
void mark_quote_tree_new(ptr_node n)
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.
ptr_psi_term quote_copy | ( | ptr_psi_term | t, |
long | heap_flag | ||
) |
quote_copy
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.
ptr_psi_term translate | ( | ptr_psi_term | a, |
long ** | infoptr | ||
) |
translate
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.
|
static |