This commit is contained in:
Vitor Santos Costa 2018-05-30 13:07:45 +01:00
parent 8cfeb53e77
commit 9afb5b07b2
8 changed files with 67 additions and 60 deletions

View File

@ -1249,7 +1249,7 @@ Term Yap_SaveTerm(Term t0) {
CACHE_REGS
Term to;
to = CopyTermToArena(
t0, LOCAL_GlobalArena, FALSE, TRUE, 2, &LOCAL_GlobalArena,
Deref(t0), LOCAL_GlobalArena, FALSE, TRUE, 2, &LOCAL_GlobalArena,
garena_overflow_size(ArenaPt(LOCAL_GlobalArena) PASS_REGS) PASS_REGS);
if (to == 0L)
return to;

View File

@ -118,8 +118,12 @@ protected:
}
YAPTerm tt = YAPTerm(tout);
ap = getPred(tt, modp);
tout = Yap_SaveTerm(tout);
tnames = Yap_SaveTerm(tnames);
}
YAPPredicate(Term &t, Term &tmod, CELL * &ts, const char *pname);
YAPPredicate(Term &to, Term &tmod, CELL * &ts, const char *pname);
/// Term constructor for predicates
///

View File

@ -477,8 +477,6 @@ const char *YAPAtom::getName(void) { return Yap_AtomToUTF8Text(a); }
void YAPQuery::openQuery() {
CACHE_REGS
int lvl = AllocLevel();
if (ap == NULL || ap->OpcodeOfPred == UNDEF_OPCODE) {
ap = rewriteUndefQuery();
}
@ -649,7 +647,7 @@ YAPQuery::YAPQuery(YAPFunctor f, YAPTerm mod, YAPTerm ts[])
goal = MkVarTerm();
}
openQuery();
names = YAPPairTerm(TermNil);
names = TermNil;
RECOVER_MACHINE_REGS();
}
@ -678,7 +676,6 @@ YAPQuery::YAPQuery(YAPTerm t) : YAPPredicate(t) {
nts = RepPair(tt);
tt = Yap_MkApplTerm(FunctorCsult, 1, nts);
}
goal = *new YAPTerm(tt);
if (IsApplTerm(tt)) {
Functor f = FunctorOfTerm(tt);
if (!IsExtensionFunctor(f)) {
@ -691,8 +688,9 @@ YAPQuery::YAPQuery(YAPTerm t) : YAPPredicate(t) {
}
}
}
goal =Yap_SaveTerm( tt);
openQuery();
names = YAPPairTerm(TermNil);
names = TermNil ;
}
YAPQuery::YAPQuery(YAPPredicate p, YAPTerm ts[]) : YAPPredicate(p.ap) {
@ -705,7 +703,7 @@ YAPQuery::YAPQuery(YAPPredicate p, YAPTerm ts[]) : YAPPredicate(p.ap) {
XREGS[i + 1] = ts[i].term();
openQuery();
} else {
goal = YAPAtomTerm((Atom)(p.ap->FunctorOfPred));
goal = MkAtomTerm((Atom)(p.ap->FunctorOfPred));
openQuery();
}
names = TermNil;
@ -718,7 +716,7 @@ RECOVER_MACHINE_REGS();
bool YAPQuery::next() {
CACHE_REGS
bool result = false;
std::cerr << "next " << goal.text() << "\n";
std::cerr << "next " << YAPTerm(goal).text() << "\n";
sigjmp_buf buf, *oldp = LOCAL_RestartEnv;
e = nullptr;
@ -739,7 +737,6 @@ bool YAPQuery::next() {
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "out %d", result);
if (!result) {
YAP_LeaveGoal(result, &q_h);
Yap_CloseHandles(q_handles);
q_open = false;
}
YAPCatchError();
@ -749,8 +746,8 @@ if (!result) {
}
PredEntry *YAPQuery::rewriteUndefQuery() {
ARG1 = goal.term();
goal = YAPApplTerm(FunctorMetaCall, &ARG1);
ARG1 = goal;
goal = Yap_SaveTerm(Yap_MkApplTerm(FunctorMetaCall, 4, &ARG1));
return ap = PredCall;
}
@ -759,7 +756,7 @@ PredEntry *YAPEngine::rewriteUndefEngineQuery(PredEntry *a, Term &tgoal,
Term ts[2];
ts[0] = mod;
ts[1] = tgoal;
ARG1 = tgoal = Yap_MkApplTerm(FunctorModule, 2, ts);
ARG1 = tgoal = Yap_SaveTerm(Yap_MkApplTerm(FunctorModule, 2, ts));
// goal = YAPTerm(Yap_MkApplTerm(FunctorMetaCall, 1, &ARG1));
return PredCall;

View File

@ -42,8 +42,8 @@ class X_API YAPQuery : public YAPPredicate {
struct yami *q_p, *q_cp;
int q_flags;
YAP_dogoalinfo q_h;
YAPPairTerm names;
YAPTerm goal;
Term names;
Term goal;
// temporaries
int lvl;
YAPError *e;
@ -92,30 +92,32 @@ public:
/// It is given a string, calls the parser and obtains a Prolog term that
/// should be a callable
/// goal.
inline YAPQuery(const char *s) : YAPPredicate(s, goal.term(), names.term()) {
inline YAPQuery(const char *s) : YAPPredicate(s, goal, names) {
CELL *qt = nullptr;
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "got game %d",
LOCAL_CurSlot);
if (!ap)
return;
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "%s", names.text());
if (IsPairTerm(goal.term())) {
qt = RepPair(goal.term());
goal.put(Yap_MkApplTerm(FunctorCsult, 1, qt));
if (IsPairTerm(goal)) {
qt = RepPair(goal);
goal = Yap_SaveTerm(Yap_MkApplTerm(FunctorCsult, 1, qt));
ap = RepPredProp(PredPropByFunc(FunctorCsult, TermProlog));
} else {
goal = Yap_SaveTerm(goal);
}
if (IsApplTerm(goal.term())) {
Functor f = FunctorOfTerm(goal.term());
if (IsApplTerm(goal)) {
Functor f = FunctorOfTerm(goal);
if (!IsExtensionFunctor(f)) {
arity_t arity = ap->ArityOfPE;
if (arity) {
qt = RepAppl(goal.term()) + 1;
qt = RepAppl(goal) + 1;
for (arity_t i = 0; i < arity; i++)
XREGS[i + 1] = qt[i];
}
}
}
names = YAPPairTerm(names.term());
names = Yap_SaveTerm(names);
openQuery();
};
// inline YAPQuery() : YAPPredicate(s, tgoal, tnames)
@ -155,10 +157,10 @@ public:
void close();
/// query variables.
void cut();
Term namedVars() { return names.term(); };
Term namedVars() { return names; };
YAPPairTerm namedVarTerms() { return names; };
/// query variables, but copied out
std::vector<Term> namedVarsVector() { return names.listToArray(); };
std::vector<Term> namedVarsVector() { return YAPPairTerm(names).listToArray(); };
/// convert a ref to a binding.
YAPTerm getTerm(yhandle_t t);
/// simple YAP Query;
@ -339,7 +341,8 @@ public:
/// current directory for the engine
bool call(YAPPredicate ap, YAPTerm ts[]);
/// current directory for the engine
bool goal(YAPTerm Yt, YAPModule module, bool release=false) { return mgoal(Yt.term(),module.term(), release); };
bool goal(YAPTerm Yt, YAPModule module, bool release=false)
{ return mgoal(Yt.term(),module.term(), release); };
/// ru1n a goal in a module.
///
/// By default, memory will only be fully

View File

@ -71,21 +71,21 @@ argi(N,I,I1) :-
python_query( Caller, String ) :-
writeln(String),
atomic_to_term( String, Goal, VarNames ),
query_to_answer( Goal, VarNames, Status, Bindings),
query_to_answer( Goal, VarNames, Status, Bindings),
Caller.q.port := Status,
% := print( gc.get_referrers(Caller.port)),
write_query_answer( Bindings ),
nl(user_error),
Caller.q.answer := {},
maplist(in_dict(Caller.answer), Bindings).
maplist(in_dict(Caller.q.answer), Bindings).
% := print( "b", gc.get_referrers(Caller.answer)).
in_dict(Dict, var([V0,V|Vs])) :- !,
Dict[V] := V0,
in_dict( Dict, var([V0|Vs])).
in_dict(Dict, var([],_G)) :- !.
in_dict(_Dict, var([_],_G)) :- !.
in_dict(Dict, nonvar([V0|Vs],G)) :- !,
Dict[V0] := G,
in_dict( Dict, var([V0|Vs])).
in_dict(Dict, nonvar([],_G)) :- !.
in_dict( Dict, nonvar(Vs, Gs)).
in_dict(_Dict, nonvar([],_G)) :- !.
in_dict(_, _).

View File

@ -65,11 +65,11 @@ if platform.system() == 'Windows':
win_libs = ['wsock32','ws2_32']
my_extra_link_args = ['-Wl,-export-all-symbols']
elif platform.system() == 'Darwin':
my_extra_link_args = ['-L','..','-Wl,-rpath,'+abspath(join(sysconfig.get_path('platlib'),'yap4py')),'-Wl,-rpath,/usr/local/lib','-Wl,-rpath,../yap4py']
my_extra_link_args = ['-L','..','-Wl,-rpath,'+abspath(join(sysconfig.get_path('platlib'),'yap4py')),'-Wl,-rpath,/lib','-Wl,-rpath,../yap4py']
win_libs = []
local_libs = ['Py4YAP']
elif platform.system() == 'Linux':
my_extra_link_args = ['-L','..','-Wl,-rpath,'+abspath(join(sysconfig.get_path('platlib'),'yap4py')),'-Wl,-rpath,/usr/local/lib','-Wl,-rpath,'+join('/usr/local/lib','..'),'-Wl,-rpath,../yap4py']
my_extra_link_args = ['-L','..','-Wl,-rpath,'+abspath(join(sysconfig.get_path('platlib'),'yap4py')),'-Wl,-rpath,/lib','-Wl,-rpath,'+join('/lib','..'),'-Wl,-rpath,../yap4py']
win_libs = []
local_libs = ['Py4YAP']
@ -90,10 +90,10 @@ extensions = [Extension('_yap', native_sources,
('YAP_PYTHON', '1'),
('_GNU_SOURCE', '1')],
runtime_library_dirs=[
abspath(join(sysconfig.get_path('platlib'),'yap4py')), abspath(sysconfig.get_path('platlib')),'/usr/local/lib'],
abspath(join(sysconfig.get_path('platlib'),'yap4py')), abspath(sysconfig.get_path('platlib')),'/lib'],
swig_opts=['-modern', '-c++', '-py3',
'-DX_API', '-Iyap4py/include' ],
library_dirs=[".",'../../..','/usr/local/lib'],
library_dirs=[".",'../../..','/lib'],
extra_link_args=my_extra_link_args,
libraries=['Yap','gmp']+win_libs+local_libs,
include_dirs=['/home/vsc/github/yap-6.3/H',

View File

@ -71,14 +71,16 @@ class Query:
def __next__(self):
if not self.q:
raise StopIteration()
if self.port == "exit":
self.close()
return
if self.q.next():
rc = self.q.answer
# if self.q.port == "exit":
rc = self.answer
return rc
else:
if self:
if self.q:
self.close()
raise StopIteration()
raise RuntimeError()
def close( self ):
if self.q:
@ -189,7 +191,7 @@ class YAPShell:
self.q = None
print("Exception",e)
e.errorNo = 0
return False, None
raise
def live(self, engine, **kwargs):
loop = True
@ -204,6 +206,7 @@ class YAPShell:
self.query_prolog(s)
except SyntaxError as err:
print("Syntax Error error: {0}".format(err))
continue
except EOFError:
return
except RuntimeError as err:

View File

@ -884,7 +884,7 @@ RECURSIVE = YES
# Note that relative paths are relative to the directory from which doxygen is
# run.
EXCLUDE = /home/vsc/github/yap-6.3/build /home/vsc/github/yap-6.3/Debug /home/vsc/github/yap-6.3/packages/jpl /home/vsc/github/yap-6.3/packages/swig /home/vsc/github/yap-6.3/packages/Problog/problog_examples/output /home/vsc/github/yap-6.3/packages/Problog/problog_examples/queries /home/vsc/github/yap-6.3/packages/myddas/sqlite3/src /home/vsc/github/yap-6.3/packages/gecode/4.4.0 /home/vsc/github/yap-6.3/packages/gecode/4.2.1 /home/vsc/github/yap-6.3/packages/gecode/4.2.0 /home/vsc/github/yap-6.3/packages/gecode/4.0.0 /home/vsc/github/yap-6.3/packages/gecode/3.7.3 /home/vsc/github/yap-6.3/packages/gecode/3.7.2 /home/vsc/github/yap-6.3/packages/gecode/3.7.1 /home/vsc/github/yap-6.3/packages/gecode/3.7.0 /home/vsc/github/yap-6.3/packages/gecode/3.6.0 /home/vsc/github/yap-6.3/packages/gecode/dev /home/vsc/github/yap-6.3/C/traced_absmi_insts.h /home/vsc/github/yap-6.3/H/globals.h /home/vsc/github/yap-6.3/packages/cplint /home/vsc/github/yap-6.3/packages/CLPBN/examples /home/vsc/github/yap-6.3/packages/CLPBN/horus /home/vsc/github/yap-6.3/packages/prosqlite /home/vsc/github/yap-6.3/packages/pyswip /home/vsc/github/yap-6.3/packages/yap-lbfgs/liblbfgs-1.10 /home/vsc/github/yap-6.3/library/dialect/swi/os /home/vsc/github/yap-6.3/packages/python /home/vsc/github/yap-6.3/*/bprolog/* /home/vsc/github/yap-6.3/*/prism/* /home/vsc/github/yap-6.3/*/gecodde/[345]* /home/vsc/github/yap-6.3/packages/gecode/gecode3_yap.cc /home/vsc/github/yap-6.3/packages/gecode/gecode4_yap.cc /home/vsc/github/yap-6.3/packages/gecode/gecode5_yap.cc /home/vsc/github/yap-6.3/packages/gecode/gecode3.yap /home/vsc/github/yap-6.3/packages/gecode/gecode4.yap /home/vsc/github/yap-6.3/packages/gecode/gecode5.yap /home/vsc/github/yap-6.3/packages/gecode/gecode3_yap_hand_written.yap /home/vsc/github/yap-6.3/packages/gecode/gecode4_yap_hand_written.yap /home/vsc/github/yap-6.3/packages/gecode/gecode5_yap_hand_written.yap */CMakeFiles/* *~ */
EXCLUDE =
# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
# directories that are symbolic links (a Unix file system feature) are excluded
@ -900,7 +900,7 @@ EXCLUDE_SYMLINKS = NO
# Note that the wildcards are matched against the file with absolute path, so to
# exclude all test directories for example use the pattern */test/*
EXCLUDE_PATTERNS = /home/vsc/github/yap-6.3/build /home/vsc/github/yap-6.3/Debug /home/vsc/github/yap-6.3/packages/jpl /home/vsc/github/yap-6.3/packages/swig /home/vsc/github/yap-6.3/packages/Problog/problog_examples/output /home/vsc/github/yap-6.3/packages/Problog/problog_examples/queries /home/vsc/github/yap-6.3/packages/myddas/sqlite3/src /home/vsc/github/yap-6.3/packages/gecode/4.4.0 /home/vsc/github/yap-6.3/packages/gecode/4.2.1 /home/vsc/github/yap-6.3/packages/gecode/4.2.0 /home/vsc/github/yap-6.3/packages/gecode/4.0.0 /home/vsc/github/yap-6.3/packages/gecode/3.7.3 /home/vsc/github/yap-6.3/packages/gecode/3.7.2 /home/vsc/github/yap-6.3/packages/gecode/3.7.1 /home/vsc/github/yap-6.3/packages/gecode/3.7.0 /home/vsc/github/yap-6.3/packages/gecode/3.6.0 /home/vsc/github/yap-6.3/packages/gecode/dev /home/vsc/github/yap-6.3/C/traced_absmi_insts.h /home/vsc/github/yap-6.3/H/globals.h /home/vsc/github/yap-6.3/packages/cplint /home/vsc/github/yap-6.3/packages/CLPBN/examples /home/vsc/github/yap-6.3/packages/CLPBN/horus /home/vsc/github/yap-6.3/packages/prosqlite /home/vsc/github/yap-6.3/packages/pyswip /home/vsc/github/yap-6.3/packages/yap-lbfgs/liblbfgs-1.10 /home/vsc/github/yap-6.3/library/dialect/swi/os /home/vsc/github/yap-6.3/packages/python /home/vsc/github/yap-6.3/*/bprolog/* /home/vsc/github/yap-6.3/*/prism/* /home/vsc/github/yap-6.3/*/gecodde/[345]* /home/vsc/github/yap-6.3/packages/gecode/gecode3_yap.cc /home/vsc/github/yap-6.3/packages/gecode/gecode4_yap.cc /home/vsc/github/yap-6.3/packages/gecode/gecode5_yap.cc /home/vsc/github/yap-6.3/packages/gecode/gecode3.yap /home/vsc/github/yap-6.3/packages/gecode/gecode4.yap /home/vsc/github/yap-6.3/packages/gecode/gecode5.yap /home/vsc/github/yap-6.3/packages/gecode/gecode3_yap_hand_written.yap /home/vsc/github/yap-6.3/packages/gecode/gecode4_yap_hand_written.yap /home/vsc/github/yap-6.3/packages/gecode/gecode5_yap_hand_written.yap */CMakeFiles/* *~ */
EXCLUDE_PATTERNS = /home/vsc/github/yap-6.3/build /home/vsc/github/yap-6.3/Debug /home/vsc/github/yap-6.3/packages/jpl /home/vsc/github/yap-6.3/packages/swig /home/vsc/github/yap-6.3/packages/Problog/problog_examples/output /home/vsc/github/yap-6.3/packages/Problog/problog_examples/queries /home/vsc/github/yap-6.3/packages/myddas/sqlite3/src /home/vsc/github/yap-6.3/packages/gecode/4.4.0 /home/vsc/github/yap-6.3/packages/gecode/4.2.1 /home/vsc/github/yap-6.3/packages/gecode/4.2.0 /home/vsc/github/yap-6.3/packages/gecode/4.0.0 /home/vsc/github/yap-6.3/packages/gecode/3.7.3 /home/vsc/github/yap-6.3/packages/gecode/3.7.2 /home/vsc/github/yap-6.3/packages/gecode/3.7.1 /home/vsc/github/yap-6.3/packages/gecode/3.7.0 /home/vsc/github/yap-6.3/packages/gecode/3.6.0 /home/vsc/github/yap-6.3/packages/gecode/dev /home/vsc/github/yap-6.3/C/traced_absmi_insts.h /home/vsc/github/yap-6.3/H/globals.h /home/vsc/github/yap-6.3/packages/cplint /home/vsc/github/yap-6.3/packages/CLPBN/examples /home/vsc/github/yap-6.3/packages/CLPBN/horus /home/vsc/github/yap-6.3/packages/prosqlite /home/vsc/github/yap-6.3/packages/pyswip /home/vsc/github/yap-6.3/packages/yap-lbfgs/liblbfgs-1.10 /home/vsc/github/yap-6.3/library/dialect/swi/os /home/vsc/github/yap-6.3/*/bprolog/* /home/vsc/github/yap-6.3/*/prism/* /home/vsc/github/yap-6.3/*/gecodde/[345]* /home/vsc/github/yap-6.3/packages/gecode/gecode3_yap.cc /home/vsc/github/yap-6.3/packages/gecode/gecode4_yap.cc /home/vsc/github/yap-6.3/packages/gecode/gecode5_yap.cc /home/vsc/github/yap-6.3/packages/gecode/gecode3.yap /home/vsc/github/yap-6.3/packages/gecode/gecode4.yap /home/vsc/github/yap-6.3/packages/gecode/gecode5.yap /home/vsc/github/yap-6.3/packages/gecode/gecode3_yap_hand_written.yap /home/vsc/github/yap-6.3/packages/gecode/gecode4_yap_hand_written.yap /home/vsc/github/yap-6.3/packages/gecode/gecode5_yap_hand_written.yap */CMakeFiles/* *~ */
# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
# (namespaces, classes, functions, etc.) that should be excluded from the
@ -2072,14 +2072,14 @@ MACRO_EXPANSION = YES
# The default value is: NO.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
EXPAND_ONLY_PREDEF = YES
EXPAND_ONLY_PREDEF = NO
# If the SEARCH_INCLUDES tag is set to YES, the include files in the
# INCLUDE_PATH will be searched if a #include is found.
# The default value is: YES.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
SEARCH_INCLUDES = NO
SEARCH_INCLUDES = YES
# The INCLUDE_PATH tag can be used to specify one or more directories that
# contain include files that are not input files but should be processed by the
@ -2109,20 +2109,20 @@ INCLUDE_FILE_PATTERNS =
# recursively expanded use the := operator instead of the = operator.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
PREDEFINED =
YAP_FLAG(ITEM,NAME,WRITABLE,DEF,INIT,HELPER)=ITEM \
START_LOCAL_FLAGS="enum THREAD_LOCAL_FLAGS {" \
END_LOCAL_FLAGS=" };"\
START_GLOBAL_FLAGS="enum GLOBAL_FLAGS {" \
END_GLOBAL_FLAGS="};" \
LOCAL(A, B)="A B" \
LOCAL_INIT(A, B, C)="A B;B = C" \
LOCAL_ARRAY(A, B, C)="A B[C]" \
LOCAL_ARRAY_ARRAY(A, B, C,D)="A B[C][D]"\
LOCAL_INIT(A, B, C, D)="A B[C][D]"\
LOCAL_INITF(A, B, C)=" A B; C"\
LOCAL_INIT_RESTORE(A,B,C,D)="A B; C; D;"\
PREG=Yap_REGS.P_
PREDEFINED = \
YAP_FLAG(ITEM,NAME,WRITABLE,DEF,INIT,HELPER):=NAME \
START_LOCAL_FLAGS:="enum THREAD_LOCAL_FLAGS {" \
END_LOCAL_FLAGS:=" };"\
START_GLOBAL_FLAGS:="enum GLOBAL_FLAGS {" \
END_GLOBAL_FLAGS:="};" \
LOCAL(A, B):="A B" \
LOCAL_INIT(A, B, C):="A B;B := C" \
LOCAL_ARRAY(A, B, C):="A B[C]" \
LOCAL_ARRAY_ARRAY(A, B, C,D):="A B[C][D]"\
LOCAL_INIT(A, B, C, D):="A B[C][D]"\
LOCAL_INITF(A, B, C):=" A B; C"\
LOCAL_INIT_RESTORE(A,B,C,D):="A B; C; D;"\
PREG:=Yap_REGS.P_
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
# tag can be used to specify a list of macro names that should be expanded. The