• R/O
  • SSH
  • HTTPS

adp: Commit


Commit MetaInfo

Revision304 (tree)
Time2012-06-08 11:21:32
Authorohfuji

Log Message

!failを入れてみた

Change Summary

Incremental Difference

--- trunk/adp_execute_factory.cpp (revision 303)
+++ trunk/adp_execute_factory.cpp (revision 304)
@@ -125,6 +125,8 @@
125125 ExecContext_Factory newExecContext_Times( newExecContext_Times_Function);
126126 ExecContextRoot *newExecContext_Cut_Function(ExecContext *p_, void *f_, const PPredicate *pred_, VLocal *l) { return new ExecContext_Cut( p_, f_, pred_, l); }
127127 ExecContext_Factory newExecContext_Cut( newExecContext_Cut_Function);
128+ExecContextRoot *newExecContext_CutFail_Function(ExecContext *p_, void *f_, const PPredicate *pred_, VLocal *l) { return new ExecContext_CutFail( p_, f_, pred_, l); }
129+ExecContext_Factory newExecContext_CutFail( newExecContext_CutFail_Function);
128130
129131 ExecContextRoot *newExecContext_Fail_Function(ExecContext *p_, void *f_, const PPredicate *pred_, VLocal *l) { return new ExecContext_Fail( p_, f_, pred_, l); }
130132 ExecContext_Factory newExecContext_Fail( newExecContext_Fail_Function);
@@ -493,6 +495,7 @@
493495 factory_map.insert(ExecContext_Factory_Pair( string("counter"), &newExecContext_Counter));
494496 factory_map.insert(ExecContext_Factory_Pair( string("times"), &newExecContext_Times));
495497 factory_map.insert(ExecContext_Factory_Pair( string("!"), &newExecContext_Cut));
498+ factory_map.insert(ExecContext_Factory_Pair( string("!fail"), &newExecContext_CutFail));
496499 factory_map.insert(ExecContext_Factory_Pair( string("fail"), &newExecContext_Fail));
497500 factory_map.insert(ExecContext_Factory_Pair( string("raise"), &newExecContext_Raise));
498501 factory_map.insert(ExecContext_Factory_Pair( string("next"), &newExecContext_Next));
--- trunk/adp_execute.h (revision 303)
+++ trunk/adp_execute.h (revision 304)
@@ -470,7 +470,6 @@
470470 // マルチスレッド動作時の整合性を保つため、gl = ExecContext.hlocalとする
471471 }
472472 ExecContextBase(ExecContext *p_, void *f_, const PPredicate *pred_, VLocal *l) : ExecContextRoot(p_, f_, pred_, l), backup(), objs() {
473- pobjs = &objs;
474473 init();
475474 }
476475 // recreate メモリマネージャレベルでのオブジェクトのリサイクル
@@ -568,7 +567,7 @@
568567 horn = 0;
569568 goal = 0;
570569 hl = &hlocal; // ローカル変数エリア
571- // ecs,afterunifyのreserveはfirst,backtrackで行う
570+ afterunify.reserve(pred->size());
572571 horns = 0;
573572 skipnamechk = false;
574573 hornidx = 0;
@@ -577,7 +576,6 @@
577576 nextidx = (size_t)-1;
578577 pipe = 0;
579578 trueflg = false;
580- afterunify.reserve(pred->size());
581579 nobacktrack = false;
582580 last_result = false;
583581 };
@@ -592,6 +590,7 @@
592590 ExecContextBase::backup = *gl; // ややこしいがCut述語使用時の整合性を取る為ここでバッグアップを取得しておく
593591 ecs.assign(goal->size(), 0);
594592 afterunify.reserve(vcnt);
593+ afterunify.clear();
595594 horns = 0;
596595 skipnamechk = false;
597596 hornidx = 0;
@@ -622,7 +621,7 @@
622621 bool execute(PException &excp, bool forward);
623622
624623 virtual void cleanup() {
625- for_each( ecs.begin(), ecs.end(), MyDeleteObject());
624+ for_each( ecs.begin(), ecs.end(), MyDeleteEC());
626625 ecs.clear();
627626 ExecContextBase::cleanup();
628627 }
@@ -704,6 +703,11 @@
704703
705704 struct ExecContext_Cut : public ExecContextRoot {
706705 ExecContext_Cut(ExecContext *p_, void *f_, const PPredicate *pred_, VLocal *l) : ExecContextRoot(p_, f_, pred_, l) { delflg = false; }
706+ virtual void recreate(const PPredicate *pred_, VLocal *l) { ExecContextRoot::init(pred_, l); delflg = false; }
707+ virtual void recreate(ExecContext *p_, void *f_, const PPredicate *pred_, VLocal *l) { ExecContextRoot::init(p_,f,pred_, l); delflg = false; }
708+ virtual void reinit(const PPredicate *pred_, VLocal *l) { ExecContextRoot::init(pred_, l); delflg = false; }
709+ virtual void reinit(ExecContext *p_, void *f_, const PPredicate *pred_, VLocal *l) { ExecContextRoot::init(p_,f,pred_, l); delflg = false; }
710+
707711 virtual bool first(PException &excp) {
708712 // 使用予定の親のローカル変数の値をcloneする、
709713 Array<bool> maker;
@@ -739,6 +743,7 @@
739743 }
740744 }
741745
746+ // 親の評価コンテクストを削除する
742747 for ( size_t i = 0; i < p->goalidx; i++ ) {
743748 ExecContextRoot *e = p->ecs[i];
744749 if ( e ) {
@@ -746,7 +751,7 @@
746751 p->ecs[i] = 0;
747752 }
748753 }
749- if ( p->goalidx >= p->goal->size() ) {
754+ if ( p->goalidx >= p->goal->size() - 1 ) {
750755 p->delflg = true;
751756 }
752757 return true;
@@ -758,6 +763,15 @@
758763 }
759764 };
760765
766+struct ExecContext_CutFail : public ExecContext_Cut {
767+ ExecContext_CutFail(ExecContext *p_, void *f_, const PPredicate *pred_, VLocal *l) : ExecContext_Cut(p_, f_, pred_, l) {}
768+ virtual bool first(PException &excp) {
769+ ExecContext_Cut::first(excp);
770+ p->nobacktrack = true;
771+ return false;
772+ }
773+};
774+
761775 struct ExecContext_Fail : public ExecContextRoot {
762776 ExecContext_Fail(ExecContext *p_, void *f_, const PPredicate *pred_, VLocal *l) : ExecContextRoot(p_, f_, pred_, l) {}
763777 virtual bool first(PException &excp) {
--- trunk/adp.cpp (revision 303)
+++ trunk/adp.cpp (revision 304)
@@ -23,12 +23,12 @@
2323
2424 // 定数
2525 #ifdef ___X64____
26-#define VERSION_TEXT "ADP Ver 0.82.0301 X64 (http://www.adp.la/)\nCopyright (C) 2010-2012 Katsuhisa Ohfuji. This progman is distributed under GPL.\n"
26+#define VERSION_TEXT "ADP Ver 0.82.0304 X64 (http://www.adp.la/)\nCopyright (C) 2010-2012 Katsuhisa Ohfuji. This progman is distributed under GPL.\n"
2727 #else
2828 #if _WIN32
29-#define VERSION_TEXT "ADP Ver 0.82.0301 x86 (http://www.adp.la/)\nCopyright (C) 2010-2012 Katsuhisa Ohfuji. This progman is distributed under GPL.\n"
29+#define VERSION_TEXT "ADP Ver 0.82.0304 x86 (http://www.adp.la/)\nCopyright (C) 2010-2012 Katsuhisa Ohfuji. This progman is distributed under GPL.\n"
3030 #else
31-#define VERSION_TEXT "ADP Ver 0.82.0301 (http://www.adp.la/)\nCopyright (C) 2010-2012 Katsuhisa Ohfuji. This progman is distributed under GPL.\n"
31+#define VERSION_TEXT "ADP Ver 0.82.0304 (http://www.adp.la/)\nCopyright (C) 2010-2012 Katsuhisa Ohfuji. This progman is distributed under GPL.\n"
3232 #endif
3333 #endif
3434
--- trunk/adp_compile.cpp (revision 303)
+++ trunk/adp_compile.cpp (revision 304)
@@ -939,30 +939,49 @@
939939 if ( *c == ';' ) c.next(); // skip ;
940940 // バックトラックの最適化
941941 if ( !body.empty() ) {
942- const PPredicate *p = dynamic_cast<const PPredicate *>(body.back());
942+ PPredicate *p = dynamic_cast<PPredicate *>(const_cast<PObject*>(body.back()));
943943 // 最後のカットは取り除く(first/backtrackメソッドで頑張る)
944944 if ( p != 0 ) {
945945 if ( p->ncmp("!") ) {
946946 body.pop_back();
947947 nobacktrack = true;
948- if ( c.cut.size() == 1 ) {
949- c.cut.clear();
948+ Array<PPredicate *>::iterator f = find( c.cut.begin(), c.cut.end(), p);
949+ if ( f != c.cut.end() ) {
950+ c.cut.erase(f);
950951 }
951952 }
953+
954+ // 最後がfalseでその前が!なら !fail に置き換える
955+ if ( body.size() >= 2 && p->ncmp("fail") ) {
956+ PPredicate *pp = dynamic_cast<PPredicate *>(const_cast<PObject*>(body[body.size()-2]));
957+ if ( pp != 0 && pp->ncmp("!") ) {
958+ PString *n = dynamic_cast<PString*>(const_cast<PObject*>(pp->name));
959+ if ( n ) {
960+ n->value = "!fail";
961+ body.pop_back();
962+ Array<PPredicate *>::iterator f = find( c.cut.begin(), c.cut.end(), pp);
963+ if ( f != c.cut.end() ) {
964+ c.cut.erase(f);
965+ }
966+ }
967+ }
968+ }
952969 }
970+
953971 // 途中のカットに関しては引数に保存する変数を入れる
954- for ( size_t i = 0; i < c.vstat.size(); i++ ) {
955- if ( c.vstat[i] == 3 ) {
956- PVeriable *v = get_gc()->factory.createObject<PVeriable>();
957- v->makeVeriable(c, c.vary[i], false );
958- // カットが複数ある場合、本来ならそのカットの位置に対して保存する変数を決定すべきだが
959- // そんなにカットを使う機会も考えられないのでカット1つを想定して最適化している
960- for ( size_t j = 0; j < c.cut.size(); j++ ) {
961- c.cut[j]->addMethodArg(c,0,v);
972+ if ( !c.cut.empty() ) {
973+ for ( size_t i = 0; i < c.vstat.size(); i++ ) {
974+ if ( c.vstat[i] == 3 ) {
975+ PVeriable *v = get_gc()->factory.createObject<PVeriable>();
976+ v->makeVeriable(c, c.vary[i], false );
977+ // カットが複数ある場合、本来ならそのカットの位置に対して保存する変数を決定すべきだが
978+ // そんなにカットを使う機会も考えられないのでカット1つを想定して最適化している
979+ for ( size_t j = 0; j < c.cut.size(); j++ ) {
980+ c.cut[j]->addMethodArg(c,0,v);
981+ }
962982 }
963983 }
964984 }
965-
966985 }
967986 return this;
968987 }
Show on old repository browser