diff --git a/C/c_interface.c b/C/c_interface.c index 82da72fdf..6d8c8549f 100755 --- a/C/c_interface.c +++ b/C/c_interface.c @@ -1756,9 +1756,8 @@ 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); + fprintf(stderr,"EnterGoal: H=%ld ENV=%ld B=%ld TR=%ld P=%p CP=%p, Slots=%ld\n",HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP, + LOCAL_CurSlot); BACKUP_MACHINE_REGS(); LOCAL_ActiveError->errorNo = YAP_NO_ERROR; @@ -1766,24 +1765,27 @@ X_API bool YAP_EnterGoal(YAP_PredEntryPtr ape, CELL *ptr, YAP_dogoalinfo *dgi) { dgi->p = P; dgi->cp = CP; dgi->b0 = LCL0 - (CELL *)B; + dgi->e = LCL0-ENV; dgi->CurSlot = LOCAL_CurSlot; // ensure our current ENV receives current P. Yap_PrepGoal(pe->ArityOfPE, nullptr, B PASS_REGS); P = pe->CodeOfPred; - // __android_log_print(ANDROID_LOG_INFO, "YAP ", "ap=%p %d %x %x args=%x,%x - // slot=%d", pe, pe->CodeOfPred->opc, FAILCODE, Deref(ARG1), Deref(ARG2), + // __android_log_print(ANDROID_LOG_INFO, "YAP ", "ap=%p %ld %x %x args=%x,%x + // slot=%ld", pe, pe->CodeOfPred->opc, FAILCODE, Deref(ARG1), Deref(ARG2), // LOCAL_CurSlot); dgi->b = LCL0 - (CELL *)B; dgi->h = HR - H0; dgi->tr = (CELL *)TR - LCL0; - // fprintf(stderr,"PrepGoal: H=%d ENV=%p B=%d TR=%d P=%p CP=%p Slots=%d\n", + // fprintf(stderr,"PrepGoal: H=%ld ENV=%p B=%ld TR=%ld P=%p CP=%p Slots=%ld\n", // HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP, LOCAL_CurSlot); out = Yap_exec_absmi(true, false); - // 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, + // fprintf(stderr,"EnterGoal success=%ld: H=%ld ENV=%p B=%ld TR=%ld P=%p CP=%p + // Slots=%ld\n", out,HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP, // LOCAL_CurSlot); - dgi->b = LCL0 - (CELL *)B; + dgi->b = (LCL0 - (CELL*)B); + dgi->e = LCL0 - (CELL *)B; + dgi->a = LCL0 - (CELL *)ASP; if (out) { dgi->EndSlot = LOCAL_CurSlot; Yap_StartSlots(); @@ -1812,16 +1814,15 @@ 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", + // fprintf(stderr,"RetryGoal: H=%ld ENV=%p B=%ld TR=%ld P=%p CP=%p Slots=%ld\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; LOCAL_CurSlot = dgi->EndSlot; out = Yap_exec_absmi(true, true ); if (out) { dgi->EndSlot = LOCAL_CurSlot; - dgi->b = LCL0 - (CELL *)B; + dgi->b = myB; } else { LOCAL_CurSlot = dgi->CurSlot; // ignore any slots created within the called goal @@ -1834,8 +1835,8 @@ X_API bool YAP_LeaveGoal(bool successful, YAP_dogoalinfo *dgi) { CACHE_REGS choiceptr myB, handler; - // fprintf(stderr,"LeaveGoal success=%d: H=%d ENV=%p B=%ld myB=%ld TR=%d - // P=%p CP=%p Slots=%d\n", + // fprintf(stderr,"LeaveGoal success=%ld: H=%d ENV=%p B=%ldd myB=%ldd TR=%ld + // P=%p CP=%p Slots=%ld\n", // successful,HR-H0,LCL0-ENV,LCL0-(CELL*)B,dgi->b0,(CELL*)TR-LCL0, P, CP, // LOCAL_CurSlot); BACKUP_MACHINE_REGS(); @@ -1865,10 +1866,12 @@ X_API bool YAP_LeaveGoal(bool successful, YAP_dogoalinfo *dgi) { } P = dgi->p; CP = dgi->cp; + ENV = LCL0-dgi->e; + ASP = LCL0-dgi->a; + B = (choiceptr)(LCL0-dgi->b) 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); + fprintf(stderr,"LeftGoal success=%ld: H=%ld ENV=%ld B=%ld TR=%ld P=%p CP=%p, Slots=%ld\n", successful,HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, + CP, LOCAL_CurSlot); return TRUE; } @@ -2152,7 +2155,7 @@ int lvl = push_text_stack(); sno = Yap_OpenStream(tat, "r", MkAtomTerm(Yap_LookupAtom(fname)), LOCAL_encoding); __android_log_print( - ANDROID_LOG_INFO, "YAPDroid", "OpenStream got %d ",sno); + ANDROID_LOG_INFO, "YAPDroid", "OpenStream got %ld ",sno); if (sno < 0 || !Yap_ChDir(dirname((char *)d))) { *full = NULL; pop_text_stack(lvl); @@ -2194,7 +2197,7 @@ X_API void YAP_EndConsult(int sno, int *osnop, const char *full) { if (osnop >= 0) Yap_AddAlias(AtomLoopStream, *osnop); Yap_end_consult(); - __android_log_print(ANDROID_LOG_INFO, "YAPDroid ", " closing %s:%s(%d), %d", + __android_log_print(ANDROID_LOG_INFO, "YAPDroid ", " closing %s:%s(%ld), %ld", CurrentModule == 0 ? "prolog" : RepAtom(AtomOfTerm(CurrentModule))->StrOfAE, diff --git a/C/modules.c b/C/modules.c index 78df7a6d8..bc710a69f 100644 --- a/C/modules.c +++ b/C/modules.c @@ -539,7 +539,6 @@ static Int current_source_module(USES_REGS1) { Yap_Error(TYPE_ERROR_ATOM, t, NULL); return false; } - Yap_DebugPlWriteln(t); LOCAL_SourceModule = CurrentModule = t; return true; } diff --git a/CXX/yapi.cpp b/CXX/yapi.cpp index 6c5b4030e..c0a907381 100644 --- a/CXX/yapi.cpp +++ b/CXX/yapi.cpp @@ -613,43 +613,8 @@ bool YAPEngine::mgoal(Term t, Term tmod, bool release) { #endif CACHE_REGS BACKUP_MACHINE_REGS(); - Term *ts = nullptr; - q.CurSlot = Yap_StartSlots(); - q.p = P; - q.cp = CP; - Term omod = CurrentModule; - PredEntry *ap = nullptr; - if (IsStringTerm(tmod)) - tmod = MkAtomTerm(Yap_LookupAtom(StringOfTerm(tmod))); - ap = Yap_get_pred(t, tmod, "C++"); - if (ap == nullptr || - ap->OpcodeOfPred == UNDEF_OPCODE) { - ap = rewriteUndefEngineQuery(ap, t, tmod); - } - if (IsApplTerm(t)) - ts = RepAppl(t) + 1; - else if (IsPairTerm(t)) - ts = RepPair(t); - /* legal ap */ - arity_t arity = ap->ArityOfPE; - - for (arity_t i = 0; i < arity; i++) { - XREGS[i + 1] = ts[i]; - } - ts = nullptr; - bool result; - // allow Prolog style exception handling - // don't forget, on success these guys may create slots - //__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec "); - - result = (bool)YAP_EnterGoal(ap, nullptr, &q); - // std::cerr << "mgoal " << YAPTerm(tmod).text() << ":" << YAPTerm(t).text() << "\n"; - - YAP_LeaveGoal(result && !release, &q); - CurrentModule = LOCAL_SourceModule = omod; - // PyEval_RestoreThread(_save); - RECOVER_MACHINE_REGS(); - return result; + bool rc = YAP_RunGoalOnce(t); + return rc; } /** * called when a query must be terminated and its state fully recovered, @@ -670,7 +635,9 @@ Term YAPEngine::fun(Term t) { arity_t arity; Functor f; Atom name; + YAP_dogoalinfo backup = q; + if (IsApplTerm(t)) { ts = RepAppl(t) + 1; f = (Functor)ts[-1]; @@ -719,6 +686,7 @@ Term YAPEngine::fun(Term t) { YAP_LeaveGoal(result, &q); // PyEval_RestoreThread(_save); RECOVER_MACHINE_REGS(); + q = backup; return ot; } } diff --git a/include/YapDefs.h b/include/YapDefs.h index f1c27bcd0..f2af9cadd 100755 --- a/include/YapDefs.h +++ b/include/YapDefs.h @@ -138,7 +138,7 @@ typedef enum { /* this should be opaque to the user */ typedef struct { - unsigned long b, b0; //> choice-point at entry + unsigned long b, b0, e, a; //> choice-point at entry YAP_handle_t CurSlot; //> variables at entry YAP_handle_t EndSlot; //> variables at successful execution struct yami *p; //> Program Counter at entry diff --git a/library/matrix.yap b/library/matrix.yap index fd5ffcc6e..9efefb539 100644 --- a/library/matrix.yap +++ b/library/matrix.yap @@ -653,7 +653,6 @@ Unify _NElems_ with the type of the elements in _Matrix_. :- use_module(library(maplist)). :- use_module(library(mapargs)). :- use_module(library(lists)). -:- start_low_level_trace. ( X <== '[]'(Dims0, array) of T ) :- var(X), ( T== ints -> true ; T== floats), @@ -661,7 +660,6 @@ Unify _NElems_ with the type of the elements in _Matrix_. foldl( norm_dim, Dims0, Dims, Bases, 1, _Size ), matrix_new( T , Dims, _, X ), matrix_base(X, Bases). -:- stop_low_level_trace. ( X <== '[]'(Dims0, array) of T ) :- atom(X), ( T== ints -> true ; T== floats), diff --git a/packages/python/py2pl.c b/packages/python/py2pl.c index b8160d88c..da5a44476 100644 --- a/packages/python/py2pl.c +++ b/packages/python/py2pl.c @@ -28,7 +28,7 @@ void YAPPy_ThrowError__(const char *file, const char *function, int lineno, // fprintf(stderr, "warning: "); Yap_ThrowError__(file, function, lineno, type, wheret, tmpbuf); } else { - Yap_ThrowError__(file, function, lineno, type, wheret); + // Yap_ThrowError__(file, function, lineno, type, wheret); } } @@ -329,6 +329,7 @@ bool python_assign(term_t t, PyObject *exp, PyObject *context) { int n, i; PL_get_name_arity(t, &s, &n); PyObject *o = term_to_python(t, true, context, true); + PyErr_Print(); if (PySequence_Check(o) && PySequence_Length(o) == n) { for (i = 1; i <= n; i++) { PyObject *p; @@ -337,12 +338,15 @@ bool python_assign(term_t t, PyObject *exp, PyObject *context) { o = false; p = Py_None; } + if ((p = PySequence_GetItem(exp, i - 1)) == NULL) p = Py_None; else if (!python_assign(arg, p, NULL)) { PL_reset_term_refs(tail); o = NULL; - } + } else { + PyErr_Print(); + } } return true; } @@ -350,6 +354,7 @@ bool python_assign(term_t t, PyObject *exp, PyObject *context) { } PL_reset_term_refs(tail); } + PyErr_Print(); return NULL; } }