Wild Life  2.30
 All Data Structures Files Functions Variables Typedefs Macros
Macros | Functions | Variables
login.c File Reference

login More...

Go to the source code of this file.

Macros

#define CLEAN_TRAIL
 
#define TRAIL_TS
 
#define TRAIL_TS
 
#define RESTORE_TIME_STAMP
 

Functions

void get_two_args (ptr_node t, ptr_psi_term *a, ptr_psi_term *b)
 get_two_args More...
 
void get_one_arg (ptr_node t, ptr_psi_term *a)
 get_one_arg More...
 
void get_one_arg_addr (ptr_node t, ptr_psi_term **a)
 get_one_arg_addr More...
 
void add_rule (ptr_psi_term head, ptr_psi_term body, def_type typ)
 add_rule More...
 
void assert_rule (psi_term t, def_type typ)
 assert_rule More...
 
void assert_clause (ptr_psi_term t)
 assert_clause More...
 
void start_chrono ()
 start_chrono More...
 
void push_ptr_value (type_ptr t, GENERIC *p)
 push_ptr_value More...
 
void push_def_ptr_value (ptr_psi_term q, GENERIC *p)
 push_def_ptr_value More...
 
void push_psi_ptr_value (ptr_psi_term q, GENERIC *p)
 push_psi_ptr_value More...
 
void push_ptr_value_global (type_ptr t, GENERIC *p)
 push_ptr_value_global More...
 
void push_window (long type, long disp, long wind)
 push_window More...
 
void push2_ptr_value (type_ptr t, GENERIC *p, GENERIC v)
 push2_ptr_value More...
 
void push_goal (goals t, ptr_psi_term aaaa_5, ptr_psi_term bbbb_5, GENERIC cccc_5)
 push_goal More...
 
void push_choice_point (goals t, ptr_psi_term aaaa_6, ptr_psi_term bbbb_6, GENERIC cccc_6)
 push_choice_point More...
 
void undo (ptr_stack limit)
 undo More...
 
void undo_actions ()
 undo_actions More...
 
void backtrack ()
 backtrack More...
 
static void clean_trail (ptr_choice_point cutpt)
 clean_trail More...
 
void clean_undo_window (long disp, long wind)
 clean_undo_window More...
 
void merge1 (ptr_node *u, ptr_node v)
 merge1 More...
 
void merge2 (ptr_node *u, ptr_node v)
 merge2 More...
 
void merge3 (ptr_node *u, ptr_node v)
 merge3 More...
 
void merge (ptr_node *u, ptr_node v)
 merge More...
 
void merge_unify (ptr_node *u, ptr_node v)
 merge_unify More...
 
void show_count ()
 show_count More...
 
void fetch_def (ptr_psi_term u, long allflag)
 fetch_def More...
 
void fetch_def_lazy (ptr_psi_term u, ptr_definition old1, ptr_definition old2, ptr_node old1attr, ptr_node old2attr, long old1stat, long old2stat)
 fetch_def_lazy More...
 
long unify_aim ()
 unify_aim More...
 
long unify_aim_noeval ()
 unify_aim_noeval More...
 
long unify_body (long eval_flag)
 unify_body More...
 
long disjunct_aim ()
 disjunct_aim More...
 
long prove_aim ()
 prove_aim More...
 
void type_disj_aim ()
 type_disj_aim More...
 
long clause_aim (long r)
 clause_aim More...
 
long no_choices ()
 no_choices More...
 
long num_choices ()
 num_choices More...
 
long num_vars (ptr_node vt)
 num_vars More...
 
long what_next_cut ()
 what_next_cut More...
 
ptr_choice_point topmost_what_next ()
 topmost_what_next More...
 
void reset_stacks ()
 reset_stacks More...
 
long what_next_aim ()
 what_next_aim More...
 
long load_aim ()
 load_aim More...
 
void main_prove ()
 main_prove More...
 
int dummy_printf (char *f, char *s, char *t)
 dummy_printf More...
 
long trail_condition (psi_term *Q)
 trail_condition More...
 

Variables

long clean_iter = 0
 
long clean_succ = 0
 
unsigned long global_time_stamp =INIT_TIME_STAMP
 

Detailed Description

login

What follows are the functions which assert facts in their correct places: function definitions, rule definitions or type definitions.

Definition in file login.c.

Macro Definition Documentation

#define CLEAN_TRAIL

Definition at line 19 of file login.c.

#define RESTORE_TIME_STAMP
Value:
unsigned long time_stamp
Definition: def_struct.h:247
unsigned long global_time_stamp
Definition: login.c:28
#define INIT_TIME_STAMP
Definition: def_const.h:375
ptr_choice_point choice_stack
Definition: def_glob.h:1026

Definition at line 670 of file login.c.

#define TRAIL_TS
#define TRAIL_TS

Function Documentation

void add_rule ( ptr_psi_term  head,
ptr_psi_term  body,
def_type  typ 
)

add_rule

Parameters
head- ptr_psi_term head
body- ptr_psi_term body
typ- def_type typ

ADD_RULE(head,body,typ) The TYP argument is either 'predicate', 'function', or 'type'. For predicates or functions, insert the clause 'HEAD :- BODY' or the rule 'HEAD -> BODY' into the definition of HEAD. For types, insert HEAD as a term of type attributes and BODY as a type constraint. The global flag ASSERT_FIRST indicates whether to do the insertion at the head or the tail of the existing list.

Definition at line 167 of file login.c.

References wl_pair_list::aaaa_2, assert_first, assert_ok, wl_psi_term::attr_list, wl_pair_list::bbbb_2, clear_copy(), wl_keyword::combined_name, wl_psi_term::coref, current_module, deref_ptr, Errorline(), HEAP, HEAP_ALLOC, wl_definition::keyword, MAX_BUILT_INS, wl_module::module_name, wl_pair_list::next, NULL, predicate_it, quote_copy(), redefine(), wl_psi_term::resid, wl_definition::rule, succeed, wl_keyword::symbol, TRUE, wl_psi_term::type, wl_definition::type_def, undef_it, and wl_psi_term::value_3.

