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
|
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
|
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,
|
||||||
// Slots=%d\n",HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP,
|
LOCAL_CurSlot);
|
||||||
// LOCAL_CurSlot);
|
|
||||||
|
|
||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
LOCAL_ActiveError->errorNo = YAP_NO_ERROR;
|
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->p = P;
|
||||||
dgi->cp = CP;
|
dgi->cp = CP;
|
||||||
dgi->b0 = LCL0 - (CELL *)B;
|
dgi->b0 = LCL0 - (CELL *)B;
|
||||||
|
dgi->e = LCL0-ENV;
|
||||||
dgi->CurSlot = LOCAL_CurSlot;
|
dgi->CurSlot = LOCAL_CurSlot;
|
||||||
// ensure our current ENV receives current P.
|
// ensure our current ENV receives current P.
|
||||||
|
|
||||||
Yap_PrepGoal(pe->ArityOfPE, nullptr, B PASS_REGS);
|
Yap_PrepGoal(pe->ArityOfPE, nullptr, B PASS_REGS);
|
||||||
P = pe->CodeOfPred;
|
P = pe->CodeOfPred;
|
||||||
// __android_log_print(ANDROID_LOG_INFO, "YAP ", "ap=%p %d %x %x args=%x,%x
|
// __android_log_print(ANDROID_LOG_INFO, "YAP ", "ap=%p %ld %x %x args=%x,%x
|
||||||
// slot=%d", pe, pe->CodeOfPred->opc, FAILCODE, Deref(ARG1), Deref(ARG2),
|
// slot=%ld", pe, pe->CodeOfPred->opc, FAILCODE, Deref(ARG1), Deref(ARG2),
|
||||||
// LOCAL_CurSlot);
|
// LOCAL_CurSlot);
|
||||||
dgi->b = LCL0 - (CELL *)B;
|
dgi->b = LCL0 - (CELL *)B;
|
||||||
dgi->h = HR - H0;
|
dgi->h = HR - H0;
|
||||||
dgi->tr = (CELL *)TR - LCL0;
|
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);
|
// 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,"EnterGoal success=%d: H=%d ENV=%p B=%d TR=%d P=%p CP=%p
|
// fprintf(stderr,"EnterGoal success=%ld: H=%ld ENV=%p B=%ld TR=%ld P=%p CP=%p
|
||||||
// Slots=%d\n", out,HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP,
|
// Slots=%ld\n", out,HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP,
|
||||||
// LOCAL_CurSlot);
|
// LOCAL_CurSlot);
|
||||||
dgi->b = LCL0 - (CELL *)B;
|
dgi->b = (LCL0 - (CELL*)B);
|
||||||
|
dgi->e = LCL0 - (CELL *)B;
|
||||||
|
dgi->a = LCL0 - (CELL *)ASP;
|
||||||
if (out) {
|
if (out) {
|
||||||
dgi->EndSlot = LOCAL_CurSlot;
|
dgi->EndSlot = LOCAL_CurSlot;
|
||||||
Yap_StartSlots();
|
Yap_StartSlots();
|
||||||
@ -1812,16 +1814,15 @@ X_API bool YAP_RetryGoal(YAP_dogoalinfo *dgi) {
|
|||||||
// 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=%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);
|
// HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP, LOCAL_CurSlot);
|
||||||
P = FAILCODE;
|
P = FAILCODE;
|
||||||
/* make sure we didn't leave live slots when we backtrack */
|
/* make sure we didn't leave live slots when we backtrack */
|
||||||
ASP = (CELL *)B;
|
|
||||||
LOCAL_CurSlot = dgi->EndSlot;
|
LOCAL_CurSlot = dgi->EndSlot;
|
||||||
out = Yap_exec_absmi(true, true );
|
out = Yap_exec_absmi(true, true );
|
||||||
if (out) {
|
if (out) {
|
||||||
dgi->EndSlot = LOCAL_CurSlot;
|
dgi->EndSlot = LOCAL_CurSlot;
|
||||||
dgi->b = LCL0 - (CELL *)B;
|
dgi->b = myB;
|
||||||
} else {
|
} else {
|
||||||
LOCAL_CurSlot =
|
LOCAL_CurSlot =
|
||||||
dgi->CurSlot; // ignore any slots created within the called goal
|
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
|
CACHE_REGS
|
||||||
choiceptr myB, handler;
|
choiceptr myB, handler;
|
||||||
|
|
||||||
// fprintf(stderr,"LeaveGoal success=%d: H=%d ENV=%p B=%ld myB=%ld TR=%d
|
// fprintf(stderr,"LeaveGoal success=%ld: H=%d ENV=%p B=%ldd myB=%ldd TR=%ld
|
||||||
// P=%p CP=%p Slots=%d\n",
|
// P=%p CP=%p Slots=%ld\n",
|
||||||
// successful,HR-H0,LCL0-ENV,LCL0-(CELL*)B,dgi->b0,(CELL*)TR-LCL0, P, CP,
|
// successful,HR-H0,LCL0-ENV,LCL0-(CELL*)B,dgi->b0,(CELL*)TR-LCL0, P, CP,
|
||||||
// LOCAL_CurSlot);
|
// LOCAL_CurSlot);
|
||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
@ -1865,10 +1866,12 @@ X_API bool YAP_LeaveGoal(bool successful, YAP_dogoalinfo *dgi) {
|
|||||||
}
|
}
|
||||||
P = dgi->p;
|
P = dgi->p;
|
||||||
CP = dgi->cp;
|
CP = dgi->cp;
|
||||||
|
ENV = LCL0-dgi->e;
|
||||||
|
ASP = LCL0-dgi->a;
|
||||||
|
B = (choiceptr)(LCL0-dgi->b)
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
// fprintf(stderr,"LeftGoal success=%d: H=%d ENV=%p B=%d TR=%d P=%p CP=%p
|
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,
|
||||||
// Slots=%d\n", successful,HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P,
|
CP, LOCAL_CurSlot);
|
||||||
// CP, LOCAL_CurSlot);
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2152,7 +2155,7 @@ int lvl = push_text_stack();
|
|||||||
sno = Yap_OpenStream(tat, "r", MkAtomTerm(Yap_LookupAtom(fname)),
|
sno = Yap_OpenStream(tat, "r", MkAtomTerm(Yap_LookupAtom(fname)),
|
||||||
LOCAL_encoding);
|
LOCAL_encoding);
|
||||||
__android_log_print(
|
__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))) {
|
if (sno < 0 || !Yap_ChDir(dirname((char *)d))) {
|
||||||
*full = NULL;
|
*full = NULL;
|
||||||
pop_text_stack(lvl);
|
pop_text_stack(lvl);
|
||||||
@ -2194,7 +2197,7 @@ X_API void YAP_EndConsult(int sno, int *osnop, const char *full) {
|
|||||||
if (osnop >= 0)
|
if (osnop >= 0)
|
||||||
Yap_AddAlias(AtomLoopStream, *osnop);
|
Yap_AddAlias(AtomLoopStream, *osnop);
|
||||||
Yap_end_consult();
|
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
|
CurrentModule == 0
|
||||||
? "prolog"
|
? "prolog"
|
||||||
: RepAtom(AtomOfTerm(CurrentModule))->StrOfAE,
|
: RepAtom(AtomOfTerm(CurrentModule))->StrOfAE,
|
||||||
|
@ -539,7 +539,6 @@ static Int current_source_module(USES_REGS1) {
|
|||||||
Yap_Error(TYPE_ERROR_ATOM, t, NULL);
|
Yap_Error(TYPE_ERROR_ATOM, t, NULL);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Yap_DebugPlWriteln(t);
|
|
||||||
LOCAL_SourceModule = CurrentModule = t;
|
LOCAL_SourceModule = CurrentModule = t;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
42
CXX/yapi.cpp
42
CXX/yapi.cpp
@ -613,43 +613,8 @@ bool YAPEngine::mgoal(Term t, Term tmod, bool release) {
|
|||||||
#endif
|
#endif
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
Term *ts = nullptr;
|
bool rc = YAP_RunGoalOnce(t);
|
||||||
q.CurSlot = Yap_StartSlots();
|
return rc;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* called when a query must be terminated and its state fully recovered,
|
* called when a query must be terminated and its state fully recovered,
|
||||||
@ -670,7 +635,9 @@ Term YAPEngine::fun(Term t) {
|
|||||||
arity_t arity;
|
arity_t arity;
|
||||||
Functor f;
|
Functor f;
|
||||||
Atom name;
|
Atom name;
|
||||||
|
YAP_dogoalinfo backup = q;
|
||||||
|
|
||||||
|
|
||||||
if (IsApplTerm(t)) {
|
if (IsApplTerm(t)) {
|
||||||
ts = RepAppl(t) + 1;
|
ts = RepAppl(t) + 1;
|
||||||
f = (Functor)ts[-1];
|
f = (Functor)ts[-1];
|
||||||
@ -719,6 +686,7 @@ Term YAPEngine::fun(Term t) {
|
|||||||
YAP_LeaveGoal(result, &q);
|
YAP_LeaveGoal(result, &q);
|
||||||
// PyEval_RestoreThread(_save);
|
// PyEval_RestoreThread(_save);
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
|
q = backup;
|
||||||
return ot;
|
return ot;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,7 @@ typedef enum {
|
|||||||
|
|
||||||
/* this should be opaque to the user */
|
/* this should be opaque to the user */
|
||||||
typedef struct {
|
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 CurSlot; //> variables at entry
|
||||||
YAP_handle_t EndSlot; //> variables at successful execution
|
YAP_handle_t EndSlot; //> variables at successful execution
|
||||||
struct yami *p; //> Program Counter at entry
|
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(maplist)).
|
||||||
:- use_module(library(mapargs)).
|
:- use_module(library(mapargs)).
|
||||||
:- use_module(library(lists)).
|
:- use_module(library(lists)).
|
||||||
:- start_low_level_trace.
|
|
||||||
( X <== '[]'(Dims0, array) of T ) :-
|
( X <== '[]'(Dims0, array) of T ) :-
|
||||||
var(X),
|
var(X),
|
||||||
( T== ints -> true ; T== floats),
|
( 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 ),
|
foldl( norm_dim, Dims0, Dims, Bases, 1, _Size ),
|
||||||
matrix_new( T , Dims, _, X ),
|
matrix_new( T , Dims, _, X ),
|
||||||
matrix_base(X, Bases).
|
matrix_base(X, Bases).
|
||||||
:- stop_low_level_trace.
|
|
||||||
( X <== '[]'(Dims0, array) of T ) :-
|
( X <== '[]'(Dims0, array) of T ) :-
|
||||||
atom(X),
|
atom(X),
|
||||||
( T== ints -> true ; T== floats),
|
( T== ints -> true ; T== floats),
|
||||||
|
@ -28,7 +28,7 @@ void YAPPy_ThrowError__(const char *file, const char *function, int lineno,
|
|||||||
// fprintf(stderr, "warning: ");
|
// fprintf(stderr, "warning: ");
|
||||||
Yap_ThrowError__(file, function, lineno, type, wheret, tmpbuf);
|
Yap_ThrowError__(file, function, lineno, type, wheret, tmpbuf);
|
||||||
} else {
|
} 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;
|
int n, i;
|
||||||
PL_get_name_arity(t, &s, &n);
|
PL_get_name_arity(t, &s, &n);
|
||||||
PyObject *o = term_to_python(t, true, context, true);
|
PyObject *o = term_to_python(t, true, context, true);
|
||||||
|
PyErr_Print();
|
||||||
if (PySequence_Check(o) && PySequence_Length(o) == n) {
|
if (PySequence_Check(o) && PySequence_Length(o) == n) {
|
||||||
for (i = 1; i <= n; i++) {
|
for (i = 1; i <= n; i++) {
|
||||||
PyObject *p;
|
PyObject *p;
|
||||||
@ -337,12 +338,15 @@ bool python_assign(term_t t, PyObject *exp, PyObject *context) {
|
|||||||
o = false;
|
o = false;
|
||||||
p = Py_None;
|
p = Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((p = PySequence_GetItem(exp, i - 1)) == NULL)
|
if ((p = PySequence_GetItem(exp, i - 1)) == NULL)
|
||||||
p = Py_None;
|
p = Py_None;
|
||||||
else if (!python_assign(arg, p, NULL)) {
|
else if (!python_assign(arg, p, NULL)) {
|
||||||
PL_reset_term_refs(tail);
|
PL_reset_term_refs(tail);
|
||||||
o = NULL;
|
o = NULL;
|
||||||
}
|
} else {
|
||||||
|
PyErr_Print();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -350,6 +354,7 @@ bool python_assign(term_t t, PyObject *exp, PyObject *context) {
|
|||||||
}
|
}
|
||||||
PL_reset_term_refs(tail);
|
PL_reset_term_refs(tail);
|
||||||
}
|
}
|
||||||
|
PyErr_Print();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user