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; return -1;
} }
#define YAP_XARGINFO(Error, Message)
#define failed(e, t, a) failed__(e, t, a PASS_REGS) #define failed(e, t, a) failed__(e, t, a PASS_REGS)
static xarg *failed__(yap_error_number e, Term t, xarg *a USES_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 CACHE_REGS
PredEntry *pe = ape; PredEntry *pe = ape;
bool out; 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(); BACKUP_MACHINE_REGS();
LOCAL_ActiveError->errorNo = YAP_NO_ERROR; 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", //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); // 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); 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) { if (out) {
dgi->EndSlot = LOCAL_CurSlot; dgi->EndSlot = LOCAL_CurSlot;
Yap_StartSlots(); Yap_StartSlots();
@ -1767,7 +1768,7 @@ X_API bool YAP_RetryGoal(YAP_dogoalinfo *dgi) {
return false; return false;
} }
if (B < myB) { if (B < myB) {
// 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", //fprintf(stderr,"RetryGoal: H=%d ENV=%p B=%d TR=%d P=%p CP=%p Slots=%d\n",
@ -1791,43 +1792,48 @@ X_API bool YAP_RetryGoal(YAP_dogoalinfo *dgi) {
X_API bool YAP_LeaveGoal(bool successful, YAP_dogoalinfo *dgi) { X_API bool YAP_LeaveGoal(bool successful, YAP_dogoalinfo *dgi) {
CACHE_REGS CACHE_REGS
choiceptr myB; 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", 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,(CELL*)TR-LCL0, P, CP, LOCAL_CurSlot); successful,HR-H0,LCL0-ENV,LCL0-(CELL*)B,dgi->b0,(CELL*)TR-LCL0, P, CP, LOCAL_CurSlot);
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
myB = (choiceptr)(LCL0 - dgi->b0); myB = (choiceptr)(LCL0 - dgi->b);
if (B < myB) { if (B > myB) {
/* someone cut us */ /* someone cut us */
return false; return false;
} }
/* prune away choicepoints */ /* prune away choicepoints */
while (B != myB) { while (B && B->cp_b && B < myB && B->cp_b < myB) {
#ifdef YAPOR #ifdef YAPOR
CUT_prune_to(myB); CUT_prune_to(B);
#endif #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 backtracking asked for, recover space and bindings */
if (!successful) { #if 0
P = FAILCODE; if (0 && !successful) {
Yap_exec_absmi(true, YAP_EXEC_ABSMI);
/* recover stack space */ /* recover stack space */
HR = B->cp_h; HR = B->cp_h;
TR = B->cp_tr; TR = B->cp_tr;
#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();
} }
#endif
/* recover local stack */ /* recover local stack */
#ifdef DEPTH_LIMIT #ifdef DEPTH_LIMIT
DEPTH = ENV[E_DEPTH]; DEPTH = ENV[E_DEPTH];
#endif #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 /* ASP should be set to the top of the local stack when we
did the call */ did the call */
ASP = B->cp_env; 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]); YENV = ENV = (CELL *)((B->cp_env)[E_E]);
B = B->cp_b; B = B->cp_b;
// SET_BB(B); // SET_BB(B);
HB = PROTECT_FROZEN_H(B); if (B) {
HB = PROTECT_FROZEN_H(B);
}
CP = dgi->cp; CP = dgi->cp;
P = dgi->p; P = dgi->p;
LOCAL_CurSlot = dgi->CurSlot; LOCAL_CurSlot = dgi->CurSlot;
@ -2279,7 +2287,7 @@ X_API bool YAP_CompileClause(Term t) {
Term mod = CurrentModule; Term mod = CurrentModule;
Term tn = TermNil; Term tn = TermNil;
bool ok = true; bool ok = true;
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
/* allow expansion during stack initialization */ /* allow expansion during stack initialization */
@ -2307,7 +2315,7 @@ X_API bool YAP_CompileClause(Term t) {
} }
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
if (!ok) { if (!ok) {
return NULL; return NULL;
} }
return ok; return ok;
} }

View File

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

View File

@ -559,7 +559,7 @@ bool YAPEngine::mgoal(Term t, Term tmod, bool release) {
return result; return result;
} catch (...) { } catch (...) {
YAPCatchError(); YAPCatchError();
return false; return false;
} }
} }
@ -736,10 +736,11 @@ bool YAPQuery::next() {
} }
q_state = 1; q_state = 1;
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "out %d", result); __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "out %d", result);
if (!result) {
YAP_LeaveGoal(result, &q_h); YAP_LeaveGoal(result, &q_h);
Yap_CloseHandles(q_handles); Yap_CloseHandles(q_handles);
q_open = false; q_open = false;
}
YAPCatchError(); YAPCatchError();
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
LOCAL_RestartEnv = oldp; LOCAL_RestartEnv = oldp;
@ -1047,7 +1048,7 @@ std::stringstream s;
void YAPEngine::reSet() { void YAPEngine::reSet() {
/* ignore flags for now */ /* ignore flags for now */
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
choiceptr b = (choiceptr)(LCL0-q.b); choiceptr b = (choiceptr)(LCL0-q.b);
if (b > B) B = b; if (b > B) B = b;
P = FAILCODE; P = FAILCODE;

View File

@ -82,7 +82,9 @@ python_query( Caller, String ) :-
in_dict(Dict, var([V0,V|Vs])) :- !, in_dict(Dict, var([V0,V|Vs])) :- !,
Dict[V] := V0, Dict[V] := V0,
in_dict( Dict, var([V0|Vs])). in_dict( Dict, var([V0|Vs])).
in_dict(Dict, var([],_G)) :- !.
in_dict(Dict, nonvar([V0|Vs],G)) :- !, in_dict(Dict, nonvar([V0|Vs],G)) :- !,
Dict[V0] := G, Dict[V0] := G,
in_dict( Dict, var([V0|Vs])). in_dict( Dict, var([V0|Vs])).
in_dict(Dict, nonvar([],_G)) :- !.
in_dict(_, _). in_dict(_, _).

View File

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

View File

@ -26,7 +26,7 @@
*/ */
:- module( attributes, [delayed_goals/4, :- module( attributes, [delayed_goals/4,
all_attvars/1, all_attvars/1,
bind_attvar/1, bind_attvar/1,
del_all_atts/1, del_all_atts/1,
del_all_module_atts/2, del_all_module_atts/2,
@ -36,7 +36,7 @@ all_attvars/1,
put_att_term/2, put_att_term/2,
put_module_atts/2, put_module_atts/2,
unbind_attvar/1, unbind_attvar/1,
woken_att_do/4] . woken_att_do/4]) .
:- use_system_module( '$_boot', ['$undefp'/1]). :- use_system_module( '$_boot', ['$undefp'/1]).

View File

@ -2,17 +2,17 @@
* @file ypp.yap * @file ypp.yap
* @author Nuno Fonseca (nunofonseca@acm.org), Tiago Soares * @author Nuno Fonseca (nunofonseca@acm.org), Tiago Soares
* @date 2005-05-14 * @date 2005-05-14
* *
* @brief Yap PreProcessing * @brief Yap PreProcessing
* *
* *
*/ */
%==================================================================================== %====================================================================================
% %
% YPP: Yap PreProcessing % YPP: Yap PreProcessing
% %
% Author: Nuno Fonseca (nunofonseca@acm.org) % Author: Nuno Fonseca (nunofonseca@acm.org)
% Date: % Date:
% $Id: ypp.yap,v 1.4 2006-03-07 17:30:47 tiagosoares Exp $ % $Id: ypp.yap,v 1.4 2006-03-07 17:30:47 tiagosoares Exp $
% %
%==================================================================================== %====================================================================================
@ -33,14 +33,16 @@
/** /**
* @defgroup ypp Yap PreProcessing * @defgroup ypp Yap PreProcessing
* @{
* @ingroup library * @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 * style of the `C` language. Currently, it must be used through
* ypp_consult and or ypp_reconsult. * 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), :-set_state(on),
ypp_extcmd('cpp -P -E -w -o '). ypp_extcmd('cpp -P -E -w -o ').
% ypp_extcmd('gpp -o'). % ypp_extcmd('gpp -o').
%% @}