168 {
169  psi_term succ;
170  ptr_psi_term head2;
171  ptr_definition def;
172  ptr_pair_list p, *p2;
173 
174  if (!body && typ==(def_type)predicate_it) {
175  succ.type=succeed;
176  succ.value_3=NULL;
177  succ.coref=NULL;
178  succ.resid=NULL;
179  succ.attr_list=NULL;
180  body= ≻
181  }
182 
183  deref_ptr(head);
184  head2=head;
185 
186  /* assert(head->resid==NULL); 10.8 */
187  /* assert(body->resid==NULL); 10.8 */
188 
189  if (redefine(head)) {
190 
191  def=head->type;
192 
193  if (def->type_def==(def_type)undef_it || def->type_def==typ)
194 
195  /* RM: Jan 27 1993 */
196  if(TRUE
197  /* def->type==undef_it ||
198  def->keyword->module==current_module */
199  /* RM: Feb 2 1993 Commented out */
200  ) {
201  if (def->rule && (unsigned long)def->rule<=MAX_BUILT_INS) {
202  Errorline("the built-in %T '%s' may not be redefined.\n",
203  def->type_def, def->keyword->symbol);
204  }
205  else {
206  def->type_def=typ;
207 
208  /* PVR single allocation in source */
210  clear_copy();
211  /* p->aaaa_3=exact_copy(head2,HEAP); 24.8 25.8 */
212  /* p->bbbb_3=exact_copy(body,HEAP); 24.8 25.8 */
213 
214  p->aaaa_2=quote_copy(head2,HEAP); /* 24.8 25.8 */
215  p->bbbb_2=quote_copy(body,HEAP); /* 24.8 25.8 */
216 
217  if (assert_first) {
218  p->next=def->rule;
219  def->rule=p;
220  }
221  else {
222  p->next=NULL;
223  p2= &(def->rule);
224  while (*p2) {
225  p2= &((*p2)->next);
226  }
227  *p2=p;
228  }
229  assert_ok=TRUE;
230  }
231  }
232  else { /* RM: Jan 27 1993 */
233  Errorline("the %T '%s' may not be redefined from within module %s.\n",
234  def->type_def,
235  def->keyword->combined_name,
237  }
238  else {
239  Errorline("the %T '%s' may not be redefined as a %T.\n",
240  def->type_def, def->keyword->symbol, typ);
241  }
242  }
243 }
ptr_psi_term aaaa_2
Definition: def_struct.h:205
ptr_residuation resid
Definition: def_struct.h:189
#define undef_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1394
ptr_definition succeed
symbol in bi module
Definition: def_glob.h:389
#define HEAP
Flag to indicate heap allocation.
Definition: def_const.h:324
long assert_first
Definition: def_glob.h:1032
void clear_copy()
clear_copy
Definition: copy.c:53
char * combined_name
Definition: def_struct.h:119
ptr_module current_module
The current module for the tokenizer.
Definition: def_glob.h:729
ptr_pair_list next
Definition: def_struct.h:207
long redefine(ptr_psi_term t)
redefine
Definition: types.c:104
def_type type_def
Definition: def_struct.h:153
#define predicate_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1401
ptr_keyword keyword
Definition: def_struct.h:147
#define NULL
Definition: def_const.h:533
char * symbol
Definition: def_struct.h:118
long assert_ok
Definition: def_glob.h:1033
ptr_psi_term quote_copy(ptr_psi_term t, long heap_flag)
quote_copy
Definition: copy.c:186
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
#define deref_ptr(P)
Definition: def_macro.h:100
#define TRUE
Standard boolean.
Definition: def_const.h:268
ptr_pair_list rule
Definition: def_struct.h:148
GENERIC value_3
Definition: def_struct.h:186
ptr_psi_term bbbb_2
Definition: def_struct.h:206
char * module_name
Definition: def_struct.h:106
ptr_psi_term coref
Definition: def_struct.h:188
#define MAX_BUILT_INS
Maximum number of built_ins.
Definition: def_const.h:154
ptr_definition type
Definition: def_struct.h:181
#define HEAP_ALLOC(A)
Definition: def_macro.h:20
ptr_node attr_list
Definition: def_struct.h:187
void assert_clause ( ptr_psi_term  t)

assert_clause

Parameters
t- ptr_psi_term t

ASSERT_CLAUSE(t) Assert the clause T. Cope with various syntaxes for predicates.

ASSERT_FIRST is a flag indicating the position: 1= insert before existing rules (asserta), 0= insert after existing rules (assert),

Definition at line 287 of file login.c.

References add_rule(), assert_attributes(), assert_complicated_type(), assert_ok, assert_rule(), deref_ptr, equ_tok, FALSE, function_it, NULL, and predicate_it.

288 {
289  assert_ok=FALSE;
290  deref_ptr(t);
291 
292  /* RM: Feb 22 1993 defined c_alias in modules.c
293  if (equ_tok((*t),"alias")) {
294  get_two_args(t->attr_list,&arg1,&arg2);
295  if (arg1 && arg2) {
296  warningline("'%s' has taken the meaning of '%s'.\n",
297  arg2->type->keyword->symbol, arg1->type->keyword->symbol);
298  str=arg2->type->keyword->symbol;
299  assert_ok=TRUE;
300  deref_ptr(arg1);
301  deref_ptr(arg2);
302  *(arg2->type)= *(arg1->type);
303  arg2->type->keyword->symbol=str;
304  }
305  else
306  Errorline("arguments missing in %P.\n",t);
307  }
308  else
309  */
310 
311  if (equ_tok((*t),":-"))
313  else
314  if (equ_tok((*t),"->"))
316  else
317  if (equ_tok((*t),"::"))
319  else
320 
321 #ifdef CLIFE
322  if (equ_tok((*t),"block_struct"))
323  define_block(t);
324  else
325 #endif /* CLIFE */
326  /* if (equ_tok((*t),"<<<-")) { RM: Feb 10 1993
327  declare T as global. To do... maybe.
328  }
329  else
330  */
331 
332  if (equ_tok((*t),"<|") || equ_tok((*t),":="))
334  else
336 
337  /* if (!assert_ok && warning()) perr("the declaration is ignored.\n"); */
338 }
#define function_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1408
#define predicate_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1401
void assert_rule(psi_term t, def_type typ)
assert_rule
Definition: login.c:257
void assert_complicated_type(ptr_psi_term t)
assert_complicated_type
Definition: types.c:405
#define NULL
Definition: def_const.h:533
long assert_ok
Definition: def_glob.h:1033
#define deref_ptr(P)
Definition: def_macro.h:100
void assert_attributes(ptr_psi_term t)
assert_attributes
Definition: types.c:500
void add_rule(ptr_psi_term head, ptr_psi_term body, def_type typ)
add_rule
Definition: login.c:167
#define FALSE
Standard boolean.
Definition: def_const.h:275
#define equ_tok(A, B)
Definition: def_macro.h:67
void assert_rule ( psi_term  t,
def_type  typ 
)

assert_rule

Parameters
t- psi_term t
typ- def_type typ

ASSERT_RULE(t,typ) Add a rule to the rule tree. It may be either a predicate or a function. The psi_term T is of the form 'H :- B' or 'H -> B', but it may be incorrect (report errors). TYP is the type, function or predicate.

Definition at line 257 of file login.c.

References add_rule(), wl_psi_term::attr_list, get_two_args(), and Syntaxerrorline().

258 {
259  ptr_psi_term head;
260  ptr_psi_term body;
261 
262  get_two_args(t.attr_list,&head,&body);
263  if (head)
264  if (body)
265  add_rule(head,body,typ);
266  else {
267  Syntaxerrorline("body missing in definition of %T '%P'.\n", typ, head);
268  }
269  else {
270  Syntaxerrorline("head missing in definition of %T.\n",typ);
271  }
272 }
void Syntaxerrorline(char *format,...)
Syntaxerrorline.
Definition: error.c:557
void add_rule(ptr_psi_term head, ptr_psi_term body, def_type typ)
add_rule
Definition: login.c:167
void get_two_args(ptr_node t, ptr_psi_term *a, ptr_psi_term *b)
get_two_args
Definition: login.c:47
ptr_node attr_list
Definition: def_struct.h:187
void backtrack ( )

backtrack

BACKTRACK() Undo everything back to the previous choice-point and take the alternative decision. This routine would have to be modified, along with UNDO to cope with goals to be proved on backtracking.

Definition at line 772 of file login.c.

References choice_stack, wl_choice_point::goal_stack, goal_stack, wl_choice_point::next, NULL, resid_aim, stack_pointer, wl_choice_point::stack_top, undo(), and wl_choice_point::undo_point.

773 {
774  // long gts;
775 
778 #ifdef TS
779  /* global_time_stamp=choice_stack->time_stamp; */ /* 9.6 */
780 #endif
783  resid_aim=NULL;
784 
785 
786  /* assert((unsigned long)stack_pointer>=(unsigned long)cut_point); 13.6 */
787  /* This situation occurs frequently in some benchmarks (e.g comb) */
788  /* printf("*** Possible GC error: cut_point is dangling\n"); */
789  /* fflush(stdout); */
790 
791  /* assert((unsigned long)stack_pointer>=(unsigned long)match_date); 13.6 */
792 }
GENERIC stack_pointer
used to allocate from stack - size allocated added - adj for alignment
Definition: def_glob.h:69
ptr_goal goal_stack
Definition: def_glob.h:1025
void undo(ptr_stack limit)
undo
Definition: login.c:691
ptr_stack undo_point
Definition: def_struct.h:248
GENERIC stack_top
Definition: def_struct.h:251
#define NULL
Definition: def_const.h:533
ptr_goal resid_aim
Definition: def_glob.h:865
ptr_choice_point next
Definition: def_struct.h:250
ptr_goal goal_stack
Definition: def_struct.h:249
ptr_choice_point choice_stack
Definition: def_glob.h:1026
long clause_aim ( long  r)

clause_aim

Parameters
r- long r

CLAUSE_AIM(r) Prove a CLAUSE or RETRACT goal. That is try to unify the calling argument with the current rule. If this succeeds and R=TRUE then delete the rule (RETRACT).

Definition at line 1879 of file login.c.

References wl_goal::aaaa_1, aim, wl_psi_term::attr_list, wl_goal::bbbb_1, wl_goal::cccc_1, clause, clear_copy(), del_clause, Errorline(), FALSE, i_eval_args(), wl_definition::keyword, MAX_BUILT_INS, NULL, push_choice_point(), push_goal(), quote_copy(), retract, STACK, wl_psi_term::status, wl_keyword::symbol, traceline(), TRUE, wl_psi_term::type, and unify.

1880 {
1881  long success=FALSE;
1882  ptr_pair_list *p;
1883  ptr_psi_term head,body,rule_head,rule_body;
1884 
1885  head=(ptr_psi_term)aim->aaaa_1;
1886  body=(ptr_psi_term)aim->bbbb_1;
1887  p=(ptr_pair_list *)aim->cccc_1;
1888 
1889  if ((unsigned long)(*p)>MAX_BUILT_INS) {
1890  success=TRUE;
1891  /* deref(head); 17.9 */
1892 
1893  if ((*p)->next) {
1894  if (r) {
1895  traceline("pushing 'retract' choice point for %P\n", head);
1896  push_choice_point(del_clause,head,(ptr_psi_term)body,(GENERIC)&((*p)->next));
1897  /* push_choice_point(del_clause,head,body,p); */
1898  }
1899  else {
1900  traceline("pushing 'clause' choice point for %P\n", head);
1901  push_choice_point(clause,head,(ptr_psi_term)body,(GENERIC)&((*p)->next));
1902  }
1903  }
1904 
1905  if (r)
1907  if ((*p)->aaaa_2) {
1908  clear_copy();
1909  rule_head=quote_copy((*p)->aaaa_2,STACK);
1910  rule_body=quote_copy((*p)->bbbb_2,STACK);
1911 
1912  push_goal(unify,(ptr_psi_term)body,(ptr_psi_term)rule_body,NULL);
1913  push_goal(unify,(ptr_psi_term)head,(ptr_psi_term)rule_head,NULL);
1914 
1915  rule_head->status=4;
1916  rule_body->status=4;
1917 
1918  (void)i_eval_args(rule_body->attr_list);
1919  (void)i_eval_args(rule_head->attr_list);
1920 
1921  traceline("fetching next clause for %s\n", head->type->keyword->symbol);
1922  }
1923  else {
1924  success=FALSE;
1925  traceline("following clause had been retracted\n");
1926  }
1927  }
1928  else if ((unsigned long)(*p)>0) {
1929  if (r)
1930  Errorline("the built-in %P cannot be retracted.\n",head);
1931  else
1932  Errorline("the definition of built-in %P is not accessible.\n",head);
1933  }
1934 
1935  return success;
1936 }
ptr_psi_term aaaa_1
Definition: def_struct.h:239
void clear_copy()
clear_copy
Definition: copy.c:53
void push_goal(goals t, ptr_psi_term aaaa_5, ptr_psi_term bbbb_5, GENERIC cccc_5)
push_goal
Definition: login.c:600
GENERIC cccc_1
Definition: def_struct.h:241
ptr_keyword keyword
Definition: def_struct.h:147
struct wl_psi_term * ptr_psi_term
quotedStackCopy
Definition: def_struct.h:62
#define NULL
Definition: def_const.h:533
char * symbol
Definition: def_struct.h:118
void traceline(char *format,...)
traceline
Definition: error.c:186
ptr_psi_term quote_copy(ptr_psi_term t, long heap_flag)
quote_copy
Definition: copy.c:186
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define FALSE
Standard boolean.
Definition: def_const.h:275
#define clause
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1135
ptr_goal aim
Definition: def_glob.h:1024
#define retract
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1149
#define unify
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1058
long i_eval_args(ptr_node n)
i_eval_args
Definition: lefun.c:874
#define del_clause
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1142
#define MAX_BUILT_INS
Maximum number of built_ins.
Definition: def_const.h:154
ptr_definition type
Definition: def_struct.h:181
ptr_psi_term bbbb_1
Definition: def_struct.h:240
ptr_node attr_list
Definition: def_struct.h:187
void push_choice_point(goals t, ptr_psi_term aaaa_6, ptr_psi_term bbbb_6, GENERIC cccc_6)
push_choice_point
Definition: login.c:638
#define STACK
Flag to indicate stack allocation.
Definition: def_const.h:331
static void clean_trail ( ptr_choice_point  cutpt)
static

clean_trail

Parameters
cutpt- ptr_choice_point cutpt

CLEAN_TRAIL(cutpt) This routine removes all trail entries between the top of the undo_stack and the cutpt, whose addresses are between the cutpt and stack_pointer. (The cutpt is the choice point that will become the most recent one after the cut.) This routine should be called when a cut built-in is done. This routine is careful not to remove any trailed entries that are on the heap or outside of Life space.

Definition at line 810 of file login.c.

References wl_stack::aaaa_3, clean_iter, clean_succ, mem_base, wl_stack::next, NULL, stack_pointer, wl_choice_point::stack_top, wl_stack::type, undo_action, wl_choice_point::undo_point, undo_stack, and VALID_RANGE.

811 {
812  ptr_stack *prev,u,cut_limit;
813  GENERIC cut_sp;
814 
815  u = undo_stack;
816  prev = &undo_stack;
817  if (cutpt) {
818  cut_sp = cutpt->stack_top;
819  cut_limit = cutpt->undo_point;
820  }
821  else {
822  cut_sp = mem_base; /* Empty stack */
823  cut_limit = NULL; /* Empty undo_stack */
824  }
825 
826  while ((unsigned long)u > (unsigned long)cut_limit) {
827  clean_iter++;
828  if (!(u->type & undo_action) && VALID_RANGE(u->aaaa_3) &&
829  (unsigned long)u->aaaa_3>(unsigned long)cut_sp && (unsigned long)u->aaaa_3<=(unsigned long)stack_pointer) {
830  *prev = u->next;
831  clean_succ++;
832  }
833  prev = &(u->next);
834  u = u->next;
835  }
836 }
GENERIC stack_pointer
used to allocate from stack - size allocated added - adj for alignment
Definition: def_glob.h:69
#define VALID_RANGE(A)
Definition: def_macro.h:127
ptr_stack undo_point
Definition: def_struct.h:248
long clean_succ
Definition: login.c:23
GENERIC stack_top
Definition: def_struct.h:251
#define NULL
Definition: def_const.h:533
ptr_stack undo_stack
Definition: def_glob.h:1027
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
type_ptr type
Definition: def_struct.h:231
GENERIC * aaaa_3
Definition: def_struct.h:232
#define undo_action
Fast checking for an undo action.
Definition: def_const.h:484
long clean_iter
Definition: login.c:22
GENERIC mem_base
mem_size memory allocated in init_memory by malloc
Definition: def_glob.h:48
ptr_stack next
Definition: def_struct.h:234
void clean_undo_window ( long  disp,
long  wind 
)

clean_undo_window

Parameters
disp- long disp
wind- long wind

CLEAN_UNDO_WINDOW(disp,wind) Remove all trail entries that reference a given window. This is called when the window is destroyed.

Definition at line 848 of file login.c.

References wl_stack::aaaa_3, wl_stack::bbbb_3, choice_stack, wl_stack::next, wl_choice_point::next, wl_stack::type, undo_action, wl_choice_point::undo_point, and undo_stack.

849 {
850  ptr_stack *prev,u;
852 
853 #ifdef X11
854  /* Remove entries on the trail */
855  u = undo_stack;
856  prev = &undo_stack;
857  while (u) {
858  if ((u->type & undo_action) &&
859  ((unsigned long)u->aaaa_3==disp) && ((unsigned long)u->bbbb_3==wind)) {
860  *prev = u->next;
861  }
862  prev = &(u->next);
863  u = u->next;
864  }
865 
866  /* Remove entries at the *tops* of trail entry points from the */
867  /* choice point stack. It's only necessary to look at the tops, */
868  /* since those are the only ones that haven't been touched by */
869  /* the previous while loop. */
870  c = choice_stack;
871  while (c) {
872  u = c->undo_point;
873  prev = &(c->undo_point);
874  while (u && (u->type & undo_action) &&
875  ((unsigned long)u->aaaa_3==disp) && ((unsigned long)u->bbbb_3==wind)) {
876  *prev = u->next;
877  prev = &(u->next);
878  u = u->next;
879  }
880  c = c->next;
881  }
882 #endif
883 }
GENERIC * bbbb_3
Definition: def_struct.h:233
ptr_stack undo_point
Definition: def_struct.h:248
ptr_choice_point next
Definition: def_struct.h:250
ptr_stack undo_stack
Definition: def_glob.h:1027
type_ptr type
Definition: def_struct.h:231
GENERIC * aaaa_3
Definition: def_struct.h:232
#define undo_action
Fast checking for an undo action.
Definition: def_const.h:484
ptr_stack next
Definition: def_struct.h:234
ptr_choice_point choice_stack
Definition: def_glob.h:1026
long disjunct_aim ( )

disjunct_aim

DISJUNCT_AIM() This is the disjunction enumeration routine. If U is the disjunction {H|T} then first bind U to H, then on backtracking enumerate the disjunction T. U is always passed along so that every choice of the disjunction can be bound to U.

Definition at line 1621 of file login.c.

References TRUE.

1622 {
1623  // ptr_psi_term u,v;
1624  // ptr_list l;
1625  long success=TRUE;
1626 
1627  printf("Call to disjunct_aim\nThis routine inhibited by RM: Dec 9 1992\n");
1628 
1629  return success;
1630 }
#define TRUE
Standard boolean.
Definition: def_const.h:268
int dummy_printf ( char *  f,
char *  s,
char *  t 
)

dummy_printf

Parameters
f- char *f
s- char *s
t- char *t

Definition at line 2617 of file login.c.

2618 {
2619  return strlen(f);
2620 }
void fetch_def ( ptr_psi_term  u,
long  allflag 
)

fetch_def

Parameters
u- ptr_psi_term u
allflag- long allflag

FETCH_DEF(psi_term) Fetch the type definition of a psi_term and execute it. That is, get the list of (term,predicate) pairs that define the type. Unify the psi_term with the term, then prove the predicate.

This routine only gets the pairs that are defined in the type itself, not those defined in any types above it. This is the correct behavior for enumerating type disjunctions–all higher constraints have already been checked.

The above is true if allflag==FALSE. If allflag==TRUE then all constraints are executed, not just those defined in the type itself.

Definition at line 1208 of file login.c.

References wl_triple_list::aaaa_4, wl_psi_term::attr_list, wl_triple_list::bbbb_4, wl_triple_list::cccc_4, clear_copy(), DEFRULES, deref_ptr, eval_copy(), i_eval_args(), int_ptr, wl_triple_list::next, NULL, wl_definition::properties, prove, push2_ptr_value(), push_goal(), RMASK, SMASK, STACK, wl_psi_term::status, traceline(), wl_psi_term::type, and unify.

1209 {
1210  ptr_triple_list prop;
1211  ptr_psi_term v,w;
1212  ptr_definition utype;
1213 
1214  /* Uses SMASK because called from check_out */
1216  u->status=(4 & SMASK) | (u->status & RMASK);
1217 
1218  utype=u->type;
1219  prop=u->type->properties;
1220  if (prop) {
1221 
1222  traceline("fetching definition of %P\n",u);
1223 
1224  while (prop) {
1225  if (allflag || prop->cccc_4==utype) {
1226  clear_copy();
1227  v=eval_copy(prop->aaaa_4,STACK);
1228  w=eval_copy(prop->bbbb_4,STACK);
1229 
1231 
1232  deref_ptr(v);
1233  v->status=4;
1235  (void)i_eval_args(v->attr_list);
1236  }
1237  prop=prop->next;
1238  }
1239  }
1240 }
#define prove
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1051
void push2_ptr_value(type_ptr t, GENERIC *p, GENERIC v)
push2_ptr_value
Definition: login.c:573
void clear_copy()
clear_copy
Definition: copy.c:53
void push_goal(goals t, ptr_psi_term aaaa_5, ptr_psi_term bbbb_5, GENERIC cccc_5)
push_goal
Definition: login.c:600
#define DEFRULES
Must be different from NULL, a built-in index, and a pointer Used to indicate that the rules of the d...
Definition: def_const.h:302
#define NULL
Definition: def_const.h:533
ptr_triple_list next
Definition: def_struct.h:215
ptr_definition cccc_4
Definition: def_struct.h:214
void traceline(char *format,...)
traceline
Definition: error.c:186
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
#define deref_ptr(P)
Definition: def_macro.h:100
#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 bbbb_4
Definition: def_struct.h:213
#define unify
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1058
long i_eval_args(ptr_node n)
i_eval_args
Definition: lefun.c:874
ptr_psi_term eval_copy(ptr_psi_term t, long heap_flag)
eval_copy
Definition: copy.c:196
ptr_definition type
Definition: def_struct.h:181
ptr_triple_list properties
Definition: def_struct.h:149
#define SMASK
Bit mask for status field of psi-terms: SMASK masks off the status bits. These are used in the 'mark'...
Definition: def_const.h:367
ptr_node attr_list
Definition: def_struct.h:187
ptr_psi_term aaaa_4
Definition: def_struct.h:212
#define STACK
Flag to indicate stack allocation.
Definition: def_const.h:331
#define int_ptr
values of type_ptr
Definition: def_const.h:397
void fetch_def_lazy ( ptr_psi_term  u,
ptr_definition  old1,
ptr_definition  old2,
ptr_node  old1attr,
ptr_node  old2attr,
long  old1stat,
long  old2stat 
)

fetch_def_lazy

Parameters
u-ptr_psi_term u
old1- ptr_definition old1
old2- ptr_definition old2
old1attr- ptr_node old1attr
old2attr- ptr_node old2attr
old1stat- long old1stat
old2stat- long old2stat

FETCH_DEF_LAZY(psi_term,type1,type2,attr_list1,attr_list2) Fetch the type definition of a psi_term and execute it. That is, get the list of (term,pred) pairs that define the type. 'Term' is one of the type's attributes and 'pred' is a constraint. Unify the psi_term with the term, then prove pred.

Only those (term,pred) pairs are executed whose original type is below both type1 and type2, the types of the two psi-terms whose unification created psi_term. This avoids doing much superfluous work.

The above behavior is correct for a psi_term when always_check==TRUE for that psi_term. If always_check==FALSE for a psi_term, then if it does not have attributes it is not checked, and the addition of an attribute will force checking to occur.

Example:

:: t(a=>one,b=>two,c=> X) | thing(X).

psi_term = A:t (it can be any psi_term of type t) term = t(a=>one,b=>two,c=> X) pred = thing(X)

Definition at line 1276 of file login.c.

References wl_triple_list::aaaa_4, wl_definition::always_check, wl_psi_term::attr_list, wl_triple_list::bbbb_4, wl_triple_list::cccc_4, clear_copy(), DEFRULES, deref_ptr, eval_copy(), FALSE, i_eval_args(), int_ptr, matches(), wl_triple_list::next, NULL, wl_definition::properties, prove, push_goal(), push_ptr_value(), STACK, wl_psi_term::status, traceline(), wl_psi_term::type, and unify.

1277 {
1278  ptr_triple_list prop;
1279  ptr_psi_term v,w;
1280  long checked1, checked2;
1281  long m1, m2;
1282 
1283  if (!u->type->always_check) if (u->attr_list==NULL) return;
1284 
1286  u->status=4;
1287 
1288  prop=u->type->properties;
1289  if (prop) {
1290  traceline("fetching partial definition of %P\n",u);
1291 
1292  checked1 = old1attr || old1->always_check;
1293  checked2 = old2attr || old2->always_check;
1294 
1295  /* checked1 = (old1stat==4); */ /* 18.2.94 */
1296  /* checked2 = (old2stat==4); */
1297 
1298  while (prop) {
1299  /* Only do those constraints that have not yet been done: */
1300  /* In matches, mi is TRUE iff oldi <| prop->cccc_1. */
1301  if (!checked1) m1=FALSE; else (void)matches(old1,prop->cccc_4,&m1);
1302  if (!checked2) m2=FALSE; else (void)matches(old2,prop->cccc_4,&m2);
1303  if (!m1 && !m2) {
1304  /* At this point, prop->cccc_1 is an attribute that has not yet */
1305  /* been checked. */
1306  clear_copy();
1307  v=eval_copy(prop->aaaa_4,STACK);
1308  w=eval_copy(prop->bbbb_4,STACK);
1309 
1311 
1312  deref_ptr(v);
1313  v->status=4;
1315  (void)i_eval_args(v->attr_list);
1316  }
1317  prop=prop->next;
1318  }
1319  }
1320 }
#define prove
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1051
void clear_copy()
clear_copy
Definition: copy.c:53
void push_goal(goals t, ptr_psi_term aaaa_5, ptr_psi_term bbbb_5, GENERIC cccc_5)
push_goal
Definition: login.c:600
long matches(ptr_definition t1, ptr_definition t2, long *smaller)
matches
Definition: types.c:1666
#define DEFRULES
Must be different from NULL, a built-in index, and a pointer Used to indicate that the rules of the d...
Definition: def_const.h:302
#define NULL
Definition: def_const.h:533
ptr_triple_list next
Definition: def_struct.h:215
ptr_definition cccc_4
Definition: def_struct.h:214
char always_check
Definition: def_struct.h:154
void traceline(char *format,...)
traceline
Definition: error.c:186
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
#define deref_ptr(P)
Definition: def_macro.h:100
#define FALSE
Standard boolean.
Definition: def_const.h:275
ptr_psi_term bbbb_4
Definition: def_struct.h:213
#define unify
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1058
long i_eval_args(ptr_node n)
i_eval_args
Definition: lefun.c:874
ptr_psi_term eval_copy(ptr_psi_term t, long heap_flag)
eval_copy
Definition: copy.c:196
ptr_definition type
Definition: def_struct.h:181
ptr_triple_list properties
Definition: def_struct.h:149
ptr_node attr_list
Definition: def_struct.h:187
void push_ptr_value(type_ptr t, GENERIC *p)
push_ptr_value
Definition: login.c:383
ptr_psi_term aaaa_4
Definition: def_struct.h:212
#define STACK
Flag to indicate stack allocation.
Definition: def_const.h:331
#define int_ptr
values of type_ptr
Definition: def_const.h:397
void get_one_arg ( ptr_node  t,
ptr_psi_term a 
)

get_one_arg

Parameters
t- ptr_node t
a- ptr_psi_term *a

GET_ONE_ARG(attr_list,arg1) Get the argument labelled '1' as quickly as possible from the binary tree ATTR_LIST, place it in ARG1. This routine nearly always makes a direct hit.

Definition at line 99 of file login.c.

References wl_node::data, FEATCMP, find(), wl_node::key, NULL, and one.

100 {
101  ptr_node n;
102 
103  *a=NULL;
104  if (t) {
105  if (t->key==one) {
106  *a=(ptr_psi_term)t->data;
107  }
108  else {
109  n=find(FEATCMP,one,t);
110  if (n==NULL)
111  *a=NULL;
112  else
113  *a=(ptr_psi_term)n->data;
114  }
115  }
116 }
#define FEATCMP
indicates to use featcmp for comparison (in trees.c)
Definition: def_const.h:979
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
char * key
Definition: def_struct.h:198
char * one
Definition: def_glob.h:891
ptr_node find(long comp, char *keystr, ptr_node tree)
find
Definition: trees.c:394
void get_one_arg_addr ( ptr_node  t,
ptr_psi_term **  a 
)

get_one_arg_addr

Parameters
t- ptr_node t
a- ptr_psi_term **a

GET_ONE_ARG_ADDR(attr_list,arg1addr) Get address of slot in the attr_list that points to the argument labelled '1' as quickly as possible from the binary tree ATTR_LIST. This routine nearly always makes a direct hit.

Definition at line 132 of file login.c.

References wl_node::data, FEATCMP, find(), wl_node::key, NULL, and one.

133 {
134  ptr_node n;
135  // ptr_psi_term *b;
136 
137  *a=NULL;
138  if (t) {
139  if (t->key==one)
140  *a= (ptr_psi_term *)(&t->data);
141  else {
142  n=find(FEATCMP,one,t);
143  if (n==NULL)
144  *a=NULL;
145  else
146  *a= (ptr_psi_term *)(&n->data);
147  }
148  }
149 }
#define FEATCMP
indicates to use featcmp for comparison (in trees.c)
Definition: def_const.h:979
GENERIC data
Definition: def_struct.h:201
#define NULL
Definition: def_const.h:533
char * key
Definition: def_struct.h:198
char * one
Definition: def_glob.h:891
ptr_node find(long comp, char *keystr, ptr_node tree)
find
Definition: trees.c:394
void get_two_args ( ptr_node  t,
ptr_psi_term a,
ptr_psi_term b 
)

get_two_args

Parameters
t- ptr_node t,
a- ptr_psi_term *a
b- ptr_psi_term *b

GET_TWO_ARGS(attr_list,arg1,arg2) Get the arguments labelled '1' and '2' as quickly as possible from the binary tree ATTR_LIST, place them in ARG1 and ARG2. This routine nearly always makes a direct hit.

Definition at line 47 of file login.c.

References wl_node::data, FEATCMP, find(), wl_node::key, NULL, one, wl_node::right, and two.

48 {
49  ptr_node n;
50 
51  *a=NULL;
52  *b=NULL;
53  if (t) {
54  if (t->key==one) {
55  *a=(ptr_psi_term )t->data;
56  n=t->right;
57  if (n)
58  if (n->key==two)
59  *b=(ptr_psi_term )n->data;
60  else {
61  n=find(FEATCMP,two,t);
62  if(n==NULL)
63  *b=NULL;
64  else
65  *b=(ptr_psi_term )n->data;
66  }
67  else
68  *b=NULL;
69  }
70  else {
71  n=find(FEATCMP,one,t);
72  if (n==NULL)
73  *a=NULL;
74  else
75  *a=(ptr_psi_term )n->data;
76  n=find(FEATCMP,two,t);
77  if (n==NULL)
78  *b=NULL;
79  else
80  *b=(ptr_psi_term )n->data;
81  }
82  }
83 }
#define FEATCMP
indicates to use featcmp for comparison (in trees.c)
Definition: def_const.h:979
char * two
Definition: def_glob.h:892
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
char * key
Definition: def_struct.h:198
char * one
Definition: def_glob.h:891
ptr_node find(long comp, char *keystr, ptr_node tree)
find
Definition: trees.c:394
ptr_node right
Definition: def_struct.h:200
long load_aim ( )

load_aim

LOAD_AIM() Continue loading a file from the current psi-term up to the next query. Files are loaded in blocks of assertions that end with a query. Such a chunk is loaded by a 'load' goal on the goal_stack. This goal contains the input file state information. This guarantees that all queries in the input file are executed in the order they are encountered (which includes load operations).

Definition at line 2232 of file login.c.

References wl_goal::aaaa_1, abort_life(), aim, assert_clause(), assert_first, wl_goal::bbbb_1, wl_goal::cccc_1, choice_stack, CURRENT_MODULE, DEFRULES, encode_types(), eof, FACT, FALSE, file_date, find_module(), general_cut, get_attr(), input_state, input_stream, load, noisy, NULL, open_input_file(), parse(), prove, push_choice_point(), push_goal(), QUERY, restore_state(), save_state(), set_current_module(), stack_copy_psi_term(), TRUE, wl_psi_term::type, var_occurred, and var_tree.

2233 {
2234  long success=TRUE,exitloop;
2235  ptr_psi_term s;
2236  long sort;
2237  char *fn;
2238  long old_noisy,old_file_date;
2239  ptr_node old_var_tree;
2240  ptr_choice_point cutpt;
2241  long old_var_occurred; /* 18.8 */
2242  int end_of_file=FALSE; /* RM: Jan 27 1993 */
2243 
2244 
2248  old_file_date=file_date;
2249  file_date=(unsigned long)aim->bbbb_1;
2250  old_noisy=noisy;
2251  noisy=FALSE;
2252  fn=(char*)aim->cccc_1;
2253  exitloop=FALSE;
2254 
2255  do {
2256  /* Variables in queries in files are *completely independent* of top- */
2257  /* level variables. I.e.: top-level variables are *not* recognized */
2258  /* while loading files and variables in file queries are *not* added. */
2259  old_var_occurred=var_occurred; /* 18.8 */
2260  old_var_tree=var_tree;
2261  var_tree=NULL;
2262  s=stack_copy_psi_term(parse(&sort));
2263  var_tree=old_var_tree;
2264  var_occurred=old_var_occurred; /* 18.8 */
2265 
2266  if (s->type==eof) {
2267  encode_types();
2268  if (input_stream!=stdin) (void)fclose(input_stream);
2269  exitloop=TRUE;
2270  end_of_file=TRUE; /* RM: Jan 27 1993 */
2271  }
2272  else if (sort==FACT) {
2274  assert_clause(s);
2275  }
2276  else if (sort==QUERY) {
2277  encode_types();
2279  /* Handle both successful and failing queries correctly. */
2280  cutpt=choice_stack;
2285  exitloop=TRUE;
2286  }
2287  else {
2288  /* fprintf(stderr,"*** Error: in input file %c%s%c.\n",34,fn,34); */
2289  /* success=FALSE; */
2290  /* fail_all(); */
2291  if (input_stream!=stdin) (void)fclose(input_stream);
2292  (void)abort_life(TRUE);
2293  /* printf("\n*** Abort\n"); */
2294  /* main_loop_ok=FALSE; */
2295  }
2296  } while (success && !exitloop);
2297 
2298 
2299  /* RM: Jan 27 1993 */
2300  if(end_of_file || !success) {
2301  /*
2302  printf("END OF FILE %s, setting module to %s\n",
2303  ((ptr_psi_term)get_attr(input_state,
2304  INPUT_FILE_NAME))->value,
2305  ((ptr_psi_term)get_attr(input_state,
2306  CURRENT_MODULE))->value);
2307  */
2308 
2309  (void)set_current_module(
2310  find_module((char *)((ptr_psi_term)get_attr(input_state,
2311  CURRENT_MODULE))->value_3));
2312  }
2313 
2314 
2315  noisy=old_noisy;
2316  file_date=old_file_date;
2317  (void)open_input_file("stdin");
2318 
2319 
2320  return success;
2321 }
void assert_clause(ptr_psi_term t)
assert_clause
Definition: login.c:287
#define prove
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1051
ptr_psi_term aaaa_1
Definition: def_struct.h:239
long assert_first
Definition: def_glob.h:1032
psi_term parse(long *q)
parse
Definition: parser.c:907
void push_goal(goals t, ptr_psi_term aaaa_5, ptr_psi_term bbbb_5, GENERIC cccc_5)
push_goal
Definition: login.c:600
GENERIC cccc_1
Definition: def_struct.h:241
#define general_cut
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1114
long file_date
Definition: def_glob.h:1034
#define DEFRULES
Must be different from NULL, a built-in index, and a pointer Used to indicate that the rules of the d...
Definition: def_const.h:302
#define CURRENT_MODULE
feature name
Definition: def_const.h:939
#define FACT
Fact Kind of user input.
Definition: def_const.h:338
struct wl_psi_term * ptr_psi_term
quotedStackCopy
Definition: def_struct.h:62
#define NULL
Definition: def_const.h:533
ptr_node var_tree
Definition: def_glob.h:1005
ptr_psi_term input_state
Definition: def_glob.h:856
#define QUERY
Query Kind of user input.
Definition: def_const.h:345
long noisy
Definition: def_glob.h:1011
long abort_life(int nlflag)
abort_life
Definition: built_ins.c:2259
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
#define TRUE
Standard boolean.
Definition: def_const.h:268
ptr_definition eof
symbol in syntax module
Definition: def_glob.h:263
#define FALSE
Standard boolean.
Definition: def_const.h:275
FILE * input_stream
Definition: def_glob.h:1014
ptr_goal aim
Definition: def_glob.h:1024
ptr_psi_term stack_copy_psi_term(psi_term t)
stack_copy_psi_term
Definition: parser.c:205
void restore_state(ptr_psi_term t)
restore_state
Definition: token.c:334
#define load
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1156
void encode_types()
encode_types
Definition: types.c:1091
void save_state(ptr_psi_term t)
save_state
Definition: token.c:293
GENERIC get_attr(ptr_psi_term t, char *attrname)
get_attr
Definition: token.c:265
ptr_module find_module(char *module)
find_module
Definition: modules.c:54
ptr_definition type
Definition: def_struct.h:181
ptr_psi_term bbbb_1
Definition: def_struct.h:240
long var_occurred
???
Definition: def_glob.h:839
long open_input_file(char *file)
open_input_file
Definition: token.c:594
ptr_module set_current_module(ptr_module module)
set_current_module
Definition: modules.c:100
void push_choice_point(goals t, ptr_psi_term aaaa_6, ptr_psi_term bbbb_6, GENERIC cccc_6)
push_choice_point
Definition: login.c:638
ptr_choice_point choice_stack
Definition: def_glob.h:1026
void main_prove ( )

main_prove

MAIN_PROVE() This is the inference engine. It distributes sub-goals to the appropriate routines. It deals with backtracking. It fails if there is not enough memory available or if there is an interrupt that causes the current query to be aborted.

Definition at line 2333 of file login.c.

References wl_goal::aaaa_1, aim, backtrack(), wl_goal::bbbb_1, c_what_next, wl_goal::cccc_1, choice_stack, clause, clause_aim(), clean_trail(), curried, cut_to, del_clause, disj, disjunct_aim(), do_currying(), do_residuation_user(), Errorline(), eval, eval_aim(), eval_cut, fail, FALSE, freeze_cut, function_it, GC_THRESHOLD, general_cut, goal_count, goal_stack, handle_interrupt(), heap_pointer, i_check_out(), implies_cut, infoline(), interrupted, load, load_aim(), main_loop_ok, match, match_aim(), memory_check(), wl_goal::next, NULL, prove, prove_aim(), release_resid(), resid_aim, resid_vars, restore_resid(), retract, show_count(), stack_pointer, stepcount, stepflag, steptrace, traceline(), TRUE, wl_goal::type, type_disj, type_disj_aim(), undo(), unify, unify_aim(), unify_aim_noeval(), unify_noeval, warningline(), what_next, what_next_aim(), x_exist_event(), xcount, xevent_existing, XEVENTDELAY, and xeventdelay.

2334 {
2335  long success=TRUE;
2336  ptr_pair_list *p;
2337  ptr_psi_term unused_match_date; /* 13.6 */
2338 
2339  xcount=0;
2343 
2344  while (main_loop_ok && goal_stack) {
2345 
2346  /* RM: Oct 28 1993 For debugging a horrible mess.
2347  {
2348  ptr_choice_point c=choice_stack;
2349  while(c) {
2350  if((ptr_psi_term)stack_pointer<(ptr_psi_term)c) {
2351  printf("########### Choice stack corrupted! %x\n",c);
2352  trace=TRUE;
2353  c=NULL;
2354  }
2355  else
2356  c=c->next;
2357  }
2358  }
2359  */
2360 
2361 
2362  aim=goal_stack;
2363  switch(aim->type) {
2364 
2365  case unify:
2366  goal_stack=aim->next;
2367  goal_count++;
2368  success=unify_aim();
2369  break;
2370 
2371  /* Same as above, but do not evaluate top level */
2372  /* Used to bind with unbound variables */
2373  case unify_noeval:
2374  goal_stack=aim->next;
2375  goal_count++;
2376  success=unify_aim_noeval();
2377  break;
2378 
2379  case prove:
2380  success=prove_aim();
2381  break;
2382 
2383  case eval:
2384  goal_stack=aim->next;
2385  goal_count++;
2386  success=eval_aim();
2387  break;
2388 
2389  case load:
2390  goal_stack=aim->next;
2391  goal_count++;
2392  success=load_aim();
2393  break;
2394 
2395  case match:
2396  goal_stack=aim->next;
2397  goal_count++;
2398  success=match_aim();
2399  break;
2400 
2401  case disj:
2402  goal_stack=aim->next;
2403  goal_count++;
2404  success=disjunct_aim();
2405  break;
2406 
2407  case general_cut:
2408  goal_stack=aim->next;
2409  goal_count++;
2410  /* assert((ptr_choice_point)aim->aaaa_1 <= choice_stack); 12.7 */
2411  /* choice_stack=(ptr_choice_point)aim->aaaa_1; */
2412  cut_to(aim->aaaa_1); /* 12.7 */
2413 #ifdef CLEAN_TRAIL
2415 #endif
2416 #ifdef TS
2417  /* RESTORE_TIME_STAMP; */ /* 9.6 */
2418 #endif
2419  break;
2420 
2421  case eval_cut:
2422  /* RESID */ restore_resid((ptr_resid_block)aim->cccc_1, &unused_match_date);
2423  if (curried)
2424  do_currying();
2425  else if (resid_vars) {
2426  success=do_residuation_user(); /* 21.9 */ /* PVR 9.2.94 */
2427  } else {
2428  if (resid_aim)
2429  traceline("result of %P is %P\n", resid_aim->aaaa_1, aim->aaaa_1);
2430  goal_stack=aim->next;
2431  goal_count++;
2432  /* resid_aim=NULL; 21.9 */
2433  /* PVR 5.11 choice_stack=(ptr_choice_point)aim->bbbb_1; */
2434  (void)i_check_out(aim->aaaa_1);
2435  }
2436  resid_aim=NULL; /* 21.9 */
2437  resid_vars=NULL; /* 22.9 */
2438  /* assert((ptr_choice_point)aim->bbbb_1<=choice_stack); 12.7 */
2439  /* PVR 5.11 */ /* choice_stack=(ptr_choice_point)aim->bbbb_1; */
2440  if (success) { /* 21.9 */
2441  cut_to(aim->bbbb_1); /* 12.7 */
2442 #ifdef CLEAN_TRAIL
2444 #endif
2445  /* match_date=NULL; */ /* 13.6 */
2446 #ifdef TS
2447  /* RESTORE_TIME_STAMP; */ /* 9.6 */
2448 #endif
2449  }
2450  break;
2451 
2452  case freeze_cut:
2453  /* RESID */ restore_resid((ptr_resid_block)aim->cccc_1, &unused_match_date);
2454  if (curried) {
2455  warningline("frozen goal has a missing parameter '%P' and fails.\n",aim->aaaa_1);
2456  success=FALSE;
2457  }
2458  else if (resid_vars) {
2459  success=do_residuation_user(); /* 21.9 */ /* PVR 9.2.94 */
2460  } else {
2461  if (resid_aim) traceline("releasing frozen goal: %P\n", aim->aaaa_1);
2462  /* resid_aim=NULL; 21.9 */
2463  /* PVR 5.12 choice_stack=(ptr_choice_point)aim->bbbb_1; */
2464  goal_stack=aim->next;
2465  goal_count++;
2466  }
2467  resid_aim=NULL; /* 21.9 */
2468  resid_vars=NULL; /* 22.9 */
2469  if (success) { /* 21.9 */
2470  /* assert((ptr_choice_point)aim->bbbb_1<=choice_stack); 12.7 */
2471  /* PVR 5.12 */ /* choice_stack=(ptr_choice_point)aim->bbbb_1; */
2472  cut_to(aim->bbbb_1); /* 12.7 */
2473 #ifdef CLEAN_TRAIL
2475 #endif
2476  /* match_date=NULL; */ /* 13.6 */
2477 #ifdef TS
2478  /* RESTORE_TIME_STAMP; */ /* 9.6 */
2479 #endif
2480  }
2481  break;
2482 
2483  case implies_cut: /* 12.10 */
2484  /* This 'cut' is actually more like a no-op! */
2485  restore_resid((ptr_resid_block)aim->cccc_1, &unused_match_date);
2486  if (curried) {
2487  warningline("implied goal has a missing parameter '%P' and fails.\n",aim->aaaa_1);
2488  success=FALSE;
2489  }
2490  else if (resid_vars)
2491  success=FALSE;
2492  else {
2493  if (resid_aim) traceline("executing implied goal: %P\n", aim->aaaa_1);
2494  goal_stack=aim->next;
2495  goal_count++;
2496  }
2497  resid_aim=NULL; /* 21.9 */
2498  resid_vars=NULL; /* 22.9 */
2499  break;
2500 
2501  case fail:
2502  goal_stack=aim->next;
2503  success=FALSE;
2504  break;
2505 
2506  case what_next:
2507  goal_stack=aim->next;
2508  success=what_next_aim();
2509  break;
2510 
2511  case type_disj:
2512  goal_stack=aim->next;
2513  goal_count++;
2514  type_disj_aim();
2515  break;
2516 
2517  case clause:
2518  goal_stack=aim->next;
2519  goal_count++;
2520  success=clause_aim(0);
2521  break;
2522 
2523  case del_clause:
2524  goal_stack=aim->next;
2525  goal_count++;
2526  success=clause_aim(1);
2527  break;
2528 
2529  case retract:
2530  goal_stack=aim->next;
2531  goal_count++;
2532  p=(ptr_pair_list*)aim->aaaa_1;
2533  traceline("deleting clause (%P%s%P)\n",
2534  (*p)->aaaa_2,((*p)->aaaa_2->type->type_def==(def_type)function_it?"->":":-"),(*p)->bbbb_2);
2535  (*p)->aaaa_2=NULL;
2536  (*p)->bbbb_2=NULL;
2537  (*p)=(*p)->next; /* Remove retracted element from pairlist */
2538  break;
2539 
2540  case c_what_next: /* RM: Mar 31 1993 */
2541  main_loop_ok=FALSE; /* Exit the main loop */
2542  break;
2543 
2544  default:
2545  Errorline("bad goal on stack %d.\n",goal_stack->type);
2546  goal_stack=aim->next;
2547  }
2548 
2549  if (main_loop_ok) {
2550 
2551  if (success) {
2552 
2553 #ifdef X11
2554  /* Polling on external events */
2555  if (xcount<=0 && aim->type==prove) {
2556  if (x_exist_event()) {
2557  /* printf("At event, xeventdelay = %ld.\n",xeventdelay); */
2558  xeventdelay=0;
2560  } else {
2562  /* If XEVENTDELAY=1000 it takes 90000 goals to get back */
2563  /* from 100 at the pace of 1%. */
2564  xeventdelay=(xeventdelay*101)/100+2;
2565  else
2567  }
2569  }
2570  else
2571  xcount--;
2572 #endif
2573 
2574  }
2575  else {
2576  if (choice_stack) {
2577  backtrack();
2578  traceline("backtracking\n");
2579  success=TRUE;
2580  }
2581  else /* if (goal_stack) */ {
2582  undo(NULL); /* 8.10 */
2583  infoline("\n*** No");
2584  /* printf("\n*** No (in main_prove)."); */
2585  show_count();
2586 #ifdef TS
2587  /* global_time_stamp=INIT_TIME_STAMP; */ /* 9.6 */
2588 #endif
2590  }
2591  }
2592 
2594  (void)memory_check();
2595 
2596  if (interrupted || (stepflag && steptrace))
2597  handle_interrupt();
2598  else if (stepcount>0) {
2599  stepcount--;
2600  if (stepcount==0 && !stepflag) {
2601  stepflag=TRUE;
2602  handle_interrupt();
2603  }
2604  }
2605  }
2606  }
2607 }
GENERIC stack_pointer
used to allocate from stack - size allocated added - adj for alignment
Definition: def_glob.h:69
#define prove
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1051
long x_exist_event()
x_exist_event
Definition: xpred.c:3787
ptr_psi_term aaaa_1
Definition: def_struct.h:239
long load_aim()
load_aim
Definition: login.c:2232
#define function_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1408
GENERIC heap_pointer
used to allocate from heap - size allocated subtracted - adj for alignment
Definition: def_glob.h:55
long main_loop_ok
Definition: def_glob.h:1023
long do_residuation_user()
do_residuation_user()
Definition: lefun.c:324
void restore_resid(ptr_resid_block rb, ptr_psi_term *match_date)
restore_resid
Definition: lefun.c:1417
void show_count()
show_count
Definition: login.c:1161
ptr_goal goal_stack
Definition: def_glob.h:1025
void undo(ptr_stack limit)
undo
Definition: login.c:691
long unify_aim()
unify_aim
Definition: login.c:1344
GENERIC cccc_1
Definition: def_struct.h:241
#define general_cut
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1114
#define implies_cut
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1107
#define XEVENTDELAY
Maximum number of goals executed between event polling.
Definition: def_const.h:240
#define NULL
Definition: def_const.h:533
long steptrace
Definition: def_glob.h:915
void type_disj_aim()
type_disj_aim
Definition: login.c:1845
ptr_goal resid_aim
Definition: def_glob.h:865
#define c_what_next
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1163
ptr_resid_list resid_vars
Definition: def_glob.h:866
#define eval
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1086
void release_resid(ptr_psi_term t)
release_resid
Definition: lefun.c:445
void traceline(char *format,...)
traceline
Definition: error.c:186
long stepcount
Definition: def_glob.h:916
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
long clause_aim(long r)
clause_aim
Definition: login.c:1879
long goal_count
Definition: def_glob.h:678
void infoline(char *format,...)
infoline
Definition: error.c:281
goals type
Definition: def_struct.h:238
void do_currying()
do_currying
Definition: lefun.c:383
#define freeze_cut
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1100
#define TRUE
Standard boolean.
Definition: def_const.h:268
static void clean_trail(ptr_choice_point cutpt)
clean_trail
Definition: login.c:810
#define what_next
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1079
#define match
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1121
#define FALSE
Standard boolean.
Definition: def_const.h:275
long unify_aim_noeval()
unify_aim_noeval
Definition: login.c:1354
#define clause
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1135
long stepflag
Definition: def_glob.h:676
#define cut_to(C)
Definition: def_macro.h:85
#define fail
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1044
ptr_goal aim
Definition: def_glob.h:1024
#define retract
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1149
#define unify
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1058
long xeventdelay
Definition: def_glob.h:941
long eval_aim()
eval_aim
Definition: lefun.c:497
#define load
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1156
long prove_aim()
prove_aim
Definition: login.c:1645
#define unify_noeval
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1065
long curried
Definition: def_glob.h:868
#define del_clause
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1142
#define eval_cut
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1093
long disjunct_aim()
disjunct_aim
Definition: login.c:1621
void handle_interrupt()
HANDLE_INTERRUPT.
Definition: interrupt.c:52
void backtrack()
backtrack
Definition: login.c:772
#define GC_THRESHOLD
Garbage collection threshold (1/8 of MEM_SIZE is reasonable).
Definition: def_const.h:117
#define disj
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1072
#define type_disj
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1128
long interrupted
used in handling user using ctrl-c
Definition: def_glob.h:672
void warningline(char *format,...)
warningline
Definition: error.c:371
long memory_check()
memory_check
Definition: memory.c:1723
ptr_psi_term bbbb_1
Definition: def_struct.h:240
ptr_psi_term xevent_existing
Definition: def_glob.h:1037
long xcount
Definition: def_glob.h:942
long match_aim()
match_aim
Definition: lefun.c:770
long i_check_out(ptr_psi_term t)
i_check_out
Definition: lefun.c:1033
ptr_choice_point choice_stack
Definition: def_glob.h:1026
long what_next_aim()
what_next_aim
Definition: login.c:2068
ptr_goal next
Definition: def_struct.h:242
void merge ( ptr_node u,
ptr_node  v 
)

merge

Parameters
u- ptr_node *u
v- ptr_node v

MERGE(u,v) U and V are two binary trees containing the attributes fields of psi-terms. U and V are merged together, that is U becomes the union of U and V: For each label L in V and L->Vpsi_term: If L is in U Then With L->Upsi_term Do unify(Upsi_term,Vpsi_term) Else merge L->Vpsi_term in U. Unification is simply done by appending the 2 psi_terms to the unification stack. All effects must be recorded in the trail so that they can be undone on backtracking.

Definition at line 1131 of file login.c.

References merge1(), merge2(), and merge3().

1132 {
1133  merge1(u,v); /* Unify corresponding arguments */
1134  merge2(u,v); /* Evaluate lone arguments (lazy failure + eager success) */
1135  merge3(u,v); /* Merge v's loners into u & evaluate corresponding arguments */
1136 }
void merge2(ptr_node *u, ptr_node v)
merge2
Definition: login.c:949
void merge3(ptr_node *u, ptr_node v)
merge3
Definition: login.c:1004
void merge1(ptr_node *u, ptr_node v)
merge1
Definition: login.c:893
void merge1 ( ptr_node u,
ptr_node  v 
)

merge1

Parameters
u- ptr_node *u
v- ptr_node v

Unify the corresponding arguments

Definition at line 893 of file login.c.

References wl_node::data, featcmp(), wl_node::key, wl_node::left, NULL, push_goal(), wl_node::right, and unify.

894 {
895  long cmp;
896  ptr_node temp;
897 
898  if (v) {
899  if (*u==NULL) {
900  /* push_ptr_value(int_ptr,u); */
901  /* (*u)=STACK_ALLOC(node); */
902  /* **u= *v; */
903  /* more_v_attr=TRUE; */
904  }
905  else {
906  cmp=featcmp((*u)->key,v->key);
907  if (cmp==0) {
908  if (v->right)
909  merge1(&((*u)->right),v->right);
910 
912 
913  if (v->left)
914  merge1(&((*u)->left),v->left);
915  }
916  else if (cmp>0) {
917  temp=v->right;
918  v->right=NULL;
919  merge1(&((*u)->left),v);
920  merge1(u,temp);
921  v->right=temp;
922  }
923  else {
924  temp=v->left;
925  v->left=NULL;
926  merge1(&((*u)->right),v);
927  merge1(u,temp);
928  v->left=temp;
929  }
930  }
931  }
932  else if (*u!=NULL) {
933  /* more_u_attr=TRUE; */
934  }
935 }
void push_goal(goals t, ptr_psi_term aaaa_5, ptr_psi_term bbbb_5, GENERIC cccc_5)
push_goal
Definition: login.c:600
GENERIC data
Definition: def_struct.h:201
#define NULL
Definition: def_const.h:533
ptr_node left
Definition: def_struct.h:199
char * key
Definition: def_struct.h:198
#define unify
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1058
long featcmp(char *str1, char *str2)
featcmp
Definition: trees.c:106
ptr_node right
Definition: def_struct.h:200
void merge1(ptr_node *u, ptr_node v)
merge1
Definition: login.c:893
void merge2 ( ptr_node u,
ptr_node  v 
)

merge2

Parameters
u- ptr_node *u
v- ptr_node v

Evaluate the lone arguments (For LAZY failure + EAGER success) Evaluate low numbered lone arguments first. For each lone argument in either u or v, create a new psi-term to put the (useless) result: This is needed so that all arguments of a uni- unified psi-term are evaluated, which avoids incorrect 'Yes' answers.

Definition at line 949 of file login.c.

References wl_node::data, deref2_rec_eval(), featcmp(), wl_node::key, wl_node::left, NULL, and wl_node::right.

950 {
951  long cmp;
952  ptr_node temp;
953 
954  if (v) {
955  if (*u==NULL) {
956  ptr_psi_term t;
957  merge2(u,v->right);
958  t = (ptr_psi_term) v->data;
959  deref2_rec_eval(t); /* Assumes goal_stack is already restored. */
960  merge2(u,v->left);
961  }
962  else {
963  cmp=featcmp((*u)->key,v->key);
964  if (cmp==0) {
965  /* if (v->right) */
966  merge2(&((*u)->right),v->right);
967 
968  /* if (v->left) */
969  merge2(&((*u)->left),v->left);
970  }
971  else if (cmp>0) {
972  temp=v->right;
973  v->right=NULL;
974  merge2(&((*u)->left),v);
975  merge2(u,temp);
976  v->right=temp;
977  }
978  else {
979  temp=v->left;
980  v->left=NULL;
981  merge2(&((*u)->right),v);
982  merge2(u,temp);
983  v->left=temp;
984  }
985  }
986  }
987  else if (*u!=NULL) {
988  ptr_psi_term t;
989  merge2(&((*u)->right),v);
990  t = (ptr_psi_term) (*u)->data;
991  deref2_rec_eval(t); /* Assumes goal_stack is already restored. */
992  merge2(&((*u)->left),v);
993  }
994 }
void deref2_rec_eval(ptr_psi_term t)
deref2_rec_eval
Definition: lefun.c:1382
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
ptr_node left
Definition: def_struct.h:199
char * key
Definition: def_struct.h:198
void merge2(ptr_node *u, ptr_node v)
merge2
Definition: login.c:949
long featcmp(char *str1, char *str2)
featcmp
Definition: trees.c:106
ptr_node right
Definition: def_struct.h:200
void merge3 ( ptr_node u,
ptr_node  v 
)

merge3

Parameters
u- ptr_node *u
v- ptr_node v

Merge v's loners into u and evaluate the corresponding arguments

Definition at line 1004 of file login.c.

References deref2_eval(), featcmp(), int_ptr, wl_node::key, wl_node::left, more_u_attr, more_v_attr, NULL, push_ptr_value(), wl_node::right, STACK_ALLOC, and TRUE.

1005 {
1006  long cmp;
1007  ptr_node temp;
1008 
1009  if (v) {
1010  if (*u==NULL) {
1012  (*u)=STACK_ALLOC(node);
1013  **u= *v;
1014  more_v_attr=TRUE;
1015  }
1016  else {
1017  ptr_psi_term t1; // ,t2;
1018 
1019  cmp=featcmp((*u)->key,v->key);
1020  if (cmp==0) {
1021  if (v->right)
1022  merge3(&((*u)->right),v->right);
1023 
1024  t1 = (ptr_psi_term) (*u)->data;
1025  /* t2 = (ptr_psi_term) v->data; */
1026  deref2_eval(t1);
1027  /* deref2_eval(t2); */
1028  /* push_goal(unify,(ptr_psi_term)(*u)->data,(ptr_psi_term)v->data,NULL); */
1029 
1030  if (v->left)
1031  merge3(&((*u)->left),v->left);
1032  }
1033  else if (cmp>0) {
1034  temp=v->right;
1035  v->right=NULL;
1036  merge3(&((*u)->left),v);
1037  merge3(u,temp);
1038  v->right=temp;
1039  }
1040  else {
1041  temp=v->left;
1042  v->left=NULL;
1043  merge3(&((*u)->right),v);
1044  merge3(u,temp);
1045  v->left=temp;
1046  }
1047  }
1048  }
1049  else if (*u!=NULL) {
1050  more_u_attr=TRUE;
1051  }
1052 }
long more_u_attr
Definition: def_glob.h:944
void deref2_eval(ptr_psi_term t)
deref2_eval
Definition: lefun.c:1356
struct wl_psi_term * ptr_psi_term
quotedStackCopy
Definition: def_struct.h:62
#define NULL
Definition: def_const.h:533
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
#define TRUE
Standard boolean.
Definition: def_const.h:268
void merge3(ptr_node *u, ptr_node v)
merge3
Definition: login.c:1004
#define STACK_ALLOC(A)
Definition: def_macro.h:21
long featcmp(char *str1, char *str2)
featcmp
Definition: trees.c:106
void push_ptr_value(type_ptr t, GENERIC *p)
push_ptr_value
Definition: login.c:383
long more_v_attr
Definition: def_glob.h:945
ptr_node right
Definition: def_struct.h:200
#define int_ptr
values of type_ptr
Definition: def_const.h:397
void merge_unify ( ptr_node u,
ptr_node  v 
)

merge_unify

Parameters
u- ptr_node *u
v- ptr_node v

For built-ins.c

Definition at line 1146 of file login.c.

References merge1(), and merge3().

1147 {
1148  merge1(u,v); /* Unify corresponding arguments */
1149  merge3(u,v); /* Merge v's loners into u & evaluate corresponding arguments */
1150 }
void merge3(ptr_node *u, ptr_node v)
merge3
Definition: login.c:1004
void merge1(ptr_node *u, ptr_node v)
merge1
Definition: login.c:893
long no_choices ( )

no_choices

Return TRUE iff the top choice point is a what_next choice point or if there are no choice points.

Definition at line 1945 of file login.c.

References choice_stack, wl_choice_point::goal_stack, NULL, wl_goal::type, and what_next.

1946 {
1948 }
#define NULL
Definition: def_const.h:533
goals type
Definition: def_struct.h:238
#define what_next
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1079
ptr_goal goal_stack
Definition: def_struct.h:249
ptr_choice_point choice_stack
Definition: def_glob.h:1026
long num_choices ( )

num_choices

Return the number of choice points on the choice point stack

Definition at line 1956 of file login.c.

References choice_stack, and wl_choice_point::next.

1957 {
1958  long num;
1959  ptr_choice_point cp;
1960 
1961  num=0;
1962  cp=choice_stack;
1963  while (cp) {
1964  num++;
1965  cp=cp->next;
1966  }
1967  return num;
1968 }
ptr_choice_point next
Definition: def_struct.h:250
ptr_choice_point choice_stack
Definition: def_glob.h:1026
long num_vars ( ptr_node  vt)

num_vars

Parameters
vt- ptr_node vt

Return the number of variables in the variable tree.

Definition at line 1976 of file login.c.

References wl_node::left, and wl_node::right.

1977 {
1978  return (vt?(num_vars(vt->left)+1+num_vars(vt->right)):0);
1979 }
long num_vars(ptr_node vt)
num_vars
Definition: login.c:1976
ptr_node left
Definition: def_struct.h:199
ptr_node right
Definition: def_struct.h:200
long prove_aim ( )

prove_aim

PROVE_AIM() This is the proving routine. It performs one proof step, that is: finding the definition to use to prove AIM, and unifying the HEAD with the GOAL before proving. It all works by pushing sub-goals onto the goal_stack. Special cases are CUT and AND (","). Built-in predicates written in C are called.

Definition at line 1645 of file login.c.

References wl_goal::aaaa_1, wl_pair_list::aaaa_2, aim, and, wl_psi_term::attr_list, wl_goal::bbbb_1, wl_pair_list::bbbb_2, boolpredsym, c_rule, call_handlersym, can_curry, choice_stack, clean_trail(), clear_copy(), wl_psi_term::coref, curried, cut, cut_to, wl_node::data, DEFRULES, deref_args, deref_ptr, do_currying(), do_residuation_user(), eval_copy(), FALSE, function_it, get_two_args(), goal_count, goal_stack, i_check_out(), i_eval_args(), wl_node::key, wl_node::left, lf_false, lf_true, life_or, MAX_BUILT_INS, merge(), wl_pair_list::next, wl_goal::next, NULL, one, predicate_it, wl_definition::protected, prove, push_choice_point(), push_goal(), push_psi_ptr_value(), quote_copy(), resid_aim, resid_vars, wl_node::right, wl_definition::rule, set_empty, STACK, stack_add_psi_attr(), STACK_ALLOC, stack_psi_term(), wl_psi_term::status, sub_type(), succeed, traceline(), tracesym, TRUE, wl_psi_term::type, wl_definition::type_def, type_it, undef_it, and wl_psi_term::value_3.

1646 {
1647  long success=TRUE;
1648  ptr_psi_term thegoal,head,body,arg1,arg2;
1649  ptr_pair_list rule;
1650 
1651  thegoal=(ptr_psi_term )aim->aaaa_1;
1652  rule=(ptr_pair_list )aim->bbbb_1;
1653 
1654  if (thegoal && rule) {
1655 
1656  deref_ptr(thegoal); /* Evaluation is explicitly handled later. */
1657 
1658  if (thegoal->type!=and) {
1659  if (thegoal->type!=cut)
1660  if(thegoal->type!=life_or) {
1661  /* User-defined predicates with unevaluated arguments */
1662  /* Built-ins do this themselves (see built_ins.c). */
1663  /* if (!thegoal->type->evaluate_args) mark_quote(thegoal); 24.8 25.8 */
1664 
1665  if(i_check_out(thegoal)) { /* RM: Apr 6 1993 */
1666 
1667  goal_stack=aim->next;
1668  goal_count++;
1669 
1670  if ((unsigned long)rule==DEFRULES) {
1671  rule=(ptr_pair_list)thegoal->type->rule;
1672  if (thegoal->type->type_def==(def_type)predicate_it) {
1673  if (!rule) /* This can happen when RETRACT is used */
1674  success=FALSE;
1675  }
1676  else if ( thegoal->type->type_def==(def_type)function_it
1677  || ( thegoal->type->type_def==(def_type)type_it
1678  && sub_type(boolean,thegoal->type)
1679  )
1680  ) {
1681  if (thegoal->type->type_def==(def_type)function_it && !rule)
1682  /* This can happen when RETRACT is used */
1683  success=FALSE;
1684  else {
1685  ptr_psi_term bool_pred;
1686  ptr_node a;
1687  /* A function F in pred. position is called as */
1688  /* '*bool_pred*'(F), which succeeds if F returns true */
1689  /* and fails if it returns false. It can residuate too. */
1690  bool_pred=stack_psi_term(0);
1691  bool_pred->type=boolpredsym;
1692  bool_pred->attr_list=(a=STACK_ALLOC(node));
1693  a->key=one;
1694  a->left=a->right=NULL;
1695  a->data=(GENERIC) thegoal;
1697  return success; /* We're done! */
1698  }
1699  }
1700  else if (!thegoal->type->protected && thegoal->type->type_def==(def_type)undef_it) {
1701  /* Don't give an error message for undefined dynamic objects */
1702  /* that do not yet have a definition */
1703  success=FALSE;
1704  }
1705  else if (thegoal->type==lf_true || thegoal->type==lf_false) {
1706  /* What if the 'lf_true' or 'lf_false' have arguments? */
1707  success=(thegoal->type==lf_true);
1708  return success; /* We're done! */
1709  }
1710  else {
1711  /* Error: undefined predicate. */
1712  /* Call the call_handler (which may do an auto-load). */
1713  ptr_psi_term call_handler;
1714  /* mark_quote(thegoal); */
1715 
1716  /* RM: Jan 27 1993 */
1717  /* warningline("call handler invoked for %P\n",thegoal); */
1718 
1719  call_handler=stack_psi_term(0);
1720  call_handler->type=call_handlersym;
1721  stack_add_psi_attr(call_handler,"1",thegoal);
1723  return success; /* We're done! */
1724  }
1725  }
1726 
1727  if (success) {
1728 
1729  if ((unsigned long)rule<=MAX_BUILT_INS) {
1730 
1731  /* For residuation (RESPRED) */
1732  curried=FALSE;
1733  can_curry=TRUE;
1734  resid_vars=NULL;
1735  /* resid_limit=(ptr_goal )stack_pointer; 12.6 */
1736 
1737  if (thegoal->type!=tracesym) /* 26.1 */
1738  traceline("prove built-in %P\n", thegoal);
1739 
1740  /* RESPRED */ resid_aim=aim;
1741  /* Residuated predicate must return success=TRUE */
1742  success=c_rule[(unsigned long)rule]();
1743 
1744  /* RESPRED */ if (curried)
1745  /* RESPRED */ do_currying();
1746  /* RESPRED */ else if (resid_vars)
1747  /* RESPRED */ success=do_residuation_user(); /* 21.9 */ /* PVR 9.2.94 */
1748  }
1749  else {
1750 
1751  /* Evaluate arguments of a predicate call before the call. */
1752  deref_args(thegoal,set_empty);
1753 
1754  traceline("prove %P\n", thegoal);
1755 
1756  /* For residuation (RESPRED) */
1757  curried=FALSE;
1758  can_curry=TRUE;
1759  resid_vars=NULL;
1760  /* resid_limit=(ptr_goal )stack_pointer; 12.6 */
1761 
1762  while (rule && (rule->aaaa_2==NULL || rule->bbbb_2==NULL)) {
1763  rule=rule->next;
1764  traceline("alternative clause has been retracted\n");
1765  }
1766  if (rule) {
1767 
1768  clear_copy();
1769  if (TRUE) /* 8.9 */
1770  /* if (thegoal->type->evaluate_args) 8.9 */
1771  head=eval_copy(rule->aaaa_2,STACK);
1772  else
1773  head=quote_copy(rule->aaaa_2,STACK);
1774 
1775  body=eval_copy(rule->bbbb_2,STACK);
1776 
1777  /* What does this do?? */
1778  /* if (body->type==built_in) */
1779  /* body->coref=head; */
1780 
1781  if (rule->next)
1782  push_choice_point(prove,thegoal,(ptr_psi_term)rule->next,NULL);
1783 
1784  if (body->type!=succeed)
1786 
1787  /* push_ptr_value(psi_term_ptr,&(head->coref)); 9.6 */
1788  push_psi_ptr_value(head,(GENERIC *)&(head->coref));
1789  head->coref=thegoal;
1790  merge(&(thegoal->attr_list),head->attr_list);
1791  if (!head->status) {
1792  (void)i_eval_args(head->attr_list);
1793  }
1794  }
1795  else {
1796  success=FALSE;
1797  }
1798  }
1799  }
1800  }
1801  }
1802  else { /* ';' built-in */
1803  /* RM: Apr 6 1993 */
1804  goal_stack=aim->next;
1805  goal_count++;
1806  get_two_args(thegoal->attr_list,&arg1,&arg2);
1809  }
1810  else { /* 'Cut' built-in*/
1811  goal_stack=aim->next;
1812  goal_count++;
1813  /* assert((ptr_choice_point)(thegoal->value)<=choice_stack); 12.7 */
1814  cut_to(thegoal->value_3); /* 12.7 */
1815 #ifdef CLEAN_TRAIL
1817 #endif
1818  traceline("cut all choice points back to %x\n",choice_stack);
1819  }
1820  }
1821  else { /* 'And' built-in */
1822  goal_stack=aim->next;
1823  goal_count++;
1824  get_two_args(thegoal->attr_list,&arg1,&arg2);
1827  }
1828  }
1829  else
1830  success=FALSE;
1831 
1832  /* RESPRED */ resid_aim=NULL;
1833  return success;
1834 }
#define prove
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1051
ptr_psi_term aaaa_1
Definition: def_struct.h:239
ptr_psi_term aaaa_2
Definition: def_struct.h:205
#define function_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1408
#define undef_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1394
ptr_definition succeed
symbol in bi module
Definition: def_glob.h:389
void clear_copy()
clear_copy
Definition: copy.c:53
struct wl_definition * def_type
Definition: def_struct.h:60
ptr_definition lf_false
symbol in bi module
Definition: def_glob.h:284
long do_residuation_user()
do_residuation_user()
Definition: lefun.c:324
ptr_goal goal_stack
Definition: def_glob.h:1025
ptr_definition cut
symbol in syntax module
Definition: def_glob.h:242
ptr_pair_list next
Definition: def_struct.h:207
void push_goal(goals t, ptr_psi_term aaaa_5, ptr_psi_term bbbb_5, GENERIC cccc_5)
push_goal
Definition: login.c:600
long(* c_rule[MAX_BUILT_INS])()
Definition: def_glob.h:888
def_type type_def
Definition: def_struct.h:153
#define predicate_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1401
#define set_empty
Set constants for deref_args in lefun.c.
Definition: def_const.h:493
#define DEFRULES
Must be different from NULL, a built-in index, and a pointer Used to indicate that the rules of the d...
Definition: def_const.h:302
ptr_definition call_handlersym
symbol in bi module
Definition: def_glob.h:508
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
ptr_goal resid_aim
Definition: def_glob.h:865
void merge(ptr_node *u, ptr_node v)
merge
Definition: login.c:1131
ptr_definition and
symbol in syntax module
Definition: def_glob.h:171
ptr_resid_list resid_vars
Definition: def_glob.h:866
void stack_add_psi_attr(ptr_psi_term t, char *attrname, ptr_psi_term g)
stack_add_psi_attr
Definition: token.c:239
ptr_node left
Definition: def_struct.h:199
long sub_type(ptr_definition t1, ptr_definition t2)
sub_type
Definition: types.c:1642
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
ptr_psi_term quote_copy(ptr_psi_term t, long heap_flag)
quote_copy
Definition: copy.c:186
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
long goal_count
Definition: def_glob.h:678
void push_psi_ptr_value(ptr_psi_term q, GENERIC *p)
push_psi_ptr_value
Definition: login.c:474
#define deref_ptr(P)
Definition: def_macro.h:100
void do_currying()
do_currying
Definition: lefun.c:383
char * key
Definition: def_struct.h:198
#define TRUE
Standard boolean.
Definition: def_const.h:268
static void clean_trail(ptr_choice_point cutpt)
clean_trail
Definition: login.c:810
ptr_pair_list rule
Definition: def_struct.h:148
#define FALSE
Standard boolean.
Definition: def_const.h:275
ptr_psi_term stack_psi_term(long stat)
stack_psi_term
Definition: lefun.c:21
GENERIC value_3
Definition: def_struct.h:186
struct wl_pair_list * ptr_pair_list
Definition: def_struct.h:64
#define cut_to(C)
Definition: def_macro.h:85
ptr_psi_term bbbb_2
Definition: def_struct.h:206
ptr_goal aim
Definition: def_glob.h:1024
ptr_psi_term coref
Definition: def_struct.h:188
void get_two_args(ptr_node t, ptr_psi_term *a, ptr_psi_term *b)
get_two_args
Definition: login.c:47
char * one
Definition: def_glob.h:891
#define STACK_ALLOC(A)
Definition: def_macro.h:21
long can_curry
Definition: def_glob.h:869
long i_eval_args(ptr_node n)
i_eval_args
Definition: lefun.c:874
long curried
Definition: def_glob.h:868
#define deref_args(P, S)
Definition: def_macro.h:150
#define MAX_BUILT_INS
Maximum number of built_ins.
Definition: def_const.h:154
ptr_psi_term eval_copy(ptr_psi_term t, long heap_flag)
eval_copy
Definition: copy.c:196
ptr_definition lf_true
symbol in bi module
Definition: def_glob.h:410
ptr_definition type
Definition: def_struct.h:181
ptr_psi_term bbbb_1
Definition: def_struct.h:240
ptr_definition boolpredsym
symbol in bi module
Definition: def_glob.h:192
ptr_node attr_list
Definition: def_struct.h:187
long i_check_out(ptr_psi_term t)
i_check_out
Definition: lefun.c:1033
void push_choice_point(goals t, ptr_psi_term aaaa_6, ptr_psi_term bbbb_6, GENERIC cccc_6)
push_choice_point
Definition: login.c:638
ptr_choice_point choice_stack
Definition: def_glob.h:1026
#define STACK
Flag to indicate stack allocation.
Definition: def_const.h:331
ptr_node right
Definition: def_struct.h:200
ptr_definition tracesym
symbol in bi module
Definition: def_glob.h:424
ptr_definition life_or
symbol in syntax module
Definition: def_glob.h:326
ptr_goal next
Definition: def_struct.h:242
void push2_ptr_value ( type_ptr  t,
GENERIC p,
GENERIC  v 
)

push2_ptr_value

Parameters
t- type_ptr t
p- GENERIC *p
v- GENERIC v

PUSH2_PTR_VALUE(t,*p,v) Push the pair (P,V) onto the stack of things to be undone (trail). It needn't be done if P is greater than the latest choice point because in that case memory is reclaimed.

Definition at line 573 of file login.c.

References wl_stack::aaaa_3, wl_stack::bbbb_3, choice_stack, wl_stack::next, STACK_ALLOC, stack_pointer, wl_stack::type, and undo_stack.

574 {
575  ptr_stack n;
576 
577  if (p<(GENERIC *)choice_stack || p>(GENERIC *)stack_pointer) {
578  n=STACK_ALLOC(stack);
579  n->type=t;
580  n->aaaa_3= (GENERIC *)p;
581  n->bbbb_3= (GENERIC *)v;
582  n->next=undo_stack;
583  undo_stack=n;
584  }
585 }
GENERIC stack_pointer
used to allocate from stack - size allocated added - adj for alignment
Definition: def_glob.h:69
GENERIC * bbbb_3
Definition: def_struct.h:233
ptr_stack undo_stack
Definition: def_glob.h:1027
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
type_ptr type
Definition: def_struct.h:231
#define STACK_ALLOC(A)
Definition: def_macro.h:21
GENERIC * aaaa_3
Definition: def_struct.h:232
ptr_stack next
Definition: def_struct.h:234
ptr_choice_point choice_stack
Definition: def_glob.h:1026
void push_choice_point ( goals  t,
ptr_psi_term  aaaa_6,
ptr_psi_term  bbbb_6,
GENERIC  cccc_6 
)

push_choice_point

Parameters
t- goals t
aaaa_6ptr_psi_term aaaa_6
bbbb_6ptr_psi_term bbbb_6
cccc_6GENERIC cccc_6

PUSH_CHOICE_POINT(t,a,b,c) T,A,B,C is an alternative goal to try. T is the type of the goal: unify or prove.

If T=prove then a=goal to prove b=definition to use if b=DEFRULES then that means it's a first call.

If T=unify then a and b are the terms to unify.

etc...

Definition at line 638 of file login.c.

References wl_goal::aaaa_1, wl_goal::bbbb_1, wl_goal::cccc_1, choice_stack, FALSE, global_time_stamp, wl_choice_point::goal_stack, goal_stack, wl_goal::next, wl_choice_point::next, wl_goal::pending, STACK_ALLOC, stack_pointer, wl_choice_point::stack_top, wl_choice_point::time_stamp, wl_goal::type, wl_choice_point::undo_point, and undo_stack.

639 {
640  ptr_goal alternative;
641  ptr_choice_point choice;
642  GENERIC top_loc;
643 
644  alternative=STACK_ALLOC(goal);
645 
646  alternative->type=t;
647  alternative->aaaa_1=aaaa_6;
648  alternative->bbbb_1=bbbb_6;
649  alternative->cccc_1=cccc_6;
650  alternative->next=goal_stack;
651  alternative->pending=FALSE;
652 
653  top_loc=stack_pointer;
654 
655  choice=STACK_ALLOC(choice_point);
656 
657  choice->undo_point=undo_stack;
658  choice->goal_stack=alternative;
659  choice->next=choice_stack;
660  choice->stack_top=top_loc;
661 
662 #ifdef TS
663  choice->time_stamp=global_time_stamp; /* 9.6 */
664  global_time_stamp++; /* 9.6 */
665 #endif
666 
667  choice_stack=choice;
668 }
GENERIC stack_pointer
used to allocate from stack - size allocated added - adj for alignment
Definition: def_glob.h:69
ptr_psi_term aaaa_1
Definition: def_struct.h:239
ptr_goal goal_stack
Definition: def_glob.h:1025
GENERIC cccc_1
Definition: def_struct.h:241
ptr_stack undo_point
Definition: def_struct.h:248
GENERIC stack_top
Definition: def_struct.h:251
unsigned long time_stamp
Definition: def_struct.h:247
ptr_choice_point next
Definition: def_struct.h:250
ptr_stack undo_stack
Definition: def_glob.h:1027
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
goals type
Definition: def_struct.h:238
#define FALSE
Standard boolean.
Definition: def_const.h:275
#define STACK_ALLOC(A)
Definition: def_macro.h:21
ptr_goal goal_stack
Definition: def_struct.h:249
unsigned long global_time_stamp
Definition: login.c:28
ptr_psi_term bbbb_1
Definition: def_struct.h:240
ptr_definition pending
Definition: def_struct.h:243
ptr_choice_point choice_stack
Definition: def_glob.h:1026
ptr_goal next
Definition: def_struct.h:242
void push_def_ptr_value ( ptr_psi_term  q,
GENERIC p 
)

push_def_ptr_value

Parameters
q- ptr_psi_term q
p- GENERIC *p

PUSH_DEF_PTR_VALUE(q,p) (9.6) Same as push_ptr_value, but only for psi-terms whose definition field is being modified. (If another field is modified, use push_ptr_value.) This routine implements the time-stamp technique of only trailing once between choice point creations, even on multiple bindings. q is address of psi-term, p is address of field inside psi-term that is modified. Both the definition and the time_stamp must be trailed.

Definition at line 416 of file login.c.

References wl_stack::aaaa_3, assert, wl_stack::bbbb_3, choice_stack, def_ptr, global_time_stamp, heap_pointer, int_ptr, wl_stack::next, push_ptr_value(), STACK_ALLOC, stack_pointer, trail_condition(), wl_stack::type, undo_stack, and VALID_ADDRESS.

417 {
418  ptr_stack m,n;
419 
420  assert(VALID_ADDRESS(q));
421  assert(VALID_ADDRESS(p));
422 #ifdef TS
423  if (trail_condition(q) &&
424  /* (q->time_stamp != global_time_stamp) && */
425  (p < (GENERIC *)choice_stack || p > (GENERIC *)stack_pointer))
426  {
427 #define TRAIL_TS
428 #ifdef TRAIL_TS
429 
430  assert((GENERIC)q<heap_pointer); /* RM: Feb 15 1993 */
431 
432  m=STACK_ALLOC(stack); /* Trail time_stamp */
433  m->type=int_ptr;
434  m->aaaa_3= (GENERIC *) &(q->time_stamp);
435  m->bbbb_3= (GENERIC *) (q->time_stamp);
436  m->next=undo_stack;
437  n=STACK_ALLOC(stack); /* Trail definition field (top of undo_stack) */
438  n->type=def_ptr;
439  n->aaaa_3= p;
440  n->bbbb_3= (GENERIC *)*p;
441  n->next=m;
442  undo_stack=n;
443 #else
444  n=STACK_ALLOC(stack); /* Trail definition field (top of undo_stack) */
445  n->type=def_ptr;
446  n->aaaa_3= p;
447  n->bbbb_3= (GENERIC *) *p;
448  n->next=undo_stack;
449  undo_stack=n;
450 #endif
451  q->time_stamp=global_time_stamp;
452  }
453 #else
455 #endif
456 }
GENERIC stack_pointer
used to allocate from stack - size allocated added - adj for alignment
Definition: def_glob.h:69
#define VALID_ADDRESS(A)
Definition: def_macro.h:137
GENERIC heap_pointer
used to allocate from heap - size allocated subtracted - adj for alignment
Definition: def_glob.h:55
#define def_ptr
values of type_ptr
Definition: def_const.h:404
GENERIC * bbbb_3
Definition: def_struct.h:233
ptr_stack undo_stack
Definition: def_glob.h:1027
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
long trail_condition(psi_term *Q)
trail_condition
Definition: login.c:2630
type_ptr type
Definition: def_struct.h:231
#define STACK_ALLOC(A)
Definition: def_macro.h:21
GENERIC * aaaa_3
Definition: def_struct.h:232
unsigned long global_time_stamp
Definition: login.c:28
ptr_stack next
Definition: def_struct.h:234
void push_ptr_value(type_ptr t, GENERIC *p)
push_ptr_value
Definition: login.c:383
ptr_choice_point choice_stack
Definition: def_glob.h:1026
#define assert(N)
Definition: memory.c:114
#define int_ptr
values of type_ptr
Definition: def_const.h:397
void push_goal ( goals  t,
ptr_psi_term  aaaa_5,
ptr_psi_term  bbbb_5,
GENERIC  cccc_5 
)

push_goal

Parameters
t- goals t
aaaa_5ptr_psi_term aaaa_5
bbbb_5ptr_psi_term bbbb_5
cccc_5GENERIC cccc_5

PUSH_GOAL(t,a,b,c) Push a goal onto the goal stack. T is the type of the goal, A,B and C are various parameters. See PUSH_CHOICE_POINT(t,a,b,c).

Definition at line 600 of file login.c.

References wl_goal::aaaa_1, wl_goal::bbbb_1, wl_goal::cccc_1, FALSE, goal_stack, wl_goal::next, wl_goal::pending, STACK_ALLOC, and wl_goal::type.

601 {
602  ptr_goal thegoal;
603 
604  thegoal=STACK_ALLOC(goal);
605 
606  thegoal->type=t;
607  thegoal->aaaa_1=aaaa_5;
608  thegoal->bbbb_1=bbbb_5;
609  thegoal->cccc_1=cccc_5;
610  thegoal->next=goal_stack;
611  thegoal->pending=FALSE;
612 
613  goal_stack=thegoal;
614 }
ptr_psi_term aaaa_1
Definition: def_struct.h:239
ptr_goal goal_stack
Definition: def_glob.h:1025
GENERIC cccc_1
Definition: def_struct.h:241
goals type
Definition: def_struct.h:238
#define FALSE
Standard boolean.
Definition: def_const.h:275
#define STACK_ALLOC(A)
Definition: def_macro.h:21
ptr_psi_term bbbb_1
Definition: def_struct.h:240
ptr_definition pending
Definition: def_struct.h:243
ptr_goal next
Definition: def_struct.h:242
void push_psi_ptr_value ( ptr_psi_term  q,
GENERIC p 
)

push_psi_ptr_value

Parameters
q- ptr_psi_term q
p- GENERIC *p

PUSH_PSI_PTR_VALUE(q,p) (9.6) Same as push_ptr_value, but only for psi-terms whose coref field is being modified. (If another field is modified, use push_ptr_value.) This routine implements the time-stamp technique of only trailing once between choice point creations, even on multiple bindings. q is address of psi-term, p is address of field inside psi-term that is modified. Both the coref and the time_stamp must be trailed.

Definition at line 474 of file login.c.

References wl_stack::aaaa_3, assert, wl_stack::bbbb_3, choice_stack, global_time_stamp, int_ptr, wl_stack::next, psi_term_ptr, push_ptr_value(), STACK_ALLOC, stack_pointer, trail_condition(), wl_stack::type, undo_stack, and VALID_ADDRESS.

475 {
476  ptr_stack m,n;
477 
478  assert(VALID_ADDRESS(q));
479  assert(VALID_ADDRESS(p));
480 #ifdef TS
481  if (trail_condition(q) &&
482  /* (q->time_stamp != global_time_stamp) && */
483  (p < (GENERIC *)choice_stack || p > (GENERIC *)stack_pointer))
484  {
485 #define TRAIL_TS
486 #ifdef TRAIL_TS
487  m=STACK_ALLOC(stack); /* Trail time_stamp */
488  m->type=int_ptr;
489  m->aaaa_3= (GENERIC *) &(q->time_stamp);
490  m->bbbb_3= (GENERIC *) (q->time_stamp);
491  m->next=undo_stack;
492  n=STACK_ALLOC(stack); /* Trail coref field (top of undo_stack) */
493  n->type=psi_term_ptr;
494  n->aaaa_3= (GENERIC *) p;
495  n->bbbb_3= (GENERIC *) *p;
496  n->next=m;
497  undo_stack=n;
498 #else
499  n=STACK_ALLOC(stack); /* Trail coref field (top of undo_stack) */
500  n->type=psi_term_ptr;
501  n->aaaa_3= (ptr_psi_term)p;
502  n->bbbb_3= *p;
503  n->next=undo_stack;
504  undo_stack=n;
505 #endif
506  q->time_stamp=global_time_stamp;
507  }
508 #else
510 #endif
511 }
GENERIC stack_pointer
used to allocate from stack - size allocated added - adj for alignment
Definition: def_glob.h:69
#define VALID_ADDRESS(A)
Definition: def_macro.h:137
GENERIC * bbbb_3
Definition: def_struct.h:233
struct wl_psi_term * ptr_psi_term
quotedStackCopy
Definition: def_struct.h:62
ptr_stack undo_stack
Definition: def_glob.h:1027
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
long trail_condition(psi_term *Q)
trail_condition
Definition: login.c:2630
type_ptr type
Definition: def_struct.h:231
#define STACK_ALLOC(A)
Definition: def_macro.h:21
GENERIC * aaaa_3
Definition: def_struct.h:232
unsigned long global_time_stamp
Definition: login.c:28
ptr_stack next
Definition: def_struct.h:234
void push_ptr_value(type_ptr t, GENERIC *p)
push_ptr_value
Definition: login.c:383
ptr_choice_point choice_stack
Definition: def_glob.h:1026
#define assert(N)
Definition: memory.c:114
#define psi_term_ptr
values of type_ptr
Definition: def_const.h:383
#define int_ptr
values of type_ptr
Definition: def_const.h:397
void push_ptr_value ( type_ptr  t,
GENERIC p 
)

push_ptr_value

Parameters
t- type_ptr t
p- GENERIC *p

PUSH_PTR_VALUE(t,*p) Push the pair (P,*P) onto the stack of things to be undone (trail). It needn't be done if P is greater than the latest choice point because in that case memory is reclaimed.

Definition at line 383 of file login.c.

References wl_stack::aaaa_3, assert, wl_stack::bbbb_3, choice_stack, heap_pointer, wl_stack::next, STACK_ALLOC, stack_pointer, wl_stack::type, undo_stack, and VALID_ADDRESS.

384 {
385  ptr_stack n;
386 
387  assert(p<(GENERIC *)heap_pointer); /* RM: Feb 15 1993 */
388 
389  assert(VALID_ADDRESS(p));
390  if (p < (GENERIC *)choice_stack || p > (GENERIC *)stack_pointer)
391  {
392  n=STACK_ALLOC(stack);
393  n->type=t;
394  n->aaaa_3= (GENERIC *) p;
395  n->bbbb_3= (GENERIC *) *p;
396  n->next=undo_stack;
397  undo_stack=n;
398  }
399 }
GENERIC stack_pointer
used to allocate from stack - size allocated added - adj for alignment
Definition: def_glob.h:69
#define VALID_ADDRESS(A)
Definition: def_macro.h:137
GENERIC heap_pointer
used to allocate from heap - size allocated subtracted - adj for alignment
Definition: def_glob.h:55
GENERIC * bbbb_3
Definition: def_struct.h:233
ptr_stack undo_stack
Definition: def_glob.h:1027
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
type_ptr type
Definition: def_struct.h:231
#define STACK_ALLOC(A)
Definition: def_macro.h:21
GENERIC * aaaa_3
Definition: def_struct.h:232
ptr_stack next
Definition: def_struct.h:234
ptr_choice_point choice_stack
Definition: def_glob.h:1026
#define assert(N)
Definition: memory.c:114
void push_ptr_value_global ( type_ptr  t,
GENERIC p 
)

push_ptr_value_global

Parameters
t- type_ptr t
p- GENERIC *p

Same as push_ptr_value, but for objects that must always be trailed. This includes objects outside of the Life data space and entries in the var_tree.

Definition at line 523 of file login.c.

References wl_stack::aaaa_3, assert, wl_stack::bbbb_3, wl_stack::next, STACK_ALLOC, wl_stack::type, undo_stack, and VALID_ADDRESS.

524 {
525  ptr_stack n;
526 
527  assert(VALID_ADDRESS(p)); /* 17.8 */
528  n=STACK_ALLOC(stack);
529  n->type=t;
530  n->aaaa_3= (GENERIC *) p;
531  n->bbbb_3= (GENERIC *) *p;
532  n->next=undo_stack;
533  undo_stack=n;
534 }
#define VALID_ADDRESS(A)
Definition: def_macro.h:137
GENERIC * bbbb_3
Definition: def_struct.h:233
ptr_stack undo_stack
Definition: def_glob.h:1027
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
type_ptr type
Definition: def_struct.h:231
#define STACK_ALLOC(A)
Definition: def_macro.h:21
GENERIC * aaaa_3
Definition: def_struct.h:232
ptr_stack next
Definition: def_struct.h:234
#define assert(N)
Definition: memory.c:114
void push_window ( long  type,
long  disp,
long  wind 
)

push_window

Parameters
type- long type
disp- long disp
wind- long wind

PUSH_WINDOW(type,disp,wind) Push the window information (operation, display and window identifiers) on the undo_stack (trail) so that the window can be destroyed, redrawn, or hidden on backtracking.

Definition at line 548 of file login.c.

References wl_stack::aaaa_3, assert, wl_stack::bbbb_3, wl_stack::next, STACK_ALLOC, wl_stack::type, undo_action, and undo_stack.

549 {
550  ptr_stack n;
551 
552  assert(type & undo_action);
553  n=STACK_ALLOC(stack);
554  n->type=type;
555  n->aaaa_3=(GENERIC *)disp;
556  n->bbbb_3=(GENERIC *)wind;
557  n->next=undo_stack;
558  undo_stack=n;
559 }
GENERIC * bbbb_3
Definition: def_struct.h:233
ptr_stack undo_stack
Definition: def_glob.h:1027
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
type_ptr type
Definition: def_struct.h:231
#define STACK_ALLOC(A)
Definition: def_macro.h:21
GENERIC * aaaa_3
Definition: def_struct.h:232
#define undo_action
Fast checking for an undo action.
Definition: def_const.h:484
ptr_stack next
Definition: def_struct.h:234
#define assert(N)
Definition: memory.c:114
void reset_stacks ( )

reset_stacks

Called when level jumps back to zero. Setting these two pointers to NULL causes an exit from main_prove and will then reset all other global information.

Definition at line 2047 of file login.c.

References choice_stack, goal_stack, NULL, and undo().

2048 {
2049  undo(NULL); /* 8.10 */
2050  goal_stack=NULL;
2052 #ifdef TS
2053  /* global_time_stamp=INIT_TIME_STAMP; */ /* 9.6 */
2054 #endif
2055 }
ptr_goal goal_stack
Definition: def_glob.h:1025
void undo(ptr_stack limit)
undo
Definition: login.c:691
#define NULL
Definition: def_const.h:533
ptr_choice_point choice_stack
Definition: def_glob.h:1026
void show_count ( )

show_count

SHOW_COUNT() This routine doesn't do anything if not in verbose mode. It prints the number of of sub-goals attempted, along with cpu-time spent during the proof etc...

Definition at line 1161 of file login.c.

References end_time, goal_count, heap_pointer, mem_base, mem_limit, NOTQUIET, stack_info(), stack_pointer, and verbose.

1162 {
1163  float t;
1164 
1165  if (verbose) {
1166  printf(" [");
1167 
1168  (void)times(&end_time);
1169  t = (end_time.tms_utime - start_time.tms_utime)/60.0;
1170 
1171  printf("%1.3fs cpu, %ld goal%s",t,goal_count,(goal_count!=1?"s":""));
1172 
1173  if (t!=0.0) printf(" (%0.0f/s)",goal_count/t);
1174 
1175  printf(", %ld stack",sizeof(mem_base)*(stack_pointer-mem_base));
1176  printf(", %ld heap",sizeof(mem_base)*(mem_limit-heap_pointer));
1177 
1178  printf("]");
1179  }
1180 
1181  if(NOTQUIET) {
1182  printf("\n");
1183  stack_info(stdout);
1184  }
1185 
1186  goal_count=0;
1187 }
GENERIC stack_pointer
used to allocate from stack - size allocated added - adj for alignment
Definition: def_glob.h:69
GENERIC heap_pointer
used to allocate from heap - size allocated subtracted - adj for alignment
Definition: def_glob.h:55
GENERIC mem_limit
starting point of heap - mem_base aligned
Definition: def_glob.h:62
#define NOTQUIET
Definition: def_macro.h:15
long verbose
Definition: def_glob.h:914
long goal_count
Definition: def_glob.h:678
void stack_info(FILE *outfile)
stack_info
Definition: error.c:77
struct tms start_time end_time
Definition: def_glob.h:939
GENERIC mem_base
mem_size memory allocated in init_memory by malloc
Definition: def_glob.h:48
void start_chrono ( )

start_chrono

START_CHRONO() This initialises the CPU time counter.

Definition at line 349 of file login.c.

350 {
351  (void)times(&start_time);
352 }
ptr_choice_point topmost_what_next ( )

topmost_what_next

UNUSED 12.7 Return the choice point corresponding to the first 'what_next' choice point in the choice point stack. Return NULL if there is none. This is used to ensure that cuts don't go below the most recent 'what_next' choice point.

Definition at line 2026 of file login.c.

References choice_stack, wl_choice_point::goal_stack, wl_choice_point::next, NULL, wl_goal::type, and what_next.

2027 {
2029 
2030  while (cp && cp->goal_stack && cp->goal_stack->type!=what_next)
2031  cp=cp->next;
2032 
2033  if (cp && cp->goal_stack && cp->goal_stack->type==what_next)
2034  return cp;
2035  else
2036  return (ptr_choice_point) NULL;
2037 }
#define NULL
Definition: def_const.h:533
ptr_choice_point next
Definition: def_struct.h:250
goals type
Definition: def_struct.h:238
#define what_next
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1079
ptr_goal goal_stack
Definition: def_struct.h:249
ptr_choice_point choice_stack
Definition: def_glob.h:1026
long trail_condition ( psi_term Q)

trail_condition

Parameters
Q- psi_term *Q

Definition at line 2630 of file login.c.

References choice_stack, and wl_choice_point::time_stamp.

2631 {
2632  return (choice_stack && choice_stack->time_stamp>=Q->time_stamp);
2633 }
unsigned long time_stamp
Definition: def_struct.h:247
ptr_choice_point choice_stack
Definition: def_glob.h:1026
void type_disj_aim ( )

type_disj_aim

TYPE_DISJ_AIM() This routine implements type disjunctions, that is, when a type has been decoded and found to be a disjunction of types, enumerates the different values one by one.

Definition at line 1845 of file login.c.

References wl_goal::aaaa_1, aim, wl_definition::always_check, wl_psi_term::attr_list, wl_goal::bbbb_1, def_ptr, FALSE, fetch_def(), wl_definition::keyword, wl_int_list::next, NULL, push_choice_point(), push_ptr_value(), wl_psi_term::status, wl_keyword::symbol, traceline(), wl_psi_term::type, type_disj, and wl_int_list::value_1.

1846 {
1847  ptr_psi_term t;
1848  ptr_int_list d;
1849 
1850  t=(ptr_psi_term)aim->aaaa_1;
1851  d=(ptr_int_list)aim->bbbb_1;
1852 
1853  if (d->next) {
1854  traceline("pushing type disjunction choice point for %P\n", t);
1856  }
1857 
1858  push_ptr_value(def_ptr,(GENERIC *)&(t->type));
1859  /* Below makes cut.lf behave incorrectly: */
1860  /* push_def_ptr_value(t,&(t->type)); */ /* 14.8 */
1861  t->type=(ptr_definition)d->value_1;
1862 
1863  traceline("setting type disjunction to %s.\n", t->type->keyword->symbol);
1864 
1865  if ((t->attr_list || t->type->always_check) && t->status<4)
1866  fetch_def(t, FALSE);
1867 }
ptr_psi_term aaaa_1
Definition: def_struct.h:239
#define def_ptr
values of type_ptr
Definition: def_const.h:404
ptr_keyword keyword
Definition: def_struct.h:147
struct wl_psi_term * ptr_psi_term
quotedStackCopy
Definition: def_struct.h:62
#define NULL
Definition: def_const.h:533
char * symbol
Definition: def_struct.h:118
char always_check
Definition: def_struct.h:154
void traceline(char *format,...)
traceline
Definition: error.c:186
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
#define FALSE
Standard boolean.
Definition: def_const.h:275
struct wl_definition * ptr_definition
Definition: def_struct.h:59
ptr_goal aim
Definition: def_glob.h:1024
#define type_disj
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1128
ptr_definition type
Definition: def_struct.h:181
GENERIC value_1
Definition: def_struct.h:85
ptr_psi_term bbbb_1
Definition: def_struct.h:240
void fetch_def(ptr_psi_term u, long allflag)
fetch_def
Definition: login.c:1208
ptr_node attr_list
Definition: def_struct.h:187
void push_ptr_value(type_ptr t, GENERIC *p)
push_ptr_value
Definition: login.c:383
void push_choice_point(goals t, ptr_psi_term aaaa_6, ptr_psi_term bbbb_6, GENERIC cccc_6)
push_choice_point
Definition: login.c:638
ptr_int_list next
Definition: def_struct.h:86
void undo ( ptr_stack  limit)

undo

Parameters
limit- ptr_stack limit

UNDO(limit) Undoes any side-effects up to LIMIT. Limit being the adress of the stack of side-effects you wish to return to.

Possible improvement: LIMIT is a useless parameter because GOAL_STACK is equivalent if one takes care when stacking UNDO actions. Namely, anything to be undone must be stacked LATER (=after) the goal which caused these things to be done, so that when the goal fails, everything done after it can be undone and the memory used can be reclaimed. This routine could be modified in order to cope with goals to be proved on backtracking: undo(goal).

Definition at line 691 of file login.c.

References wl_stack::aaaa_3, wl_stack::bbbb_3, destroy_window, hide_subwindow, hide_window, wl_stack::next, show_subwindow, show_window, wl_stack::type, undo_action, undo_stack, x_destroy_window(), x_hide_subwindow(), x_hide_window(), x_show_subwindow(), and x_show_window().

692 {
693  /*
694  while((unsigned long)undo_stack>(unsigned long)goal_stack)
695  */
696 
697  while ((unsigned long)undo_stack>(unsigned long)limit) {
698 #ifdef X11
699  if (undo_stack->type & undo_action) {
700  /* Window operation on backtracking */
701  switch(undo_stack->type) { /*** RM 8/12/92 ***/
702  case destroy_window:
703  x_destroy_window((Display *)undo_stack->aaaa_3,(Window)undo_stack->bbbb_3);
704  break;
705  case show_window:
706  x_show_window((Display *)undo_stack->aaaa_3,(Window)undo_stack->bbbb_3);
707  break;
708  case hide_window:
709  x_hide_window((Display *)undo_stack->aaaa_3,(Window)undo_stack->bbbb_3);
710  break;
711  case show_subwindow:
712  x_show_subwindow((Display *)undo_stack->aaaa_3,(Window)undo_stack->bbbb_3);
713  break;
714  case hide_subwindow:
715  x_hide_subwindow((Display *)undo_stack->aaaa_3,(Window)undo_stack->bbbb_3);
716  break;
717  }
718  }
719  else
720 #endif
721  /* Restoring variable value on backtracking */
724  }
725 }
#define show_subwindow
To backtrack on show sub windows RM 8/12/92.
Definition: def_const.h:470
#define hide_subwindow
To backtrack on hide sub windows RM 8/12/92.
Definition: def_const.h:477
#define show_window
To backtrack on show window.
Definition: def_const.h:456
void x_show_subwindow(Display *display, long window)
x_show_subwindow
Definition: xpred.c:3901
void x_hide_subwindow(Display *display, long window)
x_hide_subwindow
Definition: xpred.c:3915
GENERIC * bbbb_3
Definition: def_struct.h:233
void x_show_window(Display *display, long window)
x_show_window
Definition: xpred.c:3871
#define destroy_window
To backtrack on window creation.
Definition: def_const.h:449
#define hide_window
To backtrack on hide window.
Definition: def_const.h:463
ptr_stack undo_stack
Definition: def_glob.h:1027
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
type_ptr type
Definition: def_struct.h:231
void x_hide_window(Display *display, long window)
x_hide_window
Definition: xpred.c:3885
GENERIC * aaaa_3
Definition: def_struct.h:232
#define undo_action
Fast checking for an undo action.
Definition: def_const.h:484
ptr_stack next
Definition: def_struct.h:234
void x_destroy_window(Display *display, Window window)
x_destroy_window
Definition: xpred.c:3852
void undo_actions ( )

undo_actions

UNDO_ACTIONS() A subset of undo(limit) (the detrailing routine) that does all undo actions on the undo_stack, but does not undo any variable bindings, nor does it change the value of undo_stack.

Definition at line 736 of file login.c.

References Errorline(), NULL, and undo().

737 {
738  // ptr_stack u=undo_stack;
739 
740  Errorline("undo_actions should not be called.\n");
741  undo(NULL); /* 8.10 */
742  return;
743  /*
744  #ifdef X11
745  while ((unsigned long)u) {
746  if (u->type & undo_action) {
747  if (u->type==destroy_window) {
748  x_destroy_window((unsigned long)u->aaaa_3,(unsigned long)u->bbbb_3);
749  }
750  else if (u->type==show_window) {
751  x_show_window((unsigned long)u->aaaa_3,(unsigned long)u->bbbb_3);
752  }
753  else if (u->type==hide_window) {
754  x_hide_window((unsigned long)u->aaaa_3,(unsigned long)u->bbbb_3);
755  }
756  }
757  u=u->next;
758  }
759  #endif
760  */
761 }
void undo(ptr_stack limit)
undo
Definition: login.c:691
#define NULL
Definition: def_const.h:533
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
long unify_aim ( )

unify_aim

UNIFY_AIM() This routine performs one unification step. AIM is the current unification goal.

U and V are the two psi-terms to unify.

It swaps the two psi-terms into chronological order. U is the oldest (smallest stack address). Calculates their GLB, check their values are unifiable. It deals with all the messy things like: curried functions gaining missing arguments, types which need checking, residuation variables whose constraints must be released, disjunctions appearing in the GLB etc...

It's a rather lengthy routine, only its speed is fairly crucial in the overall performance of Wild_Life, and the code is not duplicated elsewhere.

Definition at line 1344 of file login.c.

References TRUE, and unify_body().

1345 {
1346  return unify_body(TRUE);
1347 }
long unify_body(long eval_flag)
unify_body
Definition: login.c:1365
#define TRUE
Standard boolean.
Definition: def_const.h:268
long unify_aim_noeval ( )

unify_aim_noeval

Definition at line 1354 of file login.c.

References FALSE, and unify_body().

1355 {
1356  return unify_body(FALSE);
1357 }
long unify_body(long eval_flag)
unify_body
Definition: login.c:1365
#define FALSE
Standard boolean.
Definition: def_const.h:275
long unify_body ( long  eval_flag)

unify_body

Parameters
eval_flag- long eval_flag

Definition at line 1365 of file login.c.

References wl_goal::aaaa_1, aim, wl_psi_term::attr_list, wl_goal::bbbb_1, wl_psi_term::coref, cut, cut_ptr, decode(), def_ptr, deref, deref_ptr, equal_types, Errorline(), FALSE, fetch_def_lazy(), wl_psi_term::flags, function_it, glb(), global_unify(), heap_pointer, int_ptr, integer, wl_definition::keyword, merge(), more_u_attr, more_v_attr, new_stat, wl_int_list::next, NULL, overlap_type(), push_choice_point(), push_psi_ptr_value(), push_ptr_value(), quoted_string, QUOTED_TRUE, REAL, real, release_resid(), wl_psi_term::resid, wl_psi_term::status, sub_type(), wl_keyword::symbol, sys_bytedata, traceline(), TRUE, wl_psi_term::type, wl_definition::type_def, type_disj, type_it, u_func, v_func, wl_int_list::value_1, wl_psi_term::value_3, and warningline().

1366 {
1367  long success=TRUE,compare;
1368  ptr_psi_term u,v,tmp;
1369  REAL r;
1370  ptr_definition new_type,old1,old2;
1371  ptr_node old1attr, old2attr;
1372  ptr_int_list new_code;
1373  ptr_int_list d=NULL;
1374  long old1stat,old2stat; /* 18.2.94 */
1375 
1376  u=(ptr_psi_term )aim->aaaa_1;
1377  v=(ptr_psi_term )aim->bbbb_1;
1378 
1379  deref_ptr(u);
1380  deref_ptr(v);
1381 
1382  traceline("unify %P with %P\n",u,v);
1383 
1384  if (eval_flag) {
1385  deref(u);
1386  deref(v);
1387  }
1388 
1389  if (u!=v) {
1390 
1391  /**** Swap the two psi-terms to get them into chronological order ****/
1392  if (u>v) { tmp=v; v=u; u=tmp; }
1393 
1394  /**** Check for curried functions ****/
1397  old1stat=u->status; /* 18.2.94 */
1398  old2stat=v->status; /* 18.2.94 */
1399 
1400  /* PVR 18.2.94 */
1401  /* if (u_func && !(u->flags&QUOTED_TRUE) && v->attr_list) { */
1402  if (u_func && u->status==4 && !(u->flags&QUOTED_TRUE) && v->attr_list) {
1403  Errorline("attempt to unify with curried function %P\n", u);
1404  return FALSE;
1405  }
1406  /* if (v_func && !(v->flags&QUOTED_TRUE) && u->attr_list) { */
1407  if (v_func && v->status==4 && !(v->flags&QUOTED_TRUE) && u->attr_list) {
1408  Errorline("attempt to unify with curried function %P\n", v);
1409  return FALSE;
1410  }
1411 
1412 
1413 #ifdef ARITY /* RM: Mar 29 1993 */
1414  arity_unify(u,v);
1415 #endif
1416 
1417  /***** Deal with global vars **** RM: Feb 8 1993 */
1418  if((GENERIC) v>=heap_pointer)
1419  return global_unify(u,v);
1420 
1421 
1422  /**** Calculate their Greatest Lower Bound and compare them ****/
1423  success=(compare=glb(u->type,v->type,&new_type,&new_code));
1424 
1425  if (success) {
1426 
1427  /**** Keep the old types for later use in incr. constraint checking ****/
1428  old1 = u->type;
1429  old2 = v->type;
1430  old1attr = u->attr_list;
1431  old2attr = v->attr_list;
1432 
1433  /**** DECODE THE RESULTING TYPE ****/
1434  if (!new_type) {
1435  d=decode(new_code);
1436  if (d) {
1437  new_type=(ptr_definition)d->value_1;
1438  d=d->next;
1439  }
1440  else
1441  Errorline("undecipherable sort code.\n");
1442  }
1443 
1444  /**** Make COMPARE a little more precise ****/
1445  if (compare==1)
1446  if (u->value_3 && !v->value_3)
1447  compare=2;
1448  else
1449  if (v->value_3 && !u->value_3)
1450  compare=3;
1451 
1452  /**** Determine the status of the resulting psi-term ****/
1453  new_stat=4;
1454  switch (compare) {
1455  case 1:
1456  if (u->status <4 && v->status <4)
1457  new_stat=2;
1458  break;
1459  case 2:
1460  if (u->status<4)
1461  new_stat=2;
1462  break;
1463  case 3:
1464  if (v->status<4)
1465  new_stat=2;
1466  break;
1467  case 4:
1468  new_stat=2;
1469  break;
1470  }
1471 
1472  /*
1473  printf("u=%s, v=%s, compare=%ld, u.s=%ld, v.s=%ld, ns=%ld\n",
1474  u->type->keyword->symbol,
1475  v->type->keyword->symbol,
1476  compare,
1477  u->status,
1478  v->status,
1479  new_stat);
1480  */
1481 
1482  /**** Check that integers have no decimals ****/
1483  if (u->value_3 && sub_type(new_type,integer)) {
1484  r= *(REAL *)u->value_3;
1485  success=(r==floor(r));
1486  }
1487  if (success && v->value_3 && sub_type(new_type,integer)) {
1488  r= *(REAL *)v->value_3;
1489  success=(r==floor(r));
1490  }
1491 
1492  /**** Unify the values of INTs REALs STRINGs LISTs etc... ****/
1493  if (success) {
1494  /* LAZY-EAGER */
1495  if (u->value_3!=v->value_3)
1496  if (!u->value_3) {
1497  compare=4;
1499  u->value_3=v->value_3;
1500  }
1501  else if (v->value_3) {
1502  if (overlap_type(new_type,real))
1503  success=(*((REAL *)u->value_3)==(*((REAL *)v->value_3)));
1504  else if (overlap_type(new_type,quoted_string))
1505  success=(strcmp((char *)u->value_3,(char *)v->value_3)==0);
1506  else if (overlap_type(new_type,sys_bytedata)) {
1507  unsigned long ulen = *((unsigned long *)u->value_3);
1508  unsigned long vlen = *((unsigned long *)v->value_3);
1509  success=(ulen==vlen &&
1510  (bcmp((char *)u->value_3,(char *)v->value_3,ulen)==0));
1511  }
1512  else if (u->type==cut && v->type==cut) { /* 22.9 */
1513  ptr_psi_term mincut;
1514  mincut = (ptr_psi_term) (u->value_3 < (GENERIC) v->value_3? u->value_3 : v->value_3);
1515  if (mincut!=(ptr_psi_term)u->value_3) {
1517  u->value_3=(GENERIC)mincut;
1518  }
1519  }
1520  else {
1521  warningline("'%s' may not be unified.\n",new_type->keyword->symbol);
1522  success=FALSE;
1523  }
1524  }
1525  else
1526  compare=4;
1527  }
1528 
1529  /**** Bind the two psi-terms ****/
1530  if (success) {
1531  /* push_ptr_value(psi_term_ptr,(ptr_psi_term *)&(v->coref)); 9.6 */
1532  push_psi_ptr_value(v,(GENERIC *)&(v->coref));
1533  v->coref=u;
1534 
1535  if (!equal_types(u->type,new_type)) {
1536  push_ptr_value(def_ptr,(GENERIC *)&(u->type));
1537  /* This does not seem to work right with cut.lf: */
1538  /* push_def_ptr_value(u,&(u->type_3)); */ /* 14.8 */
1539  u->type=new_type;
1540  }
1541 
1542  if (u->status!=new_stat) {
1544  u->status=new_stat;
1545  }
1546 
1547  /**** Unify the attributes ****/
1550 
1551 
1552 #ifdef ARITY /* RM: Mar 29 1993 */
1553  arity_merge(u->attr_list,v->attr_list);
1554 #endif
1555 
1556 
1557  if (u->attr_list || v->attr_list)
1558  merge(&(u->attr_list),v->attr_list);
1559 
1560  /**** Look after curried functions ****/
1561  /*
1562  if ((u_func && more_v_attr) || (v_func && more_u_attr)) {
1563  if (!(u->flags&QUOTED_TRUE | v->flags&QUOTED_TRUE)) {
1564  traceline("re-evaluating curried expression %P\n", u);
1565  if (u->status!=0) {
1566  push_ptr_value(int_ptr,(ptr_psi_term *)&(u->status));
1567  u->status=0;
1568  }
1569  check_func(u);
1570  }
1571  }
1572  */
1573 
1574  if (v->flags&QUOTED_TRUE && !(u->flags&QUOTED_TRUE)) { /* 16.9 */
1575  push_ptr_value(int_ptr,(GENERIC *)&(u->flags));
1576  u->flags|=QUOTED_TRUE;
1577  }
1578 
1579  /**** RELEASE RESIDUATIONS ****/
1580  /* This version implements the correct semantics. */
1581  if (u->resid)
1582  release_resid(u);
1583  if (v->resid)
1584  release_resid(v);
1585 
1586  /**** Alternatives in a type disjunction ****/
1587  if (d) {
1588  traceline("pushing type disjunction choice point for %P\n",u);
1590  }
1591 
1592  /**** VERIFY CONSTRAINTS ****/
1593  /* if ((old1stat<4 || old2stat<4) &&
1594  (u->type->type==type || v->type->type==type)) { 18.2.94 */
1595  if (new_stat<4 && u->type->type_def==(def_type)type_it) {
1596  /* This does not check the already-checked properties */
1597  /* (i.e. those in types t with t>=old1 or t>=old2), */
1598  /* and it does not check anything if u has no attributes. */
1599  /* It will, however, check the unchecked properties if a */
1600  /* type gains attributes. */
1601  fetch_def_lazy(u, old1, old2,
1602  old1attr, old2attr,
1603  old1stat, old2stat);
1604  }
1605  }
1606  }
1607  }
1608  return success;
1609 }
ptr_psi_term aaaa_1
Definition: def_struct.h:239
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
int global_unify(ptr_psi_term u, ptr_psi_term v)
global_unify
Definition: modules.c:1053
GENERIC heap_pointer
used to allocate from heap - size allocated subtracted - adj for alignment
Definition: def_glob.h:55
struct wl_definition * def_type
Definition: def_struct.h:60
ptr_definition integer
symbol in bi module
Definition: def_glob.h:312
long glb(ptr_definition t1, ptr_definition t2, ptr_definition *t3, ptr_int_list *c3)
glb
Definition: types.c:1481
#define def_ptr
values of type_ptr
Definition: def_const.h:404
long new_stat
Definition: def_glob.h:948
ptr_definition cut
symbol in syntax module
Definition: def_glob.h:242
ptr_int_list decode(ptr_int_list c)
decode
Definition: types.c:1784
void fetch_def_lazy(ptr_psi_term u, ptr_definition old1, ptr_definition old2, ptr_node old1attr, ptr_node old2attr, long old1stat, long old2stat)
fetch_def_lazy
Definition: login.c:1276
def_type type_def
Definition: def_struct.h:153
long more_u_attr
Definition: def_glob.h:944
ptr_keyword keyword
Definition: def_struct.h:147
struct wl_psi_term * ptr_psi_term
quotedStackCopy
Definition: def_struct.h:62
#define cut_ptr
values of type_ptr 22.9
Definition: def_const.h:425
#define NULL
Definition: def_const.h:533
#define REAL
Which C type to use to represent reals and integers in Wild_Life.
Definition: def_const.h:132
char * symbol
Definition: def_struct.h:118
void merge(ptr_node *u, ptr_node v)
merge
Definition: login.c:1131
long overlap_type(ptr_definition t1, ptr_definition t2)
overlap_type
Definition: types.c:1579
ptr_definition sys_bytedata
symbol in sys module
Definition: def_glob.h:983
void release_resid(ptr_psi_term t)
release_resid
Definition: lefun.c:445
long sub_type(ptr_definition t1, ptr_definition t2)
sub_type
Definition: types.c:1642
void traceline(char *format,...)
traceline
Definition: error.c:186
ptr_definition real
symbol in bi module
Definition: def_glob.h:375
#define type_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1415
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
void push_psi_ptr_value(ptr_psi_term q, GENERIC *p)
push_psi_ptr_value
Definition: login.c:474
#define deref_ptr(P)
Definition: def_macro.h:100
#define TRUE
Standard boolean.
Definition: def_const.h:268
long v_func
Definition: def_glob.h:947
long u_func
Definition: def_glob.h:947
#define FALSE
Standard boolean.
Definition: def_const.h:275
#define deref(P)
Definition: def_macro.h:147
struct wl_definition * ptr_definition
Definition: def_struct.h:59
GENERIC value_3
Definition: def_struct.h:186
ptr_goal aim
Definition: def_glob.h:1024
ptr_psi_term coref
Definition: def_struct.h:188
#define equal_types(A, B)
Definition: def_macro.h:111
#define type_disj
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1128
void warningline(char *format,...)
warningline
Definition: error.c:371
ptr_definition type
Definition: def_struct.h:181
GENERIC value_1
Definition: def_struct.h:85
ptr_psi_term bbbb_1
Definition: def_struct.h:240
#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 push_ptr_value(type_ptr t, GENERIC *p)
push_ptr_value
Definition: login.c:383
ptr_definition quoted_string
symbol in bi module
Definition: def_glob.h:368
void push_choice_point(goals t, ptr_psi_term aaaa_6, ptr_psi_term bbbb_6, GENERIC cccc_6)
push_choice_point
Definition: login.c:638
long more_v_attr
Definition: def_glob.h:945
ptr_int_list next
Definition: def_struct.h:86
#define int_ptr
values of type_ptr
Definition: def_const.h:397
long what_next_aim ( )

what_next_aim

WHAT_NEXT_AIM() Find out what the user wants to do: a) retry current goal -> ';' b) quit current goal -> RETURN c) add current goal -> 'new goal ?' d) return to top level -> '.'

