This commit is contained in:
Vitor Santos Costa 2018-05-29 09:59:28 +01:00
parent 2415a2e58c
commit e9274ef5d3
8 changed files with 58 additions and 40 deletions

View File

@ -38,6 +38,7 @@ int Yap_ArgKey(Atom key, const param_t *def, int n) {
return -1;
}
#define YAP_XARGINFO(Error, Message)
#define failed(e, t, a) failed__(e, t, a PASS_REGS)
static xarg *failed__(yap_error_number e, Term t, xarg *a USES_REGS) {

View File

@ -1721,6 +1721,7 @@ X_API bool YAP_EnterGoal(YAP_PredEntryPtr ape, CELL *ptr, YAP_dogoalinfo *dgi) {
CACHE_REGS
PredEntry *pe = ape;
bool out;
fprintf(stderr,"EnterGoal: 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);
BACKUP_MACHINE_REGS();
LOCAL_ActiveError->errorNo = YAP_NO_ERROR;
@ -1741,7 +1742,7 @@ X_API bool YAP_EnterGoal(YAP_PredEntryPtr ape, CELL *ptr, YAP_dogoalinfo *dgi) {
//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);
fprintf(stderr,"EnterGoal 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();
@ -1791,26 +1792,32 @@ X_API bool YAP_RetryGoal(YAP_dogoalinfo *dgi) {
X_API bool YAP_LeaveGoal(bool successful, YAP_dogoalinfo *dgi) {
CACHE_REGS
choiceptr myB;
bool backtrack = false;
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);
fprintf(stderr,"LeaveGoal success=%d: H=%d ENV=%p B=%ld myB=%ld TR=%d P=%p CP=%p Slots=%d\n",
successful,HR-H0,LCL0-ENV,LCL0-(CELL*)B,dgi->b0,(CELL*)TR-LCL0, P, CP, LOCAL_CurSlot);
BACKUP_MACHINE_REGS();
myB = (choiceptr)(LCL0 - dgi->b0);
if (B < myB) {
myB = (choiceptr)(LCL0 - dgi->b);
if (B > myB) {
/* someone cut us */
return false;
}
/* prune away choicepoints */
while (B != myB) {
while (B && B->cp_b && B < myB && B->cp_b < myB) {
#ifdef YAPOR
CUT_prune_to(myB);
CUT_prune_to(B);
#endif
B = myB;
if (successful) {
B = B->cp_b;
trim_trail();
} else {
P = TRUSTFAILCODE;
Yap_exec_absmi(true, YAP_EXEC_ABSMI);
}
}
/* if backtracking asked for, recover space and bindings */
if (!successful) {
P = FAILCODE;
Yap_exec_absmi(true, YAP_EXEC_ABSMI);
#if 0
if (0 && !successful) {
/* recover stack space */
HR = B->cp_h;
TR = B->cp_tr;
@ -1822,12 +1829,11 @@ X_API bool YAP_LeaveGoal(bool successful, YAP_dogoalinfo *dgi) {
} else {
Yap_TrimTrail();
}
#endif
/* recover local stack */
#ifdef DEPTH_LIMIT
DEPTH = ENV[E_DEPTH];
#endif
/* make sure we prune C-choicepoints */
ENV = (CELL *)(ENV[E_E]);
/* ASP should be set to the top of the local stack when we
did the call */
ASP = B->cp_env;
@ -1835,7 +1841,9 @@ X_API bool YAP_LeaveGoal(bool successful, YAP_dogoalinfo *dgi) {
YENV = ENV = (CELL *)((B->cp_env)[E_E]);
B = B->cp_b;
// SET_BB(B);
if (B) {
HB = PROTECT_FROZEN_H(B);
}
CP = dgi->cp;
P = dgi->p;
LOCAL_CurSlot = dgi->CurSlot;

View File

@ -115,7 +115,7 @@ static PredEntry *PredForChoicePt(yamop *p_code, op_numbers *opn) {
*opn = opnum;
switch (opnum) {
case _Nstop:
return NULL;
return PredFail;
case _jump:
p_code = p_code->y_u.l.l;
break;
@ -284,8 +284,9 @@ bool Yap_search_for_static_predicate_in_use(PredEntry *p,
}
/* now mark the choicepoint */
if (b_ptr)
if (b_ptr) {
pe = PredForChoicePt(b_ptr->cp_ap, NULL);
}
else
return false;
if (pe == p) {

View File

@ -736,10 +736,11 @@ bool YAPQuery::next() {
}
q_state = 1;
__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();
RECOVER_MACHINE_REGS();
LOCAL_RestartEnv = oldp;

View File

@ -82,7 +82,9 @@ python_query( Caller, String ) :-
in_dict(Dict, var([V0,V|Vs])) :- !,
Dict[V] := V0,
in_dict( Dict, var([V0|Vs])).
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(_, _).

View File

@ -56,7 +56,8 @@ class Predicate( YAPPredicate ):
class Query:
"""Goal is a predicate instantiated under a specific environment """
def __init__(self, engine, g):
engine.reSet();
engine.reSet()
self.engine = engine
self.q = engine.query(g)
if self.q:
self.port = "call"
@ -71,8 +72,8 @@ class Query:
if not self.q:
raise StopIteration()
if self.q.next():
rc = self.answer
if self.port == "exit":
rc = self.q.answer
if self.q.port == "exit":
return rc
else:
if self:
@ -80,7 +81,6 @@ class Query:
raise StopIteration()
def close( self ):
engine.reSet()
if self.q:
self.q.close()
self.q = None
@ -138,7 +138,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
@ -158,7 +158,7 @@ class YAPShell:
bindings += [bind]
if loop:
continue
if not self.q.port == "exit":
if self.q.port == "exit":
break
s = input("more(;), all(*), no(\\n), python(#) ?").lstrip()
if s.startswith(';') or s.startswith('y'):
@ -174,7 +174,7 @@ class YAPShell:
else:
break
if self.q:
self.os = query
self.q.close()
if bindings:
return True,bindings
print("No (more) answers")
@ -182,6 +182,7 @@ class YAPShell:
except Exception as e:
if not self.q:
return False, None
self.q.close()
print("Exception")
return False, None

View File

@ -36,7 +36,7 @@ all_attvars/1,
put_att_term/2,
put_module_atts/2,
unbind_attvar/1,
woken_att_do/4] .
woken_att_do/4]) .
:- use_system_module( '$_boot', ['$undefp'/1]).

View File

@ -33,13 +33,15 @@
/**
* @defgroup ypp Yap PreProcessing
* @{
* @ingroup library
*
* This program_continuation can be used as a preprocessor in the
* This program can be used as a preprocessor in the
* style of the `C` language. Currently, it must be used through
* ypp_consult and or ypp_reconsult.
*
* Notice that ypp uses `#` commands.
* Notice that ypp uses `#` commands and it is different from the Prolog if/1
* directive.
*
*/
@ -140,3 +142,5 @@ ypp_file(File,PPFile):-
:-set_state(on),
ypp_extcmd('cpp -P -E -w -o ').
% ypp_extcmd('gpp -o').
%% @}