c-interface
This commit is contained in:
parent
9ea395c031
commit
fda10395b8
@ -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,
|
||||
|
@ -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;
|
||||
}
|
||||
|
42
CXX/yapi.cpp
42
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,6 +635,8 @@ Term YAPEngine::fun(Term t) {
|
||||
arity_t arity;
|
||||
Functor f;
|
||||
Atom name;
|
||||
YAP_dogoalinfo backup = q;
|
||||
|
||||
|
||||
if (IsApplTerm(t)) {
|
||||
ts = RepAppl(t) + 1;
|
||||
@ -719,6 +686,7 @@ Term YAPEngine::fun(Term t) {
|
||||
YAP_LeaveGoal(result, &q);
|
||||
// PyEval_RestoreThread(_save);
|
||||
RECOVER_MACHINE_REGS();
|
||||
q = backup;
|
||||
return ot;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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),
|
||||
|
@ -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,11 +338,14 @@ 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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user