debug
This commit is contained in:
parent
8c3bea4bce
commit
c4a0d5766b
@ -1738,7 +1738,10 @@ X_API bool YAP_EnterGoal(YAP_PredEntryPtr ape, CELL *ptr, YAP_dogoalinfo *dgi) {
|
||||
// slot=%d", pe, pe->CodeOfPred->opc, FAILCODE, Deref(ARG1), Deref(ARG2),
|
||||
// LOCAL_CurSlot);
|
||||
dgi->b = dgi->b0 = LCL0 - (CELL *)B;
|
||||
fprintf(stderr,"PrepGoal: H=%d ENV=%p B=%d TR=%d P=%p CP=%p Slots=%d\n",
|
||||
HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP, LOCAL_CurSlot);
|
||||
out = Yap_exec_absmi(true, false);
|
||||
fprintf(stderr,"LeaveGoal success=%d: H=%d ENV=%p B=%d TR=%d P=%p CP=%p Slots=%d\n", out,HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP, LOCAL_CurSlot);
|
||||
if (out) {
|
||||
dgi->EndSlot = LOCAL_CurSlot;
|
||||
Yap_StartSlots();
|
||||
@ -1758,7 +1761,7 @@ X_API bool YAP_RetryGoal(YAP_dogoalinfo *dgi) {
|
||||
BACKUP_MACHINE_REGS();
|
||||
myB = (choiceptr)(LCL0 - dgi->b);
|
||||
myB0 = (choiceptr)(LCL0 - dgi->b0);
|
||||
CP = myB->cp_cp;
|
||||
CP = myB->cp_cp;
|
||||
/* sanity check */
|
||||
if (B >= myB0) {
|
||||
return false;
|
||||
@ -1767,6 +1770,8 @@ X_API bool YAP_RetryGoal(YAP_dogoalinfo *dgi) {
|
||||
// get rid of garbage choice-points
|
||||
B = myB;
|
||||
}
|
||||
fprintf(stderr,"RetryGoal: H=%d ENV=%p B=%d TR=%d P=%p CP=%p Slots=%d\n",
|
||||
HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP, LOCAL_CurSlot);
|
||||
P = FAILCODE;
|
||||
/* make sure we didn't leave live slots when we backtrack */
|
||||
ASP = (CELL *)B;
|
||||
@ -1787,9 +1792,11 @@ X_API bool YAP_LeaveGoal(bool successful, YAP_dogoalinfo *dgi) {
|
||||
CACHE_REGS
|
||||
choiceptr myB;
|
||||
|
||||
fprintf(stderr,"LeaveGoal success=%d: H=%d ENV=%p B=%d TR=%d P=%p CP=%p Slots=%d\n",
|
||||
successful,HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP, LOCAL_CurSlot);
|
||||
BACKUP_MACHINE_REGS();
|
||||
myB = (choiceptr)(LCL0 - dgi->b0);
|
||||
if (B >= myB) {
|
||||
if (B < myB) {
|
||||
/* someone cut us */
|
||||
return false;
|
||||
}
|
||||
@ -1810,6 +1817,7 @@ X_API bool YAP_LeaveGoal(bool successful, YAP_dogoalinfo *dgi) {
|
||||
#ifdef DEPTH_LIMIT
|
||||
DEPTH = B->cp_depth;
|
||||
#endif /* DEPTH_LIMIT */
|
||||
|
||||
YENV = ENV = B->cp_env;
|
||||
} else {
|
||||
Yap_TrimTrail();
|
||||
@ -1835,6 +1843,8 @@ X_API bool YAP_LeaveGoal(bool successful, YAP_dogoalinfo *dgi) {
|
||||
P = dgi->p;
|
||||
LOCAL_CurSlot = dgi->CurSlot;
|
||||
RECOVER_MACHINE_REGS();
|
||||
fprintf(stderr,"LeftGoal success=%d: H=%d ENV=%p B=%d TR=%d P=%p CP=%p Slots=%d\n",
|
||||
successful,HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP, LOCAL_CurSlot);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -510,7 +510,7 @@ bool YAPEngine::call(YAPPredicate ap, YAPTerm ts[]) {
|
||||
return result;
|
||||
}
|
||||
|
||||
bool YAPEngine::mgoal(Term t, Term tmod) {
|
||||
bool YAPEngine::mgoal(Term t, Term tmod, bool release) {
|
||||
#if YAP_PYTHON
|
||||
// PyThreadState *_save;
|
||||
|
||||
@ -548,7 +548,7 @@ bool YAPEngine::mgoal(Term t, Term tmod) {
|
||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec ");
|
||||
|
||||
result = (bool)YAP_EnterGoal(ap, nullptr, &q);
|
||||
YAP_LeaveGoal(result, &q);
|
||||
YAP_LeaveGoal(result && !release, &q);
|
||||
// PyEval_RestoreThread(_save);
|
||||
RECOVER_MACHINE_REGS();
|
||||
return result;
|
||||
@ -559,7 +559,10 @@ bool YAPEngine::mgoal(Term t, Term tmod) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* called when a query must be terminated and its state fully recovered,
|
||||
* @type {[type]}
|
||||
*/
|
||||
void YAPEngine::release() {
|
||||
|
||||
BACKUP_MACHINE_REGS();
|
||||
|
10
CXX/yapq.hh
10
CXX/yapq.hh
@ -339,11 +339,15 @@ public:
|
||||
bool call(YAPPredicate ap, YAPTerm ts[]);
|
||||
/// current directory for the engine
|
||||
bool goal(YAPTerm Yt, YAPModule module) { return mgoal(Yt.term(),module.term()); };
|
||||
/// current directory for the engine
|
||||
bool mgoal(Term t, Term tmod);
|
||||
/// ru1n a goal in a module.
|
||||
///
|
||||
/// By default, memory will only be fully
|
||||
/// recovered on backtracking. The release option ensures
|
||||
/// backtracking is called at the very end.
|
||||
bool mgoal(Term t, Term tmod, bool release= false);
|
||||
/// current directory for the engine
|
||||
|
||||
bool goal(Term t) { return mgoal(t, CurrentModule); }
|
||||
bool goal(Term t, bool release=false) { return mgoal(t, CurrentModule, release); }
|
||||
/// reset Prolog state
|
||||
void reSet();
|
||||
/// assune that there are no stack pointers, just release memory
|
||||
|
@ -30,15 +30,15 @@ class Engine( YAPEngine ):
|
||||
args.setYapPLDIR(yap_lib_path)
|
||||
args.setSavedState(join(yap_lib_path, "startup.yss"))
|
||||
YAPEngine.__init__(self, args)
|
||||
self.goal(set_prolog_flag('verbose', 'silent'))
|
||||
self.goal(compile(library('yapi')))
|
||||
self.goal(set_prolog_flag('verbose', 'normal'))
|
||||
self.goal(set_prolog_flag('verbose', 'silent'), recover=True)
|
||||
self.goal(compile(library('yapi')), recover=True)
|
||||
self.goal(set_prolog_flag('verbose', 'normal'), release=True)
|
||||
|
||||
def run(self, g, m=None):
|
||||
def run(self, g, m=None, release=False):
|
||||
if m:
|
||||
self.mgoal(g, m)
|
||||
self.mgoal(g, m, release=release)
|
||||
else:
|
||||
self.goal(g)
|
||||
self.goal(release=release)
|
||||
|
||||
|
||||
class EngineArgs( YAPEngineArgs ):
|
||||
@ -124,6 +124,7 @@ class YAPShell:
|
||||
|
||||
|
||||
def query_prolog(self, query):
|
||||
g = None
|
||||
#import pdb; pdb.set_trace()
|
||||
#
|
||||
# construct a query from a one-line string
|
||||
@ -134,7 +135,7 @@ class YAPShell:
|
||||
# # vs is the list of variables
|
||||
# you can print it out, the left-side is the variable name,
|
||||
# the right side wraps a handle to a variable
|
||||
import pdb; pdb.set_trace()
|
||||
#import pdb; pdb.set_trace()
|
||||
# #pdb.set_trace()
|
||||
# atom match either symbols, or if no symbol exists, sttrings, In this case
|
||||
# variable names should match strings
|
||||
@ -144,16 +145,17 @@ class YAPShell:
|
||||
# return
|
||||
try:
|
||||
engine = self.engine
|
||||
engine.ReSet()
|
||||
bindings = []
|
||||
bindings = []
|
||||
loop = False
|
||||
if g:
|
||||
g.release()
|
||||
g = python_query(self, query)
|
||||
q = Query( engine, g )
|
||||
for bind in q:
|
||||
self.q = Query( engine, g )
|
||||
for bind in self.q:
|
||||
bindings += [bind]
|
||||
if loop:
|
||||
continue
|
||||
if not q.port == "exit":
|
||||
if not self.q.port == "exit":
|
||||
break
|
||||
s = input("more(;), all(*), no(\\n), python(#) ?").lstrip()
|
||||
if s.startswith(';') or s.startswith('y'):
|
||||
@ -168,14 +170,14 @@ class YAPShell:
|
||||
continue
|
||||
else:
|
||||
break
|
||||
if q:
|
||||
if self.q:
|
||||
self.os = query
|
||||
if bindings:
|
||||
return True,bindings
|
||||
print("No (more) answers")
|
||||
return False, None
|
||||
except Exception as e:
|
||||
if not q:
|
||||
if not self.q:
|
||||
return False, None
|
||||
print("Exception")
|
||||
return False, None
|
||||
|
Reference in New Issue
Block a user