trust your head

This commit is contained in:
Vítor Santos Costa 2018-09-18 19:43:50 +01:00
parent a6e578090c
commit b6235d8ecd
5 changed files with 45 additions and 46 deletions

View File

@ -1801,20 +1801,47 @@ X_API bool YAP_RetryGoal(YAP_dogoalinfo *dgi) {
return out;
}
static void completeInnerCall( bool on_cut, yamop *old_CP, yamop *old_P)
{
if (on_cut) {
P = old_P;
ENV = (CELL *)ENV[E_E];
CP = old_CP;
LOCAL_AllowRestart = TRUE;
// we are back to user code again, need slots */
} else {
P = old_P;
ENV = B->cp_env;
ENV = (CELL *)ENV[E_E];
CP = old_CP;
HR = B->cp_h;
TR = B->cp_tr;
B = B->cp_b;
LOCAL_AllowRestart = FALSE;
SET_ASP(ENV, E_CB * sizeof(CELL));
// make sure the slots are ok.
}
}
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", successful,HR-H0,LCL0-ENV,LCL0-(CELL*)B,dgi->b0,(CELL*)TR-LCL0, P, CP, LOCAL_CurSlot);
BACKUP_MACHINE_REGS();
myB = (choiceptr)(LCL0 - dgi->b0);
myB = (choiceptr)(LCL0 - dgi->b);
if (LOCAL_PrologMode & AsyncIntMode) {
Yap_signal(YAP_FAIL_SIGNAL);
}
handler = B;
while (handler
while (handler
//&& LOCAL_CBorder > LCL0 - (CELL *)handler
//&& handler->cp_ap != NOCODE
&& handler->cp_b != NULL
&& handler <= myB
) {
if (handler < myB)
handler->cp_ap = TRUSTFAILCODE;
B = handler;
handler = handler->cp_b;
@ -1851,7 +1878,6 @@ X_API bool YAP_LeaveGoal(bool successful, YAP_dogoalinfo *dgi) {
X_API Int YAP_RunGoal(Term t) {
CACHE_REGS
Term out;
yamop *old_CP = CP;
yhandle_t cslot = LOCAL_CurSlot;
BACKUP_MACHINE_REGS();
@ -1861,25 +1887,7 @@ X_API Int YAP_RunGoal(Term t) {
LOCAL_PrologMode = UserCCallMode;
// should we catch the exception or pass it through?
// We'll pass it through
Yap_RaiseException();
if (out) {
P = (yamop *)ENV[E_CP];
ENV = (CELL *)ENV[E_E];
CP = old_CP;
LOCAL_AllowRestart = TRUE;
// we are back to user code again, need slots */
} else {
ENV = B->cp_env;
ENV = (CELL *)ENV[E_E];
CP = old_CP;
HR = B->cp_h;
TR = B->cp_tr;
B = B->cp_b;
LOCAL_AllowRestart = FALSE;
SET_ASP(ENV, E_CB * sizeof(CELL));
// make sure the slots are ok.
}
RECOVER_MACHINE_REGS();
RECOVER_MACHINE_REGS();
LOCAL_CurSlot = cslot;
return out;
}

View File

@ -367,6 +367,7 @@ 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

@ -8,7 +8,6 @@ PyObject *py_Main;
void pyErrorHandler__(int line, const char *file, const char *code) {
// this code is called if a Python error is found.
// int lvl = push_text_stack();
PyObject *type;
// PyErr_Fetch(&type, &val, NULL);
// PyErr_Print();
// Yap_ThrowError__(file,code,line,0, SYSTEM_ERROR_RUNTIME_PYTHON ,"Python
@ -235,7 +234,7 @@ static foreign_t assign_python(term_t exp, term_t name) {
static foreign_t python_string_to(term_t f) {
if (PL_is_atom(f)) {
char *s = NULL;
if (!PL_get_chars(f, &s, CVT_ALL | CVT_EXCEPTION | REP_UTF8)) {
if (!PL_get_chars(f, &s, CVT_ATOM |CVT_STRING | CVT_EXCEPTION | REP_UTF8)) {
pyErrorAndReturn(false);
}
if (!strcmp(s,"atom")) {
@ -571,27 +570,6 @@ static foreign_t python_export(term_t t, term_t pl) {
pyErrorAndReturn(rc);
}
static bool get_mod(const char *s0)
{
PyObject *pName;
term_t t0 = python_acquire_GIL();
#if PY_MAJOR_VERSION < 3
pName = PyString_FromString(s0);
#else
pName = PyUnicode_FromString(s0);
#endif
if (pName == NULL) {
python_release_GIL(t0);
}
PyObject *pModule = PyImport_Import(pName);
Py_XDECREF(pName);
python_release_GIL(t0);
return pModule;
}
/**
* @pred python_import(MName, Mod)
* Import a python module to the YAP environment.

View File

@ -479,6 +479,7 @@ If this hook preodicate succeeds it must instantiate the _Action_ argument to t
:- yap_flag(user:unknown,error).
%:- ensure_loaded('../android.yap').
%% @}

View File

@ -91,6 +91,18 @@ lists:delete([Head|List], Elem, Residue) :-
lists:delete([Head|List], Elem, [Head|Residue]) :-
lists:delete(List, Elem, Residue).
% reverse(List, Reversed)
% is true when List and Reversed are lists with the same elements
% but in opposite orders. rev/2 is a synonym for reverse/2.
lists:reverse(List, Reversed) :-
lists:reverse(List, [], Reversed).
lists:reverse([], Reversed, Reversed).
lists:reverse([Head|Tail], Sofar, Reversed) :-
lists:reverse(Tail, [Head|Sofar], Reversed).
:- set_prolog_flag(source, false). % disable source.
@ -135,4 +147,3 @@ prolog:length(L, M) :-
M is N + 1, NL = [_|L], '$$_length2'(L, O, M) ).
%% @}