Definition at line 2068 of file login.c.

References wl_goal::aaaa_1, aborthooksym, aim, assert_clause(), assert_first, wl_goal::bbbb_1, begin_terminal_io(), wl_goal::cccc_1, current_module, DEFRULES, encode_types(), end_terminal_io(), eof, EOLN, FACT, FALSE, function_it, infoline(), MAX_LEVEL, wl_module::module_name, no_choices(), NOTQUIET, NULL, parse(), print_variables(), PROMPT, prompt, prompt_buffer, prove, push_choice_point(), push_goal(), put_back_char(), QUERY, read_char(), release_resid(), reset_stacks(), reset_step(), show_count(), stack_copy_psi_term(), start_chrono(), stdin_cleareof(), TRUE, TRUEMASK, wl_psi_term::type, wl_definition::type_def, undo(), undo_stack, user_module, var_occurred, what_next, what_next_cut(), x_read_stdin_or_event(), x_window_creation, and xevent_existing.

2069 {
2070  long result=FALSE;
2071  ptr_psi_term s;
2072  long c, c2; /* 21.12 (prev. char) */
2073  char *pr;
2074  long sort,cut_loc=FALSE;
2075  long level,i;
2076  long eventflag;
2077  ptr_stack save_undo_stack;
2078  long lev1,lev2;
2080 
2081  level=((unsigned long)aim->cccc_1);
2082 
2083  if (aim->aaaa_1) {
2084  /* Must remember var_occurred from the what_next goal and from */
2085  /* execution of previous query (it may have contained a parse) */
2086  var_occurred=var_occurred || ((unsigned long)aim->bbbb_1)&TRUEMASK; /* 18.8 */
2087  eventflag=(((unsigned long)aim->bbbb_1)&(TRUEMASK*2))!=0;
2088  if (
2089  !var_occurred && no_choices() && level>0
2090 #ifdef X11
2091  /* Keep level same if no window & no X event */
2092  && !x_window_creation && !eventflag
2093 #endif
2094  ) {
2095  /* Keep level the same if in a query, the number of choice points */
2096  /* has not increased and there are no variables. */
2097  /* This has to have the same behavior as if an EOLN was typed */
2098  /* and no 'No' message should be given on the lowest level, */
2099  level--;
2100  (void)what_next_cut();
2101  if (level==0) { result=TRUE; }
2102  }
2103  }
2104 
2105 #ifdef X11
2107 #endif
2108 
2109  infoline(aim->aaaa_1?"\n*** Yes":"\n*** No");
2110  show_count();
2111  if (aim->aaaa_1 || level>0 ) (void)print_variables(NOTQUIET); // had commente || ... DJD
2112 
2113  {
2114  if (level > 0 && aborthooksym->type_def != (def_type)function_it )
2115  {
2116  lev1=MAX_LEVEL<level?MAX_LEVEL:(level);
2117  lev2=level;
2118  }
2119  else
2120  {
2121  lev1 = 0;
2122  lev2 = 0;
2123  }
2124 
2125  pr=prompt_buffer;
2126  /* RM: Oct 13 1993 */
2128  *pr='\0';
2129  else
2130  strcpy(pr,current_module->module_name);
2131  pr += strlen(pr);
2132  for(i=1;i<=lev1;i++) { *pr='-'; pr++; *pr='-'; pr++; }
2133  if (lev2>0)
2134  sprintf(pr,"%ld",lev2);
2135  strcat(pr,PROMPT);
2136 
2138  }
2139 
2140  stdin_cleareof();
2141  /* The system waits for either an input command or an X event. */
2142  /* An X event is treated *exactly* like an input command that */
2143  /* has the same effect. */
2144 #ifdef X11
2145  c=x_read_stdin_or_event(&eventflag);
2146  if (eventflag) {
2147  /* Include eventflag info in var_occurred field. */
2148  push_goal(what_next,(ptr_psi_term)TRUE,(ptr_psi_term)(FALSE+2*TRUE),(GENERIC)level /* +1 RM: Jun 22 1993 */);
2150  result=TRUE;
2151  }
2152  else
2153 #else
2154  c=read_char();
2155 #endif
2156  {
2157  while (c!=EOLN && c>0 && c<=32 && c!=EOF) {
2158  c=read_char();
2159  }
2160  if (c==EOF) {
2161  reset_stacks();
2162  }
2163  else if (c==EOLN) {
2164  cut_loc=TRUE;
2165  }
2166  else if (c==';' || c=='.') {
2167  do {
2168  c2=read_char();
2169  } while (c2!=EOLN && c2!=EOF && c2>0 && c2<=32);
2170  if (c=='.') { /* 6.10 */
2171  reset_stacks();
2172  result=TRUE;
2173  }
2174  }
2175  else {
2177 
2178  put_back_char(c);
2180  save_undo_stack=undo_stack;
2181  s=stack_copy_psi_term(parse(&sort));
2182 
2183  if (s->type==eof) {
2184  reset_stacks();
2185  put_back_char(EOF);
2186  } else if (sort==QUERY) {
2189  reset_step();
2190  result=TRUE;
2191  }
2192  else if (sort==FACT) { /* A declaration */
2193  push_goal(what_next,(ptr_psi_term)TRUE,(ptr_psi_term)FALSE,(GENERIC)(level + 1)); /* 18.5 */ // HERE
2195  assert_clause(s);
2196  /* Variables in the query may be used in a declaration, */
2197  /* but the declaration may not add any variables. */
2198  undo(save_undo_stack); /* 17.8 */
2199  encode_types();
2200  result=TRUE;
2201  }
2202  else {
2203  /* Stay at same level on syntax error */
2204  push_goal(what_next,(ptr_psi_term)TRUE,(ptr_psi_term)FALSE,(GENERIC)(level+1)); /* 20.8 */
2205  result=TRUE; /* 20.8 */
2206  }
2207  }
2208  }
2209 
2210  if (cut_loc) result = what_next_cut() || result;
2211 
2212  end_terminal_io();
2213 
2214  var_occurred=FALSE;
2215  start_chrono();
2216 
2217  return result;
2218 }
void assert_clause(ptr_psi_term t)
assert_clause
Definition: login.c:287
#define prove
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1051
long what_next_cut()
what_next_cut
Definition: login.c:1987
void reset_stacks()
reset_stacks
Definition: login.c:2047
ptr_psi_term aaaa_1
Definition: def_struct.h:239
#define function_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1408
long assert_first
Definition: def_glob.h:1032
void put_back_char(long c)
put_back_char
Definition: token.c:729
ptr_module user_module
Default module for user input.
Definition: def_glob.h:694
void show_count()
show_count
Definition: login.c:1161
#define NOTQUIET
Definition: def_macro.h:15
psi_term parse(long *q)
parse
Definition: parser.c:907
char prompt_buffer[PROMPT_BUFFER]
Definition: def_glob.h:878
#define TRUEMASK
Standard boolean.
Definition: def_const.h:282
void undo(ptr_stack limit)
undo
Definition: login.c:691
void reset_step()
reset_step
Definition: error.c:665
ptr_module current_module
The current module for the tokenizer.
Definition: def_glob.h:729
void push_goal(goals t, ptr_psi_term aaaa_5, ptr_psi_term bbbb_5, GENERIC cccc_5)
push_goal
Definition: login.c:600
GENERIC cccc_1
Definition: def_struct.h:241
def_type type_def
Definition: def_struct.h:153
#define DEFRULES
Must be different from NULL, a built-in index, and a pointer Used to indicate that the rules of the d...
Definition: def_const.h:302
#define FACT
Fact Kind of user input.
Definition: def_const.h:338
#define NULL
Definition: def_const.h:533
#define PROMPT
Head of prompt.
Definition: def_const.h:218
#define QUERY
Query Kind of user input.
Definition: def_const.h:345
long x_window_creation
Definition: def_glob.h:1046
void release_resid(ptr_psi_term t)
release_resid
Definition: lefun.c:445
ptr_stack undo_stack
Definition: def_glob.h:1027
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
#define EOLN
End of line.
Definition: def_const.h:309
#define MAX_LEVEL
Maximum indent level.
Definition: def_const.h:232
void end_terminal_io()
end_terminal_io
Definition: token.c:516
long x_read_stdin_or_event(long *ptreventflag)
x_read_stdin_or_event
Definition: xpred.c:3578
void infoline(char *format,...)
infoline
Definition: error.c:281
void begin_terminal_io()
begin_terminal_io
Definition: token.c:493
#define TRUE
Standard boolean.
Definition: def_const.h:268
ptr_definition eof
symbol in syntax module
Definition: def_glob.h:263
#define what_next
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1079
#define FALSE
Standard boolean.
Definition: def_const.h:275
ptr_goal aim
Definition: def_glob.h:1024
char * module_name
Definition: def_struct.h:106
ptr_psi_term stack_copy_psi_term(psi_term t)
stack_copy_psi_term
Definition: parser.c:205
void encode_types()
encode_types
Definition: types.c:1091
void start_chrono()
start_chrono
Definition: login.c:349
char * prompt
Definition: def_glob.h:1018
long print_variables(long printflag)
print_variables
Definition: print.c:1368
long read_char()
read_char
Definition: token.c:680
long no_choices()
no_choices
Definition: login.c:1945
ptr_definition type
Definition: def_struct.h:181
ptr_definition aborthooksym
symbol in bi module
Definition: def_glob.h:133
ptr_psi_term bbbb_1
Definition: def_struct.h:240
void stdin_cleareof()
stdin_cleareof
Definition: token.c:51
ptr_psi_term xevent_existing
Definition: def_glob.h:1037
long var_occurred
???
Definition: def_glob.h:839
void push_choice_point(goals t, ptr_psi_term aaaa_6, ptr_psi_term bbbb_6, GENERIC cccc_6)
push_choice_point
Definition: login.c:638
long what_next_cut ( )

