C-interface
This commit is contained in:
parent
7661b8581c
commit
a6e578090c
@ -1813,21 +1813,23 @@ X_API bool YAP_LeaveGoal(bool successful, YAP_dogoalinfo *dgi) {
|
|||||||
//&& LOCAL_CBorder > LCL0 - (CELL *)handler
|
//&& LOCAL_CBorder > LCL0 - (CELL *)handler
|
||||||
//&& handler->cp_ap != NOCODE
|
//&& handler->cp_ap != NOCODE
|
||||||
&& handler->cp_b != NULL
|
&& handler->cp_b != NULL
|
||||||
&& handler != myB
|
&& handler <= myB
|
||||||
) {
|
) {
|
||||||
handler->cp_ap = TRUSTFAILCODE;
|
handler->cp_ap = TRUSTFAILCODE;
|
||||||
handler = handler->cp_b;
|
|
||||||
}
|
|
||||||
if (LOCAL_PrologMode & AsyncIntMode) {
|
|
||||||
Yap_signal(YAP_FAIL_SIGNAL);
|
|
||||||
}
|
|
||||||
B = handler;
|
B = handler;
|
||||||
|
handler = handler->cp_b;
|
||||||
if (successful) {
|
if (successful) {
|
||||||
Yap_TrimTrail();
|
Yap_TrimTrail();
|
||||||
CP = dgi->cp;
|
|
||||||
P = dgi->p;
|
|
||||||
} else {
|
} else {
|
||||||
|
P=FAILCODE;
|
||||||
Yap_exec_absmi(true, YAP_EXEC_ABSMI);
|
Yap_exec_absmi(true, YAP_EXEC_ABSMI);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (successful) {
|
||||||
|
CP = dgi->cp;
|
||||||
|
P = dgi->p;
|
||||||
|
|
||||||
|
} else {
|
||||||
LOCAL_CurSlot = dgi->CurSlot;
|
LOCAL_CurSlot = dgi->CurSlot;
|
||||||
ENV = YENV = B->cp_env;
|
ENV = YENV = B->cp_env;
|
||||||
HR = B->cp_h;
|
HR = B->cp_h;
|
||||||
@ -1835,6 +1837,11 @@ X_API bool YAP_LeaveGoal(bool successful, YAP_dogoalinfo *dgi) {
|
|||||||
// use the current choicepoint
|
// use the current choicepoint
|
||||||
// B=B->cp_b;
|
// B=B->cp_b;
|
||||||
ASP=(CELL*)B;
|
ASP=(CELL*)B;
|
||||||
|
}
|
||||||
|
if (B)
|
||||||
|
B = B->cp_b;
|
||||||
|
if (LOCAL_PrologMode & AsyncIntMode) {
|
||||||
|
Yap_signal(YAP_FAIL_SIGNAL);
|
||||||
}
|
}
|
||||||
RECOVER_MACHINE_REGS();
|
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=%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);
|
||||||
|
12
CXX/yapi.cpp
12
CXX/yapi.cpp
@ -667,8 +667,10 @@ Term YAPEngine::fun(Term t) {
|
|||||||
throw YAPError(SOURCE(), TYPE_ERROR_CALLABLE, t, 0);
|
throw YAPError(SOURCE(), TYPE_ERROR_CALLABLE, t, 0);
|
||||||
return 0L;
|
return 0L;
|
||||||
}
|
}
|
||||||
XREGS[arity + 1] = MkVarTerm();
|
Term ot = XREGS[arity + 1] = MkVarTerm();
|
||||||
|
yhandle_t h = Yap_InitHandle(ot);
|
||||||
arity++;
|
arity++;
|
||||||
|
HR += arity;
|
||||||
f = Yap_MkFunctor(name, arity);
|
f = Yap_MkFunctor(name, arity);
|
||||||
ap = (PredEntry *)(PredPropByFunc(f, tmod));
|
ap = (PredEntry *)(PredPropByFunc(f, tmod));
|
||||||
if (ap == nullptr || ap->OpcodeOfPred == UNDEF_OPCODE) {
|
if (ap == nullptr || ap->OpcodeOfPred == UNDEF_OPCODE) {
|
||||||
@ -683,12 +685,16 @@ Term YAPEngine::fun(Term t) {
|
|||||||
//__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec ");
|
//__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec ");
|
||||||
|
|
||||||
bool result = (bool)YAP_EnterGoal(ap, nullptr, &q);
|
bool result = (bool)YAP_EnterGoal(ap, nullptr, &q);
|
||||||
YAPCatchError();
|
if (result)
|
||||||
|
ot = Yap_GetFromHandle(h);
|
||||||
|
else
|
||||||
|
ot = TermNone;
|
||||||
|
YAPCatchError();
|
||||||
{
|
{
|
||||||
YAP_LeaveGoal(result, &q);
|
YAP_LeaveGoal(result, &q);
|
||||||
// PyEval_RestoreThread(_save);
|
// PyEval_RestoreThread(_save);
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
return result;
|
return ot;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,7 +367,6 @@ public:
|
|||||||
//> output.
|
//> output.
|
||||||
YAPTerm funCall(YAPTerm t) { return YAPTerm(fun(t.term())); };
|
YAPTerm funCall(YAPTerm t) { return YAPTerm(fun(t.term())); };
|
||||||
Term fun(Term t);
|
Term fun(Term t);
|
||||||
Term fun(YAPTerm t) { return fun(t.term()); };
|
|
||||||
//> set a StringFlag, usually a path
|
//> set a StringFlag, usually a path
|
||||||
//>
|
//>
|
||||||
bool setStringFlag(std::string arg, std::string path) {
|
bool setStringFlag(std::string arg, std::string path) {
|
||||||
|
@ -387,7 +387,7 @@ PyObject *term_to_python(term_t t, bool eval, PyObject *o, bool cvt) {
|
|||||||
if (entry_to_dictionary(dict, yt, eval, cvt))
|
if (entry_to_dictionary(dict, yt, eval, cvt))
|
||||||
return dict;
|
return dict;
|
||||||
else
|
else
|
||||||
return NULL;
|
return Py_None;
|
||||||
}
|
}
|
||||||
atom_t name;
|
atom_t name;
|
||||||
int arity;
|
int arity;
|
||||||
@ -424,8 +424,8 @@ PyObject *term_to_python(term_t t, bool eval, PyObject *o, bool cvt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PyObject *yap_to_python(YAP_Term t, bool eval, PyObject *o, bool cvt) {
|
PyObject *yap_to_python(YAP_Term t, bool eval, PyObject *o, bool cvt) {
|
||||||
if (t == 0)
|
if (t == 0 || t == TermNone)
|
||||||
return NULL;
|
return Py_None;
|
||||||
term_t yt = YAP_InitSlot(t);
|
term_t yt = YAP_InitSlot(t);
|
||||||
o = term_to_python(yt, eval, o, cvt);
|
o = term_to_python(yt, eval, o, cvt);
|
||||||
PL_reset_term_refs(yt);
|
PL_reset_term_refs(yt);
|
||||||
|
@ -55,8 +55,9 @@ static Term python_to_term__(PyObject *pVal) {
|
|||||||
if (pVal == Py_None) {
|
if (pVal == Py_None) {
|
||||||
// fputs("<<*** ",stderr);Yap_DebugPlWrite(YAP_GetFromSlot(t)); fputs("
|
// fputs("<<*** ",stderr);Yap_DebugPlWrite(YAP_GetFromSlot(t)); fputs("
|
||||||
// >>***\n",stderr);
|
// >>***\n",stderr);
|
||||||
return YAP_MkVarTerm();
|
//return YAP_MkVarTerm();
|
||||||
// fputs("<<*** ",stderr);Yap_DebugPlWrite(YAP_GetFromSlot(t)); fputs("
|
// fputs("<<*** ",stderr);Yap_DebugPlWrite(YAP_GetFromSlot(t)); fputs("
|
||||||
|
return MkAtomTerm(Yap_LookupAtom("none"));
|
||||||
// >>***\n",stderr);
|
// >>***\n",stderr);
|
||||||
} else if (PyBool_Check(pVal)) {
|
} else if (PyBool_Check(pVal)) {
|
||||||
if(PyObject_IsTrue(pVal)) return TermTrue;
|
if(PyObject_IsTrue(pVal)) return TermTrue;
|
||||||
|
@ -238,15 +238,16 @@ static foreign_t python_string_to(term_t f) {
|
|||||||
if (!PL_get_chars(f, &s, CVT_ALL | CVT_EXCEPTION | REP_UTF8)) {
|
if (!PL_get_chars(f, &s, CVT_ALL | CVT_EXCEPTION | REP_UTF8)) {
|
||||||
pyErrorAndReturn(false);
|
pyErrorAndReturn(false);
|
||||||
}
|
}
|
||||||
if (!strcmp(s,"atom"))
|
if (!strcmp(s,"atom")) {
|
||||||
pyStringToString = false;
|
pyStringToString = false;
|
||||||
if (!strcmp(s,"string"))
|
return true;
|
||||||
|
}
|
||||||
|
if (!strcmp(s,"string")) {
|
||||||
pyStringToString = true;
|
pyStringToString = true;
|
||||||
else
|
return true;
|
||||||
return false;
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static foreign_t python_builtin_eval(term_t caller, term_t dict, term_t out) {
|
static foreign_t python_builtin_eval(term_t caller, term_t dict, term_t out) {
|
||||||
|
Reference in New Issue
Block a user