jupyter
This commit is contained in:
parent
5d7c6378e7
commit
2d65d0463c
@ -2539,7 +2539,7 @@ static Int
|
||||
// if (!pe) pe = Yap_get_pred(t1, Deref(ARG2), "system_predicate");
|
||||
if (EndOfPAEntr(pe))
|
||||
return FALSE;
|
||||
return (pe->ModuleOfPred == 0);
|
||||
return (pe->ModuleOfPred == 0 || pe-> PredFlags & UserCPredFlag);
|
||||
// return true;
|
||||
// PELOCK(27, pe);
|
||||
// out = (pe->PredFlags & SystemPredFlags);
|
||||
|
26
C/errors.c
26
C/errors.c
@ -107,6 +107,9 @@ if (strcmp(ks, q) == 0 ) \
|
||||
if (i->k == NULL) return TermNil; \
|
||||
Term t; if((t = Yap_BufferToTerm(i->k, TermNil) ) == 0 ) return TermNil; return t; }
|
||||
|
||||
static yap_error_descriptor_t *CopyException(yap_error_descriptor_t *t);
|
||||
|
||||
|
||||
static Term queryErr(const char *q, yap_error_descriptor_t *i) {
|
||||
query_key_i(errorNo, "errorNo", q, i);
|
||||
query_key_i(errorClass, "errorClass", q, i);
|
||||
@ -332,15 +335,17 @@ bool Yap_PrintWarning(Term twarning) {
|
||||
CACHE_REGS
|
||||
PredEntry *pred = RepPredProp(PredPropByFunc(
|
||||
FunctorPrintMessage, PROLOG_MODULE)); // PROCEDURE_print_message2;
|
||||
if (twarning)
|
||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid ", " warning(%s)",
|
||||
Yap_TermToBuffer(twarning, Quote_illegal_f | Ignore_ops_f | Ignore_cyclics_f));
|
||||
Term cmod = (CurrentModule == PROLOG_MODULE ? TermProlog : CurrentModule);
|
||||
bool rc;
|
||||
Term ts[2], err;
|
||||
|
||||
if (LOCAL_PrologMode & InErrorMode && LOCAL_ActiveError &&
|
||||
|
||||
if (twarning && LOCAL_PrologMode & InErrorMode &&
|
||||
LOCAL_ActiveError->errorClass != WARNING &&
|
||||
(err = LOCAL_ActiveError->errorNo)) {
|
||||
(err = LOCAL_ActiveError->errorNo) ) {
|
||||
fprintf(stderr, "%% Warning %s while processing error: %s %s\n",
|
||||
Yap_TermToBuffer(twarning,
|
||||
Quote_illegal_f | Ignore_ops_f),
|
||||
@ -352,12 +357,16 @@ bool Yap_PrintWarning(Term twarning) {
|
||||
fprintf(stderr, "%s:%ld/* d:%d warning */:\n",
|
||||
LOCAL_ActiveError->errorFile,
|
||||
LOCAL_ActiveError->errorLine, 0 );
|
||||
if (!twarning)
|
||||
twarning = Yap_MkFullError();
|
||||
Yap_DebugPlWriteln(twarning);
|
||||
LOCAL_DoingUndefp = false;
|
||||
LOCAL_PrologMode &= ~InErrorMode;
|
||||
CurrentModule = cmod;
|
||||
return false;
|
||||
}
|
||||
if (!twarning)
|
||||
twarning = Yap_MkFullError();
|
||||
ts[1] = twarning;
|
||||
ts[0] = MkAtomTerm(AtomWarning);
|
||||
rc = Yap_execute_pred(pred, ts, true PASS_REGS);
|
||||
@ -656,7 +665,7 @@ void Yap_ThrowExistingError(void) {
|
||||
|
||||
Term Yap_MkFullError(void)
|
||||
{
|
||||
yap_error_descriptor_t *i = Yap_local.ActiveError;
|
||||
yap_error_descriptor_t *i = CopyException(Yap_local.ActiveError);
|
||||
i->errorAsText = Yap_errorName( i->errorNo );
|
||||
i->errorClass = Yap_errorClass( i-> errorNo );
|
||||
i->classAsText = Yap_errorClassName(i->errorClass);
|
||||
@ -880,7 +889,8 @@ yamop *Yap_Error__(bool throw, const char *file, const char *function,
|
||||
if (LOCAL_DoingUndefp) {
|
||||
LOCAL_DoingUndefp = false;
|
||||
LOCAL_Signals = 0;
|
||||
Yap_PrintWarning(MkErrorTerm(Yap_GetException(LOCAL_ActiveError)));
|
||||
yap_error_descriptor_t *co = CopyException( LOCAL_ActiveError );
|
||||
Yap_PrintWarning(MkErrorTerm(Yap_GetException( co )));
|
||||
return P;
|
||||
}
|
||||
// LOCAL_ActiveError = Yap_GetException();
|
||||
@ -1012,6 +1022,7 @@ bool Yap_ResetException(yap_error_descriptor_t *i) {
|
||||
|
||||
static Int reset_exception(USES_REGS1) { return Yap_ResetException(worker_id); }
|
||||
|
||||
|
||||
Term MkErrorTerm(yap_error_descriptor_t *t) {
|
||||
if (t->errorClass == EVENT)
|
||||
return t->errorRawTerm;
|
||||
@ -1023,6 +1034,13 @@ Term MkErrorTerm(yap_error_descriptor_t *t) {
|
||||
err2list(t));
|
||||
}
|
||||
|
||||
|
||||
static yap_error_descriptor_t *CopyException(yap_error_descriptor_t *t) {
|
||||
yap_error_descriptor_t *n = malloc( sizeof( yap_error_descriptor_t ));
|
||||
memcpy(n, t, sizeof( yap_error_descriptor_t ) );
|
||||
return n;
|
||||
}
|
||||
|
||||
static Int read_exception(USES_REGS1) {
|
||||
yap_error_descriptor_t *t = AddressOfTerm(Deref(ARG1));
|
||||
Term rc = MkErrorTerm(t);
|
||||
|
24
C/exec.c
24
C/exec.c
@ -1065,8 +1065,8 @@ static Int _user_expand_goal(USES_REGS1) {
|
||||
ARG1 = g;
|
||||
if ((pe = RepPredProp(Yap_GetPredPropByFunc(FunctorGoalExpansion2, cmod))) &&
|
||||
pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE &&
|
||||
Yap_execute_pred(pe, NULL, true PASS_REGS)) {
|
||||
return complete_ge(true, omod, sl, creeping);
|
||||
Yap_execute_pred(pe, NULL, false PASS_REGS)) {
|
||||
return complete_ge(true , omod, sl, creeping);
|
||||
}
|
||||
/* system:goal_expansion(A,B) */
|
||||
mg_args[0] = cmod;
|
||||
@ -1076,7 +1076,7 @@ static Int _user_expand_goal(USES_REGS1) {
|
||||
if ((pe = RepPredProp(
|
||||
Yap_GetPredPropByFunc(FunctorGoalExpansion2, SYSTEM_MODULE))) &&
|
||||
pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE &&
|
||||
Yap_execute_pred(pe, NULL, true PASS_REGS)) {
|
||||
Yap_execute_pred(pe, NULL, false PASS_REGS)) {
|
||||
return complete_ge(true, omod, sl, creeping);
|
||||
}
|
||||
Yap_ResetException(NULL);
|
||||
@ -1087,7 +1087,7 @@ static Int _user_expand_goal(USES_REGS1) {
|
||||
if ((pe = RepPredProp(
|
||||
Yap_GetPredPropByFunc(FunctorGoalExpansion, USER_MODULE))) &&
|
||||
pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE &&
|
||||
Yap_execute_pred(pe, NULL, true PASS_REGS)) {
|
||||
Yap_execute_pred(pe, NULL, false PASS_REGS)) {
|
||||
return complete_ge(true, omod, sl, creeping);
|
||||
}
|
||||
Yap_ResetException(NULL);
|
||||
@ -1101,7 +1101,7 @@ static Int _user_expand_goal(USES_REGS1) {
|
||||
(pe = RepPredProp(
|
||||
Yap_GetPredPropByFunc(FunctorGoalExpansion2, USER_MODULE))) &&
|
||||
pe->OpcodeOfPred != FAIL_OPCODE && pe->OpcodeOfPred != UNDEF_OPCODE &&
|
||||
Yap_execute_pred(pe, NULL, true PASS_REGS)) {
|
||||
Yap_execute_pred(pe, NULL, false PASS_REGS)) {
|
||||
return complete_ge(true, omod, sl, creeping);
|
||||
}
|
||||
Yap_ResetException(NULL);
|
||||
@ -1164,6 +1164,12 @@ restart_exec:
|
||||
} else if (IsAtomTerm(t)) {
|
||||
Atom a = AtomOfTerm(t);
|
||||
pe = PredPropByAtom(a, mod);
|
||||
} else if (IsPairTerm(t)) {
|
||||
Term ts[2];
|
||||
ts[0] = t;
|
||||
ts[1] = (CurrentModule == 0 ? TermProlog : CurrentModule);
|
||||
t = Yap_MkApplTerm(FunctorCsult, 2, ts);
|
||||
goto restart_exec;
|
||||
} else if (IsApplTerm(t)) {
|
||||
register Functor f = FunctorOfTerm(t);
|
||||
register unsigned int i;
|
||||
@ -1207,8 +1213,9 @@ restart_exec:
|
||||
#endif
|
||||
}
|
||||
} else {
|
||||
Yap_Error(TYPE_ERROR_CALLABLE, t, "call/1");
|
||||
return false;
|
||||
//Yap_Error(TYPE_ERROR_CALLABLE, t, "call/1");
|
||||
//return false;
|
||||
return CallMetaCall(t, mod);
|
||||
}
|
||||
/* N = arity; */
|
||||
/* call may not define new system predicates!! */
|
||||
@ -1264,8 +1271,7 @@ static Int creep_step(USES_REGS1) { /* '$execute_nonstop'(Goal,Mod)
|
||||
#endif
|
||||
}
|
||||
} else {
|
||||
Yap_Error(TYPE_ERROR_CALLABLE, t, "call/1");
|
||||
return FALSE;
|
||||
return CallMetaCall(t, mod);
|
||||
}
|
||||
/* N = arity; */
|
||||
/* call may not define new system predicates!! */
|
||||
|
17
C/terms.c
17
C/terms.c
@ -89,10 +89,10 @@ typedef struct non_single_struct_t {
|
||||
CELL *pt0, *pt0_end; \
|
||||
size_t auxsz = 1024 * sizeof(struct non_single_struct_t);\
|
||||
struct non_single_struct_t *to_visit0=NULL, *to_visit,* to_visit_max;\
|
||||
to_visit0 = Realloc(to_visit0,auxsz); \
|
||||
CELL *InitialH = HR;\
|
||||
tr_fr_ptr TR0 = TR;\
|
||||
reset:\
|
||||
to_visit0 = Realloc(to_visit0,auxsz); \
|
||||
pt0 = pt0_; pt0_end = pt0_end_; \
|
||||
to_visit = to_visit0, \
|
||||
to_visit_max = to_visit + auxsz/sizeof(struct non_single_struct_t);\
|
||||
@ -306,8 +306,10 @@ static int cycles_in_complex_term( CELL *pt0_, CELL *pt0_end_ USES_REGS) {
|
||||
|
||||
reset:
|
||||
pt0 = pt0_, pt0_end = pt0_end_;
|
||||
to_visit= to_visit0,
|
||||
to_visit_max = to_visit0 + auxsz/sizeof(struct non_single_struct_t);
|
||||
to_visit0 = Realloc(to_visit0,auxsz);
|
||||
to_visit= to_visit0;
|
||||
to_visit_max = to_visit0 + auxsz/sizeof(struct non_single_struct_t);
|
||||
auxsz *= 2;
|
||||
int rc = 0;
|
||||
CELL *ptf;
|
||||
ptf = HR;
|
||||
@ -811,8 +813,8 @@ static Term new_vars_in_complex_term(
|
||||
CELL output = TermNil;
|
||||
{
|
||||
tr_fr_ptr myTR0 = TR;
|
||||
while (!IsVarTerm(inp) && IsPairTerm(inp)) {
|
||||
int lvl = push_text_stack();
|
||||
while (!IsVarTerm(inp) && IsPairTerm(inp)) {
|
||||
Term t = HeadOfTerm(inp);
|
||||
if (IsVarTerm(t)) {
|
||||
n++;
|
||||
@ -827,6 +829,7 @@ static Term new_vars_in_complex_term(
|
||||
}
|
||||
inp = TailOfTerm(inp);
|
||||
}
|
||||
pop_text_stack(lvl);
|
||||
}
|
||||
WALK_COMPLEX_TERM();
|
||||
output = MkPairTerm((CELL)ptd0, output);
|
||||
@ -958,14 +961,14 @@ static Int free_variables_in_term(
|
||||
Term out;
|
||||
Term t, t0;
|
||||
Term found_module = 0L;
|
||||
Term vlist = TermNil;
|
||||
Term bounds = TermNil;
|
||||
|
||||
t = t0 = Deref(ARG1);
|
||||
Int delta = 0;
|
||||
while (!IsVarTerm(t) && IsApplTerm(t)) {
|
||||
Functor f = FunctorOfTerm(t);
|
||||
if (f == FunctorHat) {
|
||||
vlist = Yap_TermAddVariables(ArgOfTerm(1,t), vlist PASS_REGS);
|
||||
bounds = MkPairTerm(ArgOfTerm(1,t),bounds);
|
||||
} else if (f == FunctorModule) {
|
||||
found_module = ArgOfTerm(1, t);
|
||||
} else if (f == FunctorCall) {
|
||||
@ -981,7 +984,7 @@ static Int free_variables_in_term(
|
||||
if (IsPrimitiveTerm(t))
|
||||
out = TermNil;
|
||||
else {
|
||||
out = new_vars_in_complex_term(&(t)-1, &(t), vlist PASS_REGS);
|
||||
out = new_vars_in_complex_term(&(t)-1, &(t), Yap_TermVariables(bounds, 3) PASS_REGS);
|
||||
}
|
||||
|
||||
if (found_module && t != t0) {
|
||||
|
210
C/utilpreds.c
210
C/utilpreds.c
@ -152,19 +152,20 @@ clean_complex_tr(tr_fr_ptr TR0 USES_REGS) {
|
||||
|
||||
#define expand_stack(S0,SP,SF,TYPE) \
|
||||
{ size_t sz = SF-S0, used = SP-S0; \
|
||||
S0 = Realxbloc(S0, (1024+sz)*sizeof(TYPE) PASS_REGS); \
|
||||
S0 = Realloc(S0, (1024+sz)*sizeof(TYPE) PASS_REGS); \
|
||||
SP = S0+used; SF = S0+sz; }
|
||||
|
||||
#define MIN_ARENA_SIZE (1048L)
|
||||
|
||||
|
||||
int Yap_copy_complex_term(register CELL *pt0, register CELL *pt0_end,
|
||||
bool share, Term *split, bool copy_att_vars, CELL *ptf,
|
||||
bool share, bool copy_att_vars, CELL *ptf,
|
||||
CELL *HLow USES_REGS) {
|
||||
// fprintf(stderr,"+++++++++\n");
|
||||
//CELL *x = pt0; while(x != pt0_end) Yap_DebugPlWriteln(*++ x);
|
||||
|
||||
int lvl = push_text_stack();
|
||||
Term o = TermNil;
|
||||
|
||||
struct cp_frame *to_visit0,
|
||||
*to_visit = Malloc(1024*sizeof(struct cp_frame));
|
||||
struct cp_frame *to_visit_max;
|
||||
@ -188,42 +189,25 @@ int Yap_copy_complex_term(register CELL *pt0, register CELL *pt0_end,
|
||||
copy_term_nvar : {
|
||||
if (IsPairTerm(d0)) {
|
||||
CELL *headp = RepPair(d0);
|
||||
Term head = *headp;
|
||||
if (IsPairTerm(head) && RepPair(head) >= HB && RepPair(head) < HR) {
|
||||
if (split) {
|
||||
Term v = Yap_MkNewApplTerm(FunctorEq, 2);
|
||||
RepAppl(v)[1] = AbsPair(ptf);
|
||||
*headp = *ptf++ = RepAppl(v)[0];
|
||||
o = MkPairTerm( v, o );
|
||||
} else {
|
||||
*ptf++ = RepPair(head)[0];;
|
||||
}
|
||||
continue;
|
||||
} else if (IsApplTerm(head) && RepAppl(head) >= HB && RepAppl(head) < HR) {
|
||||
*ptf++ = RepAppl(head)[0];
|
||||
if (//(share && headp < HB) ||
|
||||
(IsPairTerm(*headp) && RepPair(*headp) >= HB && RepPair(*headp) < HR)) {
|
||||
/* If this is newer than the current term, just reuse */
|
||||
*ptf++ = *headp;
|
||||
continue;
|
||||
}
|
||||
*ptf++ = AbsPair(HR);
|
||||
if (to_visit >= to_visit_max-32) {
|
||||
expand_stack(to_visit0, to_visit, to_visit_max, struct cp_frame);
|
||||
}
|
||||
*ptf = AbsPair(HR);
|
||||
ptf++;
|
||||
to_visit->start_cp = pt0;
|
||||
to_visit->end_cp = pt0_end;
|
||||
to_visit->to = ptf;
|
||||
to_visit->curp = headp;
|
||||
d0 = to_visit->oldv = head;
|
||||
to_visit->ground = ground;
|
||||
to_visit++;
|
||||
// move to new list
|
||||
if (share) {
|
||||
TrailedMaBind(headp,AbsPair(HR));
|
||||
} else {
|
||||
/* If this is newer than the current term, just reuse */
|
||||
*headp = AbsPair(HR);
|
||||
}
|
||||
if (split) {
|
||||
TrailedMaBind(ptf,AbsPair(HR));
|
||||
}
|
||||
d0 = *headp;
|
||||
TrailedMaBind(headp, AbsPair(HR));
|
||||
pt0 = headp;
|
||||
pt0_end = headp + 1;
|
||||
ptf = HR;
|
||||
@ -232,47 +216,21 @@ int Yap_copy_complex_term(register CELL *pt0, register CELL *pt0_end,
|
||||
if (HR > ASP - MIN_ARENA_SIZE) {
|
||||
goto overflow;
|
||||
}
|
||||
d0 = head;
|
||||
ptd0 = pt0;
|
||||
goto deref;
|
||||
} else if (IsApplTerm(d0)) {
|
||||
Functor f;
|
||||
CELL *headp, head;
|
||||
register Functor f;
|
||||
register CELL *headp;
|
||||
/* store the terms to visit */
|
||||
headp = RepAppl(d0);
|
||||
head = *headp;
|
||||
|
||||
if (IsPairTerm(head)) {
|
||||
if (split) {
|
||||
Term v = Yap_MkNewApplTerm(FunctorEq, 2);
|
||||
RepAppl(v)[1] = AbsPair(ptf);
|
||||
*headp = *ptf++ = RepAppl(v)[0];
|
||||
o = MkPairTerm( v, o );
|
||||
} else {
|
||||
*ptf++ = RepPair(head)[0];;
|
||||
}
|
||||
continue;
|
||||
} else if (IsApplTerm(head)) {
|
||||
*ptf++ = RepAppl(head)[0];
|
||||
if (IsApplTerm(*headp)//(share && headp < HB) ||
|
||||
) {
|
||||
/* If this is newer than the current term, just reuse */
|
||||
*ptf++ = *headp;
|
||||
continue;
|
||||
}
|
||||
f = (Functor)(head);
|
||||
if (share && (ground || IsExtensionFunctor(f))) {
|
||||
*ptf++ = d0;
|
||||
continue;
|
||||
}
|
||||
/* store the terms to visit */
|
||||
*ptf = AbsAppl(HR);
|
||||
ptf++;
|
||||
to_visit->start_cp = pt0;
|
||||
to_visit->end_cp = pt0_end;
|
||||
to_visit->to = ptf;
|
||||
to_visit->curp = headp;
|
||||
to_visit->oldv = head;
|
||||
to_visit->ground = ground;
|
||||
if (++to_visit >= to_visit_max-32) {
|
||||
expand_stack(to_visit0, to_visit, to_visit_max, struct cp_frame);
|
||||
}
|
||||
|
||||
f = (Functor)(*headp);
|
||||
|
||||
if (IsExtensionFunctor(f)) {
|
||||
switch ((CELL)f) {
|
||||
case (CELL) FunctorDBRef:
|
||||
@ -321,42 +279,44 @@ int Yap_copy_complex_term(register CELL *pt0, register CELL *pt0_end,
|
||||
/* big int */
|
||||
size_t sz = (sizeof(MP_INT) + 3 * CellSize +
|
||||
((MP_INT *)(headp + 2))->_mp_alloc * sizeof(mp_limb_t)) /
|
||||
CellSize;
|
||||
CellSize,
|
||||
i;
|
||||
|
||||
if (HR > ASP - (MIN_ARENA_SIZE + sz)) {
|
||||
goto overflow;
|
||||
}
|
||||
*ptf++ = AbsAppl(HR);
|
||||
memmove(HR, headp, sz*sizeof(CELL));
|
||||
MP_INT *new = (MP_INT *)(HR + 2);
|
||||
new->_mp_d = (mp_limb_t *)(new + 1);
|
||||
|
||||
HR[0] = (CELL)f;
|
||||
for (i = 1; i < sz; i++) {
|
||||
HR[i] = headp[i];
|
||||
|
||||
}
|
||||
HR += sz;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
*ptf = AbsAppl(HR);
|
||||
ptf++;
|
||||
/* store the terms to visit */
|
||||
to_visit->start_cp = pt0;
|
||||
to_visit->end_cp = pt0_end;
|
||||
to_visit->to = ptf;
|
||||
to_visit->ground = ground;
|
||||
if (++to_visit >= to_visit_max-32) {
|
||||
expand_stack(to_visit0, to_visit, to_visit_max, struct cp_frame);
|
||||
}
|
||||
if (share) {
|
||||
TrailedMaBind(headp,AbsPair(HR));
|
||||
} else {
|
||||
*headp = AbsPair(HR);
|
||||
}
|
||||
if (split) {
|
||||
// must be after trailing source term, so that we can check the source
|
||||
// term and confirm it is still ok.
|
||||
TrailedMaBind(ptf,AbsAppl(HR));
|
||||
}
|
||||
TrailedMaBind(headp,AbsAppl(HR));
|
||||
ptf = HR;
|
||||
ptf[0] = (CELL)f;
|
||||
*ptf++ = (CELL)f;
|
||||
ground = true;
|
||||
arity_t a = ArityOfFunctor(f);
|
||||
if (HR > ASP - MIN_ARENA_SIZE) {
|
||||
HR = ptf+a;
|
||||
if (HR > ASP - MIN_ARENA_SIZE) {
|
||||
goto overflow;
|
||||
}
|
||||
ptf++;
|
||||
HR = ptf+a;
|
||||
pt0_end = headp+(a);
|
||||
pt0 = headp;
|
||||
pt0 = headp;
|
||||
pt0_end = headp+a;
|
||||
ground = (f != FunctorMutable);
|
||||
} else {
|
||||
/* just copy atoms or integers */
|
||||
@ -369,43 +329,44 @@ int Yap_copy_complex_term(register CELL *pt0, register CELL *pt0_end,
|
||||
ground = false;
|
||||
/* don't need to copy variables if we want to share the global term */
|
||||
if (//(share && ptd0 < HB && ptd0 > H0) ||
|
||||
(ptd0 >= HB && ptd0 < HR)) {
|
||||
(ptd0 >= HLow && ptd0 < HR)) {
|
||||
/* we have already found this cell */
|
||||
*ptf++ = (CELL)ptd0;
|
||||
} else
|
||||
if (copy_att_vars && GlobalIsAttachedTerm((CELL)ptd0)) {
|
||||
/* if unbound, call the standard copy term routine */
|
||||
struct cp_frame *bp;
|
||||
|
||||
bp = to_visit;
|
||||
if (!GLOBAL_attas[ExtFromCell(ptd0)].copy_term_op(ptd0, &bp,
|
||||
ptf PASS_REGS)) {
|
||||
goto overflow;
|
||||
}
|
||||
to_visit = bp;
|
||||
if (TR > (tr_fr_ptr)LOCAL_TrailTop - 256) {
|
||||
/* Trail overflow */
|
||||
if (!Yap_growtrail((TR - TR0) * sizeof(tr_fr_ptr *), TRUE)) {
|
||||
goto trail_overflow;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
/* first time we met this term */
|
||||
RESET_VARIABLE(ptf);
|
||||
*ptd0 = (CELL)ptf;
|
||||
ptf++;
|
||||
TrailTerm(TR++) = (CELL)ptd0;
|
||||
if ((ADDR)TR > LOCAL_TrailTop - 16)
|
||||
goto trail_overflow;
|
||||
if (copy_att_vars && GlobalIsAttachedTerm((CELL)ptd0)) {
|
||||
/* if unbound, call the standard copy term routine */
|
||||
struct cp_frame *bp;
|
||||
CELL new;
|
||||
|
||||
bp = to_visit;
|
||||
if (!GLOBAL_attas[ExtFromCell(ptd0)].copy_term_op(ptd0, &bp,
|
||||
ptf PASS_REGS)) {
|
||||
goto overflow;
|
||||
}
|
||||
to_visit = bp;
|
||||
new = *ptf;
|
||||
if (TR > (tr_fr_ptr)LOCAL_TrailTop - 256) {
|
||||
/* Trail overflow */
|
||||
if (!Yap_growtrail((TR - TR0) * sizeof(tr_fr_ptr *), TRUE)) {
|
||||
goto trail_overflow;
|
||||
}
|
||||
}
|
||||
TrailedMaBind(ptd0, new);
|
||||
ptf++;
|
||||
} else {
|
||||
/* first time we met this term */
|
||||
RESET_VARIABLE(ptf);
|
||||
if ((ADDR)TR > LOCAL_TrailTop - MIN_ARENA_SIZE)
|
||||
goto trail_overflow;
|
||||
TrailedMaBind(ptd0, (CELL)ptf);
|
||||
ptf++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Do we still have compound terms to visit */
|
||||
if (to_visit > to_visit0) {
|
||||
to_visit--;
|
||||
if (!share)
|
||||
*to_visit->curp = to_visit->oldv;
|
||||
pt0 = to_visit->start_cp;
|
||||
pt0_end = to_visit->end_cp;
|
||||
ptf = to_visit->to;
|
||||
@ -414,7 +375,7 @@ int Yap_copy_complex_term(register CELL *pt0, register CELL *pt0_end,
|
||||
}
|
||||
|
||||
/* restore our nice, friendly, term to its original state */
|
||||
clean_complex_tr(TR0 PASS_REGS);
|
||||
clean_dirty_tr(TR0 PASS_REGS);
|
||||
/* follow chain of multi-assigned variables */
|
||||
pop_text_stack(lvl);
|
||||
return 0;
|
||||
@ -491,6 +452,7 @@ handle_cp_overflow(int res, tr_fr_ptr TR0, UInt arity, Term t)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static Term
|
||||
CopyTerm(Term inp, UInt arity, int share, int newattvs USES_REGS) {
|
||||
Term t = Deref(inp);
|
||||
@ -505,7 +467,7 @@ CopyTerm(Term inp, UInt arity, int share, int newattvs USES_REGS) {
|
||||
Hi = HR;
|
||||
HR ++;
|
||||
|
||||
if ((res = Yap_copy_complex_term((&t)-1, &t, share, NULL, newattvs, Hi, HR PASS_REGS)) < 0) {
|
||||
if ((res = Yap_copy_complex_term((&t)-1, &t, share, newattvs, Hi, HR PASS_REGS)) < 0) {
|
||||
HR = Hi;
|
||||
if ((t = handle_cp_overflow(res, TR0, arity, t))== 0L)
|
||||
return FALSE;
|
||||
@ -579,16 +541,6 @@ typedef struct copy_frame {
|
||||
CELL *to;
|
||||
} copy_frame_t;
|
||||
|
||||
static Term
|
||||
add_to_list( Term inp, Term v, Term t PASS_REGS)
|
||||
{
|
||||
Term ta[2];
|
||||
|
||||
ta[0] = v;
|
||||
ta[1] = t;
|
||||
return MkPairTerm(Yap_MkApplTerm( FunctorEq, 2, ta ), inp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
@ -2585,14 +2537,6 @@ p_is_list_or_partial_list( USES_REGS1 )
|
||||
return Yap_IsListOrPartialListTerm(Deref(ARG1));
|
||||
}
|
||||
|
||||
static Term
|
||||
numbervar(Int id USES_REGS)
|
||||
{
|
||||
Term ts[1];
|
||||
ts[0] = MkIntegerTerm(id);
|
||||
return Yap_MkApplTerm(FunctorDollarVar, 1, ts);
|
||||
}
|
||||
|
||||
#if 0
|
||||
static Term
|
||||
numbervar_singleton(USES_REGS1)
|
||||
|
61
CXX/yapq.hh
61
CXX/yapq.hh
@ -158,7 +158,8 @@ public:
|
||||
};
|
||||
};
|
||||
|
||||
// Java support
|
||||
|
||||
|
||||
|
||||
/// This class implements a callback Prolog-side. It will be inherited by the
|
||||
/// Java or Python
|
||||
@ -211,46 +212,56 @@ public:
|
||||
inline bool creatingSavedState() { return install; };
|
||||
|
||||
inline void setPLDIR(const char *fl) {
|
||||
LIBDIR = (const char *)malloc(strlen(fl) + 1);
|
||||
strcpy((char *)LIBDIR, fl);
|
||||
std::string *s = new std::string(fl);
|
||||
LIBDIR = s->c_str();
|
||||
};
|
||||
|
||||
inline const char *getPLDIR() { return PLDIR; };
|
||||
|
||||
inline void setINPUT_STARTUP(const char *fl) {
|
||||
INPUT_STARTUP = (const char *)malloc(strlen(fl) + 1);
|
||||
strcpy((char *)INPUT_STARTUP, fl);
|
||||
std::string *s = new std::string(fl);
|
||||
INPUT_STARTUP = s->c_str();
|
||||
};
|
||||
|
||||
inline const char *getINPUT_STARTUP() { return INPUT_STARTUP; };
|
||||
|
||||
inline void setOUTPUT_STARTUP(const char *fl) {
|
||||
std::string *s = new std::string(fl);
|
||||
OUTPUT_STARTUP = s->c_str();
|
||||
};
|
||||
|
||||
inline void setOUTPUT_RESTORE(const char *fl) {
|
||||
OUTPUT_STARTUP = (const char *)malloc(strlen(fl) + 1);
|
||||
strcpy((char *)OUTPUT_STARTUP, fl);
|
||||
std::string *s = new std::string(fl);
|
||||
OUTPUT_STARTUP = s->c_str();
|
||||
};
|
||||
|
||||
inline const char *getOUTPUT_STARTUP() { return OUTPUT_STARTUP; };
|
||||
|
||||
inline void setSOURCEBOOT(const char *fl) {
|
||||
SOURCEBOOT = (const char *)malloc(strlen(fl) + 1);
|
||||
strcpy((char *)SOURCEBOOT, fl);
|
||||
std::string *s = new std::string(fl);
|
||||
SOURCEBOOT = s->c_str();
|
||||
};
|
||||
|
||||
inline const char *getSOURCEBOOT() { return SOURCEBOOT; };
|
||||
|
||||
inline void setPrologBOOTSTRAP(const char *fl) {
|
||||
BOOTSTRAP = (const char *)malloc(strlen(fl) + 1);
|
||||
strcpy((char *)BOOTSTRAP, fl);
|
||||
std::string *s = new std::string(fl);
|
||||
BOOTSTRAP = s->c_str();
|
||||
};
|
||||
|
||||
inline const char *getBOOTSTRAP() { return BOOTSTRAP; };
|
||||
|
||||
inline void setPrologGoal(const char *fl) { PrologGoal = fl; };
|
||||
inline void setPrologGoal(const char *fl) {
|
||||
std::string *s = new std::string(fl);
|
||||
PrologGoal = s->c_str();
|
||||
|
||||
}
|
||||
|
||||
inline const char *getPrologGoal() { return PrologGoal; };
|
||||
|
||||
inline void setPrologTopLevelGoal(const char *fl) {
|
||||
PrologTopLevelGoal = fl;
|
||||
std::string *s = new std::string(fl);
|
||||
PrologTopLevelGoal = s->c_str() ;
|
||||
};
|
||||
|
||||
inline const char *getPrologTopLevelGoal() { return PrologTopLevelGoal; };
|
||||
@ -271,7 +282,27 @@ public:
|
||||
|
||||
inline char **getArgv() { return Argv; };
|
||||
|
||||
inline void setROOTDIR(char *fl) { ROOTDIR = fl; };
|
||||
inline void setBOOTDIR(const char *fl) {
|
||||
std::string *s = new std::string(fl);
|
||||
BOOTDIR = s->c_str() ;
|
||||
}
|
||||
|
||||
inline const char *getBOOTDIR() { return BOOTDIR; };
|
||||
|
||||
inline const char *getBOOTFILE() { return BOOTSTRAP; };
|
||||
|
||||
inline void setBOOTFILE(const char *fl) {
|
||||
std::string *s = new std::string(fl);
|
||||
BOOTSTRAP = s->c_str() ;
|
||||
|
||||
}
|
||||
|
||||
inline void setROOTDIR(const char *fl) {
|
||||
std::string *s = new std::string(fl);
|
||||
ROOTDIR = s->c_str() ;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
@ -295,7 +326,7 @@ public:
|
||||
YAPEngine(YAPEngineArgs *cargs) {
|
||||
engine_args = cargs;
|
||||
// doInit(cargs->boot_file_type);
|
||||
__android_log_print(
|
||||
__android_log_print(
|
||||
ANDROID_LOG_INFO, "YAPDroid", "start engine ");
|
||||
#ifdef __ANDROID__
|
||||
doInit(YAP_PL, cargs);
|
||||
|
@ -484,7 +484,7 @@ extern void Yap_InitUserBacks(void);
|
||||
|
||||
/* utilpreds.c */
|
||||
int Yap_copy_complex_term(register CELL *pt0, register CELL *pt0_end,
|
||||
bool share, Term *split, bool copy_att_vars, CELL *ptf,
|
||||
bool share, bool copy_att_vars, CELL *ptf,
|
||||
CELL *HLow USES_REGS);
|
||||
extern Term Yap_CopyTerm(Term);
|
||||
extern bool Yap_Variant(Term, Term);
|
||||
|
3
configure
vendored
3
configure
vendored
@ -358,6 +358,7 @@ while [ $# != 0 ]; do
|
||||
esac;
|
||||
shift
|
||||
done
|
||||
_LIBDIR=${LIBDIR} ${CMAKE_ARGS}
|
||||
|
||||
if [ "x${LIBDIR}" = "x" ]; then
|
||||
LIBDIR="${PREFIX}/lib"
|
||||
@ -373,4 +374,4 @@ fi
|
||||
|
||||
CMAKE_CMD="${CMAKE} ${TOP_SRCDIR}"
|
||||
|
||||
${CMAKE_CMD} "${GENERATOR}" ${TOP_SRCDIR} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=${PREFIX} -DCMAKE_INSTALL_LIBDIR=${LIBDIR} ${CMAKE_ARGS}
|
||||
${CMAKE_CMD} "${GENERATOR}" ${TOP_SRCDIR} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=${PREFIX} ${CMAKE_ARGS}
|
||||
|
@ -29,7 +29,7 @@
|
||||
%%
|
||||
%% @brief Input/Output to characters.
|
||||
|
||||
:- module(system(charsio), [
|
||||
:- module(charsio, [
|
||||
format_to_chars/3,
|
||||
format_to_chars/4,
|
||||
write_to_chars/3,
|
||||
|
@ -1,3 +1,4 @@
|
||||
|
||||
/*************************************************************************
|
||||
* *
|
||||
* YAP Prolog *
|
||||
@ -381,10 +382,12 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod, Int newpos, bool
|
||||
Int end_line = GetCurInpLine(GLOBAL_Stream + sno);
|
||||
Int endpos = GetCurInpPos(GLOBAL_Stream + sno);
|
||||
|
||||
Yap_local.ActiveError->errorNo = SYNTAX_ERROR;
|
||||
Yap_local.ActiveError->prologConsulting = Yap_Consulting();
|
||||
Yap_local.ActiveError->parserFirstLine = start_line;
|
||||
Yap_local.ActiveError->parserLine = err_line;
|
||||
Yap_local.ActiveError->parserLastLine = end_line;
|
||||
Yap_local.ActiveError->parserFirstPos = startpos;
|
||||
Yap_local.ActiveError->parserPos = errpos;
|
||||
Yap_local.ActiveError->parserLastPos = endpos;
|
||||
Yap_local.ActiveError->parserFile =
|
||||
RepAtom(AtomOfTerm((GLOBAL_Stream + sno)->user_name))->StrOfAE;
|
||||
@ -811,7 +814,7 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod, Int newpos, bool
|
||||
else
|
||||
singls[1] = TermTrue;
|
||||
Term t = Yap_MkApplTerm(Yap_MkFunctor(AtomStyleCheck, 4), 4, singls);
|
||||
Yap_PrintWarning(t);
|
||||
Yap_PrintWarning(t);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1155,8 +1158,7 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod, Int newpos, bool
|
||||
re->cpos = GLOBAL_Stream[inp_stream].charcount;
|
||||
}
|
||||
LOCAL_Error_TYPE = WARNING_SYNTAX_ERROR;
|
||||
t = Yap_MkFullError();
|
||||
Yap_PrintWarning(t);
|
||||
Yap_PrintWarning(0);
|
||||
LOCAL_Error_TYPE = YAP_NO_ERROR;
|
||||
if (ParserErrorStyle == TermDec10)
|
||||
{
|
||||
|
@ -761,31 +761,33 @@ bool python_release_GIL(term_t curBlock) {
|
||||
}
|
||||
|
||||
install_t install_pypreds(void) {
|
||||
PL_register_foreign("python_builtin_eval", 3, python_builtin_eval, 0);
|
||||
PL_register_foreign("python_builtin", 1, python_builtin, 0);
|
||||
PL_register_foreign("python_import", 2, python_import, 0);
|
||||
PL_register_foreign("python_to_rhs", 2, python_to_rhs, 0);
|
||||
PL_register_foreign("python_len", 2, python_len, 0);
|
||||
PL_register_foreign("python_is", 2, python_is, 0);
|
||||
PL_register_foreign("python_dir", 2, python_dir, 0);
|
||||
PL_register_foreign("python_apply", 4, python_apply, 0);
|
||||
PL_register_foreign("python_index", 3, python_index, 0);
|
||||
PL_register_foreign("python_field", 3, python_field, 0);
|
||||
PL_register_foreign("python_assign", 2, assign_python, 0);
|
||||
PL_register_foreign("python_represents", 2, python_represent, 0);
|
||||
PL_register_foreign("python_export", 2, python_export, 0);
|
||||
PL_register_foreign("python_function", 1, python_function, 0);
|
||||
PL_register_foreign("python_slice", 4, python_slice, 0);
|
||||
PL_register_foreign("python_run_file", 1, python_run_file, 0);
|
||||
PL_register_foreign("python_proc", 1, python_proc, 0);
|
||||
PL_register_foreign("python_run_command", 1, python_run_command, 0);
|
||||
PL_register_foreign("python_run_script", 2, python_run_script, 0);
|
||||
PL_register_foreign("python_main_module", 1, python_main_module, 0);
|
||||
PL_register_foreign("python_import", 2, python_import, 0);
|
||||
PL_register_foreign("python_access", 3, python_access, 0);
|
||||
PL_register_foreign("python_threaded", 0, p_python_threaded, 0);
|
||||
PL_register_foreign("python_clear_errors", 0, python_clear_errors, 0);
|
||||
PL_register_foreign("python_string_to", 1, python_string_to, 0);
|
||||
|
||||
PL_register_foreign_in_module("python", "python_builtin_eval", 3, python_builtin_eval, 0);
|
||||
PL_register_foreign_in_module("python", "python_builtin", 1, python_builtin, 0);
|
||||
PL_register_foreign_in_module("python", "python_import", 2, python_import, 0);
|
||||
PL_register_foreign_in_module("python", "python_to_rhs", 2, python_to_rhs, 0);
|
||||
PL_register_foreign_in_module("python", "python_len", 2, python_len, 0);
|
||||
PL_register_foreign_in_module("python", "python_is", 2, python_is, 0);
|
||||
PL_register_foreign_in_module("python", "python_dir", 2, python_dir, 0);
|
||||
PL_register_foreign_in_module("python", "python_apply", 4, python_apply, 0);
|
||||
PL_register_foreign_in_module("python", "python_index", 3, python_index, 0);
|
||||
PL_register_foreign_in_module("python", "python_field", 3, python_field, 0);
|
||||
PL_register_foreign_in_module("python", "python_assign", 2, assign_python, 0);
|
||||
PL_register_foreign_in_module("python", "python_represents", 2, python_represent, 0);
|
||||
PL_register_foreign_in_module("python", "python_export", 2, python_export, 0);
|
||||
PL_register_foreign_in_module("python", "python_function", 1, python_function, 0);
|
||||
PL_register_foreign_in_module("python", "python_slice", 4, python_slice, 0);
|
||||
PL_register_foreign_in_module("python", "python_run_file", 1, python_run_file, 0);
|
||||
PL_register_foreign_in_module("python", "python_proc", 1, python_proc, 0);
|
||||
PL_register_foreign_in_module("python", "python_run_command", 1, python_run_command, 0);
|
||||
PL_register_foreign_in_module("python", "python_run_script", 2, python_run_script, 0);
|
||||
PL_register_foreign_in_module("python", "python_main_module", 1, python_main_module, 0);
|
||||
PL_register_foreign_in_module("python", "python_import", 2, python_import, 0);
|
||||
PL_register_foreign_in_module("python", "python_access", 3, python_access, 0);
|
||||
PL_register_foreign_in_module("python", "python_threaded", 0, p_python_threaded, 0);
|
||||
PL_register_foreign_in_module("python", "python_clear_errors", 0, python_clear_errors, 0);
|
||||
PL_register_foreign_in_module("python", "python_string_to", 1, python_string_to, 0);
|
||||
|
||||
|
||||
init_python_vfs();
|
||||
}
|
||||
|
@ -43,13 +43,18 @@
|
||||
op(50, yf, []),
|
||||
op(50, yf, '()'),
|
||||
op(100, xfy, '.'),
|
||||
op(100, fy, '.')
|
||||
op(100, fy, '.'),
|
||||
(:=)/2,
|
||||
(:=)/1,
|
||||
% (<-)/1,
|
||||
% (<-)/2,
|
||||
'()'/1, '{}'/1, dot_qualified_goal/1, import_arg/1
|
||||
]).
|
||||
|
||||
|
||||
/** @defgroup Py4YAP A C-based Prolog interface to python.
|
||||
@ingroup python
|
||||
|
||||
b
|
||||
@{
|
||||
|
||||
@author Vitor Santos Costa
|
||||
@ -96,7 +101,7 @@ similar as possible.
|
||||
|
||||
Python interface
|
||||
|
||||
Data types are
|
||||
Data types arebb
|
||||
|
||||
Python Prolog
|
||||
string atoms
|
||||
@ -115,34 +120,38 @@ Data types are
|
||||
:- use_module(library(charsio)).
|
||||
:- dynamic python_mref_cache/2, python_obj_cache/2.
|
||||
|
||||
:- multifile user:(:=)/2,
|
||||
user:(:=)/1,
|
||||
% user:(<-)/1,
|
||||
% user:(<-)/2,
|
||||
user:'()'/1, user:'{}'/1, user:dot_qualified_goal/1, user:import_arg/1.
|
||||
:- op(100,fy,'$'),
|
||||
op(950,fy,:=),
|
||||
op(950,yfx,:=),
|
||||
% op(950,fx,<-),
|
||||
% op(950,yfx,<-),
|
||||
op(50, yf, []),
|
||||
op(50, yf, '()'),
|
||||
op(100, xfy, '.'),
|
||||
op(100, fy, '.').
|
||||
|
||||
:- multifile (<-)/1, (<-)/2,
|
||||
'()'/1, '{}'/1,
|
||||
dot_qualified_goal/1,
|
||||
import_arg/1.
|
||||
|
||||
|
||||
import( F ) :- catch( python:python_import(F), _, fail ).
|
||||
|
||||
user:dot_qualified_goal(Fs) :- catch( python:python_proc(Fs), _, fail ).
|
||||
dot_qualified_goal(Fs) :- catch( python:python_proc(Fs), _, fail ).
|
||||
|
||||
user:F() :-
|
||||
catch( python:python_proc(F() ), _, fail ).
|
||||
'()'(F) :-
|
||||
catch( python_proc(()(F) ), _, fail ).
|
||||
|
||||
|
||||
user(P1,P2) :- !,
|
||||
:= (P1,P2) :- !,
|
||||
:= P1,
|
||||
:= P2.
|
||||
|
||||
:= F :- catch( python:python_proc(F), _, fail ).
|
||||
|
||||
:= (P1,P2) :- !,
|
||||
:= P1,
|
||||
:= P2.
|
||||
|
||||
user:(:= F) :- catch( python:python_proc(F), _, fail ).
|
||||
|
||||
user:( V := F ) :-
|
||||
V := F :-
|
||||
python:python_assign(F, V).
|
||||
|
||||
/*
|
||||
@ -153,15 +162,15 @@ user:(V <- F) :-
|
||||
V := F.
|
||||
*/
|
||||
|
||||
python:python_import(Module) :-
|
||||
python:python_import(Module, _).
|
||||
python_import(Module) :-
|
||||
python_import(Module, _).
|
||||
|
||||
|
||||
python(Exp, Out) :-
|
||||
Out := Exp.
|
||||
|
||||
python_command(Cmd) :-
|
||||
python:python_run_command(Cmd).
|
||||
python_run_command(Cmd).
|
||||
|
||||
start_python :-
|
||||
python:python_import('inspect', _),
|
||||
|
@ -2,27 +2,27 @@
|
||||
%% @file yapi.yap
|
||||
%% @brief support yap shell
|
||||
%%
|
||||
%:- start_low_level_trace.
|
||||
%% :- module(yapi, [
|
||||
%% python_ouput/0,
|
||||
%% show_answer/2,
|
||||
%% show_answer/3,
|
||||
%% yap_query/4,
|
||||
%% python_query/2,
|
||||
%% python_query/3,
|
||||
%% python_import/1,
|
||||
%% yapi_query/2
|
||||
%% ]).
|
||||
|
||||
:- yap_flag(verbose, silent).
|
||||
:- module(yapi, [
|
||||
python_ouput/0,
|
||||
show_answer/2,
|
||||
show_answer/3,
|
||||
yap_query/4,
|
||||
python_query/2,
|
||||
python_query/3,
|
||||
python_import/1,
|
||||
yapi_query/2
|
||||
]).
|
||||
|
||||
:- use_module(library(python)).
|
||||
%:- yap_flag(verbose, silent).
|
||||
|
||||
:- reexport(library(python)).
|
||||
|
||||
:- use_module( library(lists) ).
|
||||
:- use_module( library(maplist) ).
|
||||
:- use_module( library(rbtrees) ).
|
||||
:- use_module( library(terms) ).
|
||||
|
||||
|
||||
|
||||
:- python_import(yap4py.yapi).
|
||||
:- python_import(json).
|
||||
@ -46,9 +46,6 @@ yapi_query( VarNames, Self ) :-
|
||||
|
||||
set_preds :-
|
||||
fail,
|
||||
current_predicate(P, Q),
|
||||
functor(Q,P,A),
|
||||
|
||||
current_predicate(P, Q),
|
||||
functor(Q,P,A),
|
||||
atom_string(P,S),
|
||||
@ -69,36 +66,55 @@ fail,
|
||||
set_preds.
|
||||
|
||||
argi(N,I,I1) :-
|
||||
atomic_concat(`A`,I,N),
|
||||
atomic_concat('A',I,N),
|
||||
I1 is I+1.
|
||||
|
||||
python_query( Caller, String ) :-
|
||||
python_query( Caller, String ) :-
|
||||
python_query( Caller, String, _Bindings).
|
||||
|
||||
python_query( Caller, String, Bindings ) :-
|
||||
atomic_to_term( String, Goal, VarNames ),
|
||||
query_to_answer( Goal, _, Status, VarNames, Bindings),
|
||||
query_to_answer( Goal, VarNames, Status, Bindings),
|
||||
Caller.port := Status,
|
||||
output(Caller, Bindings).
|
||||
|
||||
output( _, Bindings ) :-
|
||||
write_query_answer( Bindings ),
|
||||
fail.
|
||||
output( Caller, Bindings ) :-
|
||||
answer := {},
|
||||
Answer := {},
|
||||
% start_low_level_trace,
|
||||
foldl(ground_dict(answer), Bindings, [], Ts),
|
||||
term_variables( Ts, Hidden),
|
||||
foldl(bv, Hidden , 0, _),
|
||||
maplist(into_dict(answer),Ts),
|
||||
Caller.answer := json.dumps(answer),
|
||||
S := Caller.answer,
|
||||
format(user_error, '~nor ~s~n~n',S),
|
||||
fail.
|
||||
maplist(into_dict(Answer),Ts),
|
||||
Caller.answer := Answer,
|
||||
fail.
|
||||
|
||||
|
||||
output( _, Bindings ) :-
|
||||
write_query_answer( Bindings ),
|
||||
fail.
|
||||
output(_Caller, _Bindings).
|
||||
|
||||
|
||||
bv(V,I,I1) :-
|
||||
atomic_concat(['__',I],V),
|
||||
I1 is I+1.
|
||||
|
||||
into_dict(D,V0=T) :-
|
||||
python_represents(D[V0], T).
|
||||
atom(T),
|
||||
!,
|
||||
D[V0] := T.
|
||||
into_dict(D,V0=T) :-
|
||||
integer(T),
|
||||
writeln((D[V0]:=T)),
|
||||
!,
|
||||
D[V0] := T,
|
||||
:= print(D).
|
||||
into_dict(D,V0=T) :-
|
||||
string(T),
|
||||
!,
|
||||
D[V0] := T.
|
||||
into_dict(D,V0=T) :-
|
||||
python_represents(T1,T),
|
||||
D[V0] := T1.
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -69,7 +69,7 @@ elif platform.system() == 'Darwin':
|
||||
win_libs = []
|
||||
local_libs = ['Py4YAP']
|
||||
elif platform.system() == 'Linux':
|
||||
my_extra_link_args = ['-L','..','-Wl,-rpath,'+abspath(join(sysconfig.get_path('platlib'),'yap4py')),'-Wl,-rpath,@CMAKE_INSTALL_FULL_LIBDIR@','-Wl,-rpath,'+join('@CMAKE_INSTALL_FULL_LIBDIR@','..'),'-Wl,-rpath,../yap4py']
|
||||
my_extra_link_args = ['-L','..','-Wl,-rpath,'+abspath(join(sysconfig.get_path('platlib'),'yap4py')),'-L','@CMAKE_INSTALL_FULL_LIBDIR@','-Wl,-rpath,@CMAKE_INSTALL_FULL_LIBDIR@','-Wl,-rpath,'+join('@CMAKE_INSTALL_FULL_LIBDIR@','..'),'-Wl,-rpath,../yap4py']
|
||||
win_libs = []
|
||||
local_libs = ['Py4YAP']
|
||||
|
||||
|
@ -5,44 +5,75 @@
|
||||
* @brief JUpyter support.
|
||||
*/
|
||||
|
||||
:- yap_flag(gc_trace,verbose).
|
||||
/*
|
||||
%:- yap_flag(gc_trace,verbose).
|
||||
:- module( jupyter,
|
||||
[jupyter_queryl/3,
|
||||
[jupyter_query/3,
|
||||
jupyter_query/4,
|
||||
op(100,fy,('$')),
|
||||
op(950,fy,:=),
|
||||
op(950,yfx,:=),
|
||||
% op(950,fx,<-),
|
||||
% op(950,yfx,<-),
|
||||
op(50, yf, []),
|
||||
op(50, yf, '()'),
|
||||
op(100, xfy, '.'),
|
||||
op(100, fy, '.'),
|
||||
blank/1,
|
||||
streams/2
|
||||
streams/1
|
||||
]
|
||||
).
|
||||
*/
|
||||
|
||||
:- use_module(library(hacks)).
|
||||
|
||||
:- use_module(library(lists)).
|
||||
:- use_module(library(maplist)).
|
||||
|
||||
%% :- reexport(library(python)).
|
||||
%% :- reexport(library(yapi)).
|
||||
%% :- reexport(library(complete)).
|
||||
%% :- reexport(library(verify)).
|
||||
|
||||
:- use_module(library(python)).
|
||||
:- use_module(library(yapi)).
|
||||
:- use_module(library(complete)).
|
||||
:- use_module(library(verify)).
|
||||
|
||||
|
||||
:- python_import(sys).
|
||||
|
||||
|
||||
jupyter_query(Caller, Cell, Line, Bindings ) :-
|
||||
gated_call(
|
||||
streams(true),
|
||||
jupyter_cell(Caller, Cell, Line, Bindings),
|
||||
Port,
|
||||
next_streams( Caller, Port, Bindings )
|
||||
).
|
||||
|
||||
jupyter_query(Caller, Cell, Line ) :-
|
||||
jupyter_cell(Caller, Cell, Line).
|
||||
jupyter_query( Caller, Cell, Line, _Bindings ).
|
||||
|
||||
jupyter_cell(_Caller, Cell, _Line) :-
|
||||
jupyter_consult(Cell), %stack_dump,
|
||||
next_streams( _Caller, exit, _Bindings ) :-
|
||||
% Caller.answer := Bindings,
|
||||
!.
|
||||
next_streams( _Caller, answer, _Bindings ) :-
|
||||
% Caller.answer := Bindings,
|
||||
!.
|
||||
next_streams(_, redo, _ ) :-
|
||||
streams(true),
|
||||
!.
|
||||
next_streams( _, _, _ ) :-
|
||||
streams(false).
|
||||
|
||||
|
||||
|
||||
jupyter_cell(_Caller, Cell, _Line, _) :-
|
||||
jupyter_consult(Cell), %stack_dump,
|
||||
fail.
|
||||
jupyter_cell( _Caller, _, ¨¨ ) :- !.
|
||||
jupyter_cell( _Caller, _, Line ) :-
|
||||
jupyter_cell( _Caller, _, ¨¨ , _) :- !.
|
||||
jupyter_cell( _Caller, _, Line , _) :-
|
||||
blank( Line ),
|
||||
!.
|
||||
jupyter_cell(Caller, _, Line ) :-
|
||||
jupyter_cell(Caller, _, Line, Bindings ) :-
|
||||
Query = Caller,
|
||||
catch(
|
||||
python_query(Query,Line),
|
||||
python_query(Query,Line, Bindings),
|
||||
error(A,B),
|
||||
system_error(A,B)
|
||||
).
|
||||
@ -58,6 +89,8 @@ restreams(!).
|
||||
restreams(external_exception(_)).
|
||||
restreams(exception).
|
||||
|
||||
%:- meta_predicate
|
||||
|
||||
jupyter_consult(Text) :-
|
||||
blank( Text ),
|
||||
!.
|
||||
@ -89,7 +122,7 @@ blank(Text) :-
|
||||
maplist( code_type(space), L).
|
||||
|
||||
|
||||
streams(false) :-
|
||||
streams(false) :-
|
||||
close(user_input),
|
||||
close(user_output),
|
||||
close(user_error).
|
||||
|
@ -16,7 +16,7 @@
|
||||
:- use_module(library(lists)).
|
||||
:- use_module(library(maplist)).
|
||||
|
||||
:- use_module(library(python)).
|
||||
%% :- use_module(library(python)).
|
||||
%% :- use_module(library(yapi)).
|
||||
|
||||
:- dynamic jupyter/1.
|
||||
@ -25,7 +25,7 @@ jupyter( []).
|
||||
ready( Engine, Query) :-
|
||||
errors( Engine , Query ),
|
||||
Es := Engine.errors,
|
||||
not Es == [].
|
||||
Es \== [].
|
||||
|
||||
|
||||
|
||||
|
@ -1,19 +1,19 @@
|
||||
"""
|
||||
Shim to maintain backwards compatibility with old yap_ipython.terminal.console imports.
|
||||
Shim to maintain backwards compatibility with old IPython.terminal.console imports.
|
||||
"""
|
||||
# Copyright (c) yap_ipython Development Team.
|
||||
# Copyright (c) IPython Development Team.
|
||||
# Distributed under the terms of the Modified BSD License.
|
||||
|
||||
import sys
|
||||
from warnings import warn
|
||||
|
||||
from yap_ipython.utils.shimmodule import ShimModule, ShimWarning
|
||||
from IPython.utils.shimmodule import ShimModule, ShimWarning
|
||||
|
||||
warn("The `yap_ipython.terminal.console` package has been deprecated since yap_ipython 4.0. "
|
||||
warn("The `IPython.terminal.console` package has been deprecated since IPython 4.0. "
|
||||
"You should import from jupyter_console instead.", ShimWarning)
|
||||
|
||||
# Unconditionally insert the shim into sys.modules so that further import calls
|
||||
# trigger the custom attribute access above
|
||||
|
||||
sys.modules['yap_ipython.terminal.console'] = ShimModule(
|
||||
src='yap_ipython.terminal.console', mirror='jupyter_console')
|
||||
sys.modules['IPython.terminal.console'] = ShimModule(
|
||||
src='IPython.terminal.console', mirror='jupyter_console')
|
||||
|
@ -1,18 +1,18 @@
|
||||
import signal
|
||||
import sys
|
||||
|
||||
from yap_ipython.core.debugger import Pdb
|
||||
from IPython.core.debugger import Pdb
|
||||
|
||||
from yap_ipython.core.completer import IPCompleter
|
||||
from IPython.core.completer import IPCompleter
|
||||
from .ptutils import IPythonPTCompleter
|
||||
from .shortcuts import suspend_to_bg, cursor_in_leading_ws
|
||||
|
||||
from prompt_toolkit.enums import DEFAULT_BUFFER
|
||||
from prompt_toolkit.filters import (Condition, HasFocus, HasSelection,
|
||||
ViInsertMode, EmacsInsertMode)
|
||||
from prompt_toolkit.keys import Keys
|
||||
from prompt_toolkit.key_binding.manager import KeyBindingManager
|
||||
from prompt_toolkit.filters import (Condition, has_focus, has_selection,
|
||||
vi_insert_mode, emacs_insert_mode)
|
||||
from prompt_toolkit.key_binding import KeyBindings
|
||||
from prompt_toolkit.key_binding.bindings.completion import display_completions_like_readline
|
||||
from pygments.token import Token
|
||||
from prompt_toolkit.shortcuts.prompt import PromptSession
|
||||
from prompt_toolkit.enums import EditingMode
|
||||
from prompt_toolkit.formatted_text import PygmentsTokens
|
||||
@ -58,6 +58,7 @@ class TerminalPdb(Pdb):
|
||||
complete_style=self.shell.pt_complete_style,
|
||||
style=self.shell.style,
|
||||
inputhook=self.shell.inputhook,
|
||||
color_depth=self.shell.color_depth,
|
||||
)
|
||||
|
||||
def cmdloop(self, intro=None):
|
||||
@ -107,7 +108,7 @@ def set_trace(frame=None):
|
||||
|
||||
if __name__ == '__main__':
|
||||
import pdb
|
||||
# yap_ipython.core.debugger.Pdb.trace_dispatch shall not catch
|
||||
# IPython.core.debugger.Pdb.trace_dispatch shall not catch
|
||||
# bdb.BdbQuit. When started through __main__ and an exception
|
||||
# happened after hitting "c", this is needed in order to
|
||||
# be able to quit the debugging session (see #9950).
|
||||
|
@ -1,27 +1,27 @@
|
||||
# encoding: utf-8
|
||||
"""
|
||||
An embedded yap_ipython shell.
|
||||
An embedded IPython shell.
|
||||
"""
|
||||
# Copyright (c) yap_ipython Development Team.
|
||||
# Copyright (c) IPython Development Team.
|
||||
# Distributed under the terms of the Modified BSD License.
|
||||
|
||||
|
||||
import sys
|
||||
import warnings
|
||||
|
||||
from yap_ipython.core import ultratb, compilerop
|
||||
from yap_ipython.core import magic_arguments
|
||||
from yap_ipython.core.magic import Magics, magics_class, line_magic
|
||||
from yap_ipython.core.interactiveshell import DummyMod, InteractiveShell
|
||||
from yap_ipython.terminal.interactiveshell import TerminalInteractiveShell
|
||||
from yap_ipython.terminal.ipapp import load_default_config
|
||||
from IPython.core import ultratb, compilerop
|
||||
from IPython.core import magic_arguments
|
||||
from IPython.core.magic import Magics, magics_class, line_magic
|
||||
from IPython.core.interactiveshell import DummyMod, InteractiveShell
|
||||
from IPython.terminal.interactiveshell import TerminalInteractiveShell
|
||||
from IPython.terminal.ipapp import load_default_config
|
||||
|
||||
from traitlets import Bool, CBool, Unicode
|
||||
from yap_ipython.utils.io import ask_yes_no
|
||||
from IPython.utils.io import ask_yes_no
|
||||
|
||||
class KillEmbedded(Exception):pass
|
||||
|
||||
# kept for backward compatibility as yap_ipython 6 was released with
|
||||
# kept for backward compatibility as IPython 6 was released with
|
||||
# the typo. See https://github.com/ipython/ipython/pull/10706
|
||||
KillEmbeded = KillEmbedded
|
||||
|
||||
@ -38,10 +38,10 @@ class EmbeddedMagics(Magics):
|
||||
@magic_arguments.argument('-y', '--yes', action='store_true',
|
||||
help='Do not ask confirmation')
|
||||
def kill_embedded(self, parameter_s=''):
|
||||
"""%kill_embedded : deactivate for good the current embedded yap_ipython
|
||||
"""%kill_embedded : deactivate for good the current embedded IPython
|
||||
|
||||
This function (after asking for confirmation) sets an internal flag so
|
||||
that an embedded yap_ipython will never activate again for the given call
|
||||
that an embedded IPython will never activate again for the given call
|
||||
location. This is useful to permanently disable a shell that is being
|
||||
called inside a loop: once you've figured out what you needed from it,
|
||||
you may then kill it and the program will then continue to run without
|
||||
@ -59,7 +59,7 @@ class EmbeddedMagics(Magics):
|
||||
|
||||
.. note::
|
||||
|
||||
This was the default behavior before yap_ipython 5.2
|
||||
This was the default behavior before IPython 5.2
|
||||
|
||||
"""
|
||||
|
||||
@ -74,7 +74,7 @@ class EmbeddedMagics(Magics):
|
||||
kill = True
|
||||
if kill:
|
||||
self.shell._disable_init_location()
|
||||
print("This embedded yap_ipython instance will not reactivate anymore "
|
||||
print("This embedded IPython instance will not reactivate anymore "
|
||||
"once you exit.")
|
||||
else:
|
||||
if not args.yes:
|
||||
@ -84,7 +84,7 @@ class EmbeddedMagics(Magics):
|
||||
kill = True
|
||||
if kill:
|
||||
self.shell.embedded_active = False
|
||||
print("This embedded yap_ipython call location will not reactivate anymore "
|
||||
print("This embedded IPython call location will not reactivate anymore "
|
||||
"once you exit.")
|
||||
|
||||
if args.exit:
|
||||
@ -97,9 +97,9 @@ class EmbeddedMagics(Magics):
|
||||
def exit_raise(self, parameter_s=''):
|
||||
"""%exit_raise Make the current embedded kernel exit and raise and exception.
|
||||
|
||||
This function sets an internal flag so that an embedded yap_ipython will
|
||||
raise a `yap_ipython.terminal.embed.KillEmbedded` Exception on exit, and then exit the current I. This is
|
||||
useful to permanently exit a loop that create yap_ipython embed instance.
|
||||
This function sets an internal flag so that an embedded IPython will
|
||||
raise a `IPython.terminal.embed.KillEmbedded` Exception on exit, and then exit the current I. This is
|
||||
useful to permanently exit a loop that create IPython embed instance.
|
||||
"""
|
||||
|
||||
self.shell.should_raise = True
|
||||
@ -148,7 +148,7 @@ class InteractiveShellEmbed(TerminalInteractiveShell):
|
||||
def __init__(self, **kw):
|
||||
if kw.get('user_global_ns', None) is not None:
|
||||
raise DeprecationWarning(
|
||||
"Key word argument `user_global_ns` has been replaced by `user_module` since yap_ipython 4.0.")
|
||||
"Key word argument `user_global_ns` has been replaced by `user_module` since IPython 4.0.")
|
||||
|
||||
clid = kw.pop('_init_location_id', None)
|
||||
if not clid:
|
||||
@ -166,7 +166,7 @@ class InteractiveShellEmbed(TerminalInteractiveShell):
|
||||
|
||||
def init_sys_modules(self):
|
||||
"""
|
||||
Explicitly overwrite :mod:`yap_ipython.core.interactiveshell` to do nothing.
|
||||
Explicitly overwrite :mod:`IPython.core.interactiveshell` to do nothing.
|
||||
"""
|
||||
pass
|
||||
|
||||
@ -234,12 +234,12 @@ class InteractiveShellEmbed(TerminalInteractiveShell):
|
||||
print(self.exit_msg)
|
||||
|
||||
if self.should_raise:
|
||||
raise KillEmbedded('Embedded yap_ipython raising error, as user requested.')
|
||||
raise KillEmbedded('Embedded IPython raising error, as user requested.')
|
||||
|
||||
|
||||
def mainloop(self, local_ns=None, module=None, stack_depth=0,
|
||||
display_banner=None, global_ns=None, compile_flags=None):
|
||||
"""Embeds yap_ipython into a running python program.
|
||||
"""Embeds IPython into a running python program.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
@ -265,10 +265,10 @@ class InteractiveShellEmbed(TerminalInteractiveShell):
|
||||
"""
|
||||
|
||||
if (global_ns is not None) and (module is None):
|
||||
raise DeprecationWarning("'global_ns' keyword argument is deprecated, and has been removed in yap_ipython 5.0 use `module` keyword argument instead.")
|
||||
raise DeprecationWarning("'global_ns' keyword argument is deprecated, and has been removed in IPython 5.0 use `module` keyword argument instead.")
|
||||
|
||||
if (display_banner is not None):
|
||||
warnings.warn("The display_banner parameter is deprecated since yap_ipython 4.0", DeprecationWarning)
|
||||
warnings.warn("The display_banner parameter is deprecated since IPython 4.0", DeprecationWarning)
|
||||
|
||||
# Get locals and globals from caller
|
||||
if ((local_ns is None or module is None or compile_flags is None)
|
||||
@ -323,7 +323,7 @@ class InteractiveShellEmbed(TerminalInteractiveShell):
|
||||
with self.builtin_trap, self.display_trap:
|
||||
self.interact()
|
||||
|
||||
# now, purge out the local namespace of yap_ipython's hidden variables.
|
||||
# now, purge out the local namespace of IPython's hidden variables.
|
||||
if local_ns is not None:
|
||||
local_ns.update({k: v for (k, v) in self.user_ns.items() if k not in self.user_ns_hidden.keys()})
|
||||
|
||||
@ -335,7 +335,7 @@ class InteractiveShellEmbed(TerminalInteractiveShell):
|
||||
|
||||
|
||||
def embed(**kwargs):
|
||||
"""Call this to embed yap_ipython at the current point in your program.
|
||||
"""Call this to embed IPython at the current point in your program.
|
||||
|
||||
The first invocation of this will create an :class:`InteractiveShellEmbed`
|
||||
instance and then call it. Consecutive calls just call the already
|
||||
@ -343,12 +343,12 @@ def embed(**kwargs):
|
||||
|
||||
If you don't want the kernel to initialize the namespace
|
||||
from the scope of the surrounding function,
|
||||
and/or you want to load full yap_ipython configuration,
|
||||
you probably want `yap_ipython.start_ipython()` instead.
|
||||
and/or you want to load full IPython configuration,
|
||||
you probably want `IPython.start_ipython()` instead.
|
||||
|
||||
Here is a simple example::
|
||||
|
||||
from yap_ipython import embed
|
||||
from IPython import embed
|
||||
a = 10
|
||||
b = 20
|
||||
embed(header='First time')
|
||||
|
@ -1,15 +1,15 @@
|
||||
"""yap_ipython terminal interface using prompt_toolkit"""
|
||||
"""IPython terminal interface using prompt_toolkit"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import warnings
|
||||
from warnings import warn
|
||||
|
||||
from yap_ipython.core.interactiveshell import InteractiveShell, InteractiveShellABC
|
||||
from yap_ipython.utils import io
|
||||
from yap_ipython.utils.py3compat import input
|
||||
from yap_ipython.utils.terminal import toggle_set_term_title, set_term_title
|
||||
from yap_ipython.utils.process import abbrev_cwd
|
||||
from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC
|
||||
from IPython.utils import io
|
||||
from IPython.utils.py3compat import input
|
||||
from IPython.utils.terminal import toggle_set_term_title, set_term_title
|
||||
from IPython.utils.process import abbrev_cwd
|
||||
from traitlets import (
|
||||
Bool, Unicode, Dict, Integer, observe, Instance, Type, default, Enum, Union,
|
||||
Any, validate
|
||||
@ -98,8 +98,8 @@ class TerminalInteractiveShell(InteractiveShell):
|
||||
simple_prompt = Bool(_use_simple_prompt,
|
||||
help="""Use `raw_input` for the REPL, without completion and prompt colors.
|
||||
|
||||
Useful when controlling yap_ipython as a subprocess, and piping STDIN/OUT/ERR. Known usage are:
|
||||
yap_ipython own testing machinery, and emacs inferior-shell integration through elpy.
|
||||
Useful when controlling IPython as a subprocess, and piping STDIN/OUT/ERR. Known usage are:
|
||||
IPython own testing machinery, and emacs inferior-shell integration through elpy.
|
||||
|
||||
This mode default to `True` if the `IPY_TEST_SIMPLE_PROMPT`
|
||||
environment variable is set, or the current terminal is not a tty."""
|
||||
@ -111,7 +111,7 @@ class TerminalInteractiveShell(InteractiveShell):
|
||||
|
||||
confirm_exit = Bool(True,
|
||||
help="""
|
||||
Set to confirm when you try to exit yap_ipython with an EOF (Control-D
|
||||
Set to confirm when you try to exit IPython with an EOF (Control-D
|
||||
in Unix, Control-Z/Enter in Windows). By typing 'exit' or 'quit',
|
||||
you can force a direct exit without any confirmation.""",
|
||||
).tag(config=True)
|
||||
@ -147,7 +147,8 @@ class TerminalInteractiveShell(InteractiveShell):
|
||||
@observe('editing_mode')
|
||||
def _editing_mode(self, change):
|
||||
u_mode = change.new.upper()
|
||||
self.pt_app.editing_mode = u_mode
|
||||
if self.pt_app:
|
||||
self.pt_app.editing_mode = u_mode
|
||||
|
||||
@observe('highlighting_style')
|
||||
@observe('colors')
|
||||
@ -170,7 +171,7 @@ class TerminalInteractiveShell(InteractiveShell):
|
||||
).tag(config=True)
|
||||
|
||||
editor = Unicode(get_default_editor(),
|
||||
help="Set the editor used by yap_ipython (default to $EDITOR/vi/notepad)."
|
||||
help="Set the editor used by IPython (default to $EDITOR/vi/notepad)."
|
||||
).tag(config=True)
|
||||
|
||||
prompts_class = Type(Prompts, help='Class used to generate Prompt token for prompt_toolkit').tag(config=True)
|
||||
@ -193,7 +194,7 @@ class TerminalInteractiveShell(InteractiveShell):
|
||||
help="Automatically set the terminal title"
|
||||
).tag(config=True)
|
||||
|
||||
term_title_format = Unicode("yap_ipython: {cwd}",
|
||||
term_title_format = Unicode("IPython: {cwd}",
|
||||
help="Customize the terminal title format. This is a python format string. " +
|
||||
"Available substitutions are: {cwd}."
|
||||
).tag(config=True)
|
||||
@ -224,6 +225,10 @@ class TerminalInteractiveShell(InteractiveShell):
|
||||
help="Allows to enable/disable the prompt toolkit history search"
|
||||
).tag(config=True)
|
||||
|
||||
prompt_includes_vi_mode = Bool(True,
|
||||
help="Display the current vi mode (when using vi editing mode)."
|
||||
).tag(config=True)
|
||||
|
||||
@observe('term_title')
|
||||
def init_term_title(self, change=None):
|
||||
# Enable or disable the terminal title.
|
||||
@ -257,7 +262,7 @@ class TerminalInteractiveShell(InteractiveShell):
|
||||
# Set up keyboard shortcuts
|
||||
key_bindings = create_ipython_shortcuts(self)
|
||||
|
||||
# Pre-populate history from yap_ipython's history database
|
||||
# Pre-populate history from IPython's history database
|
||||
history = InMemoryHistory()
|
||||
last_cell = u""
|
||||
for __, ___, cell in self.history_manager.get_tail(self.history_load_length,
|
||||
@ -283,12 +288,12 @@ class TerminalInteractiveShell(InteractiveShell):
|
||||
include_default_pygments_style=False,
|
||||
mouse_support=self.mouse_support,
|
||||
enable_open_in_editor=self.extra_open_editor_shortcuts,
|
||||
color_depth=(ColorDepth.TRUE_COLOR if self.true_color else None),
|
||||
color_depth=self.color_depth,
|
||||
**self._extra_prompt_options())
|
||||
|
||||
def _make_style_from_name_or_cls(self, name_or_cls):
|
||||
"""
|
||||
Small wrapper that make an yap_ipython compatible style from a style name
|
||||
Small wrapper that make an IPython compatible style from a style name
|
||||
|
||||
We need that to add style for prompt ... etc.
|
||||
"""
|
||||
@ -360,6 +365,10 @@ class TerminalInteractiveShell(InteractiveShell):
|
||||
'readlinelike': CompleteStyle.READLINE_LIKE,
|
||||
}[self.display_completions]
|
||||
|
||||
@property
|
||||
def color_depth(self):
|
||||
return (ColorDepth.TRUE_COLOR if self.true_color else None)
|
||||
|
||||
def _extra_prompt_options(self):
|
||||
"""
|
||||
Return the current layout option for the current Terminal InteractiveShell
|
||||
@ -442,7 +451,7 @@ class TerminalInteractiveShell(InteractiveShell):
|
||||
# need direct access to the console in a way that we can't emulate in
|
||||
# GUI or web frontend
|
||||
if os.name == 'posix':
|
||||
for cmd in ['clear', 'more', 'less', 'man']:
|
||||
for cmd in ('clear', 'more', 'less', 'man'):
|
||||
self.alias_manager.soft_define_alias(cmd, cmd)
|
||||
|
||||
|
||||
@ -462,7 +471,7 @@ class TerminalInteractiveShell(InteractiveShell):
|
||||
def interact(self, display_banner=DISPLAY_BANNER_DEPRECATED):
|
||||
|
||||
if display_banner is not DISPLAY_BANNER_DEPRECATED:
|
||||
warn('interact `display_banner` argument is deprecated since yap_ipython 5.0. Call `show_banner()` if needed.', DeprecationWarning, stacklevel=2)
|
||||
warn('interact `display_banner` argument is deprecated since IPython 5.0. Call `show_banner()` if needed.', DeprecationWarning, stacklevel=2)
|
||||
|
||||
self.keep_running = True
|
||||
while self.keep_running:
|
||||
|
@ -1,11 +1,11 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
"""
|
||||
The :class:`~yap_ipython.core.application.Application` object for the command
|
||||
The :class:`~IPython.core.application.Application` object for the command
|
||||
line :command:`ipython` program.
|
||||
"""
|
||||
|
||||
# Copyright (c) yap_ipython Development Team.
|
||||
# Copyright (c) IPython Development Team.
|
||||
# Distributed under the terms of the Modified BSD License.
|
||||
|
||||
|
||||
@ -16,24 +16,24 @@ import warnings
|
||||
|
||||
from traitlets.config.loader import Config
|
||||
from traitlets.config.application import boolean_flag, catch_config_error
|
||||
from yap_ipython.core import release
|
||||
from yap_ipython.core import usage
|
||||
from yap_ipython.core.completer import IPCompleter
|
||||
from yap_ipython.core.crashhandler import CrashHandler
|
||||
from yap_ipython.core.formatters import PlainTextFormatter
|
||||
from yap_ipython.core.history import HistoryManager
|
||||
from yap_ipython.core.application import (
|
||||
ProfileDir, BaseYAPApplication, base_flags, base_aliases
|
||||
from IPython.core import release
|
||||
from IPython.core import usage
|
||||
from IPython.core.completer import IPCompleter
|
||||
from IPython.core.crashhandler import CrashHandler
|
||||
from IPython.core.formatters import PlainTextFormatter
|
||||
from IPython.core.history import HistoryManager
|
||||
from IPython.core.application import (
|
||||
ProfileDir, BaseIPythonApplication, base_flags, base_aliases
|
||||
)
|
||||
from yap_ipython.core.magics import (
|
||||
from IPython.core.magics import (
|
||||
ScriptMagics, LoggingMagics
|
||||
)
|
||||
from yap_ipython.core.shellapp import (
|
||||
from IPython.core.shellapp import (
|
||||
InteractiveShellApp, shell_flags, shell_aliases
|
||||
)
|
||||
from yap_ipython.extensions.storemagic import StoreMagics
|
||||
from IPython.extensions.storemagic import StoreMagics
|
||||
from .interactiveshell import TerminalInteractiveShell
|
||||
from yap_ipython.paths import get_ipython_dir
|
||||
from IPython.paths import get_ipython_dir
|
||||
from traitlets import (
|
||||
Bool, List, default, observe, Type
|
||||
)
|
||||
@ -52,7 +52,7 @@ ipython --profile=foo # start with profile foo
|
||||
ipython profile create foo # create profile foo w/ default config files
|
||||
ipython help profile # show the help for the profile subcmd
|
||||
|
||||
ipython locate # print the path to the yap_ipython directory
|
||||
ipython locate # print the path to the IPython directory
|
||||
ipython locate profile foo # print the path to the directory for profile `foo`
|
||||
"""
|
||||
|
||||
@ -61,7 +61,7 @@ ipython locate profile foo # print the path to the directory for profile `foo`
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
class IPAppCrashHandler(CrashHandler):
|
||||
"""sys.excepthook for yap_ipython itself, leaves a detailed report on disk."""
|
||||
"""sys.excepthook for IPython itself, leaves a detailed report on disk."""
|
||||
|
||||
def __init__(self, app):
|
||||
contact_name = release.author
|
||||
@ -106,12 +106,12 @@ addflag('simple-prompt', 'TerminalInteractiveShell.simple_prompt',
|
||||
"Use a rich interactive prompt with prompt_toolkit",
|
||||
)
|
||||
|
||||
addflag('banner', 'Terminalyap_ipythonApp.display_banner',
|
||||
"Display a banner upon starting yap_ipython.",
|
||||
"Don't display a banner upon starting yap_ipython."
|
||||
addflag('banner', 'TerminalIPythonApp.display_banner',
|
||||
"Display a banner upon starting IPython.",
|
||||
"Don't display a banner upon starting IPython."
|
||||
)
|
||||
addflag('confirm-exit', 'TerminalInteractiveShell.confirm_exit',
|
||||
"""Set to confirm when you try to exit yap_ipython with an EOF (Control-D
|
||||
"""Set to confirm when you try to exit IPython with an EOF (Control-D
|
||||
in Unix, Control-Z/Enter in Windows). By typing 'exit' or 'quit',
|
||||
you can force a direct exit without any confirmation.""",
|
||||
"Don't prompt the user when exiting."
|
||||
@ -123,7 +123,7 @@ addflag('term-title', 'TerminalInteractiveShell.term_title',
|
||||
classic_config = Config()
|
||||
classic_config.InteractiveShell.cache_size = 0
|
||||
classic_config.PlainTextFormatter.pprint = False
|
||||
classic_config.TerminalInteractiveShell.prompts_class='yap_ipython.terminal.prompts.ClassicPrompts'
|
||||
classic_config.TerminalInteractiveShell.prompts_class='IPython.terminal.prompts.ClassicPrompts'
|
||||
classic_config.InteractiveShell.separate_in = ''
|
||||
classic_config.InteractiveShell.separate_out = ''
|
||||
classic_config.InteractiveShell.separate_out2 = ''
|
||||
@ -132,7 +132,7 @@ classic_config.InteractiveShell.xmode = 'Plain'
|
||||
|
||||
frontend_flags['classic']=(
|
||||
classic_config,
|
||||
"Gives yap_ipython a similar feel to the classic Python prompt."
|
||||
"Gives IPython a similar feel to the classic Python prompt."
|
||||
)
|
||||
# # log doesn't make so much sense this way anymore
|
||||
# paa('--log','-l',
|
||||
@ -141,12 +141,12 @@ frontend_flags['classic']=(
|
||||
#
|
||||
# # quick is harder to implement
|
||||
frontend_flags['quick']=(
|
||||
{'Terminalyap_ipythonApp' : {'quick' : True}},
|
||||
{'TerminalIPythonApp' : {'quick' : True}},
|
||||
"Enable quick startup with no config files."
|
||||
)
|
||||
|
||||
frontend_flags['i'] = (
|
||||
{'Terminalyap_ipythonApp' : {'force_interact' : True}},
|
||||
{'TerminalIPythonApp' : {'force_interact' : True}},
|
||||
"""If running code from the command line, become interactive afterwards.
|
||||
It is often useful to follow this with `--` to treat remaining flags as
|
||||
script arguments.
|
||||
@ -162,11 +162,11 @@ aliases.update(shell_aliases)
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
class Locateyap_ipythonApp(BaseYAPApplication):
|
||||
description = """print the path to the yap_ipython dir"""
|
||||
class LocateIPythonApp(BaseIPythonApplication):
|
||||
description = """print the path to the IPython dir"""
|
||||
subcommands = dict(
|
||||
profile=('yap_ipython.core.profileapp.ProfileLocate',
|
||||
"print the path to an yap_ipython profile directory",
|
||||
profile=('IPython.core.profileapp.ProfileLocate',
|
||||
"print the path to an IPython profile directory",
|
||||
),
|
||||
)
|
||||
def start(self):
|
||||
@ -176,7 +176,7 @@ class Locateyap_ipythonApp(BaseYAPApplication):
|
||||
print(self.ipython_dir)
|
||||
|
||||
|
||||
class Terminalyap_ipythonApp(BaseYAPApplication, InteractiveShellApp):
|
||||
class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp):
|
||||
name = u'ipython'
|
||||
description = usage.cl_usage
|
||||
crash_handler_class = IPAppCrashHandler
|
||||
@ -194,7 +194,7 @@ class Terminalyap_ipythonApp(BaseYAPApplication, InteractiveShellApp):
|
||||
|
||||
@default('classes')
|
||||
def _classes_default(self):
|
||||
"""This has to be in a method, for Terminalyap_ipythonApp to be available."""
|
||||
"""This has to be in a method, for TerminalIPythonApp to be available."""
|
||||
return [
|
||||
InteractiveShellApp, # ShellApp comes before TerminalApp, because
|
||||
self.__class__, # it will also affect subclasses (e.g. QtConsole)
|
||||
@ -210,41 +210,41 @@ class Terminalyap_ipythonApp(BaseYAPApplication, InteractiveShellApp):
|
||||
|
||||
deprecated_subcommands = dict(
|
||||
qtconsole=('qtconsole.qtconsoleapp.JupyterQtConsoleApp',
|
||||
"""DEPRECATED, Will be removed in yap_ipython 6.0 : Launch the Jupyter Qt Console."""
|
||||
"""DEPRECATED, Will be removed in IPython 6.0 : Launch the Jupyter Qt Console."""
|
||||
),
|
||||
notebook=('notebook.notebookapp.NotebookApp',
|
||||
"""DEPRECATED, Will be removed in yap_ipython 6.0 : Launch the Jupyter HTML Notebook Server."""
|
||||
"""DEPRECATED, Will be removed in IPython 6.0 : Launch the Jupyter HTML Notebook Server."""
|
||||
),
|
||||
console=('jupyter_console.app.ZMQTerminalyap_ipythonApp',
|
||||
"""DEPRECATED, Will be removed in yap_ipython 6.0 : Launch the Jupyter terminal-based Console."""
|
||||
console=('jupyter_console.app.ZMQTerminalIPythonApp',
|
||||
"""DEPRECATED, Will be removed in IPython 6.0 : Launch the Jupyter terminal-based Console."""
|
||||
),
|
||||
nbconvert=('nbconvert.nbconvertapp.NbConvertApp',
|
||||
"DEPRECATED, Will be removed in yap_ipython 6.0 : Convert notebooks to/from other formats."
|
||||
"DEPRECATED, Will be removed in IPython 6.0 : Convert notebooks to/from other formats."
|
||||
),
|
||||
trust=('nbformat.sign.TrustNotebookApp',
|
||||
"DEPRECATED, Will be removed in yap_ipython 6.0 : Sign notebooks to trust their potentially unsafe contents at load."
|
||||
"DEPRECATED, Will be removed in IPython 6.0 : Sign notebooks to trust their potentially unsafe contents at load."
|
||||
),
|
||||
kernelspec=('jupyter_client.kernelspecapp.KernelSpecApp',
|
||||
"DEPRECATED, Will be removed in yap_ipython 6.0 : Manage Jupyter kernel specifications."
|
||||
"DEPRECATED, Will be removed in IPython 6.0 : Manage Jupyter kernel specifications."
|
||||
),
|
||||
)
|
||||
subcommands = dict(
|
||||
profile = ("yap_ipython.core.profileapp.ProfileApp",
|
||||
"Create and manage yap_ipython profiles."
|
||||
profile = ("IPython.core.profileapp.ProfileApp",
|
||||
"Create and manage IPython profiles."
|
||||
),
|
||||
kernel = ("ipykernel.kernelapp.IPKernelApp",
|
||||
"Start a kernel without an attached frontend."
|
||||
),
|
||||
locate=('yap_ipython.terminal.ipapp.Locateyap_ipythonApp',
|
||||
Locateyap_ipythonApp.description
|
||||
locate=('IPython.terminal.ipapp.LocateIPythonApp',
|
||||
LocateIPythonApp.description
|
||||
),
|
||||
history=('yap_ipython.core.historyapp.HistoryApp',
|
||||
"Manage the yap_ipython history database."
|
||||
history=('IPython.core.historyapp.HistoryApp',
|
||||
"Manage the IPython history database."
|
||||
),
|
||||
)
|
||||
deprecated_subcommands['install-nbextension'] = (
|
||||
"notebook.nbextensions.InstallNBExtensionApp",
|
||||
"DEPRECATED, Will be removed in yap_ipython 6.0 : Install Jupyter notebook extension files"
|
||||
"DEPRECATED, Will be removed in IPython 6.0 : Install Jupyter notebook extension files"
|
||||
)
|
||||
subcommands.update(deprecated_subcommands)
|
||||
|
||||
@ -252,7 +252,7 @@ class Terminalyap_ipythonApp(BaseYAPApplication, InteractiveShellApp):
|
||||
auto_create=Bool(True)
|
||||
# configurables
|
||||
quick = Bool(False,
|
||||
help="""Start yap_ipython quickly by skipping the loading of config files."""
|
||||
help="""Start IPython quickly by skipping the loading of config files."""
|
||||
).tag(config=True)
|
||||
@observe('quick')
|
||||
def _quick_changed(self, change):
|
||||
@ -260,7 +260,7 @@ class Terminalyap_ipythonApp(BaseYAPApplication, InteractiveShellApp):
|
||||
self.load_config_file = lambda *a, **kw: None
|
||||
|
||||
display_banner = Bool(True,
|
||||
help="Whether to display a banner upon starting yap_ipython."
|
||||
help="Whether to display a banner upon starting IPython."
|
||||
).tag(config=True)
|
||||
|
||||
# if there is code of files to run from the cmd line, don't interact
|
||||
@ -300,12 +300,12 @@ class Terminalyap_ipythonApp(BaseYAPApplication, InteractiveShellApp):
|
||||
" Use `--matplotlib <backend>` and import pylab manually.")
|
||||
argv[idx] = '--pylab'
|
||||
|
||||
return super(Terminalyap_ipythonApp, self).parse_command_line(argv)
|
||||
return super(TerminalIPythonApp, self).parse_command_line(argv)
|
||||
|
||||
@catch_config_error
|
||||
def initialize(self, argv=None):
|
||||
"""Do actions after construct, but before starting the app."""
|
||||
super(Terminalyap_ipythonApp, self).initialize(argv)
|
||||
super(TerminalIPythonApp, self).initialize(argv)
|
||||
if self.subapp is not None:
|
||||
# don't bother initializing further, starting subapp
|
||||
return
|
||||
@ -352,10 +352,10 @@ class Terminalyap_ipythonApp(BaseYAPApplication, InteractiveShellApp):
|
||||
return self.subapp.start()
|
||||
# perform any prexec steps:
|
||||
if self.interact:
|
||||
self.log.debug("Starting yap_ipython's mainloop...")
|
||||
self.log.debug("Starting IPython's mainloop...")
|
||||
self.shell.mainloop()
|
||||
else:
|
||||
self.log.debug("yap_ipython not interactive...")
|
||||
self.log.debug("IPython not interactive...")
|
||||
if not self.shell.last_execution_succeeded:
|
||||
sys.exit(1)
|
||||
|
||||
@ -368,12 +368,12 @@ def load_default_config(ipython_dir=None):
|
||||
ipython_dir = get_ipython_dir()
|
||||
|
||||
profile_dir = os.path.join(ipython_dir, 'profile_default')
|
||||
app = Terminalyap_ipythonApp()
|
||||
app = TerminalIPythonApp()
|
||||
app.config_file_paths.append(profile_dir)
|
||||
app.load_config_file()
|
||||
return app.config
|
||||
|
||||
launch_new_instance = Terminalyap_ipythonApp.launch_instance
|
||||
launch_new_instance = TerminalIPythonApp.launch_instance
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -1,6 +1,6 @@
|
||||
"""Extra magics for terminal use."""
|
||||
|
||||
# Copyright (c) yap_ipython Development Team.
|
||||
# Copyright (c) IPython Development Team.
|
||||
# Distributed under the terms of the Modified BSD License.
|
||||
|
||||
|
||||
@ -8,11 +8,11 @@ from logging import error
|
||||
import os
|
||||
import sys
|
||||
|
||||
from yap_ipython.core.error import TryNext, UsageError
|
||||
from yap_ipython.core.magic import Magics, magics_class, line_magic
|
||||
from yap_ipython.lib.clipboard import ClipboardEmpty
|
||||
from yap_ipython.utils.text import SList, strip_email_quotes
|
||||
from yap_ipython.utils import py3compat
|
||||
from IPython.core.error import TryNext, UsageError
|
||||
from IPython.core.magic import Magics, magics_class, line_magic
|
||||
from IPython.lib.clipboard import ClipboardEmpty
|
||||
from IPython.utils.text import SList, strip_email_quotes
|
||||
from IPython.utils import py3compat
|
||||
|
||||
def get_pasted_lines(sentinel, l_input=py3compat.input, quiet=False):
|
||||
""" Yield pasted lines until the user enters the given sentinel value.
|
||||
@ -109,7 +109,7 @@ class TerminalMagics(Magics):
|
||||
Just press enter and type -- (and press enter again) and the block
|
||||
will be what was just pasted.
|
||||
|
||||
yap_ipython statements (magics, shell escapes) are not supported (yet).
|
||||
IPython statements (magics, shell escapes) are not supported (yet).
|
||||
|
||||
See also
|
||||
--------
|
||||
@ -162,7 +162,7 @@ class TerminalMagics(Magics):
|
||||
|
||||
-q: quiet mode: do not echo the pasted text back to the terminal.
|
||||
|
||||
yap_ipython statements (magics, shell escapes) are not supported (yet).
|
||||
IPython statements (magics, shell escapes) are not supported (yet).
|
||||
|
||||
See also
|
||||
--------
|
||||
|
@ -3,7 +3,7 @@
|
||||
from pygments.token import Token
|
||||
import sys
|
||||
|
||||
from yap_ipython.core.displayhook import DisplayHook
|
||||
from IPython.core.displayhook import DisplayHook
|
||||
|
||||
from prompt_toolkit.formatted_text import fragment_list_width, PygmentsTokens
|
||||
from prompt_toolkit.shortcuts import print_formatted_text
|
||||
@ -14,9 +14,8 @@ class Prompts(object):
|
||||
self.shell = shell
|
||||
|
||||
def vi_mode(self):
|
||||
if not hasattr(self.shell.pt_app, 'editing_mode'):
|
||||
return ''
|
||||
if self.shell.pt_app.editing_mode == 'VI':
|
||||
if (getattr(self.shell.pt_app, 'editing_mode', None) == 'VI'
|
||||
and self.shell.prompt_includes_vi_mode):
|
||||
return '['+str(self.shell.pt_app.app.vi_state.input_mode)[3:6]+'] '
|
||||
return ''
|
||||
|
||||
|
@ -19,12 +19,16 @@ from prompt_toolkit.lexers import PygmentsLexer
|
||||
from prompt_toolkit.patch_stdout import patch_stdout
|
||||
|
||||
import pygments.lexers as pygments_lexers
|
||||
import os
|
||||
|
||||
_completion_sentinel = object()
|
||||
|
||||
def _elide(string, *, min_elide=30):
|
||||
"""
|
||||
If a string is long enough, and has at least 2 dots,
|
||||
If a string is long enough, and has at least 3 dots,
|
||||
replace the middle part with ellipses.
|
||||
|
||||
If a string naming a file is long enough, and has at least 3 slashes,
|
||||
replace the middle part with ellipses.
|
||||
|
||||
If three consecutive dots, or two consecutive dots are encountered these are
|
||||
@ -36,16 +40,20 @@ def _elide(string, *, min_elide=30):
|
||||
if len(string) < min_elide:
|
||||
return string
|
||||
|
||||
parts = string.split('.')
|
||||
object_parts = string.split('.')
|
||||
file_parts = string.split(os.sep)
|
||||
|
||||
if len(parts) <= 3:
|
||||
return string
|
||||
if len(object_parts) > 3:
|
||||
return '{}.{}\N{HORIZONTAL ELLIPSIS}{}.{}'.format(object_parts[0], object_parts[1][0], object_parts[-2][-1], object_parts[-1])
|
||||
|
||||
return '{}.{}\N{HORIZONTAL ELLIPSIS}{}.{}'.format(parts[0], parts[1][0], parts[-2][-1], parts[-1])
|
||||
elif len(file_parts) > 3:
|
||||
return ('{}' + os.sep + '{}\N{HORIZONTAL ELLIPSIS}{}' + os.sep + '{}').format(file_parts[0], file_parts[1][0], file_parts[-2][-1], file_parts[-1])
|
||||
|
||||
return string
|
||||
|
||||
|
||||
def _adjust_completion_text_based_on_context(text, body, offset):
|
||||
if text.endswith('=') and len(body) > offset and body[offset] is '=':
|
||||
if text.endswith('=') and len(body) > offset and body[offset] == '=':
|
||||
return text[:-1]
|
||||
else:
|
||||
return text
|
||||
|
@ -17,6 +17,9 @@ from IPython.core.inputtransformer import *
|
||||
from IPython.core.interactiveshell import *
|
||||
from ipython_genutils.py3compat import builtin_mod
|
||||
|
||||
import copy
|
||||
import json
|
||||
|
||||
from yap_kernel.displayhook import ZMQShellDisplayHook
|
||||
|
||||
import traceback
|
||||
@ -229,6 +232,7 @@ class YAPInputSplitter(InputSplitter):
|
||||
transformed_lines_list.append(transformed)
|
||||
if transformed_lines_list:
|
||||
transformed_lines = '\n'.join(transformed_lines_list)
|
||||
|
||||
else:
|
||||
# Got nothing back from transformers - they must be waiting for
|
||||
# more input.
|
||||
@ -542,7 +546,7 @@ class YAPRun(InteractiveShell):
|
||||
# construct a self.queryuery from a one-line string
|
||||
# self.query is opaque to Python
|
||||
try:
|
||||
program,squery,_ ,howmany = self.prolog_cell(s)
|
||||
program,squery,_ ,howmany = self.prolog_cell(s)
|
||||
# sys.settrace(tracefunc)
|
||||
if self.query and self.os == (program,squery):
|
||||
howmany += self.iterations
|
||||
@ -551,22 +555,29 @@ class YAPRun(InteractiveShell):
|
||||
self.query.close()
|
||||
self.query = None
|
||||
self.answers = []
|
||||
result.result = []
|
||||
self.os = (program,squery)
|
||||
self.iterations = 0
|
||||
pg = jupyter_query(self.engine,program,squery)
|
||||
self.query = Query(self.engine, pg)
|
||||
self.answers = []
|
||||
for answer in self.query:
|
||||
self.answers += [answer]
|
||||
print( answer )
|
||||
self.answers += [copy.deepcopy(answer)]
|
||||
self.iterations += 1
|
||||
|
||||
self.os = None
|
||||
self.query.close()
|
||||
self.query = None
|
||||
if self.answers:
|
||||
sys.stderr.write('Completed, with '+str(self.answers)+'\n')
|
||||
result.result = self.answers
|
||||
sys.stderr.write('\n'+'[ ' +str(len(self.answers))+' answer(s): ]\n[ ')
|
||||
print( self.answers )
|
||||
result.result = json.dumps(self.answers)
|
||||
sys.stderr.write(result.result+' ]\n\n')
|
||||
else:
|
||||
result.result = []
|
||||
return result.result
|
||||
|
||||
|
||||
except Exception as e:
|
||||
sys.stderr.write('Exception '+str(e)+'in query '+ str(self.query)+
|
||||
|
@ -444,11 +444,10 @@ be lost.
|
||||
'$trace_plan'((A|B), M, CP, S, (EA|EB)) :- !,
|
||||
'$trace_plan'(A, M, CP, S, EA),
|
||||
'$trace_plan'(B, M, CP, S, EB).
|
||||
'$trace_plan'(C, M, CP, S, EC),
|
||||
'$trace_plan'((A->*B), M, CP, S, (EA->EB)) :- !,
|
||||
'$trace_plan'((A*->B), M, CP, S, (EA->EB)) :- !,
|
||||
'$trace_plan'(A, M, CP, S, EA),
|
||||
'$trace_plan'(B, M, CP, S, EB).
|
||||
'$trace_plan'((A->*B;C), M, CP, S, (EA->EB;EC)) :- !,
|
||||
'$trace_plan'((A*->B;C), M, CP, S, (EA->EB;EC)) :- !,
|
||||
'$trace_plan'(A, M, CP, S, EA),
|
||||
'$trace_plan'(B, M, CP, S, EB),
|
||||
'$trace_plan'(C, M, CP, S, EC).
|
||||
@ -473,7 +472,7 @@ be lost.
|
||||
|
||||
%% @pred $trace_goal( +Goal, +Module, +CallId, +CallInfo)
|
||||
%%
|
||||
%% Actuallb sy debugs a
|
||||
%% Actually debugs a
|
||||
%% goal!
|
||||
'$trace_goal'(G, M, GoalNumber, _H) :-
|
||||
(
|
||||
|
@ -26,7 +26,7 @@ debug import table
|
||||
mimp :-
|
||||
recorded('$import',I,_),
|
||||
%'$import'(ExportingMod,ImportingMod,G0,G,_,_),_),
|
||||
writeln(I),
|
||||
writeln(I),
|
||||
%(ImportingMod:G :- ExportingMod:G0)),
|
||||
fail.
|
||||
|
||||
@ -39,7 +39,7 @@ fail.
|
||||
true
|
||||
;
|
||||
%% this should have been caught before
|
||||
'$is_system_predicate'(G, prolog)
|
||||
'$is_system_predicate'(G, ImportingMod)
|
||||
->
|
||||
true
|
||||
;
|
||||
@ -113,7 +113,7 @@ fail.
|
||||
'$autoloader_find_predicate'(G0,ExportingMod),
|
||||
ExportingMod \= ImportingMod,
|
||||
(recordzifnot('$import','$import'(ExportingMod,ImportingMod,G0,G0, N ,K),_),
|
||||
\+ '$system_predicate'(G0,prolog)
|
||||
\+ '$is_system_predicate'(G0, ExportingMod)
|
||||
->
|
||||
'$compile'((G:-ExportingMod:G0), reconsult ,(ImportingMod:G:-ExportingMod:G0), ImportingMod, _)
|
||||
;
|
||||
@ -133,7 +133,7 @@ fail.
|
||||
yap_flag(autoload, _, true),
|
||||
yap_flag( unknown, _, Unknown),
|
||||
yap_flag( debug, _, Debug),
|
||||
autoloader:find_predicate(G,ExportingMod).
|
||||
setup_autoloader:find_predicate(G,ExportingMod).
|
||||
|
||||
|
||||
|
||||
|
@ -133,7 +133,7 @@ prolog:message_to_string(Event, Message) :-
|
||||
% to source-location. Note that syntax errors have their own
|
||||
% source-location and should therefore not be handled this way.
|
||||
compose_message( Term, _Level ) -->
|
||||
message(Term), !.
|
||||
message(Term), !.
|
||||
compose_message( query(_QueryResult,_), _Level) -->
|
||||
[].
|
||||
compose_message( absolute_file_path(File), _Level) -->
|
||||
@ -426,14 +426,17 @@ extra_info( error(_,Info), _ ) -->
|
||||
{ '$error_descriptor'(Info, Desc) },
|
||||
{
|
||||
query_exception(errorMsg, Desc, Msg),
|
||||
Msg \= '',
|
||||
Msg \= "",
|
||||
Msg \= []
|
||||
},
|
||||
},
|
||||
!,
|
||||
['~*|user provided data is: ~q' - [10,Msg]],
|
||||
[nl].
|
||||
extra_info( _, _ ) -->
|
||||
[].
|
||||
|
||||
stack_info( _, _ ) --> !.
|
||||
stack_info( error(_,Info), _ ) -->
|
||||
{ '$error_descriptor'(Info, Desc) },
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*************************************************************************
|
||||
/*************************************************************************
|
||||
* *
|
||||
* YAP Prolog *
|
||||
* *
|
||||
@ -57,9 +57,17 @@ prolog:'$protect' :-
|
||||
\+ '$visible'(Name),
|
||||
hide_atom(Name),
|
||||
fail.
|
||||
|
||||
prolog:'$protect' :-
|
||||
recorded('$module','$module'(_F,_DonorM,_SourceF, _AllExports, _Line), R),erase(R), fail.
|
||||
prolog:'$protect' :-
|
||||
recorded('$source_file','$source_file'( _F, _Age, _M), R),erase(R), fail.
|
||||
prolog:'$protect' :-
|
||||
recorded('$lf_loaded','$lf_loaded'( _F, _M, _Reconsult, _UserFile, _OldF, _Line, _Opts), R),erase(R), fail.
|
||||
|
||||
prolog:'$protect'.
|
||||
|
||||
|
||||
/*
|
||||
% hide all atoms who start by '$'
|
||||
'$visible'('$'). /* not $VAR */
|
||||
'$visible'('$VAR'). /* not $VAR */
|
||||
|
12
pl/top.yap
12
pl/top.yap
@ -743,13 +743,13 @@ write_query_answer( Bindings ) :-
|
||||
prolog_flag(agc_margin,_,Old),
|
||||
!.
|
||||
'$loop'(Stream,Status) :-
|
||||
repeat,
|
||||
'$current_module'( OldModule, OldModule ),
|
||||
'$system_catch'( '$enter_command'(Stream,OldModule,Status),
|
||||
repeat,
|
||||
'$current_module'( OldModule, OldModule ),
|
||||
'$system_catch'( '$enter_command'(Stream,OldModule,Status),
|
||||
OldModule, Error,
|
||||
user:'$LoopError'(Error, Status)
|
||||
user:'$LoopError'(Error, Status)
|
||||
),
|
||||
!.
|
||||
!.
|
||||
|
||||
'$boot_loop'(Stream,Where) :-
|
||||
repeat,
|
||||
@ -806,7 +806,7 @@ Command = (H --> B) ->
|
||||
;
|
||||
read_clause(Stream, Command, Options)
|
||||
),
|
||||
'$command'(Command,Vars,Pos, Status).
|
||||
'$command'(Command,Vars,Pos, Status) .
|
||||
|
||||
/** @pred user:expand_term( _T_,- _X_) is dynamic,multifile.
|
||||
|
||||
|
Reference in New Issue
Block a user