what_next_cut

Cut away up to and including the first 'what_next' choice point.

Definition at line 1987 of file login.c.

References backtrack(), choice_stack, FALSE, goal_stack, NULL, TRUE, wl_goal::type, undo(), and what_next.

1988 {
1989  long flag=TRUE;
1990  long result=FALSE;
1991 
1992  do {
1993  if (choice_stack) {
1994  backtrack();
1995  if (goal_stack->type==what_next) {
1996  flag=FALSE;
1997  result=TRUE;
1998  }
1999  }
2000  else {
2001  /* This undo does the last undo actions before returning to top level. */
2002  /* It is not needed for variable undoing, but for actions (like */
2003  /* closing windows). */
2004  undo(NULL);
2005  /* undo(mem_base); 7.8 */
2006 #ifdef TS
2007  /* global_time_stamp=INIT_TIME_STAMP; */ /* 9.6 */
2008 #endif
2009  flag=FALSE;
2010  }
2011  } while (flag);
2012 
2013  return result;
2014 }
ptr_goal goal_stack
Definition: def_glob.h:1025
void undo(ptr_stack limit)
undo
Definition: login.c:691
#define NULL
Definition: def_const.h:533
goals type
Definition: def_struct.h:238
#define TRUE
Standard boolean.
Definition: def_const.h:268
#define what_next
was enum (goal) – but must be long for error.c - now typedef
Definition: def_const.h:1079
#define FALSE
Standard boolean.
Definition: def_const.h:275
void backtrack()
backtrack
Definition: login.c:772
ptr_choice_point choice_stack
Definition: def_glob.h:1026

Variable Documentation

long clean_iter = 0

Definition at line 22 of file login.c.

long clean_succ = 0

Definition at line 23 of file login.c.

unsigned long global_time_stamp =INIT_TIME_STAMP

Definition at line 28 of file login.c.