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