C-interface

This commit is contained in:
Vítor Santos Costa 2018-09-18 19:27:10 +01:00
parent 7661b8581c
commit a6e578090c
6 changed files with 36 additions and 22 deletions

View File

@ -1813,21 +1813,23 @@ X_API bool YAP_LeaveGoal(bool successful, YAP_dogoalinfo *dgi) {
//&& LOCAL_CBorder > LCL0 - (CELL *)handler
//&& handler->cp_ap != NOCODE
&& handler->cp_b != NULL
&& handler != myB
&& handler <= myB
) {
handler->cp_ap = TRUSTFAILCODE;
handler = handler->cp_b;
}
if (LOCAL_PrologMode & AsyncIntMode) {
Yap_signal(YAP_FAIL_SIGNAL);
}
B = handler;
handler = handler->cp_b;
if (successful) {
Yap_TrimTrail();
CP = dgi->cp;
P = dgi->p;
} else {
P=FAILCODE;
Yap_exec_absmi(true, YAP_EXEC_ABSMI);
}
}
if (successful) {
CP = dgi->cp;
P = dgi->p;
} else {
LOCAL_CurSlot = dgi->CurSlot;
ENV = YENV = B->cp_env;
HR = B->cp_h;
@ -1835,6 +1837,11 @@ X_API bool YAP_LeaveGoal(bool successful, YAP_dogoalinfo *dgi) {
// use the current choicepoint
// B=B->cp_b;
ASP=(CELL*)B;
}
if (B)
B = B->cp_b;
if (LOCAL_PrologMode & AsyncIntMode) {
Yap_signal(YAP_FAIL_SIGNAL);
}
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);

View File

@ -667,8 +667,10 @@ Term YAPEngine::fun(Term t) {
throw YAPError(SOURCE(), TYPE_ERROR_CALLABLE, t, 0);
return 0L;
}
XREGS[arity + 1] = MkVarTerm();
Term ot = XREGS[arity + 1] = MkVarTerm();
yhandle_t h = Yap_InitHandle(ot);
arity++;
HR += arity;
f = Yap_MkFunctor(name, arity);
ap = (PredEntry *)(PredPropByFunc(f, tmod));
if (ap == nullptr || ap->OpcodeOfPred == UNDEF_OPCODE) {
@ -683,12 +685,16 @@ Term YAPEngine::fun(Term t) {
//__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec ");
bool result = (bool)YAP_EnterGoal(ap, nullptr, &q);
YAPCatchError();
if (result)
ot = Yap_GetFromHandle(h);
else
ot = TermNone;
YAPCatchError();
{
YAP_LeaveGoal(result, &q);
// PyEval_RestoreThread(_save);
RECOVER_MACHINE_REGS();
return result;
return ot;
}
}

View File

@ -367,7 +367,6 @@ public:
//> output.
YAPTerm funCall(YAPTerm t) { return YAPTerm(fun(t.term())); };
Term fun(Term t);
Term fun(YAPTerm t) { return fun(t.term()); };
//> set a StringFlag, usually a path
//>
bool setStringFlag(std::string arg, std::string path) {

View File

@ -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))
return dict;
else
return NULL;
return Py_None;
}
atom_t name;
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) {
if (t == 0)
return NULL;
if (t == 0 || t == TermNone)
return Py_None;
term_t yt = YAP_InitSlot(t);
o = term_to_python(yt, eval, o, cvt);
PL_reset_term_refs(yt);

View File

@ -55,8 +55,9 @@ static Term python_to_term__(PyObject *pVal) {
if (pVal == Py_None) {
// fputs("<<*** ",stderr);Yap_DebugPlWrite(YAP_GetFromSlot(t)); fputs("
// >>***\n",stderr);
return YAP_MkVarTerm();
//return YAP_MkVarTerm();
// fputs("<<*** ",stderr);Yap_DebugPlWrite(YAP_GetFromSlot(t)); fputs("
return MkAtomTerm(Yap_LookupAtom("none"));
// >>***\n",stderr);
} else if (PyBool_Check(pVal)) {
if(PyObject_IsTrue(pVal)) return TermTrue;

View File

@ -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)) {
pyErrorAndReturn(false);
}
if (!strcmp(s,"atom"))
if (!strcmp(s,"atom")) {
pyStringToString = false;
if (!strcmp(s,"string"))
return true;
}
if (!strcmp(s,"string")) {
pyStringToString = true;
else
return false;
return true;
return true;
}
}
return true;
return false;
}
static foreign_t python_builtin_eval(term_t caller, term_t dict, term_t out) {