lefun More...
Go to the source code of this file.
Variables | |
static long | attr_missing |
static long | check_func_flag |
static long | deref_flag |
lefun
Definition in file lefun.c.
void append_resid | ( | ptr_psi_term | u, |
ptr_psi_term | v | ||
) |
append_resid
u | - ptr_psi_term u |
v | - ptr_psi_term v |
APPEND_RESID(u,v) Append the residuations pending on V to U. This routine does not check that the same constraint is not present twice in the end on U. This doesn't matter since RELEASE_RESID ensures that the same constraint is not released more than once.
Definition at line 474 of file lefun.c.
References push_ptr_value(), wl_psi_term::resid, and resid_ptr.
void check_disj | ( | ptr_psi_term | t | ) |
check_disj
t | - ptr_psi_term t |
CHECK_DISJ(t) Deal with disjunctions.
Definition at line 910 of file lefun.c.
References disj, fail, NULL, push_goal(), traceline(), TRUE, and wl_psi_term::value_3.
void check_func | ( | ptr_psi_term | t | ) |
check_func
t | - ptr_psi_term t |
CHECK_FUNC(t) Deal with an unevaluated function: push an 'eval' goal for it, which will cause it to be evaluated.
Definition at line 928 of file lefun.c.
References wl_psi_term::attr_list, check_func_flag, check_out(), copy(), wl_psi_term::coref, disjunction, eval, eval_args(), wl_definition::evaluate_args, get_one_arg(), iff, push_goal(), push_psi_ptr_value(), RMASK, wl_definition::rule, stack_copy_psi_term(), stack_psi_term(), wl_psi_term::status, such_that, traceline(), TRUE, and wl_psi_term::type.
long check_out | ( | ptr_psi_term | t | ) |
Definition at line 1083 of file lefun.c.
References wl_psi_term::attr_list, check_func(), check_func_flag, check_type(), deref_ptr, eval_args(), eval_global_var(), FALSE, function_it, global_it, heap_pointer, RMASK, wl_psi_term::status, traceline(), TRUE, wl_psi_term::type, wl_definition::type_def, and type_it.
long check_type | ( | ptr_psi_term | t | ) |
check_type
t | - ptr_psi_term t |
CHECK_TYPE(t) Here we deal with a type which may need checking. This routine will have to be modified to deal with the infinite loops currently caused by definitions such as:
:: H:husband(spouse => wife(spouse => H)). :: W:wife(spouse => husband(spouse => W)).
Definition at line 990 of file lefun.c.
References wl_definition::always_check, wl_psi_term::attr_list, eval_args(), FALSE, fetch_def(), int_ptr, wl_definition::properties, push2_ptr_value(), RMASK, SMASK, wl_psi_term::status, TRUE, and wl_psi_term::type.
void curry | ( | ) |
void deref2_eval | ( | ptr_psi_term | t | ) |
deref2_eval
t | - ptr_psi_term t |
Definition at line 1356 of file lefun.c.
References check_func(), deref_ptr, eval_global_var(), function_it, global_it, wl_psi_term::status, wl_psi_term::type, and wl_definition::type_def.
void deref2_rec_eval | ( | ptr_psi_term | t | ) |
deref2_rec_eval
t | - ptr_psi_term t |
Same as deref_rec_eval, but assumes goal_stack already restored.
Definition at line 1382 of file lefun.c.
References deref_ptr, and deref_rec_body().
long deref_args_eval | ( | ptr_psi_term | t, |
long | set | ||
) |
deref_args_eval
t | - ptr_psi_term t |
set | - long set |
Same as deref_rec_eval, but doesn't look at either the top level or the arguments in the set.
Definition at line 1294 of file lefun.c.
References aim, wl_psi_term::attr_list, deref_flag, deref_rec_args_exc(), FALSE, and goal_stack.
long deref_eval | ( | ptr_psi_term | t | ) |
deref_eval
t | - ptr_psi_term t |
deref_eval(P) If the psi-term P is a function, call check_func to push eval goals so that the function will be evaluated. Then return TRUE so that the caller can itself return. This only looks at the top level.
Definition at line 1180 of file lefun.c.
References aim, check_func(), deref_flag, deref_ptr, eval_global_var(), FALSE, function_it, global_it, goal_stack, heap_pointer, int_ptr, push_ptr_value(), wl_psi_term::status, TRUE, wl_psi_term::type, and wl_definition::type_def.
void deref_rec_args | ( | ptr_node | n | ) |
deref_rec_args
n | - ptr_node n |
Definition at line 1272 of file lefun.c.
References wl_node::data, deref_ptr, deref_rec_body(), wl_node::left, and wl_node::right.
void deref_rec_args_exc | ( | ptr_node | n, |
long | set | ||
) |
deref_rec_args_exc
n | - ptr_node n |
set | - long set |
Definition at line 1332 of file lefun.c.
References wl_node::data, deref_ptr, deref_rec_body(), in_set(), wl_node::key, wl_node::left, and wl_node::right.
void deref_rec_body | ( | ptr_psi_term | t | ) |
deref_rec_body
t | - ptr_psi_term t |
Definition at line 1243 of file lefun.c.
References wl_psi_term::attr_list, check_func(), deref_flag, deref_ptr, deref_rec_args(), eval_global_var(), function_it, global_it, heap_pointer, int_ptr, push_ptr_value(), wl_psi_term::status, TRUE, wl_psi_term::type, and wl_definition::type_def.
long deref_rec_eval | ( | ptr_psi_term | t | ) |
deref_rec_eval
t | - ptr_psi_term t |
deref_rec(P) If the psi-term P recursively contains any functions, then push eval goals to evaluate all of them. Set a global variable deref_flag if this is the case.
Definition at line 1226 of file lefun.c.
References aim, deref_flag, deref_rec_body(), FALSE, and goal_stack.
void do_currying | ( | ) |
do_currying
This performs CURRYing: all that needs to be done is to yield the calling term as the result after having given up on evaluation. In effect the calling psi-term is left intact.
Definition at line 383 of file lefun.c.
References wl_goal::aaaa_1, wl_goal::bbbb_1, goal_stack, wl_goal::next, NULL, push_goal(), resid_aim, traceline(), and unify_noeval.
long do_residuation | ( | ) |
do_residuation
C-defined routines do all stack manipulation themselves
Definition at line 336 of file lefun.c.
References wl_goal::aaaa_1, deref_ptr, FALSE, wl_resid_list::next, wl_resid_list::othervar, print_resid_message(), resid_aim, resid_vars, residuateGoalOnVar(), trace, traceline(), tracing(), TRUE, and wl_resid_list::var.
long do_residuation_user | ( | ) |
Undo anything that matching may have done, then create a residuated expression. Check that the same constraint does not hang several times on the same variable.
This routine takes time proportional to the square of the number of residuations. This is too slow; eventually it should be sped up, especially if equality constraints are often used.
Definition at line 324 of file lefun.c.
References do_residuation(), goal_stack, wl_goal::next, and resid_aim.
long eval_aim | ( | ) |
eval_aim
EVAL_AIM() Evaluate a function. This copies the current definition of the function and stacking the various goals that are necessary to evaluate the function correctly. It creates an extra psi-term (with value top) in which to write the result.
Definition at line 497 of file lefun.c.
References wl_goal::aaaa_1, wl_pair_list::aaaa_2, aim, wl_goal::bbbb_1, wl_pair_list::bbbb_2, c_rule, can_curry, wl_goal::cccc_1, choice_stack, clear_copy(), curried, deref_ptr, do_currying(), do_residuation(), eval, eval_copy(), eval_cut, FALSE, int_ptr, match, MAX_BUILT_INS, wl_pair_list::next, NULL, push2_ptr_value(), push_choice_point(), push_goal(), quote_copy(), resid_aim, resid_vars, save_resid(), SMASK, STACK, STACK_ALLOC, stack_pointer, wl_psi_term::status, traceline(), TRUE, and unify.
long eval_args | ( | ptr_node | n | ) |
eval_args
n | - ptr_node n |
EVAL_ARGS(n) N is an attribute tree, the attributes must be examined, if any reveal themselves to need evaluating then return FALSE.
Definition at line 889 of file lefun.c.
References check_out(), wl_node::data, wl_node::left, wl_node::right, and TRUE.
void eval_global_var | ( | ptr_psi_term | t | ) |
eval_global_var
t | - ptr_psi_term t |
EVAL_GLOBAL_VAR(t) Dereference a global variable.
Definition at line 1440 of file lefun.c.
References wl_stack::aaaa_3, wl_stack::bbbb_3, clear_copy(), wl_psi_term::coref, deref_ptr, eval_copy(), global_it, wl_definition::global_value, wl_definition::init_value, wl_stack::next, NULL, psi_term_ptr, push_psi_ptr_value(), STACK, STACK_ALLOC, traceline(), wl_psi_term::type, wl_stack::type, wl_definition::type_def, and undo_stack.
long f_check_out | ( | ptr_psi_term | t | ) |
f_check_out
t | - ptr_psi_term t |
Definition at line 1046 of file lefun.c.
References check_func_flag, check_out(), and TRUE.
ptr_psi_term heap_psi_term | ( | long | stat | ) |
heap_psi_term
stat | - long stat |
Create a new psi_term on the heap with value '@' (top) and no attributes.
Definition at line 75 of file lefun.c.
References wl_psi_term::attr_list, wl_psi_term::coref, FALSE, wl_psi_term::flags, global_time_stamp, HEAP_ALLOC, NULL, QUOTED_TRUE, wl_psi_term::resid, wl_psi_term::status, top, wl_psi_term::type, and wl_psi_term::value_3.
long i_check_out | ( | ptr_psi_term | t | ) |
i_check_out
t | - ptr_psi_term t |
Definition at line 1033 of file lefun.c.
References check_func_flag, check_out(), and FALSE.
long i_eval_args | ( | ptr_node | n | ) |
i_eval_args
n | - ptr_node n |
I_EVAL_ARGS(n) N is an attribute tree, the attributes must be examined, if any reveal themselves to need evaluating then return FALSE.
Definition at line 874 of file lefun.c.
References check_func_flag, eval_args(), and FALSE.
long in_set | ( | char * | str, |
long | set | ||
) |
void init_global_vars | ( | ) |
init_global_vars
INIT_GLOBAL_VARS() Initialize all non-persistent global variables.
Definition at line 1484 of file lefun.c.
References first_definition, wl_definition::global_value, heap_pointer, wl_definition::next, and NULL.
long match_aim | ( | ) |
match_aim
long match_aim() MATCH_AIM() This is very similar to UNIFY_AIM, only matching cannot modify the calling psi_term. The first argument is the calling term (which may not be changed) and the second argument is the function definition (which may be changed). Residuate the expression if the calling term is more general than the function definition.
Definition at line 770 of file lefun.c.
References wl_goal::aaaa_1, aim, wl_psi_term::attr_list, attr_missing, wl_goal::bbbb_1, can_curry, wl_goal::cccc_1, wl_psi_term::coref, curried, cut, deref_ptr, FALSE, FUNC_ARG, integer, match_attr(), matches(), NULL, overlap_type(), quoted_string, REAL, real, resid_aim, residuate_double(), restore_resid(), save_resid(), sys_bytedata, TRUE, wl_psi_term::type, and wl_psi_term::value_3.
void match_attr | ( | ptr_node * | u, |
ptr_node | v, | ||
ptr_resid_block | rb | ||
) |
match_attr
u | - ptr_node *u |
v | - ptr_node v |
rb | - ptr_resid_block rb |
MATCH_ATTR(u,v) Match the attribute trees of psi_terms U and V. If V has an attribute that U doesn't then curry. U is the calling term, V is the definition. This routine is careful to push nested eval and match goals in descending order of feature names.
Definition at line 752 of file lefun.c.
References match_attr1(), match_attr2(), and match_attr3().
void match_attr1 | ( | ptr_node * | u, |
ptr_node | v, | ||
ptr_resid_block | rb | ||
) |
void match_attr1
u | - ptr_node *u |
v | - ptr_node v |
rb | - ptr_resid_block rb |
Match the corresponding arguments
Definition at line 599 of file lefun.c.
References attr_missing, wl_node::data, featcmp(), wl_node::key, wl_node::left, match, NULL, push_goal(), wl_node::right, and TRUE.
void match_attr2 | ( | ptr_node * | u, |
ptr_node | v, | ||
ptr_resid_block | rb | ||
) |
match_attr2
u | - ptr_node *u |
v | - ptr_node v |
rb | - ptr_resid_block rb |
Evaluate the lone arguments (for lazy failure + eager success)
Definition at line 644 of file lefun.c.
References wl_node::data, deref2_rec_eval(), featcmp(), wl_node::key, wl_node::left, match_attr1(), NULL, and wl_node::right.
void match_attr3 | ( | ptr_node * | u, |
ptr_node | v, | ||
ptr_resid_block | rb | ||
) |
match_attr3
u | - ptr_node *u |
v | - ptr_node v |
rb | - ptr_resid_block rb |
Evaluate the corresponding arguments
Definition at line 700 of file lefun.c.
References attr_missing, wl_node::data, deref2_eval(), featcmp(), wl_node::key, wl_node::left, NULL, wl_node::right, and TRUE.
ptr_psi_term real_stack_psi_term | ( | long | stat, |
REAL | thereal | ||
) |
real_stack_psi_term
stat | - long stat |
thereal | - REAL thereal |
Create a new psi_term on the stack with a real number value.
Definition at line 48 of file lefun.c.
References wl_psi_term::attr_list, wl_psi_term::coref, FALSE, wl_psi_term::flags, global_time_stamp, heap_alloc(), integer, NULL, QUOTED_TRUE, REAL, real, wl_psi_term::resid, STACK_ALLOC, wl_psi_term::status, wl_psi_term::type, and wl_psi_term::value_3.
void release_resid | ( | ptr_psi_term | t | ) |
release_resid
t | - ptr_psi_term t |
Definition at line 445 of file lefun.c.
References release_resid_main(), and TRUE.
void release_resid_main | ( | ptr_psi_term | t, |
long | trailflag | ||
) |
release_resid_main
t | - ptr_psi_term t |
trailflag | - long trailflag |
Release the residuations pending on the Residuation Variable T. This is done by simply pushing the residuated goals onto the goal-stack. A goal is not added if already present on the stack. Two versions of this routine exist: one which trails t and one which never trails t.
Definition at line 411 of file lefun.c.
References wl_goal::aaaa_1, FALSE, wl_residuation::goal, goal_ptr, goal_stack, int_ptr, wl_residuation::next, wl_goal::next, NULL, wl_goal::pending, push_ptr_value(), wl_psi_term::resid, resid_ptr, and traceline().
void release_resid_notrail | ( | ptr_psi_term | t | ) |
release_resid_notrail
t | - ptr_psi_term t |
Definition at line 456 of file lefun.c.
References FALSE, and release_resid_main().
void residuate | ( | ptr_psi_term | t | ) |
residuate
t | - ptr_psi_term t |
Residuate the current expression with T in the Residuation Variable set.
Definition at line 125 of file lefun.c.
References wl_resid_list::next, NULL, wl_resid_list::othervar, resid_vars, STACK_ALLOC, and wl_resid_list::var.
void residuate2 | ( | ptr_psi_term | u, |
ptr_psi_term | v | ||
) |
residuate2
u | - ptr_psi_term u |
v | - ptr_psi_term v |
Residuate the current function on the two variables U and V.
Definition at line 144 of file lefun.c.
References residuate().
void residuate3 | ( | ptr_psi_term | u, |
ptr_psi_term | v, | ||
ptr_psi_term | w | ||
) |
residuate3
u | - ptr_psi_term u |
v | - ptr_psi_term v |
w | - ptr_psi_term w |
Residuate the current function on the three variables U, V, and W.
Definition at line 159 of file lefun.c.
References residuate().
void residuate_double | ( | ptr_psi_term | t, |
ptr_psi_term | u | ||
) |
residuate_double
t | - ptr_psi_term t |
u | - ptr_psi_term u |
Residuate the current expression with T in the Residuation Variable set. Also store the other variable, so that its sort can be used in the 'bestsort' calculation needed to implement disequality constraints.
Definition at line 107 of file lefun.c.
References wl_resid_list::next, wl_resid_list::othervar, resid_vars, STACK_ALLOC, and wl_resid_list::var.
long residuateGoalOnVar | ( | ptr_goal | g, |
ptr_psi_term | var, | ||
ptr_psi_term | othervar | ||
) |
residuateGoalOnVar
g | - ptr_goal g |
var | - ptr_psi_term var |
othervar | - ptr_psi_term othervar |
Add the goal to the variable's residuation list. Also update the residuation's 'bestsort' field if it exists (needed to implement complete disequality semantics). The 'othervar' parameter is needed for this.
Definition at line 192 of file lefun.c.
References code_ptr, def_ptr, Errorline(), FALSE, glb_code(), glb_value(), heap_pointer, int_ptr, wl_goal::next, NULL, wl_goal::pending, push_ptr_value(), wl_psi_term::resid, resid_ptr, STACK_ALLOC, TRUE, wl_psi_term::type, and wl_psi_term::value_3.
void restore_resid | ( | ptr_resid_block | rb, |
ptr_psi_term * | match_date | ||
) |
restore_resid
rb | - ptr_resid_block rb |
match_date | - ptr_psi_term *match_date |
Definition at line 1417 of file lefun.c.
References can_curry, wl_resid_block::cc_cr, curried, FALSE, wl_resid_block::md, wl_resid_block::ra, resid_aim, resid_vars, wl_resid_block::rv, and TRUE.
void save_resid | ( | ptr_resid_block | rb, |
ptr_psi_term | match_date | ||
) |
save_resid
rb | - ptr_resid_block rb |
match_date | - ptr_psi_term match_date |
Saving & restoring residuation information
Definition at line 1398 of file lefun.c.
References can_curry, wl_resid_block::cc_cr, curried, wl_resid_block::md, wl_resid_block::ra, resid_aim, resid_vars, and wl_resid_block::rv.
ptr_psi_term stack_psi_term | ( | long | stat | ) |
stack_psi_term
Create a new psi_term on the stack with value '@' (top) and no attributes.
Definition at line 21 of file lefun.c.
References wl_psi_term::attr_list, wl_psi_term::coref, FALSE, wl_psi_term::flags, global_time_stamp, NULL, QUOTED_TRUE, wl_psi_term::resid, STACK_ALLOC, wl_psi_term::status, top, wl_psi_term::type, and wl_psi_term::value_3.