• R/O
  • SSH
  • HTTPS

adp: Commit


Commit MetaInfo

Revision284 (tree)
Time2012-06-04 19:46:49
Authorohfuji

Log Message

改造中一部バグが残っているがとりあえずコミット

Change Summary

Incremental Difference

--- trunk/unit/testall.sh (revision 283)
+++ trunk/unit/testall.sh (revision 284)
@@ -39,6 +39,8 @@
3939 sh test.sh debug027
4040 sh test.sh debug028
4141 sh test.sh debug029
42+sh test.sh debug030
43+sh test.sh debug031
4244 sh test.sh each
4345 sh test.sh eiwa
4446 sh test.sh euc2sjis
--- trunk/unit/testall.bat (revision 283)
+++ trunk/unit/testall.bat (revision 284)
@@ -39,6 +39,8 @@
3939 call test.bat debug027
4040 call test.bat debug028
4141 call test.bat debug029
42+call test.bat debug030
43+call test.bat debug031
4244 call test.bat each
4345 call test.bat eiwa
4446 call test.bat euc2sjis
--- trunk/adp_builtin_system.h (revision 283)
+++ trunk/adp_builtin_system.h (revision 284)
@@ -266,7 +266,7 @@
266266
267267 bc = get_gc();
268268 set_gc(c); // グローバルコンテクストをセット
269- ec = new ExecContext( c->topgoals.upHorn(0).getGoal(), c->topgoals.upHorn(0).getVcnt());
269+ ec = new ExecContext( c->topgoals.upHorn(0)->getGoal(), c->topgoals.upHorn(0)->getVcnt());
270270 bool ret = ec->execute(excp, true);
271271
272272 set_gc(bc); // グローバルコンテクストを元に戻す
--- trunk/adp_unify.cpp (revision 283)
+++ trunk/adp_unify.cpp (revision 284)
@@ -69,77 +69,169 @@
6969 /*************************************** unify ******************************************/
7070
7171 // 変項のunify本体で使うテンプレート関数
72-template <class T> bool PEVeriable::vunify(const T &horn, ExecContextRoot *c, VLocal *, VLocal *hlocal) const
72+template <class T> bool PVeriable::vunify(const T &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const
7373 {
74- VLocal *local = vl;
75- const PObject *gitem = (*local)[idx];
74+ const PObject *gitem = (*glocal)[idx];
7675 if ( gitem == 0 ) {
77- (*local)[idx] = &horn;
76+ (*glocal)[idx] = &horn;
77+ return true;
7878 } else {
79- return gitem->unify( horn, c, local, hlocal);
79+ return gitem->unify( horn, c, glocal, hlocal);
8080 }
8181 return true;
8282 }
8383
84-// 変項のunify本体で使うテンプレート関数
85-template <class T> bool PEVeriable::vunify_getval(const T &horn, ExecContextRoot *c, VLocal *, VLocal *hlocal) const
84+template <class T> bool PVeriable::vunify_getval(const T &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const
8685 {
87- VLocal *local = vl;
88- const PObject *gitem = (*local)[idx];
86+ const PObject *gitem = (*glocal)[idx];
8987 if ( gitem == 0 ) {
90- //c->assign( local, idx, horn.getval(c, hlocal));
91- (*local)[idx] = horn.getval(c, hlocal);
88+ const PObject *p = horn.getval(c, hlocal);
89+ if ( p->isc() ) {
90+ (*glocal)[idx] = p;
91+ return true;
92+ }
9293 } else {
93- return gitem->unify( horn, c, local, hlocal);
94+ return gitem->unify( horn, c, glocal, hlocal);
9495 }
96+
97+#if 1
98+ ExecContext *ec = dynamic_cast<ExecContext*>(c);
99+ if ( ec != 0 ) {
100+ ec->afterunify.push_back(c->uidx);
101+ }
102+#endif
95103 return true;
96104 }
97105
106+template <class T> bool PVeriable::vunify_ver(const T &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const
107+{
108+ const PObject *gval = (*glocal)[idx];
109+ const PObject *hval = (*hlocal)[horn.idx];
110+ if ( gval != 0 ) {
111+ if ( hval != 0 ) {
112+ return hval->unify( *gval, c, hlocal, glocal);
113+ } else if ( gval->isc() ) {
114+ (*hlocal)[horn.idx] = gval;
115+ return true;
116+ }
117+ } else if ( hval != 0 && hval->isc() ) {
118+ (*glocal)[idx] = hval;
119+ return true;
120+ }
121+
122+#if 1
123+ ExecContext *ec = dynamic_cast<ExecContext*>(c);
124+ if ( ec != 0 ) {
125+ ec->afterunify.push_back(c->uidx);
126+ }
127+#endif
128+ return true;
129+}
130+
131+
132+template <class T> bool PEVeriable::vunify(const T &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const
133+{
134+ const PObject *gitem = (*glocal)[idx];
135+ if ( gitem == 0 ) {
136+ (*glocal)[idx] = &horn;
137+ } else {
138+ return gitem->unify( horn, c, glocal, hlocal);
139+ }
140+ return true;
141+}
142+
143+template <class T> bool PEVeriable::vunify_getval(const T &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const
144+{
145+ const PObject *gitem = (*glocal)[idx];
146+ if ( gitem == 0 ) {
147+ const PObject *p = horn.getval(c, hlocal);
148+ if ( p->isc() ) {
149+ (*glocal)[idx] = p;
150+ return true;
151+ }
152+ } else {
153+ return gitem->unify( horn, c, glocal, hlocal);
154+ }
155+
156+#if 1
157+ ExecContext *ec = dynamic_cast<ExecContext*>(c);
158+ if ( ec != 0 ) {
159+ ec->afterunify.push_back(c->uidx);
160+ }
161+#endif
162+ return true;
163+}
164+
165+template <class T> bool PEVeriable::vunify_ver(const T &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const
166+{
167+ const PObject *gval = (*glocal)[idx];
168+ const PObject *hval = (*hlocal)[horn.idx];
169+ if ( gval != 0 ) {
170+ if ( hval != 0 ) {
171+ return hval->unify( *gval, c, hlocal, glocal);
172+ } else if ( gval->isc() ) {
173+ (*hlocal)[horn.idx] = gval;
174+ return true;
175+ }
176+ } else if ( hval != 0 && hval->isc() ) {
177+ (*glocal)[idx] = hval;
178+ return true;
179+ }
180+
181+#if 1
182+ ExecContext *ec = dynamic_cast<ExecContext*>(c);
183+ if ( ec != 0 ) {
184+ ec->afterunify.push_back(c->uidx);
185+ }
186+#endif
187+ return true;
188+}
189+
98190 bool PNil::unify(const PObject &goal, ExecContextRoot *c, VLocal *hlocal, VLocal *glocal) const { return goal.unify(*this, c, glocal, hlocal); }
99191 bool PNil::unify(const PNil &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return true; }
100192 bool PNil::unify(const PList &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return horn.unify( *this, c, hlocal, glocal); }
101193 bool PNil::unify(const PVeriable &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return horn.vunify<PNil>(*this, c, hlocal, glocal); }
102-bool PNil::unify(const PEVeriable &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return horn.vunify<PNil>(*this, c, hlocal, glocal); }
194+bool PNil::unify(const PEVeriable &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return horn.vunify<PNil>(*this, c, horn.vl, glocal); }
103195
104196 bool PNil::unify(const PObject &goal, ExecContextRoot *c) const { return goal.unify(*this, c); }
105197 bool PNil::unify(const PNil &horn, ExecContextRoot *c) const { return true; }
106198 bool PNil::unify(const PList &horn, ExecContextRoot *c) const { return horn.unify( *this, c); }
107199 bool PNil::unify(const PVeriable &horn, ExecContextRoot *c) const { return horn.vunify<PNil>(*this, c, c->hl, c->gl); }
108-bool PNil::unify(const PEVeriable &horn, ExecContextRoot *c) const { return horn.vunify<PNil>(*this, c, c->hl, c->gl); }
200+bool PNil::unify(const PEVeriable &horn, ExecContextRoot *c) const { return horn.vunify<PNil>(*this, c, horn.vl, c->gl); }
109201
110202 bool PString::unify(const PObject &goal, ExecContextRoot *c, VLocal *hlocal, VLocal *glocal) const { return goal.unify(*this, c, glocal, hlocal); }
111203 bool PString::unify(const PString &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return strcmp( value.c_str(), horn.value.c_str()) == 0; }
112204 bool PString::unify(const PVeriable &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return horn.vunify<PString>(*this, c, hlocal, glocal); }
113-bool PString::unify(const PEVeriable &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return horn.vunify<PString>(*this, c, hlocal, glocal); }
205+bool PString::unify(const PEVeriable &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return horn.vunify<PString>(*this, c, horn.vl, glocal); }
114206
115207 bool PString::unify(const PObject &goal, ExecContextRoot *c) const { return goal.unify(*this, c); }
116208 bool PString::unify(const PString &horn, ExecContextRoot *c) const { return strcmp( value.c_str(), horn.value.c_str()) == 0; }
117209 bool PString::unify(const PVeriable &horn, ExecContextRoot *c) const { return horn.vunify<PString>(*this, c, c->hl, c->gl); }
118-bool PString::unify(const PEVeriable &horn, ExecContextRoot *c) const { return horn.vunify<PString>(*this, c, c->hl, c->gl); }
210+bool PString::unify(const PEVeriable &horn, ExecContextRoot *c) const { return horn.vunify<PString>(*this, c, horn.vl, c->gl); }
119211
120212 bool PDouble::unify(const PObject &goal, ExecContextRoot *c, VLocal *hlocal, VLocal *glocal) const { return goal.unify(*this, c, glocal, hlocal); }
121213 bool PDouble::unify(const PDouble &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return fabs(value - (double)horn.value) < DBL_EPSILON; }
122214 bool PDouble::unify(const PInteger &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return fabs(value - (double)horn.value) < DBL_EPSILON; }
123215 bool PDouble::unify(const PVeriable &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return horn.vunify<PDouble>(*this, c, hlocal, glocal); }
124-bool PDouble::unify(const PEVeriable &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return horn.vunify<PDouble>(*this, c, hlocal, glocal); }
216+bool PDouble::unify(const PEVeriable &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return horn.vunify<PDouble>(*this, c, horn.vl, glocal); }
125217
126218 bool PDouble::unify(const PObject &goal, ExecContextRoot *c) const { return goal.unify(*this, c); }
127219 bool PDouble::unify(const PDouble &horn, ExecContextRoot *c) const { return fabs(value - (double)horn.value) < DBL_EPSILON; }
128220 bool PDouble::unify(const PInteger &horn, ExecContextRoot *c) const { return fabs(value - (double)horn.value) < DBL_EPSILON; }
129221 bool PDouble::unify(const PVeriable &horn, ExecContextRoot *c) const { return horn.vunify<PDouble>(*this, c, c->hl, c->gl); }
130-bool PDouble::unify(const PEVeriable &horn, ExecContextRoot *c) const { return horn.vunify<PDouble>(*this, c, c->hl, c->gl); }
222+bool PDouble::unify(const PEVeriable &horn, ExecContextRoot *c) const { return horn.vunify<PDouble>(*this, c, horn.vl, c->gl); }
131223
132224 bool PInteger::unify(const PObject &goal, ExecContextRoot *c, VLocal *hlocal, VLocal *glocal) const { return goal.unify(*this, c, glocal, hlocal); }
133225 bool PInteger::unify(const PDouble &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return fabs(value - (double)horn.value) < DBL_EPSILON; }
134226 bool PInteger::unify(const PInteger &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return value == horn.value; }
135227 bool PInteger::unify(const PVeriable &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return horn.vunify<PInteger>(*this, c, hlocal, glocal); }
136-bool PInteger::unify(const PEVeriable &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return horn.vunify<PInteger>(*this, c, hlocal, glocal); }
228+bool PInteger::unify(const PEVeriable &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return horn.vunify<PInteger>(*this, c, horn.vl, glocal); }
137229
138230 bool PInteger::unify(const PObject &goal, ExecContextRoot *c) const { return goal.unify(*this, c); }
139231 bool PInteger::unify(const PDouble &horn, ExecContextRoot *c) const { return fabs(value - (double)horn.value) < DBL_EPSILON; }
140232 bool PInteger::unify(const PInteger &horn, ExecContextRoot *c) const { return value == horn.value; }
141233 bool PInteger::unify(const PVeriable &horn, ExecContextRoot *c) const { return horn.vunify<PInteger>(*this, c, c->hl, c->gl); }
142-bool PInteger::unify(const PEVeriable &horn, ExecContextRoot *c) const { return horn.vunify<PInteger>(*this, c, c->hl, c->gl); }
234+bool PInteger::unify(const PEVeriable &horn, ExecContextRoot *c) const { return horn.vunify<PInteger>(*this, c, horn.vl, c->gl); }
143235
144236 bool PList::unify(const PObject &goal, ExecContextRoot *c, VLocal *hlocal, VLocal *glocal) const { return goal.unify(*this, c, glocal, hlocal); }
145237 bool PList::unify(const PNil &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const {
@@ -152,7 +244,7 @@
152244 return false;
153245 }
154246 bool PList::unify(const PVeriable &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return horn.vunify_getval<PList>(*this, c, hlocal, glocal); }
155-bool PList::unify(const PEVeriable &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return horn.vunify_getval<PList>(*this, c, hlocal, glocal); }
247+bool PList::unify(const PEVeriable &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return horn.vunify_getval<PList>(*this, c, horn.vl, glocal); }
156248
157249 bool PList::unify(const PObject &goal, ExecContextRoot *c) const { return goal.unify(*this, c); }
158250 bool PList::unify(const PNil &horn, ExecContextRoot *c) const {
@@ -165,7 +257,7 @@
165257 return false;
166258 }
167259 bool PList::unify(const PVeriable &horn, ExecContextRoot *c) const { return horn.vunify_getval<PList>(*this, c, c->hl, c->gl); }
168-bool PList::unify(const PEVeriable &horn, ExecContextRoot *c) const { return horn.vunify_getval<PList>(*this, c, c->hl, c->gl); }
260+bool PList::unify(const PEVeriable &horn, ExecContextRoot *c) const { return horn.vunify_getval<PList>(*this, c, horn.vl, c->gl); }
169261
170262 bool PArray::unify(const PObject &goal, ExecContextRoot *c, VLocal *hlocal, VLocal *glocal) const { return goal.unify(*this, c, glocal, hlocal); }
171263 bool PArray::unify(const PNil &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { if ( value.empty() ) return true; return false; }
@@ -173,77 +265,59 @@
173265 {
174266 size_t gsiz = value.size();
175267 size_t hsiz = horn.value.size();
176- // 片方に@がある場合、引数展開を行なう。両方にある場合、普通に処理する(引数展開しない)
177- if ( (args == true || horn.args == true) && (args == false || horn.args == false) ) {
178- // 引数展開あり
179- size_t lidx = 0;
180- size_t hridx = hsiz - 1;
181- size_t gridx = gsiz - 1;
182- const PObjectArray *pvalue;
183- const PArray *vary;
184- if ( args == true ) {
185- // ゴール側引数展開
186- if ( hsiz < gsiz ) return false; // 引数展開側の引数数が多い
187- pvalue = &value;
188- vary = &horn;
189- } else {
190- // ホーン側引数展開
191- if ( gsiz < hsiz ) return false; // 引数展開側の引数数が多い
192- pvalue = &horn.value;
193- vary = this;
194- }
195- // 左からのチェック(@が出るまで)
196- while ( lidx <= gridx && lidx <= hridx ) {
197- if ( (*pvalue)[lidx]->isargs() ) break; // 引数展開の確認
198- if ( !horn.value[lidx]->unify( *value[lidx], c, hlocal, glocal) ) return false;
199- lidx++;
200- }
201- // 右からのチェック(引数展開以降のチェック)
202- while ( lidx < gridx && lidx < hridx ) {
203- if ( horn.value[hridx]->isargs() || value[gridx]->isargs() ) break; // 引数展開の確認
204- if ( !horn.value[hridx]->unify( *value[gridx], c, hlocal, glocal) ) return false;
205- hridx--;
206- gridx--;
207- }
208268
209- if ( args == true ) {
210- PArray *ao = pmm.newPArray(c->pobjs, *vary, lidx, hridx + 1);
211- return (*pvalue)[lidx]->unify( *ao, c, glocal, hlocal);
212- } else {
213- PArray *ao = pmm.newPArray(c->pobjs, *vary, lidx, gridx + 1);
214- return (*pvalue)[lidx]->unify( *ao, c, hlocal, glocal);
269+ c->ao = 0;
270+ // 引数の数が同じ場合
271+ if ( gsiz == hsiz ) {
272+ for ( size_t i = 0; i < gsiz; i++ ) {
273+ c->uidx = i;
274+ if ( !horn.value[i]->unify( *value[i], c, hlocal, glocal) ) {
275+ return false;
276+ }
277+ }
278+ } else if ( gsiz < hsiz && args == true && horn.args == false ) {
279+ // 引数の数が異なる場合、片方に@がある場合、可変長引数の対応を行う。
280+ size_t m = gsiz - 1;
281+ // @変数の前まで普通にマッチングさせる
282+ for ( size_t i = 0; i < m; i++ ) {
283+ c->uidx = i;
284+ if ( !horn.value[i]->unify( *value[i], c, hlocal, glocal) ) {
285+ return false;
286+ }
215287 }
288+ // @用の配列を作成する
289+ c->uidx = m;
290+ c->ao = pmm.newPArray(c->pobjs, horn, m, hsiz);
291+ return value[m]->unify( *c->ao, c, glocal, hlocal);
216292
217- } else {
218- // 引数展開なし
219- if ( gsiz != hsiz ) return false;
220-#if 1
221- const PObject ** __restrict hargs = &horn.value.front();
222- const PObject ** __restrict gargs = &value.front();
223- while ( gsiz-- > 0 ) {
224- if ( !(*hargs)->unify( **gargs, c, hlocal, glocal) ) return false;
225- hargs++;
226- gargs++;
227- }
228-#else
229- for ( size_t i = 0; i < gsiz; i++ ) {
230- if ( !horn.value[i]->unify( *value[i], c, hlocal, glocal) ) {
293+ } else if ( gsiz > hsiz && args == false && horn.args == true ) {
294+ // 引数の数が異なる場合、片方に@がある場合、可変長引数の対応を行う。
295+ size_t m = hsiz - 1;
296+ // @変数の前まで普通にマッチングさせる
297+ for ( size_t i = 0; i < m; i++ ) {
298+ c->uidx = i;
299+ if ( !horn.value[i]->unify( *value[i], c, hlocal, glocal) ) {
231300 return false;
232- }
301+ }
233302 }
234-#endif
303+ // @用の配列を作成する
304+ c->uidx = m;
305+ c->ao = pmm.newPArray(c->pobjs, *this, m, gsiz);
306+ return horn.value[m]->unify( *c->ao, c, hlocal, glocal);
307+ } else {
308+ return false;
235309 }
236310
237311 return true;
238312 }
239313 bool PArray::unify(const PVeriable &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return horn.vunify_getval<PArray>(*this, c, hlocal, glocal); }
240-bool PArray::unify(const PEVeriable &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return horn.vunify_getval<PArray>(*this, c, hlocal, glocal); }
314+bool PArray::unify(const PEVeriable &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return horn.vunify_getval<PArray>(*this, c, horn.vl, glocal); }
241315
242316 bool PArray::unify(const PObject &goal, ExecContextRoot *c) const { return goal.unify(*this, c); }
243317 bool PArray::unify(const PNil &horn, ExecContextRoot *c) const { if ( value.empty() ) return true; return false; }
244318 bool PArray::unify(const PArray &horn, ExecContextRoot *c) const { return unify( horn, c, c->gl, c->hl);}
245319 bool PArray::unify(const PVeriable &horn, ExecContextRoot *c) const { return horn.vunify_getval<PArray>(*this, c, c->hl, c->gl); }
246-bool PArray::unify(const PEVeriable &horn, ExecContextRoot *c) const { return horn.vunify_getval<PArray>(*this, c,c->hl, c->gl); }
320+bool PArray::unify(const PEVeriable &horn, ExecContextRoot *c) const { return horn.vunify_getval<PArray>(*this, c, horn.vl, c->gl); }
247321
248322 bool PPredicate::unify(const PObject &goal, ExecContextRoot *c, VLocal *hlocal, VLocal *glocal) const { return goal.unify(*this, c, glocal, hlocal); }
249323 bool PPredicate::unify(const PPredicate &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const
@@ -255,7 +329,7 @@
255329 return arglist.unify( horn.arglist, c, glocal, hlocal); // horn.arglistがPObjextでない場合はこのように呼び出す
256330 }
257331 bool PPredicate::unify(const PVeriable &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return horn.vunify_getval<PPredicate>(*this, c, hlocal, glocal); }
258-bool PPredicate::unify(const PEVeriable &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return horn.vunify_getval<PPredicate>(*this, c, hlocal, glocal); }
332+bool PPredicate::unify(const PEVeriable &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return horn.vunify_getval<PPredicate>(*this, c, horn.vl, glocal); }
259333
260334 bool PPredicate::unify(const PObject &goal, ExecContextRoot *c) const { return goal.unify(*this, c); }
261335 bool PPredicate::unify(const PPredicate &horn, ExecContextRoot *c) const
@@ -267,7 +341,7 @@
267341 return arglist.unify( horn.arglist, c); // horn.arglistがPObjextでない場合はこのように呼び出す
268342 }
269343 bool PPredicate::unify(const PVeriable &horn, ExecContextRoot *c) const { return horn.vunify_getval<PPredicate>(*this, c, c->hl, c->gl); }
270-bool PPredicate::unify(const PEVeriable &horn, ExecContextRoot *c) const { return horn.vunify_getval<PPredicate>(*this, c, c->hl, c->gl); }
344+bool PPredicate::unify(const PEVeriable &horn, ExecContextRoot *c) const { return horn.vunify_getval<PPredicate>(*this, c, horn.vl, c->gl); }
271345
272346
273347 bool PVeriable::unify(const PObject &goal, ExecContextRoot *c, VLocal *hlocal, VLocal *glocal) const { return goal.unify(*this, c, glocal, hlocal); }
@@ -278,50 +352,8 @@
278352 bool PVeriable::unify(const PList &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return vunify_getval<PList>(horn, c, glocal, hlocal); }
279353 bool PVeriable::unify(const PArray &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return vunify_getval<PArray>(horn, c, glocal, hlocal); }
280354 bool PVeriable::unify(const PPredicate &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return vunify_getval<PPredicate>(horn, c, glocal, hlocal); }
281-bool PVeriable::unify(const PVeriable &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const {
282- const PObject *gval = (*glocal)[idx];
283- const PObject *hval = (*hlocal)[horn.idx];
284- if ( gval != 0 ) {
285- if ( hval != 0 ) {
286- return hval->unify( *gval, c, hlocal, glocal);
287- } else {
288- (*hlocal)[horn.idx] = gval;
289- }
290- } else {
291- if ( hval != 0 ) {
292- (*glocal)[idx] = hval;
293- } else {
294- ExecContext *ec = dynamic_cast<ExecContext*>(c);
295- if ( ec != 0 ) {
296- ec->substitutepair.push_back( SubstitutePair(horn.idx, idx) );
297- } else {
298- (*hlocal)[horn.idx] = getval( c, glocal);
299- }
300- }
301- }
302- return true;
303-}
304-bool PVeriable::unify(const PEVeriable &horn, ExecContextRoot *c, VLocal *glocal, VLocal *) const {
305- VLocal *hlocal = horn.vl;
306- const PObject *gval = (*glocal)[idx];
307- const PObject *hval = (*hlocal)[horn.idx];
308- if ( gval != 0 ) {
309- if ( hval != 0 ) {
310- return hval->unify( *gval, c, hlocal, glocal);
311- } else {
312- (*hlocal)[horn.idx] = gval;
313- }
314- } else {
315- if ( hval != 0 ) {
316- (*glocal)[idx] = hval;
317- } else {
318- // ここには来ないはず
319- (*glocal)[idx] = &horn;
320- }
321- }
322- return true;
323-}
324-
355+bool PVeriable::unify(const PVeriable &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return vunify_ver<PVeriable>(horn, c, glocal, hlocal); }
356+bool PVeriable::unify(const PEVeriable &horn, ExecContextRoot *c, VLocal *glocal, VLocal *) const { return vunify_ver<PEVeriable>(horn, c, glocal, horn.vl); }
325357 bool PVeriable::unify(const PObject &goal, ExecContextRoot *c) const { return goal.unify(*this, c); }
326358 bool PVeriable::unify(const PNil &horn, ExecContextRoot *c) const { return vunify<PNil>(horn, c, c->gl, c->hl); }
327359 bool PVeriable::unify(const PString &horn, ExecContextRoot *c) const { return vunify<PString>(horn, c, c->gl, c->hl); }
@@ -330,160 +362,29 @@
330362 bool PVeriable::unify(const PList &horn, ExecContextRoot *c) const { return vunify_getval<PList>(horn, c, c->gl, c->hl); }
331363 bool PVeriable::unify(const PArray &horn, ExecContextRoot *c) const { return vunify_getval<PArray>(horn, c, c->gl, c->hl); }
332364 bool PVeriable::unify(const PPredicate &horn, ExecContextRoot *c) const { return vunify_getval<PPredicate>(horn, c, c->gl, c->hl); }
333-bool PVeriable::unify(const PVeriable &horn, ExecContextRoot *c) const {
334- VLocal *glocal = c->gl;
335- VLocal *hlocal = c->hl;
336- const PObject *gval = (*glocal)[idx];
337- const PObject *hval = (*hlocal)[horn.idx];
338- if ( gval != 0 ) {
339- if ( hval != 0 ) {
340- return hval->unify( *gval, c, hlocal, glocal);
341- } else {
342- (*hlocal)[horn.idx] = gval;
343- }
344- } else {
345- if ( hval != 0 ) {
346- (*glocal)[idx] = hval;
347- } else {
348- ExecContext *ec = dynamic_cast<ExecContext*>(c);
349- if ( ec != 0 ) {
350- ec->substitutepair.push_back( SubstitutePair(horn.idx, idx) );
351- } else {
352- (*hlocal)[horn.idx] = getval( c, glocal);
353- }
354- }
355- }
356- return true;
357-}
358-bool PVeriable::unify(const PEVeriable &horn, ExecContextRoot *c) const {
359- VLocal *glocal = c->gl;
360- VLocal *hlocal = horn.vl;
361- const PObject *gval = (*glocal)[idx];
362- const PObject *hval = (*hlocal)[horn.idx];
363- if ( gval != 0 ) {
364- if ( hval != 0 ) {
365- return hval->unify( *gval, c, hlocal, glocal);
366- } else {
367- (*hlocal)[horn.idx] = gval;
368- }
369- } else {
370- if ( hval != 0 ) {
371- (*glocal)[idx] = hval;
372- } else {
373- // ここには来ないはず
374- (*glocal)[idx] = &horn;
375- }
376- }
377- return true;
378-}
365+bool PVeriable::unify(const PVeriable &horn, ExecContextRoot *c) const { return vunify_ver<PVeriable>(horn, c, c->gl, c->hl); }
366+bool PVeriable::unify(const PEVeriable &horn, ExecContextRoot *c) const { return vunify_ver<PEVeriable>(horn, c, c->gl, horn.vl); }
379367
380-
381368 bool PEVeriable::unify(const PObject &goal, ExecContextRoot *c, VLocal *hlocal, VLocal *glocal) const { return goal.unify(*this, c, glocal, hlocal); }
382-bool PEVeriable::unify(const PNil &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return vunify<PNil>(horn, c, glocal, hlocal); }
383-bool PEVeriable::unify(const PString &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return vunify<PString>(horn, c, glocal, hlocal); }
384-bool PEVeriable::unify(const PDouble &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return vunify<PDouble>(horn, c, glocal, hlocal); }
385-bool PEVeriable::unify(const PInteger &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return vunify<PInteger>(horn, c, glocal, hlocal); }
386-bool PEVeriable::unify(const PList &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return vunify_getval<PList>(horn, c, glocal, hlocal); }
387-bool PEVeriable::unify(const PArray &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return vunify_getval<PArray>(horn, c, glocal, hlocal); }
388-bool PEVeriable::unify(const PPredicate &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return vunify_getval<PPredicate>(horn, c, glocal, hlocal); }
389-bool PEVeriable::unify(const PVeriable &horn, ExecContextRoot *c, VLocal *, VLocal *hlocal) const {
390- VLocal *glocal = vl;
391- const PObject *gval = (*glocal)[idx];
392- const PObject *hval = (*hlocal)[horn.idx];
393- if ( gval != 0 ) {
394- if ( hval != 0 ) {
395- return hval->unify( *gval, c, hlocal, glocal);
396- } else {
397- (*hlocal)[horn.idx] = gval;
398- }
399- } else {
400- if ( hval != 0 ) {
401- (*glocal)[idx] = hval;
402- } else {
403- (*hlocal)[horn.idx] = this;
404- }
405- }
406- return true;
407-}
408-bool PEVeriable::unify(const PEVeriable &horn, ExecContextRoot *c, VLocal *, VLocal *) const {
409- VLocal *glocal = vl;
410- VLocal *hlocal = horn.vl;
411- const PObject *gval = (*glocal)[idx];
412- const PObject *hval = (*hlocal)[horn.idx];
413- if ( gval != 0 ) {
414- if ( hval != 0 ) {
415- return hval->unify( *gval, c, hlocal, glocal);
416- } else {
417- (*hlocal)[horn.idx] = gval;
418- }
419- } else {
420- if ( hval != 0 ) {
421- (*glocal)[idx] = hval;
422- } else {
423- ExecContext *ec = dynamic_cast<ExecContext*>(c);
424- if ( ec != 0 ) {
425- ec->substitutepair.push_back( SubstitutePair(horn.idx, idx) );
426- } else {
427- (*hlocal)[horn.idx] = this;
428- }
429- }
430- }
431- return true;
432-}
433-
369+bool PEVeriable::unify(const PNil &horn, ExecContextRoot *c, VLocal *, VLocal *hlocal) const { return vunify<PNil>(horn, c, vl, hlocal); }
370+bool PEVeriable::unify(const PString &horn, ExecContextRoot *c, VLocal *, VLocal *hlocal) const { return vunify<PString>(horn, c, vl, hlocal); }
371+bool PEVeriable::unify(const PDouble &horn, ExecContextRoot *c, VLocal *, VLocal *hlocal) const { return vunify<PDouble>(horn, c, vl, hlocal); }
372+bool PEVeriable::unify(const PInteger &horn, ExecContextRoot *c, VLocal *, VLocal *hlocal) const { return vunify<PInteger>(horn, c, vl, hlocal); }
373+bool PEVeriable::unify(const PList &horn, ExecContextRoot *c, VLocal *, VLocal *hlocal) const { return vunify_getval<PList>(horn, c, vl, hlocal); }
374+bool PEVeriable::unify(const PArray &horn, ExecContextRoot *c, VLocal *, VLocal *hlocal) const { return vunify_getval<PArray>(horn, c, vl, hlocal); }
375+bool PEVeriable::unify(const PPredicate &horn, ExecContextRoot *c, VLocal *, VLocal *hlocal) const { return vunify_getval<PPredicate>(horn, c, vl, hlocal); }
376+bool PEVeriable::unify(const PVeriable &horn, ExecContextRoot *c, VLocal *, VLocal *hlocal) const { return vunify_ver<PVeriable>(horn, c, vl, hlocal); }
377+bool PEVeriable::unify(const PEVeriable &horn, ExecContextRoot *c, VLocal *, VLocal *) const { return vunify_ver<PEVeriable>(horn, c, vl, horn.vl); }
434378 bool PEVeriable::unify(const PObject &goal, ExecContextRoot *c) const { return goal.unify(*this, c); }
435-bool PEVeriable::unify(const PNil &horn, ExecContextRoot *c) const { return vunify<PNil>(horn, c, c->gl, c->hl); }
436-bool PEVeriable::unify(const PString &horn, ExecContextRoot *c) const { return vunify<PString>(horn, c, c->gl, c->hl); }
437-bool PEVeriable::unify(const PDouble &horn, ExecContextRoot *c) const { return vunify<PDouble>(horn, c, c->gl, c->hl); }
438-bool PEVeriable::unify(const PInteger &horn, ExecContextRoot *c) const { return vunify<PInteger>(horn, c, c->gl, c->hl); }
439-bool PEVeriable::unify(const PList &horn, ExecContextRoot *c) const { return vunify_getval<PList>(horn, c, c->gl, c->hl); }
440-bool PEVeriable::unify(const PArray &horn, ExecContextRoot *c) const { return vunify_getval<PArray>(horn, c, c->gl, c->hl); }
441-bool PEVeriable::unify(const PPredicate &horn, ExecContextRoot *c) const { return vunify_getval<PPredicate>(horn, c, c->gl, c->hl); }
442-bool PEVeriable::unify(const PVeriable &horn, ExecContextRoot *c) const {
443- VLocal *glocal = vl;
444- VLocal *hlocal = c->hl;
445- const PObject *gval = (*glocal)[idx];
446- const PObject *hval = (*hlocal)[horn.idx];
447- if ( gval != 0 ) {
448- if ( hval != 0 ) {
449- return hval->unify( *gval, c, hlocal, glocal);
450- } else {
451- (*hlocal)[horn.idx] = gval;
452- }
453- } else {
454- if ( hval != 0 ) {
455- (*glocal)[idx] = hval;
456- } else {
457- (*hlocal)[horn.idx] = this;
458- }
459- }
460- return true;
461-}
462-bool PEVeriable::unify(const PEVeriable &horn, ExecContextRoot *c) const {
463- VLocal *glocal = vl;
464- VLocal *hlocal = horn.vl;
465- const PObject *gval = (*glocal)[idx];
466- const PObject *hval = (*hlocal)[horn.idx];
467- if ( gval != 0 ) {
468- if ( hval != 0 ) {
469- return hval->unify( *gval, c, hlocal, glocal);
470- } else {
471- (*hlocal)[horn.idx] = gval;
472- }
473- } else {
474- if ( hval != 0 ) {
475- (*glocal)[idx] = hval;
476- } else {
477- ExecContext *ec = dynamic_cast<ExecContext*>(c);
478- if ( ec != 0 ) {
479- ec->substitutepair.push_back( SubstitutePair(horn.idx, idx) );
480- } else {
481- (*hlocal)[horn.idx] = this;
482- }
483- }
484- }
485- return true;
486-}
379+bool PEVeriable::unify(const PNil &horn, ExecContextRoot *c) const { return vunify<PNil>(horn, c, vl, c->hl); }
380+bool PEVeriable::unify(const PString &horn, ExecContextRoot *c) const { return vunify<PString>(horn, c, vl, c->hl); }
381+bool PEVeriable::unify(const PDouble &horn, ExecContextRoot *c) const { return vunify<PDouble>(horn, c, vl, c->hl); }
382+bool PEVeriable::unify(const PInteger &horn, ExecContextRoot *c) const { return vunify<PInteger>(horn, c, vl, c->hl); }
383+bool PEVeriable::unify(const PList &horn, ExecContextRoot *c) const { return vunify_getval<PList>(horn, c, vl, c->hl); }
384+bool PEVeriable::unify(const PArray &horn, ExecContextRoot *c) const { return vunify_getval<PArray>(horn, c, vl, c->hl); }
385+bool PEVeriable::unify(const PPredicate &horn, ExecContextRoot *c) const { return vunify_getval<PPredicate>(horn, c, vl, c->hl); }
386+bool PEVeriable::unify(const PVeriable &horn, ExecContextRoot *c) const { return vunify_ver<PVeriable>(horn, c, vl, c->hl); }
387+bool PEVeriable::unify(const PEVeriable &horn, ExecContextRoot *c) const { return vunify_ver<PEVeriable>(horn, c, vl, horn.vl); }
487388
488389 /*************************************** uphorn ******************************************/
489390 bool PHorn::upHorn(const PPredicate &goal, ExecContext &c, bool skipnamechk)
@@ -530,6 +431,7 @@
530431 const PObject *p = (*i)->getval( c);
531432 if ( p != *i && po == 0 ) {
532433 po = pmm.newPArray(c->pobjs, *this);
434+ po->constant = true;
533435 }
534436 if ( po ) {
535437 po->value[i - value.begin()] = p;
--- trunk/adp_compile.h (revision 283)
+++ trunk/adp_compile.h (revision 284)
@@ -1495,27 +1495,10 @@
14951495 virtual bool unify(const PEVeriable &horn, ExecContextRoot *c) const;
14961496
14971497 // 変項のunify本体で使うテンプレート関数
1498- template <class T> bool vunify(const T &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const {
1499- const PObject *gitem = (*glocal)[idx];
1500- if ( gitem == 0 ) {
1501- (*glocal)[idx] = &horn;
1502- } else {
1503- return gitem->unify( horn, c, glocal, hlocal);
1504- }
1505- return true;
1506- }
1498+ template <class T> bool vunify(const T &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const;
1499+ template <class T> bool vunify_getval(const T &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const;
1500+ template <class T> bool vunify_ver(const T &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const;
15071501
1508- // 変項のunify本体で使うテンプレート関数
1509- template <class T> bool vunify_getval(const T &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const {
1510- const PObject *gitem = (*glocal)[idx];
1511- if ( gitem == 0 ) {
1512- (*glocal)[idx] = horn.getval(c, hlocal);
1513- } else {
1514- return gitem->unify( horn, c, glocal, hlocal);
1515- }
1516- return true;
1517- }
1518-
15191502 // 値の取得
15201503 virtual const PObject *getval( ExecContextRoot *c) const ;
15211504 virtual const PObject *getval( ExecContextRoot *c, VLocal *vlocal) const ;
@@ -1689,9 +1672,8 @@
16891672
16901673 // 変項のunify本体で使うテンプレート関数
16911674 template <class T> bool vunify(const T &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const;
1692-
1693- // 変項のunify本体で使うテンプレート関数
16941675 template <class T> bool vunify_getval(const T &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const;
1676+ template <class T> bool vunify_ver(const T &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const;
16951677
16961678 // 値の取得
16971679 virtual const PObject *getval( ExecContextRoot *c) const;
@@ -1902,7 +1884,7 @@
19021884 void addPHorns(PHorns &horns_);
19031885 size_t size() { return horns.size(); }
19041886 bool empty() { return horns.empty(); }
1905- PHorn &upHorn(size_t idx) { return *horns[idx]; }
1887+ PHorn *upHorn(size_t idx) { return horns[idx]; }
19061888 };
19071889
19081890
--- trunk/kz_array_noexpand.h (revision 283)
+++ trunk/kz_array_noexpand.h (revision 284)
@@ -127,10 +127,7 @@
127127 return _data[_size-1];
128128 }
129129 __forceinline _T &operator[](size_t idx) __attribute__((always_inline)) {
130- //assert(idx < _size);
131- // debug
132- if ( idx >= _size ) { char *p = 0; *p = '0'; }
133-
130+ assert(idx < _size);
134131 return _data[idx];
135132 }
136133 __forceinline const _T operator[](size_t idx) const __attribute__((always_inline)) {
--- trunk/kz_array.h (revision 283)
+++ trunk/kz_array.h (revision 284)
@@ -128,9 +128,6 @@
128128 }
129129
130130 __forceinline const _T operator[](size_t idx) const __attribute__((always_inline)) {
131- if ( idx >= _size ) {
132- cout << "error!";
133- }
134131 assert(idx < _size);
135132 return _data[idx];
136133 }
--- trunk/adp_execute.h (revision 283)
+++ trunk/adp_execute.h (revision 284)
@@ -34,6 +34,9 @@
3434 VLocal *gl; /* Goal側のローカル変数のポインタ */
3535 VLocal *hl; /* Horn側のローカル変数のポインタ */
3636
37+ size_t uidx; /* ユニフィケート中の引数のidx */
38+ const PArray *ao; /* 可変長引数対応時の配列 */
39+
3740 __forceinline void init(ExecContext *p_, void *f_, const PPredicate *pred_, VLocal *l) __attribute__((always_inline)) {
3841 p = p_;
3942 f = (ExecContext_Factory*)f_;
@@ -42,6 +45,7 @@
4245 pobjs = 0;
4346 pred = pred_;
4447 gl = hl = l;
48+ uidx = 0;
4549 }
4650 __forceinline void init(const PPredicate *pred_, VLocal *l) __attribute__((always_inline)) {
4751 delflg = true;
@@ -48,6 +52,7 @@
4852 firstflg = true;
4953 pred = pred_;
5054 gl = hl = l;
55+ uidx = 0;
5156 }
5257
5358 ExecContextRoot(ExecContext *p_, void *f_, const PPredicate *pred_, VLocal *l) { init(p_, f_, pred_, l); }
@@ -516,12 +521,6 @@
516521 }
517522 };
518523
519-struct SubstitutePair {
520- size_t idxh;
521- size_t idxg;
522- SubstitutePair() : idxh(0), idxg(0) {}
523- SubstitutePair( size_t idxh_, size_t idxg_) : idxh(idxh_), idxg(idxg_) {}
524-};
525524
526525 // オブジェクトの破棄
527526 struct MyDeleteEC {
@@ -534,9 +533,10 @@
534533 struct ExecContext : public ExecContextBase {
535534 VLocal hlocal; /* ホーン節側ローカル */
536535
537- ArrayNoexpand<SubstitutePair> substitutepair; /* 代入最適化用 */
536+ ArrayNoexpand<size_t> afterunify; /* 評価後に再度ユニふぃけーしょんを行う(戻り値) */
538537
539- const PGoal *goal; /* 評価中のゴール */
538+ PHorn *horn; /* 評価中のホーン */
539+ const PGoal *goal; /* 評価中のゴール(ホーン節の本体) */
540540 size_t vcnt; /* 変数スタックのサイズ、p == 0 のときのみ有効 */
541541 const PPredicate *g; /* 評価中の述語 */
542542
@@ -556,9 +556,10 @@
556556 bool last_result; /* 最新の述語の評価結果(result_returnフラグが追加述語の評価後のみ有効) */
557557
558558 __forceinline void init() __attribute__((always_inline)) {
559+ horn = 0;
559560 goal = 0;
560561 hl = &hlocal; // ローカル変数エリア
561- // ecs,substitutepairのreserveはfirst,backtrackで行う
562+ // ecs,afterunifyのreserveはfirst,backtrackで行う
562563 horns = 0;
563564 skipnamechk = false;
564565 hornidx = 0;
@@ -567,13 +568,14 @@
567568 nextidx = (size_t)-1;
568569 pipe = 0;
569570 trueflg = false;
570- substitutepair.reserve(pred->size());
571+ afterunify.reserve(pred->size());
571572 nobacktrack = false;
572573 last_result = false;
573574 };
574575
575576 ExecContext(PGoal &goal_, size_t vcnt_) : ExecContextBase(),
576- hlocal(), substitutepair(), vcnt(vcnt_), g(0), ecs() {
577+ hlocal(), afterunify(), vcnt(vcnt_), g(0), ecs() {
578+ horn = 0;
577579 goal = &goal_;
578580 hlocal.assign( vcnt, 0); // ローカル変数エリアの確保
579581 hl = &hlocal; // ローカル変数エリア
@@ -580,7 +582,7 @@
580582 gl = hl;
581583 ExecContextBase::backup = *gl; // ややこしいがCut述語使用時の整合性を取る為ここでバッグアップを取得しておく
582584 ecs.assign(goal->size(), 0);
583- substitutepair.reserve(vcnt);
585+ afterunify.reserve(vcnt);
584586 horns = 0;
585587 skipnamechk = false;
586588 hornidx = 0;
@@ -594,7 +596,7 @@
594596 }
595597
596598 ExecContext(ExecContext *p_, void *f_, const PPredicate *pred_, VLocal *l) : ExecContextBase(p_, f_, pred_, l),
597- hlocal(), substitutepair(), vcnt(0), g(0), ecs() {
599+ hlocal(), afterunify(), vcnt(0), g(0), ecs() {
598600 init();
599601 }
600602
@@ -694,30 +696,6 @@
694696 struct ExecContext_Cut : public ExecContextRoot {
695697 ExecContext_Cut(ExecContext *p_, void *f_, const PPredicate *pred_, VLocal *l) : ExecContextRoot(p_, f_, pred_, l) { delflg = false; }
696698 virtual bool first(PException &excp) {
697-#if 0
698- if ( this->p->pred ) {
699- for ( size_t i = 0; i < this->p->pred->arglist.size(); i++ ) {
700- const PVeriable *v = dynamic_cast<const PVeriable*>((*this->p->pred)[i]);
701- if ( v ) {
702- const PObject *p = (*this->p->gl)[v->idx];
703- if ( p ) (*this->p->gl)[v->idx] = p->getval(this->p,gl)->clone(&this->p->objs);
704- }
705- }
706- }
707-
708-#else
709- for ( Array<SubstitutePair>::iterator i = p->substitutepair.begin(); i < p->substitutepair.end(); i++ ) {
710- const PObject *g = (*p->gl)[(*i).idxg];
711- if ( g ) {
712- if ( !g->unify( *(*p->hl)[(*i).idxh], this->p, p->gl, p->hl) ) return false;
713- } else {
714- const PObject *n = (*p->hl)[(*i).idxh];
715- if ( n ) {
716- (*p->gl)[(*i).idxg] = n->getval(this->p, p->hl);
717- }
718- }
719- }
720-
721699 // 親のローカル変数の値をcloneする、
722700 for ( size_t i = 0; i < p->hlocal.size(); i++ ) {
723701 if ( p->hlocal[i] != 0 ) {
@@ -724,12 +702,6 @@
724702 p->hlocal[i] = p->hlocal[i]->getval(p,&p->hlocal)->clone(&p->objs);
725703 }
726704 }
727- for ( size_t i = 0; i < p->gl->size(); i++ ) {
728- if ( (*p->gl)[i] != p->backup[i] ) {
729- (*p->gl)[i] = (*p->gl)[i]->getval(p,p->gl)->clone(&p->objs);
730- }
731- }
732-#endif
733705 for ( size_t i = 0; i < p->goalidx; i++ ) {
734706 ExecContextRoot *e = p->ecs[i];
735707 if ( e ) {
--- trunk/adp_mm.cpp (revision 283)
+++ trunk/adp_mm.cpp (revision 284)
@@ -40,11 +40,11 @@
4040 }
4141 void PList::del() {
4242 #ifndef NDEBUG
43- cerr << "delete[" ;
44- lvalue->recompile(cerr);
45- cerr << "|" ;
46- rvalue->recompile(cerr);
47- cerr << "]" << endl;
43+// cerr << "delete[" ;
44+// lvalue->recompile(cerr);
45+// cerr << "|" ;
46+// rvalue->recompile(cerr);
47+// cerr << "]" << endl;
4848 lvalue = 0;
4949 rvalue = 0;
5050 constant = false;
--- trunk/adp_execute.cpp (revision 283)
+++ trunk/adp_execute.cpp (revision 284)
@@ -207,7 +207,7 @@
207207 } else {
208208 // コンテクストの保存
209209 hlocal = p->hlocal;
210- substitutepair = p->substitutepair;
210+ afterunify = p->afterunify;
211211 goal = p->goal;
212212 vcnt = p->vcnt;
213213 g = p->g;
@@ -295,7 +295,7 @@
295295
296296 // コンテクストのコピーバック
297297 d->hlocal = hlocal;
298- d->substitutepair = substitutepair;
298+ d->afterunify = afterunify;
299299 //d->goal = goal;
300300 //d->vcnt = vcnt;
301301 //d->g = g;
@@ -623,11 +623,11 @@
623623 // ホーン節の検索
624624 while ( true ) {
625625 goal = 0;
626- PHorn &horn = horns->upHorn(hornidx);
627- hl->assign( horn.getVcnt(), 0);
628- substitutepair.clear();
629- if ( horn.upHorn(*pred, *this, skipnamechk) ) {
630- goal = &horn.getGoal();
626+ horn = horns->upHorn(hornidx);
627+ hl->assign( horn->getVcnt(), 0);
628+ afterunify.clear();
629+ if ( horn->upHorn(*pred, *this, skipnamechk) ) {
630+ goal = &horn->getGoal();
631631 if ( goal->empty() ) {
632632 if ( goal->nobacktrack == true ) delflg = true;
633633 return true;
@@ -640,23 +640,25 @@
640640 ecs.assign(s,0); // メモリの予約
641641 bool flg = execute(excp, true);
642642 if ( flg ) {
643+ size_t hsiz = horn->head.arglist.value.size();
644+ size_t gsiz = pred->arglist.value.size();
645+ ExecContext *e = goal->nobacktrack == true ? this->p : this;
643646 // 実行後の代入処理
644- for ( Array<SubstitutePair>::iterator i = substitutepair.begin(); i < substitutepair.end(); i++ ) {
645- const PObject *g = (*gl)[(*i).idxg];
646- if ( g ) {
647- flg = g->unify( *(*hl)[(*i).idxh], this->p, gl, hl);
648- if ( !flg ) break;
649- } else {
650- const PObject *n = (*hl)[(*i).idxh];
651- if ( n ) {
652- (*gl)[(*i).idxg] = n->getval(this->p, hl);
653- }
647+ for ( ArrayNoexpand<size_t>::iterator i = afterunify.begin(); i < afterunify.end(); i++ ) {
648+ if ( hsiz == gsiz || ((*i) < hsiz - 1 && (*i) < gsiz - 1) ) {
649+ flg = horn->head.arglist.value[*i]->unify( *pred->arglist.value[*i], e, hl, gl);
650+ } else if ( gsiz < hsiz ) {
651+ flg = pred->arglist.value[*i]->unify( *ao, e, gl, hl);
652+ } else {
653+ flg = horn->head.arglist.value[*i]->unify( *ao, e, hl, gl);
654654 }
655+ if ( !flg ) break;
655656 }
656657 if ( flg ) {
657658 if ( goal->nobacktrack == true ) {
658659 // ↓変数の受け渡しをclone/deleteで行っているが、objs間の移動の方が効率はよくないか?(検索が入るのでこちらの方が早い?)
659660 // バグフィックス
661+#if 1
660662 for ( size_t i = 0; i < pred->arglist.size(); i++ ) {
661663 const PVeriable *v = dynamic_cast<const PVeriable*>((*pred)[i]);
662664 if ( v ) {
@@ -664,6 +666,7 @@
664666 if ( p ) (*gl)[v->idx] = p->getval(this->p,gl)->clone(&this->p->objs);
665667 }
666668 }
669+#endif
667670 // バグフィックス(開放処理をここで行う
668671 for (size_t i = 0; i < ecs.size(); i++ ) {
669672 ExecContextRoot *e = ecs[i];
@@ -718,22 +721,24 @@
718721 // ゴールの評価が成功すれば代入を行う(成功終了)。
719722 if ( flg ) {
720723 // 実行後の代入処理
721- for ( Array<SubstitutePair>::iterator i = substitutepair.begin(); i < substitutepair.end(); i++ ) {
722- const PObject *g = (*gl)[(*i).idxg];
723- if ( g ) {
724- flg = g->unify( *(*hl)[(*i).idxh], this, gl, hl);
725- if ( !flg ) break;
726- } else {
727- const PObject *n = (*hl)[(*i).idxh];
728- if ( n ) {
729- (*gl)[(*i).idxg] = n->getval(this, hl);
730- }
724+ size_t hsiz = horn->head.arglist.value.size();
725+ size_t gsiz = pred->arglist.value.size();
726+ // 実行後の代入処理
727+ for ( ArrayNoexpand<size_t>::iterator i = afterunify.begin(); i < afterunify.end(); i++ ) {
728+ if ( hsiz == gsiz || ((*i) < hsiz - 1 && (*i) < gsiz - 1) ) {
729+ flg = horn->head.arglist.value[*i]->unify( *pred->arglist.value[*i], this->p, hl, gl);
730+ } else if ( gsiz < hsiz ) {
731+ flg = pred->arglist.value[*i]->unify( *ao, this->p, gl, hl);
732+ } else {
733+ flg = horn->head.arglist.value[*i]->unify( *ao, this->p, hl, gl);
731734 }
735+ if ( !flg ) break;
732736 }
733737 if ( flg ) {
734738 if ( goal->nobacktrack == true ) {
735739 // ↓変数の受け渡しをclone/deleteで行っているが、objs間の移動の方が効率はよくないか?(検索が入るのでこちらの方が早い?)
736740 // バグフィックス
741+#if 1
737742 for ( size_t i = 0; i < pred->arglist.size(); i++ ) {
738743 const PVeriable *v = dynamic_cast<const PVeriable*>((*pred)[i]);
739744 if ( v ) {
@@ -741,6 +746,7 @@
741746 if ( p ) (*gl)[v->idx] = p->getval(this->p,gl)->clone(&this->p->objs);
742747 }
743748 }
749+#endif
744750 // バグフィックス(開放処理をここで行う
745751 for (size_t i = 0; i < ecs.size(); i++ ) {
746752 ExecContextRoot *e = ecs[i];
@@ -765,12 +771,12 @@
765771 }
766772 // 別のホーン節の検索
767773 goal = 0;
768- PHorn &horn = horns->upHorn(hornidx);
769- hl->assign( horn.getVcnt(), 0);
774+ horn = horns->upHorn(hornidx);
775+ hl->assign( horn->getVcnt(), 0);
770776 (*gl) = backup; // 保存していた変数の復元
771- substitutepair.clear();
772- if ( horn.upHorn(*pred, *this, skipnamechk) ) {
773- goal = &horn.getGoal();
777+ afterunify.clear();
778+ if ( horn->upHorn(*pred, *this, skipnamechk) ) {
779+ goal = &horn->getGoal();
774780 if ( goal->empty() ) {
775781 if ( goal->nobacktrack == true ) delflg = true;
776782 return true;
@@ -874,8 +880,8 @@
874880 set_gc(this);
875881 PException excp;
876882 for ( goalidx = 0; goalidx < topgoals.size(); goalidx++ ) {
877- PGoal &g = topgoals.upHorn(goalidx).getGoal();
878- ExecContext ec( g, topgoals.upHorn(goalidx).getVcnt());
883+ PGoal &g = topgoals.upHorn(goalidx)->getGoal();
884+ ExecContext ec( g, topgoals.upHorn(goalidx)->getVcnt());
879885 try {
880886 excp.clear();
881887 ret = ec.execute(excp, true);
Show on old repository browser