またパフォーマンスが下がったのでいったん戻し、ExecContextのリサイクルを入れた。
@@ -125,8 +125,6 @@ | ||
125 | 125 | ExecContext_Factory newExecContext_Times( newExecContext_Times_Function); |
126 | 126 | ExecContextRoot *newExecContext_Cut_Function(ExecContext *p_, void *f_, const PPredicate *pred_, VLocal *l) { return new ExecContext_Cut( p_, f_, pred_, l); } |
127 | 127 | 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); | |
130 | 128 | |
131 | 129 | ExecContextRoot *newExecContext_Fail_Function(ExecContext *p_, void *f_, const PPredicate *pred_, VLocal *l) { return new ExecContext_Fail( p_, f_, pred_, l); } |
132 | 130 | ExecContext_Factory newExecContext_Fail( newExecContext_Fail_Function); |
@@ -495,7 +493,6 @@ | ||
495 | 493 | factory_map.insert(ExecContext_Factory_Pair( string("counter"), &newExecContext_Counter)); |
496 | 494 | factory_map.insert(ExecContext_Factory_Pair( string("times"), &newExecContext_Times)); |
497 | 495 | factory_map.insert(ExecContext_Factory_Pair( string("!"), &newExecContext_Cut)); |
498 | - factory_map.insert(ExecContext_Factory_Pair( string("!fail"), &newExecContext_CutFail)); | |
499 | 496 | factory_map.insert(ExecContext_Factory_Pair( string("fail"), &newExecContext_Fail)); |
500 | 497 | factory_map.insert(ExecContext_Factory_Pair( string("raise"), &newExecContext_Raise)); |
501 | 498 | factory_map.insert(ExecContext_Factory_Pair( string("next"), &newExecContext_Next)); |
@@ -567,7 +567,7 @@ | ||
567 | 567 | horn = 0; |
568 | 568 | goal = 0; |
569 | 569 | hl = &hlocal; // ローカル変数エリア |
570 | - afterunify.reserve(pred->size()); | |
570 | + // ecs,afterunifyのreserveはfirst,backtrackで行う | |
571 | 571 | horns = 0; |
572 | 572 | skipnamechk = false; |
573 | 573 | hornidx = 0; |
@@ -576,6 +576,7 @@ | ||
576 | 576 | nextidx = (size_t)-1; |
577 | 577 | pipe = 0; |
578 | 578 | trueflg = false; |
579 | + afterunify.reserve(pred->size()); | |
579 | 580 | nobacktrack = false; |
580 | 581 | last_result = false; |
581 | 582 | }; |
@@ -590,7 +591,6 @@ | ||
590 | 591 | ExecContextBase::backup = *gl; // ややこしいがCut述語使用時の整合性を取る為ここでバッグアップを取得しておく |
591 | 592 | ecs.assign(goal->size(), 0); |
592 | 593 | afterunify.reserve(vcnt); |
593 | - afterunify.clear(); | |
594 | 594 | horns = 0; |
595 | 595 | skipnamechk = false; |
596 | 596 | hornidx = 0; |
@@ -703,6 +703,7 @@ | ||
703 | 703 | |
704 | 704 | struct ExecContext_Cut : public ExecContextRoot { |
705 | 705 | ExecContext_Cut(ExecContext *p_, void *f_, const PPredicate *pred_, VLocal *l) : ExecContextRoot(p_, f_, pred_, l) { delflg = false; } |
706 | + | |
706 | 707 | virtual void recreate(const PPredicate *pred_, VLocal *l) { ExecContextRoot::init(pred_, l); delflg = false; } |
707 | 708 | virtual void recreate(ExecContext *p_, void *f_, const PPredicate *pred_, VLocal *l) { ExecContextRoot::init(p_,f,pred_, l); delflg = false; } |
708 | 709 | virtual void reinit(const PPredicate *pred_, VLocal *l) { ExecContextRoot::init(pred_, l); delflg = false; } |
@@ -743,7 +744,6 @@ | ||
743 | 744 | } |
744 | 745 | } |
745 | 746 | |
746 | - // 親の評価コンテクストを削除する | |
747 | 747 | for ( size_t i = 0; i < p->goalidx; i++ ) { |
748 | 748 | ExecContextRoot *e = p->ecs[i]; |
749 | 749 | if ( e ) { |
@@ -763,15 +763,6 @@ | ||
763 | 763 | } |
764 | 764 | }; |
765 | 765 | |
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 | - | |
775 | 766 | struct ExecContext_Fail : public ExecContextRoot { |
776 | 767 | ExecContext_Fail(ExecContext *p_, void *f_, const PPredicate *pred_, VLocal *l) : ExecContextRoot(p_, f_, pred_, l) {} |
777 | 768 | virtual bool first(PException &excp) { |
@@ -23,12 +23,12 @@ | ||
23 | 23 | |
24 | 24 | // 定数 |
25 | 25 | #ifdef ___X64____ |
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" | |
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" | |
27 | 27 | #else |
28 | 28 | #if _WIN32 |
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" | |
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" | |
30 | 30 | #else |
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" | |
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" | |
32 | 32 | #endif |
33 | 33 | #endif |
34 | 34 |
@@ -939,49 +939,30 @@ | ||
939 | 939 | if ( *c == ';' ) c.next(); // skip ; |
940 | 940 | // バックトラックの最適化 |
941 | 941 | if ( !body.empty() ) { |
942 | - PPredicate *p = dynamic_cast<PPredicate *>(const_cast<PObject*>(body.back())); | |
942 | + const PPredicate *p = dynamic_cast<const PPredicate *>(body.back()); | |
943 | 943 | // 最後のカットは取り除く(first/backtrackメソッドで頑張る) |
944 | 944 | if ( p != 0 ) { |
945 | 945 | if ( p->ncmp("!") ) { |
946 | 946 | body.pop_back(); |
947 | 947 | nobacktrack = true; |
948 | - Array<PPredicate *>::iterator f = find( c.cut.begin(), c.cut.end(), p); | |
949 | - if ( f != c.cut.end() ) { | |
950 | - c.cut.erase(f); | |
948 | + if ( c.cut.size() == 1 ) { | |
949 | + c.cut.clear(); | |
951 | 950 | } |
952 | 951 | } |
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 | - } | |
969 | 952 | } |
970 | - | |
971 | 953 | // 途中のカットに関しては引数に保存する変数を入れる |
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 | - } | |
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); | |
982 | 962 | } |
983 | 963 | } |
984 | 964 | } |
965 | + | |
985 | 966 | } |
986 | 967 | return this; |
987 | 968 | } |