Wild Life  2.30
 All Data Structures Files Functions Variables Typedefs Macros
types.c
Go to the documentation of this file.
1 
8 /* Copyright 1991 Digital Equipment Corporation.
9 ** All Rights Reserved.
10 *****************************************************************/
11 
12 #include "defs.h"
13 
15 
25 {
26  switch ((long)t) {
27  case (long)predicate_it:
28  perr("predicate");
29  break;
30  case (long)function_it:
31  perr("function");
32  break;
33  case (long)type_it:
34  perr("sort");
35  break;
36  case (long)global_it: /* RM: Feb 8 1993 */
37  perr("global variable");
38  break;
39  default:
40  perr("undefined");
41  }
42 }
43 
50 long yes_or_no()
51 {
52  char *old_prompt;
53  long c,d;
54  ptr_psi_term old_state_loc;
55 
56  perr("*** Are you really sure you want to do that ");
57  old_prompt=prompt;
58  prompt="(y/n)?";
59  old_state_loc=input_state;
60  (void)open_input_file("stdin");
61 
62  do {
63  do {
64  c=read_char();
65  } while (c!=EOLN && c>0 && c<=32);
66  } while (c!='y' && c!='n');
67 
68  d=c;
69  while (d!=EOLN && d!=EOF) d=read_char();
70 
71  prompt=old_prompt;
72  input_state=old_state_loc;
73  restore_state(old_state_loc);
74  return (c=='y');
75 }
76 
86 {
87  while (*dl) {
88  if (((ptr_definition)(*dl)->value_1)==d)
89  *dl = (*dl)->next;
90  else
91  dl= &((*dl)->next);
92  }
93 }
94 
105 {
106  ptr_definition d; // ,d2;
107  // ptr_int_list l,*l2;
108  long success=TRUE;
109 
110  deref_ptr(t);
111  d=t->type;
112  if (d->date<file_date) {
113  if (d->type_def==(def_type)type_it) {
114  /* Except for top, sorts are always unprotected, with a warning. */
115  if (FALSE /*d==top*/) {
116  Errorline("the top sort '@' may not be extended.\n");
117  success=FALSE;
118  }
119  /* RM: Mar 25 1993
120  else if (d!=top)
121  warningline("extending definition of sort '%s'.\n",d->keyword->symbol);
122  */
123  }
124  else if (d->protected && d->type_def!=(def_type)undef_it) {
125  if (d->date>0) {
126  /* The term was entered in a previous file, and therefore */
127  /* cannot be altered. */
128  Errorline("the %T '%s' may not be changed.\n", /* RM: Jan 27 1993 */
129  d->type_def, d->keyword->combined_name);
130  success=FALSE;
131  }
132  else {
133  if (d->rule && (unsigned long)d->rule<=MAX_BUILT_INS /*&& input_stream==stdin*/) {
134  /* d is a built-in, and therefore cannot be altered. */
135  Errorline("the built-in %T '%s' may not be extended.\n",
136  d->type_def, d->keyword->symbol);
137  success=FALSE;
138  }
139  else {
140  /* d is not a built-in, and therefore can be altered. */
141  warningline("extending the %T '%s'.\n",d->type_def,d->keyword->symbol);
142  if (warningflag) if (!yes_or_no()) success=FALSE;
143  }
144  }
145  }
146 
147  if (success) {
148  if (d->type_def==(def_type)type_it) { /* d is an already existing type */
149  /* Remove cycles in the type hierarchy of d */
150  /* This is done by Richard's version, and I don't know why. */
151  /* It seems to be a no-op. */
152  remove_cycles(d, &(d->children));
153  remove_cycles(d, &(d->parents));
154  /* d->rule=NULL; */ /* Types must keep their rules! */
155  /* d->properties=NULL; */ /* Types get new properties from encode */
156  }
157  if (d->date==0) d->date=file_date;
158  /* d->type=undef_it; */ /* Objects keep their type! */
159  /* d->always_check=TRUE; */
160  /* d->protected=TRUE; */
161  /* d->children=NULL; */
162  /* d->parents=NULL; */
163  /* d->code=NOT_CODED; */
164  }
165  }
166 
167  return success;
168 }
169 
180 {
181  ptr_int_list n;
182 
183  n=HEAP_ALLOC(int_list);
184  n->value_1=v;
185  n->next=l;
186 
187  return n;
188 }
189 
201 {
202  ptr_definition d1,d2;
203  long ok=FALSE;
204  deref_ptr(t1);
205  deref_ptr(t2);
206 
207  if (t1->type==top) {
208  Errorline("the top sort '@' may not be a subsort.\n");
209  return FALSE;
210  }
211  if (t1->value_3 || t2->value_3) {
212  Errorline("the declaration '%P <| %P' is illegal.\n",t1,t2);
213  return FALSE;
214  }
215  /* Note: A *full* cyclicity check of the hierarchy is done in encode_types. */
216  if (t1->type==t2->type) {
217  Errorline("cyclic sort declarations are not allowed.\n");
218  return FALSE;
219  }
220 
221  if (!redefine(t1)) return FALSE;
222  if (!redefine(t2)) return FALSE;
223  d1=t1->type;
224  d2=t2->type;
226  Errorline("the %T '%s' may not be redefined as a sort.\n",
227  d1->type_def, d1->keyword->symbol);
228  }
229  else if (d2->type_def==(def_type)predicate_it || d2->type_def==(def_type)function_it) {
230  Errorline("the %T '%s' may not be redefined as a sort.\n",
231  d2->type_def, d2->keyword->symbol);
232  }
233  else {
237  make_type_link(d1, d2); /* 1.7 */
238  /* d1->parents=cons(d2,d1->parents); */
239  /* d2->children=cons(d1,d2->children); */
240  ok=TRUE;
241  }
242 
243  return ok;
244 }
245 
255 void assert_protected(ptr_node n,long prot)
256 {
257  ptr_psi_term t;
258 
259  if (n) {
260  assert_protected(n->left,prot);
261 
262  t=(ptr_psi_term)n->data;
263  deref_ptr(t);
264  if (t->type) {
265  if (t->type->type_def==(def_type)type_it) {
266  warningline("'%s' is a sort. It can be extended without a declaration.\n",
267  t->type->keyword->symbol);
268  }
269  else if ((unsigned long)t->type->rule<MAX_BUILT_INS &&
270  (unsigned long)t->type->rule>0) {
271  if (!prot)
272  warningline("'%s' is a built-in--it has not been made dynamic.\n",
273  t->type->keyword->symbol);
274  }
275  else {
276  t->type->protected=prot;
277  if (prot) t->type->date&=(~1); else t->type->date|=1;
278  }
279  }
280 
281  assert_protected(n->right,prot);
282  }
283 }
284 
295 {
296  ptr_psi_term t;
297 
298  if (n) {
300 
301  t=(ptr_psi_term)n->data;
302  deref_ptr(t);
303  if (t->type) {
304  if (t->type->type_def==(def_type)type_it) {
305  warningline("'%s' is a sort--only functions and predicates\
306  can have unevaluated arguments.\n",t->type->keyword->symbol);
307  }
308  else
310  }
311 
313  }
314 }
315 
327 {
328  if (n) {
329  ptr_psi_term t;
331 
332  t=(ptr_psi_term)n->data;
333  deref_ptr(t);
334  if (t->type) {
335  t->type->always_check=FALSE;
336  }
337 
339  }
340 }
341 
352 {
353  ptr_definition d;
354 
355  if (n) {
356  d=((ptr_keyword)n->data)->definition;
360  }
361 }
362 
373 {
374  ptr_psi_term arg1,arg2;
375 
376  get_two_args(t->attr_list,&arg1,&arg2);
377  if(arg1==NULL || arg2==NULL) {
378  Errorline("bad sort declaration '%P' (%E).\n",t);
379  }
380  else
381  assert_ok=assert_less(arg1,arg2);
382 }
383 
406 {
407  ptr_psi_term arg2,typ1,typ2,pred=NULL;
408  // ptr_list lst;
409  long eqflag = equ_tok((*t),":=");
410  long ok, any_ok=FALSE;
411 
412  get_two_args(t->attr_list,&typ1,&arg2);
413 
414  if (typ1 && arg2) {
415  deref_ptr(typ1);
416  deref_ptr(arg2);
417  typ2=arg2;
418  if (!strcmp(arg2->type->keyword->symbol,"|")) {
419  typ2=NULL;
420  get_two_args(arg2->attr_list,&arg2,&pred);
421  if (arg2) {
422  deref_ptr(arg2);
423  typ2=arg2;
424  }
425  }
426  if (typ2) {
427  if (typ2->type==disjunction) {
428 
429  if (typ1->attr_list && eqflag) {
430  warningline("attributes ignored left of ':=' declaration (%E).\n");
431  }
432  while(typ2 && typ2->type!=nil) {
433  get_two_args(typ2->attr_list,&arg2,&typ2); /* RM: Dec 14 1992 */
434  if(typ2)
435  deref_ptr(typ2);
436  if (arg2) {
437  deref_ptr(arg2);
438  if (eqflag) {
439  ok=assert_less(arg2,typ1);
440  if (ok) any_ok=TRUE;
441  if (ok && (arg2->attr_list || pred!=NULL)) {
442  add_rule(arg2,pred,(def_type)type_it);
443  }
444  }
445  else {
446  ok=assert_less(typ1,arg2);
447  if (ok) any_ok=TRUE;
448  if (ok && arg2->attr_list) {
449  warningline("attributes ignored in sort declaration (%E).\n");
450  }
451  }
452  }
453  }
454  assert_ok=TRUE;
455  }
456  else if (eqflag) {
457  if (typ1->attr_list) {
458  warningline("attributes ignored left of ':=' declaration (%E).\n");
459  }
460  ok=assert_less(typ1,typ2);
461  if (ok) any_ok=TRUE;
462  typ2->type=typ1->type;
463  if (ok && (typ2->attr_list || pred!=NULL))
464  add_rule(typ2,pred,(def_type)type_it);
465  else
466  assert_ok=TRUE;
467  }
468  else {
469  if (typ2->attr_list) {
470  warningline("attributes ignored right of '<|' declaration (%E).\n");
471  }
472  ok=assert_less(typ1,typ2);
473  if (ok) any_ok=TRUE;
474  if (ok && (typ1->attr_list || pred!=NULL))
475  add_rule(typ1,pred,(def_type)type_it);
476  else
477  assert_ok=TRUE;
478  }
479  }
480  else {
481  Errorline("argument missing in sort declaration (%E).\n");
482  }
483  }
484  else {
485  Errorline("argument missing in sort declaration (%E).\n");
486  }
487  if (!any_ok) assert_ok=FALSE;
488 }
489 
501 {
502  ptr_psi_term arg1,arg2,pred=NULL,typ;
503  ptr_definition d;
504 
505  get_two_args(t->attr_list,&arg1,&arg2);
506 
507  if (arg1) {
508  typ=arg1;
509  deref_ptr(arg1);
510  if (!strcmp(arg1->type->keyword->symbol,"|")) {
511  get_two_args(arg1->attr_list,&arg1,&pred);
512  if (arg1) {
513  typ=arg1;
514  deref_ptr(arg1);
515  }
516  }
517 
518  if (arg1 && wl_const_3(*arg1)) {
519  /* if (!redefine(arg1)) return; RM: Feb 19 1993 */
520  d=arg1->type;
522  Errorline("the %T '%s' may not be redefined as a sort.\n",
523  d->type_def, d->keyword->symbol);
524  }
525  else {
528  add_rule(typ,pred,(def_type)type_it);
529  }
530  }
531  else {
532  Errorline("bad argument in sort declaration '%P' (%E).\n",t);
533  }
534  }
535  else {
536  Errorline("argument missing in sort declaration (%E).\n");
537  }
538 }
539 
549 void find_adults() /* RM: Feb 3 1993 */
550 
551 {
552  ptr_definition d;
553  ptr_int_list l;
554 
555  for(d=first_definition;d;d=d->next)
556  if(d->type_def==(def_type)type_it && d->parents==NULL) {
557  l=HEAP_ALLOC(int_list);
558  l->value_1=(GENERIC)d;
559  l->next=adults;
560  adults=l;
561  }
562 }
563 
576 {
577  ptr_int_list l;
578  ptr_pair_list rule;
579  ptr_triple_list *t;
580  long flag;
581 
582  l=HEAP_ALLOC(int_list);
583  l->value_1=(GENERIC)d;
584  l->next=children;
585  children=l;
586 
587  rule = d->rule;
588  while (rule) {
589  t= &(d->properties);
590  flag=TRUE;
591 
592  while (flag) {
593  if (*t)
594  if ((*t)->aaaa_4==rule->aaaa_2 && (*t)->bbbb_4==rule->bbbb_2 && (*t)->cccc_4==d)
595  flag=FALSE;
596  else
597  t= &((*t)->next);
598  else {
599  *t = HEAP_ALLOC(triple_list);
600  (*t)->aaaa_4=rule->aaaa_2;
601  (*t)->bbbb_4=rule->bbbb_2;
602  (*t)->cccc_4=d;
603  (*t)->next=NULL;
604  flag=FALSE;
605  }
606  }
607  rule=rule->next;
608  }
609 }
610 
621 {
622  ptr_int_list l;
623  ptr_triple_list *t;
624  long flag;
625 
626  l=HEAP_ALLOC(int_list);
627  l->value_1=(GENERIC)d;
628  l->next=children;
629  children=l;
630 
631  while (prop) {
632  t= &(d->properties);
633  flag=TRUE;
634 
635  while (flag) {
636  if (*t)
637  if ((*t)->aaaa_4==prop->aaaa_4 && (*t)->bbbb_4==prop->bbbb_4 && (*t)->cccc_4==prop->cccc_4)
638  flag=FALSE;
639  else
640  t= &((*t)->next);
641  else {
642  *t = HEAP_ALLOC(triple_list);
643  (*t)->aaaa_4=prop->aaaa_4;
644  (*t)->bbbb_4=prop->bbbb_4;
645  (*t)->cccc_4=prop->cccc_4;
646  (*t)->next=NULL;
647  flag=FALSE;
648  }
649  }
650  prop=prop->next;
651  }
652 }
653 
663 {
664  ptr_int_list kids;
665  ptr_definition d;
666 
667  adults=NULL;
668  find_adults();
669 
670  while (adults) {
671 
672  children=NULL;
673 
674  while (adults) {
676 
677  insert_own_prop(d);
679 
680  kids=d->children;
681 
682  while(kids) {
684  /* if (d->always_check && kids->value_1)
685  ((ptr_definition)kids->value_1)->always_check=TRUE; */
686  kids=kids->next;
687  }
688  adults=adults->next;
689  }
691  }
692 }
693 
694 /******************************************************************************
695 
696  The following routines implement sort encoding.
697 
698 */
699 
710 long count_sorts(long c0) /* RM: Feb 3 1993 */
711 {
712  ptr_definition d;
713 
714  for(d=first_definition;d;d=d->next)
715  if (d->type_def==(def_type)type_it) c0++;
716 
717  return c0;
718 }
719 
727 void clear_coding() /* RM: Feb 3 1993 */
728 {
729  ptr_definition d;
730 
731  for(d=first_definition;d;d=d->next)
732  if (d->type_def==(def_type)type_it) d->code=NOT_CODED;
733 }
734 
743 void least_sorts() /* RM: Feb 3 1993 */
744 {
745  ptr_definition d;
746 
747  for(d=first_definition;d;d=d->next)
748  if (d->type_def==(def_type)type_it && d->children==NULL && d!=nothing)
750 }
751 
759 void all_sorts() /* RM: Feb 3 1993 */
760 {
761  ptr_definition d;
762 
763  for(d=first_definition;d;d=d->next)
764  if (d->type_def==(def_type)type_it && d!=nothing)
766 }
767 
777 {
778  ptr_int_list result,code;
779  long v=1;
780 
781  code=HEAP_ALLOC(int_list);
782  code->value_1=0;
783  code->next=NULL;
784  result=code;
785 
786  while (p>=INT_SIZE) {
787  code->next=HEAP_ALLOC(int_list);
788  code=code->next;
789  code->value_1=0;
790  code->next=NULL;
791  p=p-INT_SIZE;
792  }
793 
794  v= v<<p ;
795  code->value_1=(GENERIC)v;
796 
797  return result;
798 }
799 
809 {
810  ptr_int_list code;
811 
812  code = HEAP_ALLOC(int_list);
813  code->value_1=0;
814  code->next=NULL;
815 
816  or_codes(code, u);
817 
818  return code;
819 }
820 
832 {
833  while (v) {
834  u->value_1= (GENERIC)(((unsigned long)(u->value_1)) | ((unsigned long)(v->value_1)));
835  v=v->next;
836  if (u->next==NULL && v) {
838  u=u->next;
839  u->value_1=0;
840  u->next=NULL;
841  }
842  else
843  u=u->next;
844  }
845 }
846 
859 void equalize_codes(int len) /* RM: Feb 3 1993 */
860 {
861  ptr_definition d;
862  ptr_int_list c,*ci;
863  long i;
864  int w;
865 
866  for(d=first_definition;d;d=d->next)
867  if (d->type_def==(def_type)type_it) {
868  c = d->code;
869  ci = &(d->code); /* RM: Feb 15 1993 */
870  w=len;
871 
872  /* Count how many words have to be added */
873  while (c) {
874  ci= &(c->next);
875  c=c->next;
876  w--;
877  }
878  assert(w>=0);
879  /* Add the words */
880  for (i=0; i<w; i++) {
881  *ci = HEAP_ALLOC(int_list);
882  (*ci)->value_1=0;
883  ci= &((*ci)->next);
884  }
885  (*ci)=NULL;
886  }
887 }
888 
902 {
903  if (t2!=top && !type_member(t2,t1->parents))
904  t1->parents=cons((GENERIC)t2,t1->parents);
905  if (t2!=top && !type_member(t1,t2->children))
906  t2->children=cons((GENERIC)t1,t2->children);
907 }
908 
919 {
920  while (tlst) {
921  if (t==(ptr_definition)tlst->value_1) return TRUE;
922  tlst=tlst->next;
923  }
924  return FALSE;
925 }
926 
934 {
935  perr_s("%s",d->keyword->symbol);
936 }
937 
945 {
946  if (anc) {
947  perr_sort_list(anc->next);
948  if (anc->next) perr(" <| ");
950  }
951 }
952 
960 {
962  perr(" <| ");
963  perr_sort_list(anc);
964 }
965 
978 {
979  ptr_int_list p=d->parents;
980  ptr_definition pd;
981  long errflag;
982  int_list anc2;
983 
984  while (p) {
985  pd=(ptr_definition)p->value_1;
986  /* If unmarked, mark and recurse */
987  if (pd->code==NOT_CODED) {
988  pd->code = (ptr_int_list)TRUE;
989  anc2.value_1=(GENERIC)pd;
990  anc2.next=anc;
991  errflag=type_cyclicity(pd,&anc2);
992  if (errflag) return TRUE;
993  }
994  /* If marked, check if it's in the ancestor list */
995  else {
996  if (type_member(pd,anc)) {
997  Errorline("there is a cycle in the sort hierarchy\n");
998  perr("*** Cycle: [");
999  perr_sort_cycle(anc);
1000  perr("]\n");
1001  exit_life(TRUE);
1002  return TRUE;
1003  }
1004  }
1005  p=p->next;
1006  }
1007  return FALSE;
1008 }
1009 
1023 {
1024  ptr_int_list child_list;
1025  ptr_definition child;
1026 
1027  child_list = d->children;
1028  while (child_list) {
1029  child = (ptr_definition)child_list->value_1;
1030  if (child->always_check) {
1031  child->always_check = FALSE;
1032  *ch = TRUE;
1033  propagate_always_check(child,ch);
1034  }
1035  child_list = child_list->next;
1036  }
1037 }
1038 
1050 {
1051  ptr_definition d;
1052 
1053 
1054  for(d=first_definition;d;d=d->next)
1055  if (d->type_def==(def_type)type_it && !d->always_check)
1056  propagate_always_check(d,ch);
1057 }
1058 
1069 {
1070  long change;
1071 
1072  do {
1073  change=FALSE;
1074  one_pass_always_check(&change);
1075  } while (change);
1076 }
1077 
1092 {
1093  long p=0,i,possible,ok=TRUE;
1094  ptr_int_list layer,l,kids,dads,code;
1095  ptr_definition xdef,kdef,ddef; //,err;
1096 
1097  if (types_modified) {
1098 
1099  nothing->parents=NULL;
1101 
1102  top->parents=NULL;
1103  top->children=NULL;
1104 
1105  /* The following definitions are vital to avoid crashes */
1107  make_type_link(lf_true,boolean);
1108  make_type_link(lf_false,boolean);
1109 
1110  /* These just might be useful */
1112  make_type_link(boolean,built_in);
1114 
1116 
1117  type_count=count_sorts(-1); /* bottom does not count */
1118  clear_coding();
1119  nothing->parents=NULL; /* Must be cleared before all_sorts */
1120  all_sorts();
1121  if (type_cyclicity(nothing,NULL)) {
1122  clear_coding();
1123  return;
1124  }
1125  clear_coding();
1126  nothing->parents=NULL; /* Must be cleared before least_sorts */
1127  least_sorts();
1128 
1129  nothing->code=NULL;
1130 
1131  /* RM: Feb 17 1993 */
1132  traceline("*** Codes:\n%C= %s\n", NULL, nothing->keyword->symbol);
1133 
1134  gamma_table=(ptr_definition *) heap_alloc(type_count*sizeof(definition));
1135 
1136  layer=nothing->parents;
1137 
1138  while (layer) {
1139  l=layer;
1140  do {
1141  xdef=(ptr_definition)l->value_1;
1142  if (xdef->code==NOT_CODED && xdef!=top) {
1143 
1144  kids=xdef->children;
1145  code=two_to_the(p);
1146 
1147  while (kids) {
1148  kdef=(ptr_definition)kids->value_1;
1149  or_codes(code,kdef->code);
1150  kids=kids->next;
1151  }
1152 
1153  xdef->code=code;
1154  gamma_table[p]=xdef;
1155 
1156  /* RM: Feb 17 1993 */
1157  traceline("%C = %s\n", code, xdef->keyword->symbol);
1158  p=p+1;
1159  }
1160 
1161  l=l->next;
1162 
1163  } while (l);
1164 
1165  l=layer;
1166  layer=NULL;
1167 
1168  do {
1169  xdef=(ptr_definition)l->value_1;
1170  dads=xdef->parents;
1171 
1172  while (dads) {
1173  ddef=(ptr_definition)dads->value_1;
1174  if(ddef->code==NOT_CODED) {
1175 
1176  possible=TRUE;
1177  kids=ddef->children;
1178 
1179  while(kids && possible) {
1180  kdef=(ptr_definition)kids->value_1;
1181  if(kdef->code==NOT_CODED)
1182  possible=FALSE;
1183  kids=kids->next;
1184  }
1185  if(possible)
1186  layer=cons((GENERIC)ddef,layer);
1187  }
1188  dads=dads->next;
1189  }
1190  l=l->next;
1191  } while(l);
1192  }
1193 
1194  top->code=two_to_the(p);
1195  for (i=0;i<p;i++)
1196  or_codes(top->code,two_to_the(i));
1197 
1198  gamma_table[p]=top;
1199 
1200  /* RM: Jan 13 1993 */
1201  /* Added the following line because type_count is now over generous
1202  because the same definition can be referenced several times in
1203  the symbol table because of modules
1204  */
1205  type_count=p+1;
1206  for(i=type_count;i<type_count;i++)
1207  gamma_table[i]=NULL;
1208 
1209  traceline("%C = @\n\n", top->code);
1210  equalize_codes(p/32+1);
1211 
1213 
1214  /* Inherit 'FALSE' always_check flags to all types' children */
1216 
1217  traceline("*** Encoding done, %d sorts\n",type_count);
1218 
1220  Errorline("the sorts 'real' and 'string' are not disjoint.\n");
1221  ok=FALSE;
1222  }
1223 
1224  /* RM: Dec 15 1992 I don't think this really matters any more
1225  if (overlap_type(real,alist)) {
1226  Errorline("the sorts 'real' and 'list' are not disjoint.\n");
1227  ok=FALSE;
1228  }
1229  */
1230 
1231  /* RM: Dec 15 1992 I don't think this really matters any more
1232  if (overlap_type(alist,quoted_string)) {
1233  Errorline("the sorts 'list' and 'string' are not disjoint.\n");
1234  ok=FALSE;
1235  }
1236  */
1237 
1238  if (!ok) {
1239  perr("*** Internal problem:\n");
1240  perr("*** Wild_Life may behave abnormally because some basic types\n");
1241  perr("*** have been defined incorrectly.\n\n");
1242  }
1243 
1245  types_done=TRUE;
1246  }
1247 }
1248 
1257 {
1258  long i;
1259 
1260  for (i=0; i<type_count; i++) {
1261  outputline("%C = %s\n",
1262  gamma_table[i]->code,
1263  gamma_table[i]->keyword->combined_name);
1264  }
1265 }
1266 
1290 long glb_value(long result,long f,GENERIC c,GENERIC value1,GENERIC value2,GENERIC *value)
1291 {
1292  ptr_int_list code;
1293 
1294  if (!result) return FALSE;
1295  if (value1==NULL) {
1296  *value=value2;
1297  return TRUE;
1298  }
1299  if (value2==NULL) {
1300  *value=value1;
1301  return TRUE;
1302  }
1303  /* At this point, both value fields are non-NULL */
1304  /* and must be compared. */
1305 
1306  /* Get a pointer to the sort code */
1307  code = f ? ((ptr_definition)c)->code : (ptr_int_list)c;
1308 
1309  /* This rather time-consuming analysis is necessary if both objects */
1310  /* have non-NULL value fields. Note that only those objects with a */
1311  /* non-NULL value field needed for disentailment are looked at. */
1312  if (sub_CodeType(code,real->code)) {
1313  *value=value1;
1314  return (*(REAL *)value1 == *(REAL *)value2);
1315  }
1316  else if (sub_CodeType(code,quoted_string->code)) {
1317  *value=value1;
1318  return (!strcmp((char *)value1,(char *)value2));
1319  }
1320  else {
1321  /* All other sorts with 'value' fields always return TRUE, that is, */
1322  /* the value field plays no role in disentailment. */
1323  *value=value1;
1324  return TRUE;
1325  }
1326 }
1327 
1351 long glb_code(long f1,GENERIC c1,long f2,GENERIC c2,long *f3,GENERIC *c3)
1352 {
1353  long result=0;
1354  unsigned long v1,v2,v3;
1355  ptr_int_list cd1,cd2,*cd3; /* sort codes */
1356 
1357  /* First, the cases where c1 & c2 are ptr_definitions: */
1358  if (f1 && f2) {
1359  if ((ptr_definition)c1==(ptr_definition)c2) {
1360  *c3=c1;
1361  result=1;
1362  }
1363  else if ((ptr_definition)c1==top) {
1364  *c3=c2;
1365  if ((ptr_definition)c2==top)
1366  result=1;
1367  else
1368  result=3;
1369  }
1370  else if ((ptr_definition)c2==top) {
1371  *c3=c1;
1372  result=2;
1373  }
1374  /* If both inputs are either top or the same ptr_definition */
1375  /* then can return quickly with a ptr_definition. */
1376  if (result) {
1377  *f3=TRUE; /* c3 is ptr_definition (an interned symbol) */
1378  return result;
1379  }
1380  }
1381  /* In the other cases, can't return with a ptr_definition: */
1382  cd1=(ptr_int_list)(f1?(GENERIC)((ptr_definition)c1)->code:c1);
1383  cd2=(ptr_int_list)(f2?(GENERIC)((ptr_definition)c2)->code:c2);
1384  cd3=(ptr_int_list*)c3;
1385  *f3=FALSE; /* cd3 is ptr_int_list (a sort code) */
1386  if (cd1==NOT_CODED) {
1387  if (cd2==NOT_CODED) {
1388  if (c1==c2) {
1389  *cd3=cd1;
1390  result=1;
1391  }
1392  else
1393  result=0;
1394  }
1395  else if (cd2==top->code) {
1396  *cd3=cd1;
1397  result=2;
1398  }
1399  else
1400  result=0;
1401  }
1402  else if (cd1==top->code) {
1403  if (cd2==top->code) {
1404  *cd3=cd1;
1405  result=1;
1406  }
1407  else {
1408  *cd3=cd2;
1409  result=3;
1410  }
1411  }
1412  else if (cd2==NOT_CODED)
1413  result=0;
1414  else if (cd2==top->code) {
1415  *cd3=cd1;
1416  result=2;
1417  }
1418  else while (cd1 && cd2) {
1419  /* Bit operations needed only if c1 & c2 coded & different from top */
1420  *cd3 = STACK_ALLOC(int_list);
1421  (*cd3)->next=NULL;
1422 
1423  v1=(unsigned long)(cd1->value_1);
1424  v2=(unsigned long)(cd2->value_1);
1425  v3=v1 & v2;
1426  (*cd3)->value_1=(GENERIC)v3;
1427 
1428  if (v3) {
1429  if (v3<v1 && v3<v2)
1430  result=4;
1431  else if (result!=4)
1432  if (v1<v2)
1433  result=2;
1434  else if (v1>v2)
1435  result=3;
1436  else
1437  result=1;
1438  }
1439  else if (result)
1440  if (v1 || v2)
1441  result=4;
1442 
1443  cd1=cd1->next;
1444  cd2=cd2->next;
1445  cd3= &((*cd3)->next);
1446  }
1447 
1448  return result;
1449 }
1450 
1482 {
1483  ptr_int_list c1,c2;
1484  long result=0;
1485  unsigned long v1,v2,v3;
1486  int e1,e2,b; /* RM: May 7 1993 */
1487 
1488 
1489 
1490  *c3=NULL;
1491 
1492  if (t1==t2) {
1493  result=1;
1494  *t3= t1;
1495  }
1496  else if (t1==top) {
1497  *t3= t2;
1498  if (t2==top)
1499  result=1;
1500  else
1501  result=3;
1502  }
1503  else if (t2==top) {
1504  result=2;
1505  *t3= t1;
1506  }
1507  else {
1508  /* printf("glb of %s and %s\n",
1509  t1->keyword->combined_name,
1510  t2->keyword->combined_name); */
1511 
1512  c1=t1->code;
1513  c2=t2->code;
1514 
1515  e1=TRUE;e2=TRUE;b=TRUE;
1516 
1517  if (c1!=NOT_CODED && c2!=NOT_CODED) {
1518  result=0;
1519  while (c1 && c2) {
1520 
1521  *c3 = STACK_ALLOC(int_list);
1522  (*c3)->next=NULL;
1523 
1524  v1=(unsigned long)(c1->value_1);
1525  v2=(unsigned long)(c2->value_1);
1526  v3=v1 & v2;
1527 
1528  /* printf("v1=%d, v2=%d, v3=%d\n",v1,v2,v3); */
1529 
1530  (*c3)->value_1=(GENERIC)v3;
1531 
1532  if(v3!=v1) /* RM: May 7 1993 */
1533  e1=FALSE;
1534  if(v3!=v2)
1535  e2=FALSE;
1536  if(v3)
1537  b=FALSE;
1538 
1539  c1=c1->next;
1540  c2=c2->next;
1541  c3= &((*c3)->next);
1542  }
1543  *t3=NULL;
1544 
1545  if(b) /* RM: May 7 1993 */
1546  result=0; /* 0 if T3 = bottom */
1547  else
1548  if(e1)
1549  if(e2)
1550  result=1; /* 1 if T1 = T2 */
1551  else
1552  result=2; /* 2 if T1 <| T2 ( T3 = T1 ) */
1553  else
1554  if(e2)
1555  result=3; /* 3 if T1 |> T2 ( T3 = T2 ) */
1556  else
1557  result=4; /* 4 otherwise */
1558  }
1559  }
1560 
1561  if (!result) *t3=nothing;
1562 
1563  /* printf("result=%d\n\n",result); */
1564 
1565  return result;
1566 }
1567 
1580 {
1581  ptr_int_list c1,c2;
1582  long result=TRUE;
1583 
1584  if (t1!=t2 && t1!=top && t2!=top) {
1585 
1586  c1=t1->code;
1587  c2=t2->code;
1588  result=FALSE;
1589 
1590  if (c1!=NOT_CODED && c2!=NOT_CODED) {
1591  while (!result && c1 && c2) {
1592  result=(((unsigned long)(c1->value_1)) & ((unsigned long)(c2->value_1)));
1593  c1=c1->next;
1594  c2=c2->next;
1595  }
1596  }
1597  }
1598 
1599  /*
1600  printf("overlap_type(%s,%s) => %ld\n",t1->def->keyword->symbol,t2->def->keyword->symbol,result);
1601  */
1602 
1603  return result;
1604 }
1605 
1619 {
1620  if (c1!=NOT_CODED && c2!=NOT_CODED) {
1621  while (c1 && c2) {
1622  if ((unsigned long)c1->value_1 & ~(unsigned long)c2->value_1) return FALSE;
1623  c1=c1->next;
1624  c2=c2->next;
1625  }
1626  }
1627  else
1628  return FALSE;
1629 
1630  return TRUE;
1631 }
1632 
1643 {
1644  if (t1!=t2)
1645  if (t2!=top)
1646  {
1647  if (t1==top)
1648  return FALSE;
1649  else
1650  return sub_CodeType(t1->code, t2->code);
1651  }
1652  return TRUE;
1653 }
1654 
1666 long matches(ptr_definition t1,ptr_definition t2,long *smaller)
1667 {
1668  ptr_int_list c1,c2;
1669  long result=TRUE;
1670 
1671  *smaller=TRUE;
1672 
1673  if (t1!=t2)
1674  if (t2!=top)
1675  if (t1==top)
1676  *smaller=FALSE;
1677  else {
1678  c1=t1->code;
1679  c2=t2->code;
1680  result=FALSE;
1681 
1682  if (c1!=NOT_CODED && c2!=NOT_CODED) {
1683  while (c1 && c2) {
1684  if ((unsigned long)c1->value_1 & (unsigned long)c2->value_1) result=TRUE;
1685  if ((unsigned long)c1->value_1 & ~(unsigned long)c2->value_1) *smaller=FALSE;
1686  c1=c1->next;
1687  c2=c2->next;
1688  }
1689  }
1690  else
1691  *smaller=FALSE;
1692  }
1693 
1694  return result;
1695 }
1696 
1697 
1698 
1713 long strict_matches(ptr_psi_term t1,ptr_psi_term t2,long *smaller)
1714 {
1715  long result,sm;
1716 
1717  result=matches(t1->type,t2->type,&sm);
1718 
1719  if (sm) {
1720  /* At this point, t1->type <| t2->type */
1721  if (t1->type==t2->type) {
1722  /* Same types: strict only if first has a value & second does not */
1723  if (t1->value_3!=NULL && t2->value_3==NULL)
1724  sm=TRUE;
1725  else
1726  sm=FALSE;
1727  }
1728  else {
1729  /* Different types: the first must be strictly smaller */
1730  sm=TRUE;
1731  }
1732  }
1733 
1734  *smaller=sm;
1735  return result;
1736 }
1737 
1754 {
1755  unsigned long p=0,dp=0,v=0,dv=0;
1756 
1757  while (c) {
1758  v=(unsigned long)c->value_1;
1759  if(v) {
1760  dp=p;
1761  dv=v;
1762  }
1763  c=c->next;
1764  p=p+INT_SIZE;
1765  }
1766 
1767  while (dv) {
1768  dp++;
1769  dv=dv>>1;
1770  }
1771 
1772  return dp;
1773 }
1774 
1785 {
1786  ptr_int_list c2,c3,c4,result=NULL,*prev;
1787  long p;
1788 
1789  p=bit_length(c);
1790 
1791  while (p) {
1792  p--;
1793  c2=gamma_table[p]->code;
1794  result=cons((GENERIC)gamma_table[p],result);
1795  prev= &c4;
1796  *prev=NULL;
1797 
1798  while (c2) {
1799  c3=STACK_ALLOC(int_list);
1800  *prev=c3;
1801  prev= &(c3->next);
1802  *prev=NULL;
1803 
1804  c3->value_1=(GENERIC)(((unsigned long)(c->value_1)) & ~((unsigned long)(c2->value_1)));
1805 
1806  c=c->next;
1807  c2=c2->next;
1808  }
1809 
1810  c=c4;
1811  p=bit_length(c);
1812  }
1813 
1814  return result;
1815 }
ptr_definition disjunction
symbol in bi module
Definition: def_glob.h:249
void find_adults()
find_adults
Definition: types.c:549
ptr_psi_term aaaa_2
Definition: def_struct.h:205
long type_cyclicity(ptr_definition d, ptr_int_list anc)
type_cyclicity
Definition: types.c:977
#define function_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1408
char already_loaded
Definition: def_struct.h:157
#define undef_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1394
void get_two_args(ptr_node t, ptr_psi_term *a, ptr_psi_term *b)
get_two_args
Definition: login.c:47
ptr_definition * gamma_table
Definition: types.c:14
void least_sorts()
void least_sorts()
Definition: types.c:743
void perr(char *str)
perr
Definition: error.c:763
struct wl_definition * def_type
Definition: def_struct.h:60
void assert_complicated_type(ptr_psi_term t)
assert_complicated_type
Definition: types.c:405
char evaluate_args
Definition: def_struct.h:156
void assert_args_not_eval(ptr_node n)
assert_args_not_eval
Definition: types.c:294
void encode_types()
encode_types
Definition: types.c:1091
void exit_life(long nl_flag)
exit_life
Definition: built_ins.c:2219
ptr_definition lf_false
symbol in bi module
Definition: def_glob.h:284
ptr_definition integer
symbol in bi module
Definition: def_glob.h:312
ptr_definition nothing
symbol in bi module
Definition: def_glob.h:347
char * combined_name
Definition: def_struct.h:119
long type_count
Definition: def_glob.h:1021
ptr_definition first_definition
All definition are stores in a linked list starting at first_definition.
Definition: def_glob.h:13
long strict_matches(ptr_psi_term t1, ptr_psi_term t2, long *smaller)
strict_matches
Definition: types.c:1713
#define NOT_CODED
For LIFE boolean calculation built-in.
Definition: def_const.h:294
long redefine(ptr_psi_term t)
redefine
Definition: types.c:104
ptr_pair_list next
Definition: def_struct.h:207
ptr_int_list two_to_the(long p)
two_to_the
Definition: types.c:776
long assert_less(ptr_psi_term t1, ptr_psi_term t2)
assert_less
Definition: types.c:200
void perr_sort_list(ptr_int_list anc)
perr_sort_list
Definition: types.c:944
void propagate_definitions()
propagate_definitions
Definition: types.c:662
void clear_coding()
clear_coding
Definition: types.c:727
def_type type_def
Definition: def_struct.h:153
includes
#define predicate_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1401
long sub_CodeType(ptr_int_list c1, ptr_int_list c2)
sub_CodeType
Definition: types.c:1618
long file_date
Definition: def_glob.h:1034
void perr_sort_cycle(ptr_int_list anc)
perr_sort_cycle
Definition: types.c:959
#define INT_SIZE
How many types can be encoded on one integer in the transitive closure encoding.
Definition: def_const.h:317
long overlap_type(ptr_definition t1, ptr_definition t2)
overlap_type
Definition: types.c:1579
void clear_already_loaded(ptr_node n)
clear_already_loaded
Definition: types.c:351
ptr_keyword keyword
Definition: def_struct.h:147
void assert_protected(ptr_node n, long prot)
assert_protected
Definition: types.c:255
ptr_int_list copyTypeCode(ptr_int_list u)
copyTypeCode
Definition: types.c:808
void perr_s(char *s1, char *s2)
perr_s
Definition: error.c:775
struct wl_psi_term * ptr_psi_term
quotedStackCopy
Definition: def_struct.h:62
#define global_it
was enum (def_type) in extern.h now there is typedef ptr_definition
Definition: def_const.h:1422
GENERIC data
Definition: def_struct.h:201
void remove_cycles(ptr_definition d, ptr_int_list *dl)
remove_cycles
Definition: types.c:85
ptr_int_list cons(GENERIC v, ptr_int_list l)
cons
Definition: types.c:179
#define NULL
Definition: def_const.h:533
long warningflag
Definition: def_glob.h:911
ptr_psi_term input_state
Definition: def_glob.h:856
void make_sys_type_links()
make_sys_type_links
Definition: sys.c:2168
#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
ptr_triple_list next
Definition: def_struct.h:215
ptr_definition cccc_4
Definition: def_struct.h:214
long types_modified
Definition: def_glob.h:1022
void inherit_always_check()
inherit_always_check
Definition: types.c:1068
long assert_ok
Definition: def_glob.h:1033
char always_check
Definition: def_struct.h:154
ptr_definition built_in
symbol in bi module
Definition: def_glob.h:199
ptr_node left
Definition: def_struct.h:199
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
ptr_definition next
Definition: def_struct.h:164
void make_type_link(ptr_definition t1, ptr_definition t2)
make_type_link
Definition: types.c:901
void Errorline(char *format,...)
Errorline.
Definition: error.c:465
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
#define EOLN
End of line.
Definition: def_const.h:309
long bit_length(ptr_int_list c)
bit_length
Definition: types.c:1753
#define wl_const_3(S)
Definition: def_macro.h:109
#define deref_ptr(P)
Definition: def_macro.h:100
long glb(ptr_definition t1, ptr_definition t2, ptr_definition *t3, ptr_int_list *c3)
glb
Definition: types.c:1481
void perr_sort(ptr_definition d)
perr_sort
Definition: types.c:933
#define TRUE
Standard boolean.
Definition: def_const.h:268
void propagate_always_check(ptr_definition d, long *ch)
propagate_always_check
Definition: types.c:1022
void all_sorts()
all_sorts
Definition: types.c:759
void one_pass_always_check(long *ch)
one_pass_always_check
Definition: types.c:1049
long glb_value(long result, long f, GENERIC c, GENERIC value1, GENERIC value2, GENERIC *value)
glb_value
Definition: types.c:1290
ptr_pair_list rule
Definition: def_struct.h:148
#define FALSE
Standard boolean.
Definition: def_const.h:275
long glb_code(long f1, GENERIC c1, long f2, GENERIC c2, long *f3, GENERIC *c3)
glb_code
Definition: types.c:1351
void assert_delay_check(ptr_node n)
assert_delay_check
Definition: types.c:326
void insert_prop(ptr_definition d, ptr_triple_list prop)
insert_prop
Definition: types.c:620
struct wl_definition * ptr_definition
Definition: def_struct.h:59
long sub_type(ptr_definition t1, ptr_definition t2)
sub_type
Definition: types.c:1642
ptr_definition nil
symbol in bi module
Definition: def_glob.h:340
GENERIC value_3
Definition: def_struct.h:186
ptr_psi_term bbbb_2
Definition: def_struct.h:206
ptr_psi_term bbbb_4
Definition: def_struct.h:213
#define STACK_ALLOC(A)
Definition: def_macro.h:21
void assert_type(ptr_psi_term t)
assert_type
Definition: types.c:372
void restore_state(ptr_psi_term t)
restore_state
Definition: token.c:334
void outputline(char *format,...)
void outputline(char *format,...)
Definition: error.c:101
struct wl_keyword * ptr_keyword
Definition: def_struct.h:125
ptr_definition top
symbol in syntax module
Definition: def_glob.h:403
void print_codes()
print_codes
Definition: types.c:1256
void equalize_codes(int len)
equalize_codes
Definition: types.c:859
long types_done
Definition: def_glob.h:1012
char * prompt
Definition: def_glob.h:1018
long read_char()
read_char
Definition: token.c:680
#define MAX_BUILT_INS
Maximum number of built_ins.
Definition: def_const.h:154
#define equ_tok(A, B)
Definition: def_macro.h:67
void insert_own_prop(ptr_definition d)
insert_own_prop
Definition: types.c:575
ptr_int_list code
Definition: def_struct.h:150
ptr_int_list decode(ptr_int_list c)
decode
Definition: types.c:1784
void add_rule(ptr_psi_term head, ptr_psi_term body, def_type typ)
add_rule
Definition: login.c:167
void warningline(char *format,...)
warningline
Definition: error.c:371
ptr_int_list children
Definition: def_glob.h:1001
ptr_int_list adults
Definition: def_glob.h:1001
ptr_definition lf_true
symbol in bi module
Definition: def_glob.h:410
ptr_definition type
Definition: def_struct.h:181
void assert_attributes(ptr_psi_term t)
assert_attributes
Definition: types.c:500
GENERIC value_1
Definition: def_struct.h:85
void print_def_type(def_type t)
print_def_type
Definition: types.c:24
long count_sorts(long c0)
count_sorts
Definition: types.c:710
ptr_triple_list properties
Definition: def_struct.h:149
struct wl_int_list * ptr_int_list
Definition: def_struct.h:57
ptr_int_list children
Definition: def_struct.h:152
#define HEAP_ALLOC(A)
Definition: def_macro.h:20
ptr_node attr_list
Definition: def_struct.h:187
long open_input_file(char *file)
open_input_file
Definition: token.c:594
long yes_or_no()
yes_or_no
Definition: types.c:50
ptr_psi_term aaaa_4
Definition: def_struct.h:212
ptr_definition quoted_string
symbol in bi module
Definition: def_glob.h:368
GENERIC heap_alloc(long s)
heap_alloc
Definition: memory.c:1616
long type_member(ptr_definition t, ptr_int_list tlst)
type_member
Definition: types.c:918
#define assert(N)
Definition: memory.c:114
void or_codes(ptr_int_list u, ptr_int_list v)
or_codes
Definition: types.c:831
ptr_node right
Definition: def_struct.h:200
long matches(ptr_definition t1, ptr_definition t2, long *smaller)
matches
Definition: types.c:1666
ptr_int_list next
Definition: def_struct.h:86
ptr_int_list parents
Definition: def_struct.h:151