Wild Life  2.29
 All Data Structures Files Functions Variables Typedefs Macros
arity.c
Go to the documentation of this file.
1 /* $Id: arity.c,v 1.2 1994/12/08 23:03:22 duchier Exp $ */
2 
3 #ifdef ARITY
4 
5 #include "defs.h"
6 
7 static int Aunif=0;
8 static int Amerge=0;
9 static int Aadd=0;
10 static int Atop=0;
11 static int Atoptop=0;
12 static int Auid=0;
13 static int Audiff=0;
14 static int Anil=0;
15 static int Anilnil=0;
16 static int Aident=0;
17 static int Adiff=0;
18 static int Aglb=0;
19 
20 
21 
22 
23 void arity_init()
24 {
25  /*
26  features=fopen("features.log","w");
27  if(!features) {
28  Errorline("Couldn't open feature log file\n");
29  abort_life(TRUE); // djd added TRUE
30  }
31  */ // RECOMMENTED 2.16 DJD
32 }
33 
34 
35 void arity_end()
36 {
37 
38  fclose(features);
39 
40  features=fopen("profile.log","w");
41  if(features) {
42  fprintf(features,"---- Unifications and Features ----\n\n");
43 
44  fprintf(features,"add feature: %d\n\n",Aadd);
45 
46  fprintf(features,"unify: %d\n",Aunif);
47  fprintf(features,"types:\n");
48  fprintf(features,"\ttop-top: %d = %3.1lf\n",PERUNIF(Atoptop));
49  fprintf(features,"\ttop-X: %d = %3.1lf\n",PERUNIF(Atop));
50  fprintf(features,"\tX-X: %d = %3.1lf\n",PERUNIF(Auid));
51  fprintf(features,"\tX-Y: %d = %3.1lf\n",PERUNIF(Audiff));
52  fprintf(features,"\tGLB: %d = %3.1lf\n",PERUNIF(Aglb));
53 
54  fprintf(features,"merges: %d = %3.1lf\n",PERUNIF(Amerge));
55 
56  fprintf(features,"\tnil-nil: %d = %3.1lf\n",PERMERGE(Anilnil));
57  fprintf(features,"\tnil-X: %d = %3.1lf\n",PERMERGE(Anil));
58  fprintf(features,"\tX-X: %d = %3.1lf\n",PERMERGE(Aident));
59  fprintf(features,"\tX-Y: %d = %3.1lf\n",PERMERGE(Adiff));
60 
61  fclose(features);
62  }
63 }
64 
65 
66 
67 void rec_print_feat(n)
68 
69  ptr_node n;
70 {
71  if(n) {
72  if(n->left) {
73  rec_print_feat(n->left);
74  fprintf(features,",");
75  }
76 
77  fprintf(features,n->key);
78 
79  if(n->right) {
80  fprintf(features,",");
81  rec_print_feat(n->right);
82  }
83  }
84 }
85 
86 
87 
88 void print_features(u)
89 
90  ptr_node u;
91 {
92  fprintf(features,"(");
93  rec_print_feat(u);
94  fprintf(features,")");
95 }
96 
97 
98 
99 int check_equal(u,v)
100 
101  ptr_node u;
102  ptr_node v;
103 {
104  int same=TRUE;
105 
106  if(u) {
107  same=check_equal(u->left,v) &&
108  find(FEATCMP,u->key,v) &&
109  check_equal(u->right,v);
110  }
111 
112  return same;
113 }
114 
115 
116 
117 void arity_unify(u,v)
118  ptr_psi_term u;
119  ptr_psi_term v;
120 {
121  Aunif++;
122 
123  if(u->type==top)
124  if(v->type==top)
125  Atoptop++;
126  else
127  Atop++;
128  else
129  if(v->type==top)
130  Atop++;
131  else
132  if(u->type==v->type)
133  Auid++;
134  else
135  if(u->type->children || v->type->children)
136  Aglb++;
137  else
138  Audiff++;
139 
140  /*
141  fprintf(features,
142  "unify: %s %s\n",
143  u->type->keyword->symbol,
144  v->type->keyword->symbol);
145  */
146 }
147 
148 
149 
150 void arity_merge(u,v)
151  ptr_node u;
152  ptr_node v;
153 {
154  Amerge++;
155 
156  if(u)
157  if(v)
158  if(check_equal(u,v))
159  Aident++;
160  else
161  Adiff++;
162  else
163  Anil++;
164  else
165  if(v)
166  Anil++;
167  else
168  Anilnil++;
169 
170  /*
171  fprintf(features,"merge: ");
172  print_features(u);
173  fprintf(features," ");
174  print_features(v);
175  fprintf(features,"\n");
176  */
177 }
178 
179 
180 
181 void arity_add(u,s)
182 
183  ptr_psi_term u;
184  char *s;
185 {
186  Aadd++;
187 
188  /*
189  fprintf(features,"add %s to %s",s,u->type->keyword->symbol);
190  print_features(u->attr_list);
191  fprintf(features,"\n");
192  */
193 }
194 
195 #endif
#define FEATCMP
Definition: def_const.h:257
ptr_definition top
Definition: def_glob.h:106
#define TRUE
Definition: def_const.h:127
ptr_node find(long comp, char *keystr, ptr_node tree)
Definition: trees.c:341
FILE * features
Definition: def_glob.h:242
#define PERUNIF(X)
Definition: def_macro.h:268
#define PERMERGE(X)
Definition: def_macro.h:269
ptr_definition type
Definition: def_struct.h:165
ptr_int_list children
Definition: def_struct.h:131