• R/O
  • SSH
  • HTTPS

adp: Commit


Commit MetaInfo

Revision285 (tree)
Time2012-06-05 12:56:42
Authorohfuji

Log Message

すべてのテストが通ったのでコミット

Change Summary

Incremental Difference

--- trunk/adp_unify.cpp (revision 284)
+++ trunk/adp_unify.cpp (revision 285)
@@ -86,18 +86,15 @@
8686 const PObject *gitem = (*glocal)[idx];
8787 if ( gitem == 0 ) {
8888 const PObject *p = horn.getval(c, hlocal);
89- if ( p->isc() ) {
90- (*glocal)[idx] = p;
91- return true;
92- }
89+ (*glocal)[idx] = p;
90+ if ( p->isc() ) return true;
9391 } else {
9492 return gitem->unify( horn, c, glocal, hlocal);
9593 }
9694
9795 #if 1
98- ExecContext *ec = dynamic_cast<ExecContext*>(c);
99- if ( ec != 0 ) {
100- ec->afterunify.push_back(c->uidx);
96+ if ( c->pafterunify != 0 ) {
97+ c->pafterunify->push_back(c->uidx);
10198 }
10299 #endif
103100 return true;
@@ -110,19 +107,20 @@
110107 if ( gval != 0 ) {
111108 if ( hval != 0 ) {
112109 return hval->unify( *gval, c, hlocal, glocal);
113- } else if ( gval->isc() ) {
114- (*hlocal)[horn.idx] = gval;
115- return true;
110+ } else {
111+ const PObject *p = gval->getval(c, glocal);
112+ (*hlocal)[horn.idx] = p;
113+ if ( p->isc() ) return true;
116114 }
117- } else if ( hval != 0 && hval->isc() ) {
118- (*glocal)[idx] = hval;
119- return true;
115+ } else if ( hval != 0 ) {
116+ const PObject *p = hval->getval(c, hlocal);
117+ (*glocal)[idx] = p;
118+ if ( p->isc() ) return true;
120119 }
121120
122121 #if 1
123- ExecContext *ec = dynamic_cast<ExecContext*>(c);
124- if ( ec != 0 ) {
125- ec->afterunify.push_back(c->uidx);
122+ if ( c->pafterunify != 0 ) {
123+ c->pafterunify->push_back(c->uidx);
126124 }
127125 #endif
128126 return true;
@@ -145,18 +143,15 @@
145143 const PObject *gitem = (*glocal)[idx];
146144 if ( gitem == 0 ) {
147145 const PObject *p = horn.getval(c, hlocal);
148- if ( p->isc() ) {
149- (*glocal)[idx] = p;
150- return true;
151- }
146+ (*glocal)[idx] = p;
147+ if ( p->isc() ) return true;
152148 } else {
153149 return gitem->unify( horn, c, glocal, hlocal);
154150 }
155151
156152 #if 1
157- ExecContext *ec = dynamic_cast<ExecContext*>(c);
158- if ( ec != 0 ) {
159- ec->afterunify.push_back(c->uidx);
153+ if ( c->pafterunify != 0 ) {
154+ c->pafterunify->push_back(c->uidx);
160155 }
161156 #endif
162157 return true;
@@ -169,19 +164,19 @@
169164 if ( gval != 0 ) {
170165 if ( hval != 0 ) {
171166 return hval->unify( *gval, c, hlocal, glocal);
172- } else if ( gval->isc() ) {
173- (*hlocal)[horn.idx] = gval;
174- return true;
167+ } else {
168+ const PObject *p = gval->getval(c, glocal);
169+ (*hlocal)[horn.idx] = p;
170+ if ( p->isc() ) return true;
175171 }
176- } else if ( hval != 0 && hval->isc() ) {
177- (*glocal)[idx] = hval;
178- return true;
172+ } else if ( hval != 0 ) {
173+ const PObject *p = hval->getval(c, hlocal);
174+ (*glocal)[idx] = p;
175+ if ( p->isc() ) return true;
179176 }
180-
181177 #if 1
182- ExecContext *ec = dynamic_cast<ExecContext*>(c);
183- if ( ec != 0 ) {
184- ec->afterunify.push_back(c->uidx);
178+ if ( c->pafterunify != 0 ) {
179+ c->pafterunify->push_back(c->uidx);
185180 }
186181 #endif
187182 return true;
@@ -326,7 +321,7 @@
326321 if ( !nspace.empty() && strcmp( horn.nspace.c_str(), nspace.c_str()) != 0 ) { return false; }
327322
328323 if ( !horn.name->unify( *name, c, hlocal, glocal) ) { return false; }
329- return arglist.unify( horn.arglist, c, glocal, hlocal); // horn.arglistがPObjextでない場合はこのように呼び出す
324+ return arglist.unify( horn.arglist, c, glocal, hlocal); // horn.arglistがPObjectでない場合はこのように呼び出す
330325 }
331326 bool PPredicate::unify(const PVeriable &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return horn.vunify_getval<PPredicate>(*this, c, hlocal, glocal); }
332327 bool PPredicate::unify(const PEVeriable &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal) const { return horn.vunify_getval<PPredicate>(*this, c, horn.vl, glocal); }
@@ -338,7 +333,7 @@
338333 if ( !nspace.empty() && strcmp( horn.nspace.c_str(), nspace.c_str()) != 0 ) { return false; }
339334
340335 if ( !horn.name->unify( *name, c) ) { return false; }
341- return arglist.unify( horn.arglist, c); // horn.arglistがPObjextでない場合はこのように呼び出す
336+ return arglist.unify( horn.arglist, c); // horn.arglistがPObjectでない場合はこのように呼び出す
342337 }
343338 bool PPredicate::unify(const PVeriable &horn, ExecContextRoot *c) const { return horn.vunify_getval<PPredicate>(*this, c, c->hl, c->gl); }
344339 bool PPredicate::unify(const PEVeriable &horn, ExecContextRoot *c) const { return horn.vunify_getval<PPredicate>(*this, c, horn.vl, c->gl); }
--- trunk/adp_execute.h (revision 284)
+++ trunk/adp_execute.h (revision 285)
@@ -35,7 +35,9 @@
3535 VLocal *hl; /* Horn側のローカル変数のポインタ */
3636
3737 size_t uidx; /* ユニフィケート中の引数のidx */
38- const PArray *ao; /* 可変長引数対応時の配列 */
38+ ArrayNoexpand<size_t> *pafterunify; /* ExecContext::afterunifyのエリアス 0:評価後で使用しないまたはExecContextではない */
39+ const PArray *ao; /* 可変長引数対応時の配列 PArray::unifyで設定 */
40+
3941
4042 __forceinline void init(ExecContext *p_, void *f_, const PPredicate *pred_, VLocal *l) __attribute__((always_inline)) {
4143 p = p_;
@@ -46,6 +48,7 @@
4648 pred = pred_;
4749 gl = hl = l;
4850 uidx = 0;
51+ pafterunify = 0;
4952 }
5053 __forceinline void init(const PPredicate *pred_, VLocal *l) __attribute__((always_inline)) {
5154 delflg = true;
@@ -53,6 +56,7 @@
5356 pred = pred_;
5457 gl = hl = l;
5558 uidx = 0;
59+ pafterunify = 0;
5660 }
5761
5862 ExecContextRoot(ExecContext *p_, void *f_, const PPredicate *pred_, VLocal *l) { init(p_, f_, pred_, l); }
@@ -533,7 +537,7 @@
533537 struct ExecContext : public ExecContextBase {
534538 VLocal hlocal; /* ホーン節側ローカル */
535539
536- ArrayNoexpand<size_t> afterunify; /* 評価後に再度ユニふぃけーしょんを行う(戻り値) */
540+ ArrayNoexpand<size_t> afterunify; /* 評価後に再度ユニフィケーションを行う引数のIDX */
537541
538542 PHorn *horn; /* 評価中のホーン */
539543 const PGoal *goal; /* 評価中のゴール(ホーン節の本体) */
@@ -569,6 +573,7 @@
569573 pipe = 0;
570574 trueflg = false;
571575 afterunify.reserve(pred->size());
576+ pafterunify = &afterunify;
572577 nobacktrack = false;
573578 last_result = false;
574579 };
@@ -583,6 +588,7 @@
583588 ExecContextBase::backup = *gl; // ややこしいがCut述語使用時の整合性を取る為ここでバッグアップを取得しておく
584589 ecs.assign(goal->size(), 0);
585590 afterunify.reserve(vcnt);
591+ pafterunify = &afterunify;
586592 horns = 0;
587593 skipnamechk = false;
588594 hornidx = 0;
--- trunk/adp_execute.cpp (revision 284)
+++ trunk/adp_execute.cpp (revision 285)
@@ -626,6 +626,7 @@
626626 horn = horns->upHorn(hornidx);
627627 hl->assign( horn->getVcnt(), 0);
628628 afterunify.clear();
629+ pafterunify = &afterunify;
629630 if ( horn->upHorn(*pred, *this, skipnamechk) ) {
630631 goal = &horn->getGoal();
631632 if ( goal->empty() ) {
@@ -643,6 +644,9 @@
643644 size_t hsiz = horn->head.arglist.value.size();
644645 size_t gsiz = pred->arglist.value.size();
645646 ExecContext *e = goal->nobacktrack == true ? this->p : this;
647+ ArrayNoexpand<size_t> *bk = this->p->pafterunify;
648+ this->p->pafterunify = 0;
649+ this->pafterunify = 0;
646650 // 実行後の代入処理
647651 for ( ArrayNoexpand<size_t>::iterator i = afterunify.begin(); i < afterunify.end(); i++ ) {
648652 if ( hsiz == gsiz || ((*i) < hsiz - 1 && (*i) < gsiz - 1) ) {
@@ -652,8 +656,11 @@
652656 } else {
653657 flg = horn->head.arglist.value[*i]->unify( *ao, e, hl, gl);
654658 }
655- if ( !flg ) break;
659+ if ( !flg ) {
660+ break;
661+ }
656662 }
663+ this->p->pafterunify = bk;
657664 if ( flg ) {
658665 if ( goal->nobacktrack == true ) {
659666 // ↓変数の受け渡しをclone/deleteで行っているが、objs間の移動の方が効率はよくないか?(検索が入るのでこちらの方が早い?)
@@ -723,17 +730,22 @@
723730 // 実行後の代入処理
724731 size_t hsiz = horn->head.arglist.value.size();
725732 size_t gsiz = pred->arglist.value.size();
733+ ExecContext *e = goal->nobacktrack == true ? this->p : this;
734+ ArrayNoexpand<size_t> *bk = this->p->pafterunify;
735+ this->p->pafterunify = 0;
736+ this->pafterunify = 0;
726737 // 実行後の代入処理
727738 for ( ArrayNoexpand<size_t>::iterator i = afterunify.begin(); i < afterunify.end(); i++ ) {
728739 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);
740+ flg = horn->head.arglist.value[*i]->unify( *pred->arglist.value[*i], e, hl, gl);
730741 } else if ( gsiz < hsiz ) {
731- flg = pred->arglist.value[*i]->unify( *ao, this->p, gl, hl);
742+ flg = pred->arglist.value[*i]->unify( *ao, e, gl, hl);
732743 } else {
733- flg = horn->head.arglist.value[*i]->unify( *ao, this->p, hl, gl);
744+ flg = horn->head.arglist.value[*i]->unify( *ao, e, hl, gl);
734745 }
735746 if ( !flg ) break;
736747 }
748+ this->p->pafterunify = bk;
737749 if ( flg ) {
738750 if ( goal->nobacktrack == true ) {
739751 // ↓変数の受け渡しをclone/deleteで行っているが、objs間の移動の方が効率はよくないか?(検索が入るのでこちらの方が早い?)
@@ -775,6 +787,7 @@
775787 hl->assign( horn->getVcnt(), 0);
776788 (*gl) = backup; // 保存していた変数の復元
777789 afterunify.clear();
790+ pafterunify = &afterunify;
778791 if ( horn->upHorn(*pred, *this, skipnamechk) ) {
779792 goal = &horn->getGoal();
780793 if ( goal->empty() ) {
Show on old repository browser