• R/O
  • SSH
  • HTTPS

adp: Commit


Commit MetaInfo

Revision300 (tree)
Time2012-06-08 00:07:48
Authorohfuji

Log Message

getconstant_hを入れてみた。

Change Summary

Incremental Difference

--- trunk/adp_unify.cpp (revision 299)
+++ trunk/adp_unify.cpp (revision 300)
@@ -123,8 +123,8 @@
123123 {
124124 const PObject *item = (*glocal)[goal.idx];
125125 if ( item == 0 ) {
126- const PObject *p = horn.getval2(c, c->hl);
127- if ( p->isc() ) {
126+ const PObject *p = horn.getconstant_h(c);
127+ if ( p ) {
128128 (*glocal)[goal.idx] = p;
129129 return true;
130130 }
@@ -171,9 +171,12 @@
171171 }
172172 }
173173 } else if ( hval != 0 ) {
174- const PObject *p = hval->getval2(c, c->hl);
175- (*glocal)[goal.idx] = p;
176- if ( p->isc() ) return true;
174+ const PObject *p = hval->getconstant_h(c);
175+ if ( p ) {
176+ // ホーン→ゴールは定数(またはワイルドカード)なら渡す。変数なら後で代入する。
177+ (*glocal)[goal.idx] = p;
178+ return true;
179+ }
177180 }
178181
179182 c->afterunify.push_back(c->uidx);
@@ -586,6 +589,21 @@
586589 return lo ? lo : this;
587590 }
588591
592+const PObject *PList::getconstant_h( ExecContext *c) const
593+{
594+ if ( constant ) return this;
595+ PList *lo = 0;
596+ const PObject *l = lvalue->getconstant_h(c);
597+ const PObject *r = rvalue->getconstant_h(c);
598+
599+ if ( !l || !r ) return 0;
600+ if ( !l->isc() || !r->isc() ) return 0;
601+
602+ assert( l != lvalue || r != rvalue);
603+ lo = pmm.newPList(c->pobjs, const_cast<PObject*>(l), const_cast<PObject*>(r));
604+ return lo;
605+}
606+
589607 void PList::mark_hlocal(ExecContext *c, Array<bool> &marker) const
590608 {
591609 if ( constant ) return;
@@ -630,6 +648,26 @@
630648 return po ? po : this;
631649 }
632650
651+const PObject *PArray::getconstant_h( ExecContext *c) const
652+{
653+ if ( constant ) return this;
654+ PArray *po = 0;
655+ for ( PObjectArray::const_iterator i = value.begin(); i < value.end(); i++ ) {
656+ const PObject *p = (*i)->getconstant_h( c);
657+ if ( p == 0 ) return 0;
658+ if ( p != *i && po == 0 ) {
659+ po = pmm.newPArray(c->pobjs, *this);
660+ po->constant = true;
661+ }
662+ if ( po ) {
663+ po->value[i - value.begin()] = p;
664+ po->constant = po->constant && p->isc();
665+ if ( !po->constant ) return 0;
666+ }
667+ }
668+ return po ? po : this;
669+}
670+
633671 void PArray::mark_hlocal(ExecContext *c, Array<bool> &marker) const
634672 {
635673 if ( constant ) return;
@@ -670,6 +708,22 @@
670708 return this;
671709 }
672710
711+const PObject *PPredicate::getconstant_h( ExecContext *c) const
712+{
713+ if ( constant ) return this;
714+
715+ const PObject *no = name->getconstant_h(c);
716+ if ( !no ) return 0;
717+ const PArray *ao = dynamic_cast<const PArray *>(arglist.getconstant_h( c));
718+ if ( !ao ) return 0;
719+ if ( no != name || ao != &arglist ) {
720+ PPredicate *po = pmm.newPPredicate(c->pobjs,nspace,no,ao,opt);
721+ return po;
722+ }
723+
724+ return this;
725+}
726+
673727 void PPredicate::mark_hlocal(ExecContext *c, Array<bool> &marker) const
674728 {
675729 name->mark_hlocal(c, marker);
@@ -700,6 +754,17 @@
700754 }
701755 }
702756
757+const PObject *PVeriable::getconstant_h( ExecContext *c) const
758+{
759+ assert( idx < c->gl->size());
760+ const PObject *item = (*c->hl)[idx];
761+ if ( item == 0 ) {
762+ return 0;
763+ } else {
764+ return item->getval(c);
765+ }
766+}
767+
703768 void PVeriable::mark_hlocal(ExecContext *c, Array<bool> &marker) const
704769 {
705770 marker[idx] = true;
@@ -709,6 +774,17 @@
709774 const PObject *PEVeriable::getval( ExecContextRoot *c) const { return GetValsOne<const PObject *>( *this, c, vl, &PObject::getval, this); }
710775 const PObject *PEVeriable::getval2( ExecContextRoot *c, VLocal *) const { return GetValsTwo<const PObject *>( *this, c, vl, vl, &PObject::getval2, this); }
711776
777+const PObject *PEVeriable::getconstant_h( ExecContext *c) const
778+{
779+ assert( idx < c->gl->size());
780+ const PObject *item = (*vl)[idx];
781+ if ( item == 0 ) {
782+ return 0;
783+ } else {
784+ return item->getval(c);
785+ }
786+}
787+
712788 void PEVeriable::mark_hlocal(ExecContext *c, Array<bool> &marker) const
713789 {
714790 if ( vl == c->hl ) {
--- trunk/adp_compile.h (revision 299)
+++ trunk/adp_compile.h (revision 300)
@@ -199,6 +199,9 @@
199199 virtual const PObject *getval( ExecContextRoot *) const { return this; }
200200 virtual const PObject *getval2( ExecContextRoot *, VLocal *) const { return this; }
201201
202+ // 値の取得(match時に使用、PEVariableは作成しない。その場合は0を返す。)
203+ virtual const PObject *getconstant_h( ExecContext *c ) const { return this; };
204+
202205 // 変数の追跡(cutで使用)
203206 virtual void mark_hlocal( ExecContext *, Array<bool> &marker) const {};
204207
@@ -912,6 +915,9 @@
912915 virtual const PObject *getval( ExecContextRoot *) const;
913916 virtual const PObject *getval2( ExecContextRoot *c, VLocal *vlocal) const;
914917
918+ // 値の取得(match時に使用、PEVariableは作成しない。その場合は0を返す。)
919+ virtual const PObject *getconstant_h( ExecContext *c ) const ;
920+
915921 // 変数の追跡(cutで使用)
916922 virtual void mark_hlocal( ExecContext *c, Array<bool> &marker) const;
917923
@@ -1233,6 +1239,9 @@
12331239 virtual const PObject *getval( ExecContextRoot *c) const;
12341240 virtual const PObject *getval2( ExecContextRoot *c, VLocal *vlocal) const;
12351241
1242+ // 値の取得(match時に使用、PEVariableは作成しない。その場合は0を返す。)
1243+ virtual const PObject *getconstant_h( ExecContext *c ) const ;
1244+
12361245 // 変数の追跡(cutで使用)
12371246 virtual void mark_hlocal( ExecContext *c, Array<bool> &marker) const;
12381247
@@ -1482,6 +1491,9 @@
14821491 virtual const PObject *getval( ExecContextRoot *c) const;
14831492 virtual const PObject *getval2( ExecContextRoot *c, VLocal *vlocal) const;
14841493
1494+ // 値の取得(match時に使用、PEVariableは作成しない。その場合は0を返す。)
1495+ virtual const PObject *getconstant_h( ExecContext *c ) const ;
1496+
14851497 // 変数の追跡(cutで使用)
14861498 virtual void mark_hlocal( ExecContext *c, Array<bool> &marker) const;
14871499
@@ -1604,6 +1616,9 @@
16041616 virtual const PObject *getval( ExecContextRoot *c) const ;
16051617 virtual const PObject *getval2( ExecContextRoot *c, VLocal *vlocal) const ;
16061618
1619+ // 値の取得(match時に使用、PEVariableは作成しない。その場合は0を返す。)
1620+ virtual const PObject *getconstant_h( ExecContext *c ) const ;
1621+
16071622 // 変数の追跡(cutで使用)
16081623 virtual void mark_hlocal( ExecContext *c, Array<bool> &marker) const;
16091624
@@ -1820,6 +1835,9 @@
18201835 virtual const PObject *getval( ExecContextRoot *c) const;
18211836 virtual const PObject *getval2( ExecContextRoot *c, VLocal *) const;
18221837
1838+ // 値の取得(match時に使用、PEVariableは作成しない。その場合は0を返す。)
1839+ virtual const PObject *getconstant_h( ExecContext *c ) const ;
1840+
18231841 // 変数の追跡(cutで使用)
18241842 virtual void mark_hlocal( ExecContext *c, Array<bool> &marker) const;
18251843
--- trunk/adp.cpp (revision 299)
+++ trunk/adp.cpp (revision 300)
@@ -23,12 +23,12 @@
2323
2424 // 定数
2525 #ifdef ___X64____
26-#define VERSION_TEXT "ADP Ver 0.82.0298 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.0300 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.0298 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.0300 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.0298 (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.0300 (http://www.adp.la/)\nCopyright (C) 2010-2012 Katsuhisa Ohfuji. This progman is distributed under GPL.\n"
3232 #endif
3333 #endif
3434
Show on old repository browser