debwq
This commit is contained in:
parent
2415a2e58c
commit
e9274ef5d3
1
C/args.c
1
C/args.c
@ -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) {
|
||||
|
@ -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();
|
||||
@ -1767,7 +1768,7 @@ X_API bool YAP_RetryGoal(YAP_dogoalinfo *dgi) {
|
||||
return false;
|
||||
}
|
||||
if (B < myB) {
|
||||
// get rid of garbage choice-points
|
||||
// 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",
|
||||
@ -1791,43 +1792,48 @@ 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;
|
||||
#ifdef DEPTH_LIMIT
|
||||
DEPTH = B->cp_depth;
|
||||
#endif /* DEPTH_LIMIT */
|
||||
|
||||
|
||||
YENV = ENV = B->cp_env;
|
||||
} 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);
|
||||
HB = PROTECT_FROZEN_H(B);
|
||||
if (B) {
|
||||
HB = PROTECT_FROZEN_H(B);
|
||||
}
|
||||
CP = dgi->cp;
|
||||
P = dgi->p;
|
||||
LOCAL_CurSlot = dgi->CurSlot;
|
||||
@ -2279,7 +2287,7 @@ X_API bool YAP_CompileClause(Term t) {
|
||||
Term mod = CurrentModule;
|
||||
Term tn = TermNil;
|
||||
bool ok = true;
|
||||
|
||||
|
||||
BACKUP_MACHINE_REGS();
|
||||
|
||||
/* allow expansion during stack initialization */
|
||||
@ -2307,7 +2315,7 @@ X_API bool YAP_CompileClause(Term t) {
|
||||
}
|
||||
RECOVER_MACHINE_REGS();
|
||||
if (!ok) {
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -559,7 +559,7 @@ bool YAPEngine::mgoal(Term t, Term tmod, bool release) {
|
||||
return result;
|
||||
} catch (...) {
|
||||
YAPCatchError();
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
@ -1047,7 +1048,7 @@ std::stringstream s;
|
||||
void YAPEngine::reSet() {
|
||||
/* ignore flags for now */
|
||||
BACKUP_MACHINE_REGS();
|
||||
|
||||
|
||||
choiceptr b = (choiceptr)(LCL0-q.b);
|
||||
if (b > B) B = b;
|
||||
P = FAILCODE;
|
||||
|
@ -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(_, _).
|
||||
|
@ -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
|
||||
@ -148,7 +148,7 @@ class YAPShell:
|
||||
# return
|
||||
try:
|
||||
engine = self.engine
|
||||
bindings = []
|
||||
bindings = []
|
||||
loop = False
|
||||
if g:
|
||||
g.release()
|
||||
@ -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
|
||||
|
||||
|
@ -26,7 +26,7 @@
|
||||
*/
|
||||
|
||||
:- module( attributes, [delayed_goals/4,
|
||||
all_attvars/1,
|
||||
all_attvars/1,
|
||||
bind_attvar/1,
|
||||
del_all_atts/1,
|
||||
del_all_module_atts/2,
|
||||
@ -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]).
|
||||
|
||||
|
18
pl/ypp.yap
18
pl/ypp.yap
@ -2,17 +2,17 @@
|
||||
* @file ypp.yap
|
||||
* @author Nuno Fonseca (nunofonseca@acm.org), Tiago Soares
|
||||
* @date 2005-05-14
|
||||
*
|
||||
*
|
||||
* @brief Yap PreProcessing
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
%====================================================================================
|
||||
%
|
||||
% YPP: Yap PreProcessing
|
||||
%
|
||||
% Author: Nuno Fonseca (nunofonseca@acm.org)
|
||||
% Date:
|
||||
% Date:
|
||||
% $Id: ypp.yap,v 1.4 2006-03-07 17:30:47 tiagosoares Exp $
|
||||
%
|
||||
%====================================================================================
|
||||
@ -33,14 +33,16 @@
|
||||
|
||||
/**
|
||||
* @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').
|
||||
|
||||
%% @}
|
||||
|
Reference in New Issue
Block a user