error
This commit is contained in:
parent
37992c77be
commit
e5748f3c9f
@ -960,7 +960,9 @@ yap_error_descriptor_t *Yap_GetException(yap_error_descriptor_t *i) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Yap_PrintException(void) { printErr(LOCAL_ActiveError); }
|
||||
void Yap_PrintException(yap_error_descriptor_t *i) {
|
||||
printErr(LOCAL_ActiveError);
|
||||
}
|
||||
|
||||
bool Yap_RaiseException(void) {
|
||||
if (LOCAL_ActiveError == NULL ||
|
||||
|
26
C/yap-args.c
26
C/yap-args.c
@ -145,11 +145,12 @@ static void init_globals(YAP_init_args *yap_init) {
|
||||
}
|
||||
|
||||
const char *Yap_BINDIR, *Yap_ROOTDIR, *Yap_SHAREDIR, *Yap_LIBDIR, *Yap_DLLDIR,
|
||||
*Yap_PLDIR, *Yap_BOOTSTRAP, *Yap_COMMONSDIR,
|
||||
*Yap_INPUT_STARTUP, *Yap_OUTPUT_STARTUP, *Yap_BOOTFILE, *Yap_INCLUDEDIR;
|
||||
*Yap_PLDIR, *Yap_BOOTSTRAP, *Yap_COMMONSDIR, *Yap_INPUT_STARTUP,
|
||||
*Yap_OUTPUT_STARTUP, *Yap_BOOTFILE, *Yap_INCLUDEDIR;
|
||||
|
||||
/**
|
||||
* consult loop in C: used to boot the system, butt supports goal execution and recursive consulting.
|
||||
* consult loop in C: used to boot the system, butt supports goal execution and
|
||||
* recursive consulting.
|
||||
*
|
||||
* */
|
||||
static bool consult(const char *b_file USES_REGS) {
|
||||
@ -204,10 +205,9 @@ static bool consult(const char *b_file USES_REGS) {
|
||||
YAP_CompileClause(t);
|
||||
}
|
||||
yap_error_descriptor_t *errd;
|
||||
if ((errd =
|
||||
Yap_GetException(LOCAL_ActiveError))) {
|
||||
fprintf(stderr, "%s:%ld:0: Error %s %s Found\n", errd->errorFile, (long int) errd->errorLine, errd->classAsText,
|
||||
errd->errorAsText);
|
||||
if ((errd = Yap_GetException(LOCAL_ActiveError))) {
|
||||
fprintf(stderr, "%s:%ld:0: Error %s %s Found\n", errd->errorFile,
|
||||
(long int)errd->errorLine, errd->classAsText, errd->errorAsText);
|
||||
}
|
||||
} while (true);
|
||||
BACKUP_MACHINE_REGS();
|
||||
@ -222,8 +222,8 @@ static bool consult(const char *b_file USES_REGS) {
|
||||
|
||||
///
|
||||
///
|
||||
static const char *sel(bool dir, bool ok1, const char *s1, bool ok2, const char *s2,
|
||||
...) {
|
||||
static const char *sel(bool dir, bool ok1, const char *s1, bool ok2,
|
||||
const char *s2, ...) {
|
||||
if (ok1 && s1)
|
||||
return s1;
|
||||
if (ok2)
|
||||
@ -982,7 +982,8 @@ yap_init->PrologCannotHandleInterrupts = true;
|
||||
|
||||
static void end_init(YAP_init_args *iap) {
|
||||
YAP_initialized = true;
|
||||
if (iap->HaltAfterBoot) Yap_exit(0);
|
||||
if (iap->HaltAfterBoot)
|
||||
Yap_exit(0);
|
||||
LOCAL_PrologMode &= ~BootMode;
|
||||
CurrentModule = USER_MODULE;
|
||||
}
|
||||
@ -1037,8 +1038,7 @@ X_API void YAP_Init(YAP_init_args *yap_init) {
|
||||
Yap_ExecutionMode = yap_init->ExecutionMode;
|
||||
Yap_set_locations(yap_init);
|
||||
|
||||
if (do_bootstrap ||
|
||||
!try_restore ||
|
||||
if (do_bootstrap || !try_restore ||
|
||||
!Yap_SavedInfo(Yap_INPUT_STARTUP, &minfo.Trail, &minfo.Stack,
|
||||
&minfo.Heap)) {
|
||||
init_globals(yap_init);
|
||||
@ -1046,6 +1046,7 @@ X_API void YAP_Init(YAP_init_args *yap_init) {
|
||||
start_modules();
|
||||
CurrentModule = PROLOG_MODULE;
|
||||
TermEof = MkAtomTerm(Yap_LookupAtom("end_of_file"));
|
||||
LOCAL_consult_level = -1;
|
||||
consult(Yap_BOOTSTRAP PASS_REGS);
|
||||
setAtomicGlobalPrologFlag(RESOURCE_DATABASE_FLAG,
|
||||
MkAtomTerm(Yap_LookupAtom(Yap_BOOTFILE)));
|
||||
@ -1060,6 +1061,7 @@ X_API void YAP_Init(YAP_init_args *yap_init) {
|
||||
MkAtomTerm(Yap_LookupAtom(Yap_INPUT_STARTUP)));
|
||||
setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, true);
|
||||
}
|
||||
LOCAL_consult_level = -1;
|
||||
}
|
||||
YAP_RunGoalOnce(TermInitProlog);
|
||||
if (yap_init->install && Yap_OUTPUT_STARTUP) {
|
||||
|
39
CXX/yapdb.hh
39
CXX/yapdb.hh
@ -2,7 +2,6 @@
|
||||
///
|
||||
/// @brief C++ Interface to generated code.
|
||||
|
||||
|
||||
#ifndef _YAPDB_H
|
||||
#define _YAPDB_H
|
||||
|
||||
@ -10,7 +9,6 @@
|
||||
|
||||
#define YAP_CPP_DB_INTERFACE 1
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @defgroup yap-cplus-db-interface Data-Base Component of YAP interface.
|
||||
@ -72,11 +70,10 @@ class X_API YAPModuleProp : public YAPProp {
|
||||
|
||||
public:
|
||||
YAPModuleProp(YAPModule tmod) { m = Yap_GetModuleEntry(tmod.gt()); };
|
||||
YAPModuleProp() { m = Yap_GetModuleEntry(YAP_CurrentModule()); };
|
||||
YAPModuleProp() { m = Yap_GetModuleEntry(Yap_CurrentModule()); };
|
||||
virtual YAPModule module() { return YAPModule(m->AtomOfME); };
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Predicates
|
||||
*
|
||||
@ -92,31 +89,31 @@ protected:
|
||||
/// auxiliary routine to find a predicate in the current module.
|
||||
|
||||
/// auxiliary routine to find a predicate in the current module.
|
||||
PredEntry *getPred(Term &t, CELL *& outp);
|
||||
PredEntry *getPred(Term &t, Term &tm, CELL *&outp);
|
||||
|
||||
PredEntry *asPred() { return ap; };
|
||||
|
||||
/// Empty constructor for predicates
|
||||
///
|
||||
/// Just do nothing.
|
||||
inline YAPPredicate() {
|
||||
}
|
||||
inline YAPPredicate() {}
|
||||
YAPPredicate(Term &to, Term &tmod, CELL *&ts, const char *pname);
|
||||
|
||||
|
||||
/// Term constructor for predicates
|
||||
///
|
||||
/// It is just a call to getPred
|
||||
inline YAPPredicate(Term t, CELL *&v) {
|
||||
if (t) {
|
||||
ap = getPred(t, v);
|
||||
Term tm = Yap_CurrentModule();
|
||||
ap = getPred(t, tm, v);
|
||||
}
|
||||
}
|
||||
|
||||
inline YAPPredicate(Term t) {
|
||||
if (t) {
|
||||
CELL *v = nullptr;
|
||||
ap = getPred(t, v);
|
||||
Term tm = Yap_CurrentModule();
|
||||
ap = getPred(t, tm, v);
|
||||
}
|
||||
}
|
||||
|
||||
@ -124,13 +121,14 @@ inline YAPPredicate(Term t) {
|
||||
///
|
||||
/// It is just a call to getPred
|
||||
inline YAPPredicate(YAPTerm t, CELL *&v) {
|
||||
Term tp = t.term();
|
||||
ap = getPred(tp, v);
|
||||
Term tp = t.term(), tm = Yap_CurrentModule();
|
||||
ap = getPred(tp, tm, v);
|
||||
}
|
||||
inline YAPPredicate(YAPTerm t) {
|
||||
CELL *v = nullptr;
|
||||
Term tp = t.term();
|
||||
ap = getPred(tp, v);
|
||||
Term tm = Yap_CurrentModule();
|
||||
ap = getPred(tp, tm, v);
|
||||
}
|
||||
|
||||
/// Cast constructor for predicates,
|
||||
@ -144,9 +142,7 @@ inline YAPPredicate(YAPTerm t) {
|
||||
ap = RepPredProp(PredPropByFunc(f, mod));
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/// String constructor for predicates
|
||||
///
|
||||
/// It also communicates the array of arguments t[]
|
||||
@ -164,12 +160,12 @@ public:
|
||||
return;
|
||||
throw YAPError();
|
||||
}
|
||||
ap = getPred(tout, nts);
|
||||
Term tm = Yap_CurrentModule();
|
||||
ap = getPred(tout, tm, nts);
|
||||
tout = Yap_SaveTerm(tout);
|
||||
names = YAPPairTerm(tnames);
|
||||
}
|
||||
|
||||
|
||||
/// Functor constructor for predicates
|
||||
///
|
||||
/// Asssumes that we use the current module.
|
||||
@ -194,7 +190,6 @@ public:
|
||||
///
|
||||
YAPPredicate(YAPAtom at);
|
||||
|
||||
|
||||
/// Mod:Name/Arity constructor for predicates.
|
||||
///
|
||||
inline YAPPredicate(YAPAtom at, uintptr_t arity, YAPModule mod) {
|
||||
@ -214,7 +209,7 @@ public:
|
||||
///
|
||||
inline YAPPredicate(const char *at, uintptr_t arity) {
|
||||
ap = RepPredProp(PredPropByFunc(Yap_MkFunctor(Yap_LookupAtom(at), arity),
|
||||
CurrentModule));
|
||||
Yap_CurrentModule()));
|
||||
};
|
||||
|
||||
/// char */module constructor for predicates.
|
||||
@ -256,7 +251,8 @@ public:
|
||||
YAPFunctor functor() {
|
||||
if (ap->ArityOfPE)
|
||||
return YAPFunctor(ap->FunctorOfPred);
|
||||
Yap_ThrowError(DOMAIN_ERROR_OUT_OF_RANGE, MkIntTerm(0), "YAPFunctor::functor");
|
||||
Yap_ThrowError(DOMAIN_ERROR_OUT_OF_RANGE, MkIntTerm(0),
|
||||
"YAPFunctor::functor");
|
||||
}
|
||||
|
||||
/// arity of predicate
|
||||
@ -302,8 +298,7 @@ public:
|
||||
YAP_UserCPred cut = 0, YAP_Arity extra = 0, bool test = false)
|
||||
: YAPPredicate(name, arity, module) {
|
||||
if (retry) {
|
||||
YAP_UserBackCutCPredicate(name.getName(), call, retry, cut, arity, extra
|
||||
);
|
||||
YAP_UserBackCutCPredicate(name.getName(), call, retry, cut, arity, extra);
|
||||
} else {
|
||||
if (test) {
|
||||
YAP_UserCPredicate(name.getName(), call, arity);
|
||||
|
10
CXX/yapi.cpp
10
CXX/yapi.cpp
@ -529,6 +529,8 @@ bool YAPEngine::mgoal(Term t, Term tmod, bool release) {
|
||||
q.p = P;
|
||||
q.cp = CP;
|
||||
PredEntry *ap = nullptr;
|
||||
std::cerr << "mgoal " << YAPTerm(t).text() << "\n";
|
||||
std::cerr << "mgoal " << YAPTerm(tmod).text() << "\n";
|
||||
if (IsStringTerm(tmod))
|
||||
tmod = MkAtomTerm(Yap_LookupAtom(StringOfTerm(tmod)));
|
||||
YAPPredicate *p = new YAPPredicate(t, tmod, ts, "C++");
|
||||
@ -553,7 +555,8 @@ bool YAPEngine::mgoal(Term t, Term tmod, bool release) {
|
||||
//__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec ");
|
||||
|
||||
result = (bool)YAP_EnterGoal(ap, nullptr, &q);
|
||||
//std::cerr << "mgoal " << YAPTerm(t).text() << "\n";
|
||||
std::cerr << "mgoal " << YAPTerm(t).text() << "\n";
|
||||
std::cerr << "mgoal " << YAPTerm(tmod).text() << "\n";
|
||||
|
||||
YAP_LeaveGoal(result && !release, &q);
|
||||
// PyEval_RestoreThread(_save);
|
||||
@ -574,7 +577,7 @@ void YAPEngine::release() {
|
||||
Term YAPEngine::fun(Term t) {
|
||||
CACHE_REGS
|
||||
BACKUP_MACHINE_REGS();
|
||||
Term tmod = CurrentModule, *ts = nullptr;
|
||||
Term tmod = Yap_CurrentModule(), *ts = nullptr;
|
||||
PredEntry *ap;
|
||||
arity_t arity;
|
||||
Functor f;
|
||||
@ -874,9 +877,8 @@ YAPPredicate::YAPPredicate(YAPAtom at, uintptr_t arity) {
|
||||
}
|
||||
|
||||
/// auxiliary routine to find a predicate in the current module.
|
||||
PredEntry *YAPPredicate::getPred(Term &t, CELL *&out) {
|
||||
PredEntry *YAPPredicate::getPred(Term &t, Term &m, CELL *&out) {
|
||||
CACHE_REGS
|
||||
Term m = Yap_CurrentModule();
|
||||
t = Yap_StripModule(t, &m);
|
||||
|
||||
if (IsVarTerm(t) || IsNumTerm(t)) {
|
||||
|
11
CXX/yapq.hh
11
CXX/yapq.hh
@ -326,14 +326,15 @@ public:
|
||||
/// build a query from a Prolog term (internal)
|
||||
YAPQuery *qt(Term t) { return new YAPQuery(YAPTerm(t)); };
|
||||
/// current module for the engine
|
||||
YAPModule currentModule() { return YAPModule(); }
|
||||
Term Yap_CurrentModule() { return CurrentModule; }
|
||||
/// given a handle, fetch a term from the engine
|
||||
inline YAPTerm getTerm(yhandle_t h) { return YAPTerm(h); }
|
||||
/// current directory for the engine
|
||||
bool call(YAPPredicate ap, YAPTerm ts[]);
|
||||
/// current directory for the engine
|
||||
bool goal(YAPTerm Yt, YAPModule module, bool release=false)
|
||||
{ return mgoal(Yt.term(),module.term(), release); };
|
||||
bool goal(YAPTerm Yt, YAPModule module, bool release = false) {
|
||||
return mgoal(Yt.term(), module.term(), release);
|
||||
};
|
||||
/// ru1n a goal in a module.
|
||||
///
|
||||
/// By default, memory will only be fully
|
||||
@ -342,7 +343,9 @@ public:
|
||||
bool mgoal(Term t, Term tmod, bool release = false);
|
||||
/// current directory for the engine
|
||||
|
||||
bool goal(Term t, bool release=false) { return mgoal(t, CurrentModule, release); }
|
||||
bool goal(Term t, bool release = false) {
|
||||
return mgoal(t, Yap_CurrentModule(), release);
|
||||
}
|
||||
/// reset Prolog state
|
||||
void reSet();
|
||||
/// assune that there are no stack pointers, just release memory
|
||||
|
153
H/Yatom.h
153
H/Yatom.h
@ -20,15 +20,11 @@
|
||||
#ifndef YATOM_H
|
||||
#define YATOM_H 1
|
||||
|
||||
|
||||
INLINE_ONLY Atom AbsAtom(AtomEntry *p);
|
||||
INLINE_ONLY AtomEntry *RepAtom(Atom a);
|
||||
|
||||
|
||||
#ifdef USE_OFFSETS
|
||||
INLINE_ONLY Atom AbsAtom(AtomEntry *p) {
|
||||
return (Atom)(Addr(p) - AtomBase);
|
||||
}
|
||||
INLINE_ONLY Atom AbsAtom(AtomEntry *p) { return (Atom)(Addr(p) - AtomBase); }
|
||||
|
||||
INLINE_ONLY AtomEntry *RepAtom(Atom a) {
|
||||
return (AtomEntry *) (AtomBase + Unsigned (a);
|
||||
@ -36,9 +32,7 @@ INLINE_ONLY AtomEntry *RepAtom(Atom a) {
|
||||
|
||||
#else
|
||||
INLINE_ONLY Atom AbsAtom(AtomEntry *p) { return (Atom)(p); }
|
||||
INLINE_ONLY AtomEntry *RepAtom(Atom a) {
|
||||
return (AtomEntry *)(a);
|
||||
}
|
||||
INLINE_ONLY AtomEntry *RepAtom(Atom a) { return (AtomEntry *)(a); }
|
||||
|
||||
#endif
|
||||
|
||||
@ -46,9 +40,7 @@ INLINE_ONLY AtomEntry *RepAtom(Atom a) {
|
||||
|
||||
INLINE_ONLY Prop AbsProp(PropEntry *p);
|
||||
|
||||
INLINE_ONLY Prop AbsProp(PropEntry *p) {
|
||||
return (Prop)(Addr(p) - AtomBase);
|
||||
}
|
||||
INLINE_ONLY Prop AbsProp(PropEntry *p) { return (Prop)(Addr(p) - AtomBase); }
|
||||
|
||||
INLINE_ONLY PropEntry *RepProp(Prop p);
|
||||
|
||||
@ -64,9 +56,7 @@ INLINE_ONLY Prop AbsProp(PropEntry *p) { return (Prop)(p); }
|
||||
|
||||
INLINE_ONLY PropEntry *RepProp(Prop p);
|
||||
|
||||
INLINE_ONLY PropEntry *RepProp(Prop p) {
|
||||
return (PropEntry *)(p);
|
||||
}
|
||||
INLINE_ONLY PropEntry *RepProp(Prop p) { return (PropEntry *)(p); }
|
||||
|
||||
#endif
|
||||
|
||||
@ -88,15 +78,11 @@ INLINE_ONLY Prop AbsFunctorProp(FunctorEntry *p) {
|
||||
|
||||
INLINE_ONLY FunctorEntry *RepFunctorProp(Prop p);
|
||||
|
||||
INLINE_ONLY FunctorEntry *RepFunctorProp(Prop p) {
|
||||
return (FunctorEntry *)(p);
|
||||
}
|
||||
INLINE_ONLY FunctorEntry *RepFunctorProp(Prop p) { return (FunctorEntry *)(p); }
|
||||
|
||||
INLINE_ONLY Prop AbsFunctorProp(FunctorEntry *p);
|
||||
|
||||
INLINE_ONLY Prop AbsFunctorProp(FunctorEntry *p) {
|
||||
return (Prop)(p);
|
||||
}
|
||||
INLINE_ONLY Prop AbsFunctorProp(FunctorEntry *p) { return (Prop)(p); }
|
||||
|
||||
#endif
|
||||
|
||||
@ -172,15 +158,11 @@ INLINE_ONLY Prop AbsGlobalProp(GlobalEntry *p) {
|
||||
|
||||
INLINE_ONLY GlobalEntry *RepGlobalProp(Prop p);
|
||||
|
||||
INLINE_ONLY GlobalEntry *RepGlobalProp(Prop p) {
|
||||
return (GlobalEntry *)(p);
|
||||
}
|
||||
INLINE_ONLY GlobalEntry *RepGlobalProp(Prop p) { return (GlobalEntry *)(p); }
|
||||
|
||||
INLINE_ONLY Prop AbsGlobalProp(GlobalEntry *p);
|
||||
|
||||
INLINE_ONLY Prop AbsGlobalProp(GlobalEntry *p) {
|
||||
return (Prop)(p);
|
||||
}
|
||||
INLINE_ONLY Prop AbsGlobalProp(GlobalEntry *p) { return (Prop)(p); }
|
||||
|
||||
#endif
|
||||
|
||||
@ -221,17 +203,13 @@ INLINE_ONLY ModEntry *RepModProp(Prop p) {
|
||||
|
||||
INLINE_ONLY Prop AbsModProp(ModEntry *p);
|
||||
|
||||
INLINE_ONLY Prop AbsModProp(ModEntry *p) {
|
||||
return (Prop)(Addr(p) - AtomBase);
|
||||
}
|
||||
INLINE_ONLY Prop AbsModProp(ModEntry *p) { return (Prop)(Addr(p) - AtomBase); }
|
||||
|
||||
#else
|
||||
|
||||
INLINE_ONLY ModEntry *RepModProp(Prop p);
|
||||
|
||||
INLINE_ONLY ModEntry *RepModProp(Prop p) {
|
||||
return (ModEntry *)(p);
|
||||
}
|
||||
INLINE_ONLY ModEntry *RepModProp(Prop p) { return (ModEntry *)(p); }
|
||||
|
||||
INLINE_ONLY Prop AbsModProp(ModEntry *p);
|
||||
|
||||
@ -245,9 +223,7 @@ INLINE_ONLY Prop AbsModProp(ModEntry *p) { return (Prop)(p); }
|
||||
|
||||
INLINE_ONLY bool IsModProperty(int);
|
||||
|
||||
INLINE_ONLY bool IsModProperty(int flags) {
|
||||
return flags == ModProperty;
|
||||
}
|
||||
INLINE_ONLY bool IsModProperty(int flags) { return flags == ModProperty; }
|
||||
|
||||
/* Flags on module. Most of these flags are copied to the read context
|
||||
in pl-read.c.
|
||||
@ -305,9 +281,7 @@ INLINE_ONLY OpEntry *RepOpProp(Prop p) {
|
||||
|
||||
INLINE_ONLY Prop AbsOpProp(OpEntry *p);
|
||||
|
||||
INLINE_ONLY Prop AbsOpProp(OpEntry *p) {
|
||||
return (Prop)(Addr(p) - AtomBase);
|
||||
}
|
||||
INLINE_ONLY Prop AbsOpProp(OpEntry *p) { return (Prop)(Addr(p) - AtomBase); }
|
||||
|
||||
#else
|
||||
|
||||
@ -324,9 +298,7 @@ INLINE_ONLY Prop AbsOpProp(OpEntry *p) { return (Prop)(p); }
|
||||
|
||||
INLINE_ONLY bool IsOpProperty(PropFlags);
|
||||
|
||||
INLINE_ONLY bool IsOpProperty(PropFlags flags) {
|
||||
return flags == OpProperty;
|
||||
}
|
||||
INLINE_ONLY bool IsOpProperty(PropFlags flags) { return flags == OpProperty; }
|
||||
|
||||
typedef enum { INFIX_OP = 0, POSFIX_OP = 1, PREFIX_OP = 2 } op_type;
|
||||
|
||||
@ -365,17 +337,13 @@ INLINE_ONLY ExpEntry *RepExpProp(Prop p) {
|
||||
|
||||
INLINE_ONLY Prop AbsExpProp(ExpEntry *p);
|
||||
|
||||
INLINE_ONLY Prop AbsExpProp(ExpEntry *p) {
|
||||
return (Prop)(Addr(p) - AtomBase);
|
||||
}
|
||||
INLINE_ONLY Prop AbsExpProp(ExpEntry *p) { return (Prop)(Addr(p) - AtomBase); }
|
||||
|
||||
#else
|
||||
|
||||
INLINE_ONLY ExpEntry *RepExpProp(Prop p);
|
||||
|
||||
INLINE_ONLY ExpEntry *RepExpProp(Prop p) {
|
||||
return (ExpEntry *)(p);
|
||||
}
|
||||
INLINE_ONLY ExpEntry *RepExpProp(Prop p) { return (ExpEntry *)(p); }
|
||||
|
||||
INLINE_ONLY Prop AbsExpProp(ExpEntry *p);
|
||||
|
||||
@ -411,17 +379,13 @@ INLINE_ONLY ValEntry *RepValProp(Prop p) {
|
||||
|
||||
INLINE_ONLY Prop AbsValProp(ValEntry *p);
|
||||
|
||||
INLINE_ONLY Prop AbsValProp(ValEntry *p) {
|
||||
return (Prop)(Addr(p) - AtomBase);
|
||||
}
|
||||
INLINE_ONLY Prop AbsValProp(ValEntry *p) { return (Prop)(Addr(p) - AtomBase); }
|
||||
|
||||
#else
|
||||
|
||||
INLINE_ONLY ValEntry *RepValProp(Prop p);
|
||||
|
||||
INLINE_ONLY ValEntry *RepValProp(Prop p) {
|
||||
return (ValEntry *)(p);
|
||||
}
|
||||
INLINE_ONLY ValEntry *RepValProp(Prop p) { return (ValEntry *)(p); }
|
||||
|
||||
INLINE_ONLY Prop AbsValProp(ValEntry *p);
|
||||
|
||||
@ -592,10 +556,7 @@ INLINE_ONLY Prop AbsPredProp(PredEntry *p) {
|
||||
|
||||
INLINE_ONLY PredEntry *RepPredProp(Prop p);
|
||||
|
||||
INLINE_ONLY PredEntry *RepPredProp(Prop p) {
|
||||
|
||||
return (PredEntry *)(p);
|
||||
}
|
||||
INLINE_ONLY PredEntry *RepPredProp(Prop p) { return (PredEntry *)(p); }
|
||||
|
||||
INLINE_ONLY Prop AbsPredProp(PredEntry *p);
|
||||
|
||||
@ -755,9 +716,7 @@ INLINE_ONLY Term MkDBRefTerm(DBRef p) {
|
||||
|
||||
INLINE_ONLY DBRef DBRefOfTerm(Term t);
|
||||
|
||||
INLINE_ONLY DBRef DBRefOfTerm(Term t) {
|
||||
return (DBRef)(((DBRef)(RepAppl(t))));
|
||||
}
|
||||
INLINE_ONLY DBRef DBRefOfTerm(Term t) { return (DBRef)(((DBRef)(RepAppl(t)))); }
|
||||
|
||||
INLINE_ONLY int IsRefTerm(Term);
|
||||
|
||||
@ -767,9 +726,7 @@ INLINE_ONLY int IsRefTerm(Term t) {
|
||||
|
||||
INLINE_ONLY CODEADDR RefOfTerm(Term t);
|
||||
|
||||
INLINE_ONLY CODEADDR RefOfTerm(Term t) {
|
||||
return (CODEADDR)(DBRefOfTerm(t));
|
||||
}
|
||||
INLINE_ONLY CODEADDR RefOfTerm(Term t) { return (CODEADDR)(DBRefOfTerm(t)); }
|
||||
|
||||
typedef struct struct_dbentry {
|
||||
Prop NextOfPE; /* used to chain properties */
|
||||
@ -822,9 +779,7 @@ INLINE_ONLY DBProp RepDBProp(Prop p) {
|
||||
|
||||
INLINE_ONLY Prop AbsDBProp(DBProp p);
|
||||
|
||||
INLINE_ONLY Prop AbsDBProp(DBProp p) {
|
||||
return (Prop)(Addr(p) - AtomBase);
|
||||
}
|
||||
INLINE_ONLY Prop AbsDBProp(DBProp p) { return (Prop)(Addr(p) - AtomBase); }
|
||||
|
||||
#else
|
||||
|
||||
@ -885,9 +840,7 @@ INLINE_ONLY BlackBoardEntry *RepBBProp(Prop p) {
|
||||
|
||||
INLINE_ONLY Prop AbsBBProp(BlackBoardEntry *p);
|
||||
|
||||
INLINE_ONLY Prop AbsBBProp(BlackBoardEntry *p) {
|
||||
return (Prop)(p);
|
||||
}
|
||||
INLINE_ONLY Prop AbsBBProp(BlackBoardEntry *p) { return (Prop)(p); }
|
||||
|
||||
#endif
|
||||
|
||||
@ -924,9 +877,7 @@ INLINE_ONLY Prop AbsHoldProp(HoldEntry *p) {
|
||||
|
||||
INLINE_ONLY HoldEntry *RepHoldProp(Prop p);
|
||||
|
||||
INLINE_ONLY HoldEntry *RepHoldProp(Prop p) {
|
||||
return (HoldEntry *)(p);
|
||||
}
|
||||
INLINE_ONLY HoldEntry *RepHoldProp(Prop p) { return (HoldEntry *)(p); }
|
||||
|
||||
INLINE_ONLY Prop AbsHoldProp(HoldEntry *p);
|
||||
|
||||
@ -968,9 +919,7 @@ INLINE_ONLY TranslationEntry *RepTranslationProp(Prop p) {
|
||||
|
||||
INLINE_ONLY Prop AbsTranslationProp(TranslationEntry *p);
|
||||
|
||||
INLINE_ONLY Prop AbsTranslationProp(TranslationEntry *p) {
|
||||
return (Prop)(p);
|
||||
}
|
||||
INLINE_ONLY Prop AbsTranslationProp(TranslationEntry *p) { return (Prop)(p); }
|
||||
|
||||
#endif
|
||||
#define TranslationProperty 0xfff4
|
||||
@ -1027,9 +976,7 @@ INLINE_ONLY Prop AbsMutexProp(MutexEntry *p) {
|
||||
|
||||
INLINE_ONLY MutexEntry *RepMutexProp(Prop p);
|
||||
|
||||
INLINE_ONLY MutexEntry *RepMutexProp(Prop p) {
|
||||
return (MutexEntry *)(p);
|
||||
}
|
||||
INLINE_ONLY MutexEntry *RepMutexProp(Prop p) { return (MutexEntry *)(p); }
|
||||
|
||||
INLINE_ONLY Prop AbsMutexProp(MutexEntry *p);
|
||||
|
||||
@ -1151,9 +1098,7 @@ INLINE_ONLY Prop AbsStaticArrayProp(StaticArrayEntry *p) {
|
||||
|
||||
INLINE_ONLY ArrayEntry *RepArrayProp(Prop p);
|
||||
|
||||
INLINE_ONLY ArrayEntry *RepArrayProp(Prop p) {
|
||||
return (ArrayEntry *)(p);
|
||||
}
|
||||
INLINE_ONLY ArrayEntry *RepArrayProp(Prop p) { return (ArrayEntry *)(p); }
|
||||
|
||||
INLINE_ONLY Prop AbsArrayProp(ArrayEntry *p);
|
||||
|
||||
@ -1167,9 +1112,7 @@ INLINE_ONLY StaticArrayEntry *RepStaticArrayProp(Prop p) {
|
||||
|
||||
INLINE_ONLY Prop AbsStaticArrayProp(StaticArrayEntry *p);
|
||||
|
||||
INLINE_ONLY Prop AbsStaticArrayProp(StaticArrayEntry *p) {
|
||||
return (Prop)(p);
|
||||
}
|
||||
INLINE_ONLY Prop AbsStaticArrayProp(StaticArrayEntry *p) { return (Prop)(p); }
|
||||
|
||||
#endif
|
||||
#define ArrayProperty ((PropFlags)0xfff7)
|
||||
@ -1217,9 +1160,7 @@ INLINE_ONLY YAP_BlobPropEntry *RepBlobProp(Prop p) {
|
||||
|
||||
INLINE_ONLY Prop AbsBlobProp(YAP_BlobPropEntry *p);
|
||||
|
||||
INLINE_ONLY Prop AbsBlobProp(YAP_BlobPropEntry *p) {
|
||||
return (Prop)(p);
|
||||
}
|
||||
INLINE_ONLY Prop AbsBlobProp(YAP_BlobPropEntry *p) { return (Prop)(p); }
|
||||
|
||||
#endif
|
||||
|
||||
@ -1240,9 +1181,7 @@ INLINE_ONLY bool IsBlob(Atom at) {
|
||||
|
||||
INLINE_ONLY bool IsValProperty(PropFlags);
|
||||
|
||||
INLINE_ONLY bool IsValProperty(PropFlags flags) {
|
||||
return flags == ValProperty;
|
||||
}
|
||||
INLINE_ONLY bool IsValProperty(PropFlags flags) { return flags == ValProperty; }
|
||||
|
||||
/* flag property entry structure */
|
||||
|
||||
@ -1270,17 +1209,13 @@ INLINE_ONLY FlagEntry *RepFlagProp(Prop p) {
|
||||
|
||||
INLINE_ONLY Prop AbsFlagProp(FlagEntry *p);
|
||||
|
||||
INLINE_ONLY Prop AbsValProp(FlagEntry *p) {
|
||||
return (Prop)(Addr(p) - AtomBase);
|
||||
}
|
||||
INLINE_ONLY Prop AbsValProp(FlagEntry *p) { return (Prop)(Addr(p) - AtomBase); }
|
||||
|
||||
#else
|
||||
|
||||
INLINE_ONLY FlagEntry *RepFlagProp(Prop p);
|
||||
|
||||
INLINE_ONLY FlagEntry *RepFlagProp(Prop p) {
|
||||
return (FlagEntry *)(p);
|
||||
}
|
||||
INLINE_ONLY FlagEntry *RepFlagProp(Prop p) { return (FlagEntry *)(p); }
|
||||
|
||||
INLINE_ONLY Prop AbsFlagProp(FlagEntry *p);
|
||||
|
||||
@ -1297,7 +1232,6 @@ INLINE_ONLY bool IsFlagProperty(PropFlags flags) {
|
||||
|
||||
/* Proto types */
|
||||
|
||||
|
||||
extern char *Yap_TermToBuffer(Term t, int flags);
|
||||
|
||||
extern Term Yap_BufferToTerm(const char *s, Term opts);
|
||||
@ -1337,17 +1271,14 @@ Prop Yap_GetAPropHavingLock(AtomEntry *, PropFlags);
|
||||
|
||||
INLINE_ONLY UInt PRED_HASH(FunctorEntry *, Term, UInt);
|
||||
|
||||
INLINE_ONLY UInt PRED_HASH(FunctorEntry *fe, Term cur_mod,
|
||||
UInt size) {
|
||||
INLINE_ONLY UInt PRED_HASH(FunctorEntry *fe, Term cur_mod, UInt size) {
|
||||
return (((CELL)fe + cur_mod) >> 2) % size;
|
||||
}
|
||||
|
||||
INLINE_ONLY Prop GetPredPropByFuncAndModHavingLock(FunctorEntry *,
|
||||
Term);
|
||||
INLINE_ONLY Prop GetPredPropByFuncAndModHavingLock(FunctorEntry *, Term);
|
||||
INLINE_ONLY Prop PredPropByFuncAndMod(FunctorEntry *, Term);
|
||||
INLINE_ONLY Prop PredPropByAtomAndMod(Atom, Term);
|
||||
INLINE_ONLY Prop GetPredPropByFuncHavingLock(FunctorEntry *,
|
||||
Term);
|
||||
INLINE_ONLY Prop GetPredPropByFuncHavingLock(FunctorEntry *, Term);
|
||||
INLINE_ONLY Prop PredPropByFunc(Functor fe, Term cur_mod);
|
||||
INLINE_ONLY Prop PredPropByAtom(Atom at, Term cur_mod);
|
||||
|
||||
@ -1355,8 +1286,7 @@ INLINE_ONLY Prop PredPropByAtom(Atom at, Term cur_mod);
|
||||
|
||||
Prop Yap_NewThreadPred(struct pred_entry *CACHE_TYPE);
|
||||
Prop Yap_NewPredPropByFunctor(Functor, Term);
|
||||
INLINE_ONLY struct pred_entry *
|
||||
Yap_GetThreadPred(struct pred_entry *CACHE_TYPE);
|
||||
INLINE_ONLY struct pred_entry *Yap_GetThreadPred(struct pred_entry *CACHE_TYPE);
|
||||
|
||||
INLINE_ONLY struct pred_entry *
|
||||
Yap_GetThreadPred(struct pred_entry *ap USES_REGS) {
|
||||
@ -1374,8 +1304,7 @@ Yap_GetThreadPred(struct pred_entry *ap USES_REGS) {
|
||||
}
|
||||
#endif
|
||||
|
||||
INLINE_ONLY Prop GetPredPropByFuncHavingLock(FunctorEntry *fe,
|
||||
Term cur_mod) {
|
||||
INLINE_ONLY Prop GetPredPropByFuncHavingLock(FunctorEntry *fe, Term cur_mod) {
|
||||
PredEntry *p;
|
||||
|
||||
if (!(p = RepPredProp(fe->PropsOfFE))) {
|
||||
@ -1428,8 +1357,8 @@ INLINE_ONLY Prop PredPropByFunc(Functor fe, Term cur_mod)
|
||||
return Yap_NewPredPropByFunctor(fe, cur_mod);
|
||||
}
|
||||
|
||||
INLINE_ONLY Prop
|
||||
GetPredPropByFuncAndModHavingLock(FunctorEntry *fe, Term cur_mod) {
|
||||
INLINE_ONLY Prop GetPredPropByFuncAndModHavingLock(FunctorEntry *fe,
|
||||
Term cur_mod) {
|
||||
PredEntry *p;
|
||||
|
||||
if (!(p = RepPredProp(fe->PropsOfFE))) {
|
||||
@ -1574,9 +1503,7 @@ INLINE_ONLY const char *AtomName(Atom at);
|
||||
*
|
||||
* @return a ponter to an immutable sequence of characters.
|
||||
*/
|
||||
INLINE_ONLY const char *AtomName(Atom at) {
|
||||
return RepAtom(at)->rep.uStrOfAE;
|
||||
}
|
||||
INLINE_ONLY const char *AtomName(Atom at) { return RepAtom(at)->rep.uStrOfAE; }
|
||||
|
||||
INLINE_ONLY const char *AtomTermName(Term t);
|
||||
|
||||
@ -1600,7 +1527,7 @@ extern Term MkErrorTerm(yap_error_descriptor_t *t);
|
||||
extern bool Yap_ResetException(yap_error_descriptor_t *i);
|
||||
extern bool Yap_HasException(void);
|
||||
extern yap_error_descriptor_t *Yap_GetException();
|
||||
extern void Yap_PrintException(void);
|
||||
extern void Yap_PrintException(yap_error_descriptor_t *i);
|
||||
INLINE_ONLY bool Yap_HasException(void) {
|
||||
return LOCAL_ActiveError->errorNo != YAP_NO_ERROR;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
l/****************************************************************************
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2012 Denis Shienkov <denis.shienkov@gmail.com>
|
||||
** Copyright (C) 2012 Laszlo Papp <lpapp@kde.org>
|
||||
@ -37,8 +37,7 @@ l/****************************************************************************
|
||||
|
||||
#include <QPlainTextEdit>
|
||||
|
||||
class Console : public QPlainTextEdit
|
||||
{
|
||||
class Console : public QPlainTextEdit {
|
||||
Q_OBJECT
|
||||
|
||||
signals:
|
||||
@ -59,7 +58,6 @@ protected:
|
||||
|
||||
private:
|
||||
bool localEchoEnabled;
|
||||
|
||||
};
|
||||
|
||||
#endif // CONSOLE_H
|
||||
|
@ -38,13 +38,12 @@
|
||||
|
||||
#define MAX_ERROR_MSG_SIZE 1024
|
||||
|
||||
extern void
|
||||
Yap_InitError__(const char *file, const char *function, int lineno,
|
||||
extern void Yap_InitError__(const char *file, const char *function, int lineno,
|
||||
yap_error_number e, YAP_Term g, ...);
|
||||
|
||||
extern struct yami *Yap_Error__(bool thrw, const char *file, const char *function,
|
||||
int lineno, yap_error_number err,
|
||||
YAP_Term wheret, ...);
|
||||
extern struct yami *Yap_Error__(bool thrw, const char *file,
|
||||
const char *function, int lineno,
|
||||
yap_error_number err, YAP_Term wheret, ...);
|
||||
|
||||
extern void Yap_ThrowError__(const char *file, const char *function, int lineno,
|
||||
yap_error_number err, YAP_Term wheret, ...)
|
||||
@ -74,8 +73,8 @@ extern void Yap_ThrowError__(const char *file, const char *function, int lineno,
|
||||
{ if ( (TF = Yap_ensure_atom__(__FILE__, __FUNCTION__, __LINE__, T0 ) == 0L ) return false; \
|
||||
}
|
||||
|
||||
INLINE_ONLY Term Yap_ensure_atom__(const char *fu, const char *fi,
|
||||
int line, Term in) {
|
||||
INLINE_ONLY Term Yap_ensure_atom__(const char *fu, const char *fi, int line,
|
||||
Term in) {
|
||||
Term t = Deref(in);
|
||||
// Term Context = Deref(ARG2);
|
||||
if (!IsVarTerm(t) && IsAtomTerm(t))
|
||||
@ -243,20 +242,24 @@ INLINE_ONLY Term Yap_ensure_atom__(const char *fu, const char *fi,
|
||||
|
||||
extern void Yap_CatchError(void);
|
||||
extern void Yap_ThrowExistingError(void);
|
||||
extern bool Yap_MkErrorRecord( yap_error_descriptor_t *r,
|
||||
const char *file, const char *function,
|
||||
int lineno, yap_error_number type, YAP_Term where,
|
||||
const char *msg);
|
||||
extern bool Yap_MkErrorRecord(
|
||||
yap_error_descriptor_t * r, const char *file, const char *function,
|
||||
int lineno, yap_error_number type, YAP_Term where, const char *msg);
|
||||
|
||||
extern yap_error_descriptor_t * Yap_pc_add_location(yap_error_descriptor_t *t, void *pc0, void *b_ptr0, void *env0);
|
||||
extern yap_error_descriptor_t *Yap_env_add_location(yap_error_descriptor_t *t,void *cp0, void * b_ptr0, void *env0, YAP_Int ignore_first);
|
||||
extern yap_error_descriptor_t *Yap_pc_add_location(
|
||||
yap_error_descriptor_t * t, void *pc0, void *b_ptr0, void *env0);
|
||||
extern yap_error_descriptor_t *Yap_env_add_location(
|
||||
yap_error_descriptor_t * t, void *cp0, void *b_ptr0, void *env0,
|
||||
YAP_Int ignore_first);
|
||||
|
||||
extern yap_error_descriptor_t *Yap_prolog_add_culprit(yap_error_descriptor_t *t);
|
||||
extern yap_error_descriptor_t *Yap_prolog_add_culprit(yap_error_descriptor_t *
|
||||
t);
|
||||
extern yap_error_class_number Yap_errorClass(yap_error_number e);
|
||||
extern const char *Yap_errorName(yap_error_number e);
|
||||
extern const char *Yap_errorClassName(yap_error_class_number e);
|
||||
|
||||
extern bool Yap_pushErrorContext(bool pass, yap_error_descriptor_t *new_error);
|
||||
extern bool Yap_pushErrorContext(bool pass,
|
||||
yap_error_descriptor_t *new_error);
|
||||
extern yap_error_descriptor_t *Yap_popErrorContext(bool oerr, bool pass);
|
||||
|
||||
#endif
|
||||
|
@ -33,7 +33,7 @@
|
||||
'$is_metapredicate'( G, M) :-
|
||||
predicate_property(M:G, meta_predicate(_)).
|
||||
|
||||
'$imported_predicate'(G,M,G,M0) :-
|
||||
'$is_imported_predicate'(G,M,G,M0) :-
|
||||
predicate_property(M:G, imported_from(M0)).
|
||||
|
||||
'$is_system_predicate'( call(_), _M) :- !.
|
||||
|
@ -22,6 +22,7 @@ X_API PyObject *py_Atoms;
|
||||
X_API PyObject *py_Builtin;
|
||||
X_API PyObject *py_Yapex;
|
||||
X_API PyObject *py_Sys;
|
||||
X_API PyObject * pYAPError;
|
||||
PyObject *py_Context;
|
||||
PyObject *py_ModDict;
|
||||
|
||||
|
@ -88,6 +88,7 @@ extensions = [Extension('_yap', native_sources,
|
||||
('MINOR_VERSION', '0'),
|
||||
('_YAP_NOT_INSTALLED_', '1'),
|
||||
('YAP_PYTHON', '1'),
|
||||
('PYTHONSWIG', '1'),
|
||||
('_GNU_SOURCE', '1')],
|
||||
runtime_library_dirs=[
|
||||
abspath(join(sysconfig.get_path('platlib'),'yap4py')), abspath(sysconfig.get_path('platlib')),'${CMAKE_INSTALL_FULL_LIBDIR}'],
|
||||
|
@ -49,6 +49,7 @@ class JupyterEngine( Engine ):
|
||||
args = EngineArgs(**kwargs)
|
||||
args.jupyter = True
|
||||
Engine.__init__(self, args)
|
||||
self.errors = None
|
||||
self.goal(set_prolog_flag('verbose', 'silent'),True)
|
||||
self.goal(compile(library('jupyter')), True)
|
||||
self.goal(set_prolog_flag('verbose', 'normal'), True)
|
||||
|
@ -95,7 +95,6 @@ set (PYTHON_SOURCES backcall.py yap_kernel_launcher.py docs/conf.py
|
||||
yap_ipython/lib/kernel.py yap_ipython/lib/latextools.py
|
||||
yap_ipython/lib/lexers.py yap_ipython/lib/pretty.py
|
||||
yap_ipython/lib/security.py yap_ipython/lib/tests
|
||||
yap_ipython/prolog/jupyter.yap
|
||||
yap_ipython/sphinxext/custom_doctests.py
|
||||
yap_ipython/sphinxext/__init__.py
|
||||
yap_ipython/sphinxext/ipython_console_highlighting.py
|
||||
|
@ -6,13 +6,11 @@
|
||||
|
||||
:- yap_flag(gc_trace,verbose).
|
||||
|
||||
% :- module( jupyter,
|
||||
% [jupyter_query/3,
|
||||
% errors/2,
|
||||
% ready/2,
|
||||
% completion/2,
|
||||
% ]
|
||||
%% ).
|
||||
:- module( jupyter,
|
||||
[jupyter_query/3,
|
||||
blank/1
|
||||
]
|
||||
).
|
||||
:- use_module(library(hacks)).
|
||||
|
||||
:- use_module(library(lists)).
|
||||
@ -21,6 +19,7 @@
|
||||
:- use_module(library(python)).
|
||||
:- use_module(library(yapi)).
|
||||
:- use_module(library(complete)).
|
||||
:- use_module(library(verify)).
|
||||
|
||||
:- python_import(sys).
|
||||
|
||||
@ -92,103 +91,6 @@ streams(true) :-
|
||||
open('/python/sys.stdout', append, Output, [alias(user_output)]),
|
||||
open('/python/sys.stderr', append, Error, [alias(user_error)]).
|
||||
|
||||
ready(_Self, Line ) :-
|
||||
blank( Line ),
|
||||
!.
|
||||
ready(Self, Line ) :-
|
||||
errors( Self, Line ),
|
||||
\+ syntax_error(_,_).
|
||||
|
||||
errors( Self, Text ) :-
|
||||
setup_call_cleanup(
|
||||
open_events( Self, Text, Stream),
|
||||
goals(Self, Stream),
|
||||
close_events( Self )
|
||||
).
|
||||
|
||||
clauses(_Self, Stream) :-
|
||||
repeat,
|
||||
read_clause(Stream, Cl, [term_position(_Pos), syntax_errors(fail)] ),
|
||||
% command( Self, Cl ),
|
||||
Cl == end_of_file,
|
||||
!.
|
||||
|
||||
goals(_Self, Stream) :-
|
||||
repeat,
|
||||
read_term(Stream, Cl, [term_position(_Pos), syntax_errors(fail)] ),
|
||||
% command( Self, Cl ),
|
||||
Cl == end_of_file,
|
||||
!.
|
||||
|
||||
command(_, end_of_file) :- !.
|
||||
|
||||
command( _Self, ( :- op(Prio,Assoc,Name) ) ) :-
|
||||
addop(Prio,Assoc,Name).
|
||||
|
||||
command( _Self, ( :- module(Name, Exports) )) :-
|
||||
retract( active_module( M0 ) ),
|
||||
atom_concat( '__m0_', Name, M ),
|
||||
assert( active_module(M) ),
|
||||
assert( undo( active_module(M0) ) ),
|
||||
maplist( addop2(M), Exports).
|
||||
|
||||
|
||||
addop(Prio,Assoc,Name) :-
|
||||
(
|
||||
current_op(OPrio, SimilarAssoc, Name),
|
||||
op(Prio, Assoc, Name),
|
||||
matched_op(Assoc, SimilarAssoc)
|
||||
->
|
||||
assertz( undo(op( OPrio, Assoc, Name ) ) )
|
||||
;
|
||||
assertz( undo(op( 0, Assoc, Name ) ) )
|
||||
).
|
||||
|
||||
addop2(M, op(Prio, Assoc, Name)) :-
|
||||
addop( Prio, Assoc, M:Name ).
|
||||
|
||||
matched_op(A, B) :-
|
||||
optype( A, T),
|
||||
optype( B, T).
|
||||
|
||||
optype(fx,pre).
|
||||
optype(fy,pre).
|
||||
optype(xfx,in).
|
||||
optype(xfy,in).
|
||||
optype(yfx,in).
|
||||
optype(yfy,in).
|
||||
optype(xf,pos).
|
||||
optype(yf,pos).
|
||||
|
||||
:- dynamic user:portray_message/2.
|
||||
:- multifile user:portray_message/2.
|
||||
|
||||
:- dynamic syntax_error/4, undo/1.
|
||||
|
||||
user:portray_message(_Severity, error(syntax_error(Cause),info(between(_,LN,_), _FileName, CharPos, Details))) :-
|
||||
nb_getval(jupyter_cell, on),
|
||||
assert( syntax_error(Cause,LN,CharPos,Details) ).
|
||||
user:portray_message(_Severity, error(style_check(_),_) ) :-
|
||||
nb_getval(jupyter_cell, on).
|
||||
|
||||
open_events(Self, Text, Stream) :-
|
||||
Self.errors := [],
|
||||
nb_setval( jupyter, on),
|
||||
open_mem_read_stream( Text, Stream ).
|
||||
|
||||
:- initialization( nb_setval( jupyter, off ) ).
|
||||
|
||||
close_events( _Self ) :-
|
||||
nb_setval( jupyter, off ),
|
||||
retract( undo(G) ),
|
||||
call(G),
|
||||
fail.
|
||||
close_events( Self ) :-
|
||||
retract( syntax_error( C, L, N, A )),
|
||||
Self.errors := [t(C,L,N,A)] + Self.errors,
|
||||
fail.
|
||||
close_events( _ ).
|
||||
|
||||
|
||||
:- if( current_prolog_flag(apple, true) ).
|
||||
|
||||
|
@ -5,14 +5,12 @@
|
||||
*/
|
||||
|
||||
|
||||
% :- module( verify,
|
||||
% [all_clear/4,
|
||||
% errors/2,
|
||||
% ready/2,
|
||||
s % completion/2,
|
||||
% ]
|
||||
%% ).
|
||||
:- module( verify,
|
||||
[errors/2,
|
||||
ready/2]
|
||||
).
|
||||
:- use_module(library(hacks)).
|
||||
:- use_module(library(jupyter)).
|
||||
|
||||
:- use_module(library(lists)).
|
||||
:- use_module(library(maplist)).
|
||||
@ -20,43 +18,155 @@ s % completion/2,
|
||||
:- use_module(library(python)).
|
||||
:- use_module(library(yapi)).
|
||||
|
||||
:- python_import(sys).
|
||||
|
||||
p_errors( Errors, Cell) :-
|
||||
blank( Cell ),
|
||||
!.
|
||||
p_errors( Errors, Cell) :-
|
||||
no_errors( Errors , Cell ).
|
||||
ready( Engine, Query) :-
|
||||
errors( Engine , Cell ),
|
||||
Es := Engine.errors,
|
||||
Es == [].
|
||||
|
||||
no_errors( _Errors , Text ) :-
|
||||
|
||||
|
||||
errors( _Engine , Text ) :-
|
||||
blank(Text).
|
||||
no_errors( Errors , Text ) :-
|
||||
setup_call_cleanup(
|
||||
open_esh( Errors , Text, Stream),
|
||||
esh(Errors , Stream),
|
||||
close_esh( Errors , Stream )
|
||||
).
|
||||
|
||||
syntax(_Errors , E) :- writeln(user_error, E), fail.
|
||||
syntax(Errors , error(syntax_error(Cause),info(between(_,LN,_), _FileName, CharPos, Details))) :-
|
||||
Errors.errors := [t(Cause,LN,CharPos,Details)] + Errors.errors,
|
||||
!.
|
||||
syntax(_Errors , E) :- throw(E).
|
||||
errors( Engine , Text ) :-
|
||||
b_setval(jupyter, Engine),
|
||||
setup_call_cleanup(
|
||||
open_esh( Engine , Text, Stream, Name ),
|
||||
esh(Engine , Name, Stream),
|
||||
close_esh( Engine , Stream )
|
||||
),
|
||||
fail.
|
||||
errors( _Engine , _Text ).
|
||||
|
||||
open_esh(_Errors , Text, Stream) :-
|
||||
open_esh(Engine , Text, Stream, Name) :-
|
||||
Engine.errors := [],
|
||||
b_setval( jupyter, Engine),
|
||||
Name := Engine.stream_name,
|
||||
open_mem_read_stream( Text, Stream ).
|
||||
|
||||
esh(Errors , Stream) :-
|
||||
esh(Engine , Name, Stream) :-
|
||||
repeat,
|
||||
catch(
|
||||
read_clause(Stream, Cl, [term_position(_Pos), syntax_errors(fail)] ),
|
||||
Error,
|
||||
syntax(Errors , Error)
|
||||
read_clause(Stream, Cl,[]),
|
||||
E=error(C,E),
|
||||
p_message(C,E)
|
||||
),
|
||||
Cl == end_of_file,
|
||||
!.
|
||||
|
||||
|
||||
|
||||
close_esh( _Errors , Stream ) :-
|
||||
close_esh( _Engine , Stream ) :-
|
||||
close(Stream).
|
||||
|
||||
|
||||
p_message(Severity, Error) :-
|
||||
writeln((Severity->Error)),
|
||||
catch( b_getval(jupyter, Engine), _, fail ),
|
||||
p_message(Severity, Engine, Error).
|
||||
|
||||
p_message( _Severity, Engine, error(syntax_error(Cause),info(between(_,LN,_), _FileName, CharPos, Details))) :-
|
||||
%% nb_getval(jupyter_cell, on),
|
||||
%% assert( syntax_error(Cause,LN,CharPos,Details) ).
|
||||
%% user:portray_message(_Severity, error(style_check(_),_) ) :-
|
||||
%% nb_getval(jupyter_cell, on).
|
||||
Engine.errors := [t(Cause,LN,CharPos,Details)] + Engine.errors,
|
||||
!.
|
||||
p_message(error, Engine, E) :-
|
||||
writeln(E),
|
||||
!.
|
||||
p_message(warning, Engine, E) :-
|
||||
writeln(E),
|
||||
!.
|
||||
p_message(error, Engine, E) :-
|
||||
Engine.errors := [E] + Engine.errors.
|
||||
p_message(warning, Engine, E) :-
|
||||
Engine.errors := [E] + Engine.errors.
|
||||
%% ready(_Self, Line ) :-
|
||||
%% blank( Line ),
|
||||
%% !.
|
||||
%% ready(Self, Line ) :-
|
||||
%% errors( Self, Line ),
|
||||
%% \+ syntax_error(_,_).
|
||||
|
||||
%% errors( Self, Text ) :-
|
||||
%% setup_call_cleanup(
|
||||
%% open_events( Self, Text, Stream),
|
||||
%% goals(Self, Stream),
|
||||
%% close_events( Self )
|
||||
%% ).
|
||||
|
||||
%% clauses(_Self, Stream) :-
|
||||
%% repeat,
|
||||
%% read_clause(Stream, Cl, [term_position(_Pos), syntax_errors(fail)] ),
|
||||
%% % command( Self, Cl ),
|
||||
%% Cl == end_of_file,
|
||||
%% !.
|
||||
|
||||
%% goals(_Self, Stream) :-
|
||||
%% repeat,
|
||||
%% read_term(Stream, Cl, [term_position(_Pos), syntax_errors(fail)] ),
|
||||
%% % command( Self, Cl ),
|
||||
%% Cl == end_of_file,
|
||||
%% !.
|
||||
|
||||
%% command(_, end_of_file) :- !.
|
||||
|
||||
%% command( _Self, ( :- op(Prio,Assoc,Name) ) ) :-
|
||||
%% addop(Prio,Assoc,Name).
|
||||
|
||||
%% command( _Self, ( :- module(Name, Exports) )) :-
|
||||
%% retract( active_module( M0 ) ),
|
||||
%% atom_concat( '__m0_', Name, M ),
|
||||
%% assert( active_module(M) ),
|
||||
%% assert( undo( active_module(M0) ) ),
|
||||
%% maplist( addop2(M), Exports).
|
||||
|
||||
|
||||
%% addop(Prio,Assoc,Name) :-
|
||||
%% (
|
||||
%% current_op(OPrio, SimilarAssoc, Name),
|
||||
%% op(Prio, Assoc, Name),
|
||||
%% matched_op(Assoc, SimilarAssoc)
|
||||
%% ->
|
||||
%% assertz( undo(op( OPrio, Assoc, Name ) ) )
|
||||
%% ;
|
||||
%% assertz( undo(op( 0, Assoc, Name ) ) )
|
||||
%% ).
|
||||
|
||||
%% addop2(M, op(Prio, Assoc, Name)) :-
|
||||
%% addop( Prio, Assoc, M:Name ).
|
||||
|
||||
%% matched_op(A, B) :-
|
||||
%% optype( A, T),
|
||||
%% optype( B, T).
|
||||
|
||||
%% optype(fx,pre).
|
||||
%% optype(fy,pre).
|
||||
%% optype(xfx,in).
|
||||
%% optype(xfy,in).
|
||||
%% optype(yfx,in).
|
||||
%% optype(yfy,in).
|
||||
%% optype(xf,pos).
|
||||
%% optype(yf,pos).
|
||||
|
||||
%% :- dynamic syntax_error/4, undo/1.
|
||||
|
||||
%%
|
||||
%% open_events(Self, Text, Stream) :-
|
||||
%% Self.errors := [],
|
||||
%% nb_setval( jupyter, on),
|
||||
%% open_mem_read_stream( Text, Stream ).
|
||||
|
||||
%% :- initialization( nb_setval( jupyter, off ) ).
|
||||
|
||||
%% close_events( _Self ) :-
|
||||
%% nb_setval( jupyter, off ),
|
||||
%% retract( undo(G) ),
|
||||
%% call(G),
|
||||
%% fail.
|
||||
%% close_events( Self ) :-
|
||||
%% retract( syntax_error( C, L, N, A )),
|
||||
%% Self.errors := [t(C,L,N,A)] + Self.errors,
|
||||
%% fail.
|
||||
%% close_events( _ ).
|
||||
|
@ -114,7 +114,7 @@ class YAPInputSplitter(InputSplitter):
|
||||
if not line:
|
||||
line = text.rstrip()
|
||||
self.errors = []
|
||||
engine.mgoal(errors(self, line),"user",True)
|
||||
engine.mgoal(errors(self, line),"verify",True)
|
||||
return self.errors != []
|
||||
|
||||
|
||||
@ -528,7 +528,7 @@ class YAPRun:
|
||||
return self.errors
|
||||
self.errors=[]
|
||||
(text,_,_,_) = self.clean_end(text)
|
||||
self.yapeng.mgoal(errors(self,text),"user",True)
|
||||
self.yapeng.mgoal(errors(self,text),"verify",True)
|
||||
return self.errors
|
||||
|
||||
def jupyter_query(self, s):
|
||||
@ -653,6 +653,7 @@ class YAPRun:
|
||||
# except SyntaxError:
|
||||
# preprocessing_exc_tuple = self.shell.syntax_error() # sys.exc_info()
|
||||
cell = raw_cell # cell has to exist so it can be stored/logged
|
||||
self.yapeng.mgoal(streams(True),"jupyter", True)
|
||||
for i in self.syntaxErrors(raw_cell):
|
||||
try:
|
||||
(what,lin,_,text) = i
|
||||
@ -679,6 +680,7 @@ class YAPRun:
|
||||
# compiler
|
||||
# compiler = self.shell.compile if shell_futures else CachingCompiler()
|
||||
cell_name = str( self.shell.execution_count)
|
||||
engine.stream_name = cell_name
|
||||
if cell[0] == '%':
|
||||
if cell[1] == '%':
|
||||
linec = False
|
||||
@ -707,7 +709,6 @@ class YAPRun:
|
||||
self.shell.displayhook.exec_result = self.result
|
||||
has_raised = False
|
||||
try:
|
||||
self.yapeng.mgoal(streams(True),"user", True)
|
||||
self.bindings = dicts = []
|
||||
if cell.strip('\n \t'):
|
||||
#create a Trace object, telling it what to ignore, and whether to
|
||||
@ -732,9 +733,9 @@ class YAPRun:
|
||||
except Exception as e:
|
||||
has_raised = True
|
||||
self.result.result = False
|
||||
self.yapeng.mgoal(streams(False),"user", True)
|
||||
self.yapeng.mgoal(streams(False),"jupyter", True)
|
||||
|
||||
self.yapeng.mgoal(streams(False),"user", True)
|
||||
self.yapeng.mgoal(streams(False),"jupyter", True)
|
||||
self.shell.last_execution_succeeded = not has_raised
|
||||
|
||||
# Reset this so later displayed values do not modify the
|
||||
|
@ -203,7 +203,7 @@ class YAPKernel(KernelBase):
|
||||
self._forward_input(allow_stdin)
|
||||
|
||||
reply_content = {}
|
||||
import trace;
|
||||
# import trace;
|
||||
try:
|
||||
res = shell.run_cell(code, store_history=store_history, silent=silent)
|
||||
finally:
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
|
||||
/* example.i */
|
||||
#if PYTHONSWIG
|
||||
#if defined(SWIGPYTHON)
|
||||
%module(directors = "1", package="yap4py") yap
|
||||
#else
|
||||
%module(directors = "1") yap
|
||||
@ -31,44 +31,13 @@ class YAPAtom;
|
||||
class YAPPredicate;
|
||||
class YAPEngine;
|
||||
|
||||
%{
|
||||
|
||||
#if defined(SWIGPYTHON)
|
||||
|
||||
#include <cmath>
|
||||
#include <gmpxx.h>
|
||||
|
||||
extern "C"{
|
||||
#include "Yap.h"
|
||||
|
||||
X_API extern Term YAP_MkCharPTerm( char *n);
|
||||
|
||||
|
||||
#ifdef SWIGPYTHON
|
||||
#include <py4yap.h>
|
||||
|
||||
extern inline PyObject *AtomToPy(const char *s) {
|
||||
if (strcmp(s, "true") == 0)
|
||||
return Py_True;
|
||||
if (strcmp(s, "false") == 0)
|
||||
return Py_False;
|
||||
if (strcmp(s, "none") == 0)
|
||||
return Py_None;
|
||||
if (strcmp(s, "[]") == 0)
|
||||
return PyList_New(0);
|
||||
else if (strcmp(s, "{}") == 0)
|
||||
return PyDict_New();
|
||||
/* return __main__,s */
|
||||
else if (PyObject_HasAttrString(py_Main, s)) {
|
||||
return PyObject_GetAttrString(py_Main, s);
|
||||
}
|
||||
// no way to translate
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
%pythoncode %{
|
||||
YAPError = _yap.YAPError
|
||||
%}
|
||||
|
||||
#ifdef SWIGPYTHON
|
||||
%typemap(typecheck) Term* {
|
||||
$1 = PySequence_Check($input);
|
||||
}
|
||||
@ -135,127 +104,17 @@ X_API extern Term YAP_MkCharPTerm( char *n);
|
||||
}
|
||||
return $result; }
|
||||
|
||||
|
||||
|
||||
// Language independent exception handler
|
||||
|
||||
%exception next {
|
||||
%exception {
|
||||
try {
|
||||
$action
|
||||
} catch (YAPError &e) {
|
||||
yap_error_number en = e.getID();
|
||||
PyObject *pyerr = PyExc_RuntimeError;
|
||||
|
||||
LOCAL_Error_TYPE = YAP_NO_ERROR;
|
||||
switch (e.getErrorClass()) {
|
||||
case YAPC_NO_ERROR:
|
||||
break;
|
||||
/// bad domain, "first argument often is the predicate.
|
||||
case DOMAIN_ERROR: {
|
||||
switch (en) {
|
||||
case DOMAIN_ERROR_OUT_OF_RANGE:
|
||||
pyerr = PyExc_GeneratorExit;
|
||||
break;
|
||||
case DOMAIN_ERROR_NOT_LESS_THAN_ZERO:
|
||||
pyerr = PyExc_IndexError;
|
||||
break;
|
||||
case DOMAIN_ERROR_CLOSE_OPTION:
|
||||
case DOMAIN_ERROR_ENCODING:
|
||||
case DOMAIN_ERROR_PROLOG_FLAG:
|
||||
case DOMAIN_ERROR_ABSOLUTE_FILE_NAME_OPTION:
|
||||
case DOMAIN_ERROR_READ_OPTION:
|
||||
case DOMAIN_ERROR_SET_STREAM_OPTION:
|
||||
pyerr = PyExc_KeyError;
|
||||
break;
|
||||
case DOMAIN_ERROR_FILE_ERRORS:
|
||||
case DOMAIN_ERROR_FILE_TYPE:
|
||||
case DOMAIN_ERROR_IO_MODE:
|
||||
case DOMAIN_ERROR_SOURCE_SINK:
|
||||
case DOMAIN_ERROR_STREAM_POSITION:
|
||||
pyerr = PyExc_IOError;
|
||||
break;
|
||||
default:
|
||||
pyerr = PyExc_ValueError;
|
||||
}
|
||||
} break;
|
||||
/// bad arithmetic
|
||||
case EVALUATION_ERROR: {
|
||||
switch (en) {
|
||||
case EVALUATION_ERROR_FLOAT_OVERFLOW:
|
||||
case EVALUATION_ERROR_INT_OVERFLOW:
|
||||
pyerr = PyExc_OverflowError;
|
||||
break;
|
||||
case EVALUATION_ERROR_FLOAT_UNDERFLOW:
|
||||
case EVALUATION_ERROR_UNDERFLOW:
|
||||
case EVALUATION_ERROR_ZERO_DIVISOR:
|
||||
pyerr = PyExc_ArithmeticError;
|
||||
break;
|
||||
default:
|
||||
pyerr = PyExc_RuntimeError;
|
||||
}
|
||||
} break;
|
||||
/// missing object (I/O mostly)
|
||||
case EXISTENCE_ERROR:
|
||||
pyerr = PyExc_NotImplementedError;
|
||||
break;
|
||||
/// should be bound
|
||||
case INSTANTIATION_ERROR_CLASS:
|
||||
pyerr = PyExc_RuntimeError;
|
||||
break;
|
||||
/// bad access, I/O
|
||||
case PERMISSION_ERROR: {
|
||||
switch (en) {
|
||||
case PERMISSION_ERROR_INPUT_BINARY_STREAM:
|
||||
case PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM:
|
||||
case PERMISSION_ERROR_INPUT_STREAM:
|
||||
case PERMISSION_ERROR_INPUT_TEXT_STREAM:
|
||||
case PERMISSION_ERROR_OPEN_SOURCE_SINK:
|
||||
case PERMISSION_ERROR_OUTPUT_BINARY_STREAM:
|
||||
case PERMISSION_ERROR_REPOSITION_STREAM:
|
||||
case PERMISSION_ERROR_OUTPUT_STREAM:
|
||||
case PERMISSION_ERROR_OUTPUT_TEXT_STREAM:
|
||||
pyerr = PyExc_OverflowError;
|
||||
break;
|
||||
default:
|
||||
pyerr = PyExc_RuntimeError;
|
||||
}
|
||||
} break;
|
||||
/// something that could not be represented into a type
|
||||
case REPRESENTATION_ERROR:
|
||||
pyerr = PyExc_RuntimeError;
|
||||
break;
|
||||
/// not enough ....
|
||||
case RESOURCE_ERROR:
|
||||
pyerr = PyExc_RuntimeError;
|
||||
break;
|
||||
/// bad text
|
||||
case SYNTAX_ERROR_CLASS:
|
||||
pyerr = PyExc_SyntaxError;
|
||||
break;
|
||||
/// OS or internal
|
||||
case SYSTEM_ERROR_CLASS:
|
||||
pyerr = PyExc_RuntimeError;
|
||||
break;
|
||||
/// bad typing
|
||||
case TYPE_ERROR:
|
||||
pyerr = PyExc_TypeError;
|
||||
break;
|
||||
/// should be unbound
|
||||
case UNINSTANTIATION_ERROR_CLASS:
|
||||
pyerr = PyExc_RuntimeError;
|
||||
break;
|
||||
/// escape hatch
|
||||
default:
|
||||
break;
|
||||
}
|
||||
PyErr_SetString(pyerr, e.text().c_str());
|
||||
YAPPycatch(e);
|
||||
SWIG_fail;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
%typemap(in) arity_t { (jlong)($input); }
|
||||
|
||||
%typecheck(2) Int { $1 = PyLong_Check($input); }
|
||||
%typecheck(3) double { $1 = PyFloat_Check($input); }
|
||||
%typecheck(2) const char * { $1 = PyUnicode_Check($input); }
|
||||
@ -265,6 +124,11 @@ X_API extern Term YAP_MkCharPTerm( char *n);
|
||||
|
||||
%typecheck(0) YAPTerm { $1 = !PyUnicode_Check($input); }
|
||||
|
||||
#else
|
||||
|
||||
%typemap(in) arity_t { (jlong)($input); }
|
||||
|
||||
|
||||
|
||||
%typemap(in) jlong %{
|
||||
$1 = (jlong)$input;
|
||||
@ -288,16 +152,16 @@ X_API extern Term YAP_MkCharPTerm( char *n);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
%{
|
||||
/* Put header files here or function declarations like below */
|
||||
#include "yapi.hh"
|
||||
|
||||
|
||||
|
||||
extern "C" {
|
||||
extern void Yap_PrintException(yap_error_descriptor_t *i);
|
||||
|
||||
#if THREADS
|
||||
#define Yap_regp regcache
|
||||
@ -310,10 +174,160 @@ X_API extern Term YAP_MkCharPTerm( char *n);
|
||||
|
||||
extern void init_sqlite();
|
||||
|
||||
%}
|
||||
|
||||
#define X_API
|
||||
|
||||
|
||||
#include <cmath>
|
||||
#include <gmpxx.h>
|
||||
|
||||
extern "C"{
|
||||
#include "Yap.h"
|
||||
|
||||
X_API extern Term YAP_MkCharPTerm( char *n);
|
||||
|
||||
#if defined(SWIGPYTHON)
|
||||
|
||||
#include <py4yap.h>
|
||||
|
||||
X_API extern PyObject * pYAPError;
|
||||
|
||||
extern inline PyObject *AtomToPy(const char *s) {
|
||||
if (strcmp(s, "true") == 0)
|
||||
return Py_True;
|
||||
if (strcmp(s, "false") == 0)
|
||||
return Py_False;
|
||||
if (strcmp(s, "none") == 0)
|
||||
return Py_None;
|
||||
if (strcmp(s, "[]") == 0)
|
||||
return PyList_New(0);
|
||||
else if (strcmp(s, "{}") == 0)
|
||||
return PyDict_New();
|
||||
/* return __main__,s */
|
||||
else if (PyObject_HasAttrString(py_Main, s)) {
|
||||
return PyObject_GetAttrString(py_Main, s);
|
||||
}
|
||||
// no way to translate
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
YAPPycatch(YAPError &e)
|
||||
{
|
||||
|
||||
yap_error_number en = e.getID();
|
||||
std::cerr << e.text() << "\n";
|
||||
|
||||
|
||||
return;
|
||||
switch (e.getErrorClass()) {
|
||||
case YAPC_NO_ERROR:
|
||||
break;
|
||||
/// bad domain, "first argument often is the predicate.
|
||||
case DOMAIN_ERROR: {
|
||||
switch (en) {
|
||||
case DOMAIN_ERROR_OUT_OF_RANGE:
|
||||
pYAPError = PyExc_GeneratorExit;
|
||||
break;
|
||||
case DOMAIN_ERROR_NOT_LESS_THAN_ZERO:
|
||||
pYAPError = PyExc_IndexError;
|
||||
break;
|
||||
case DOMAIN_ERROR_CLOSE_OPTION:
|
||||
case DOMAIN_ERROR_ENCODING:
|
||||
case DOMAIN_ERROR_PROLOG_FLAG:
|
||||
case DOMAIN_ERROR_ABSOLUTE_FILE_NAME_OPTION:
|
||||
case DOMAIN_ERROR_READ_OPTION:
|
||||
case DOMAIN_ERROR_SET_STREAM_OPTION:
|
||||
pYAPError = PyExc_KeyError;
|
||||
break;
|
||||
case DOMAIN_ERROR_FILE_ERRORS:
|
||||
case DOMAIN_ERROR_FILE_TYPE:
|
||||
case DOMAIN_ERROR_IO_MODE:
|
||||
case DOMAIN_ERROR_SOURCE_SINK:
|
||||
case DOMAIN_ERROR_STREAM_POSITION:
|
||||
pYAPError = PyExc_IOError;
|
||||
break;
|
||||
default:
|
||||
pYAPError = PyExc_ValueError;
|
||||
}
|
||||
} break;
|
||||
/// bad arithmetic
|
||||
case EVALUATION_ERROR: {
|
||||
switch (en) {
|
||||
case EVALUATION_ERROR_FLOAT_OVERFLOW:
|
||||
case EVALUATION_ERROR_INT_OVERFLOW:
|
||||
pYAPError = PyExc_OverflowError;
|
||||
break;
|
||||
case EVALUATION_ERROR_FLOAT_UNDERFLOW:
|
||||
case EVALUATION_ERROR_UNDERFLOW:
|
||||
case EVALUATION_ERROR_ZERO_DIVISOR:
|
||||
pYAPError = PyExc_ArithmeticError;
|
||||
break;
|
||||
default:
|
||||
pYAPError = PyExc_RuntimeError;
|
||||
}
|
||||
} break;
|
||||
/// missing object (I/O mostly)
|
||||
case EXISTENCE_ERROR:
|
||||
pYAPError = PyExc_NotImplementedError;
|
||||
break;
|
||||
/// should be bound
|
||||
case INSTANTIATION_ERROR_CLASS:
|
||||
pYAPError = PyExc_RuntimeError;
|
||||
break;
|
||||
/// bad access, I/O
|
||||
case PERMISSION_ERROR: {
|
||||
switch (en) {
|
||||
case PERMISSION_ERROR_INPUT_BINARY_STREAM:
|
||||
case PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM:
|
||||
case PERMISSION_ERROR_INPUT_STREAM:
|
||||
case PERMISSION_ERROR_INPUT_TEXT_STREAM:
|
||||
case PERMISSION_ERROR_OPEN_SOURCE_SINK:
|
||||
case PERMISSION_ERROR_OUTPUT_BINARY_STREAM:
|
||||
case PERMISSION_ERROR_REPOSITION_STREAM:
|
||||
case PERMISSION_ERROR_OUTPUT_STREAM:
|
||||
case PERMISSION_ERROR_OUTPUT_TEXT_STREAM:
|
||||
pYAPError = PyExc_OverflowError;
|
||||
break;
|
||||
default:
|
||||
pYAPError = PyExc_RuntimeError;
|
||||
}
|
||||
} break;
|
||||
/// something that could not be represented into a type
|
||||
case REPRESENTATION_ERROR:
|
||||
pYAPError = PyExc_RuntimeError;
|
||||
break;
|
||||
/// not enough ....
|
||||
case RESOURCE_ERROR:
|
||||
pYAPError = PyExc_RuntimeError;
|
||||
break;
|
||||
/// bad text
|
||||
case SYNTAX_ERROR_CLASS:
|
||||
pYAPError = PyExc_SyntaxError;
|
||||
break;
|
||||
/// OS or internal
|
||||
case SYSTEM_ERROR_CLASS:
|
||||
pYAPError = PyExc_RuntimeError;
|
||||
break;
|
||||
/// bad typing
|
||||
case TYPE_ERROR:
|
||||
pYAPError = PyExc_TypeError;
|
||||
break;
|
||||
/// should be unbound
|
||||
case UNINSTANTIATION_ERROR_CLASS:
|
||||
pYAPError = PyExc_RuntimeError;
|
||||
break;
|
||||
/// escape hatch
|
||||
default:
|
||||
break;
|
||||
}
|
||||
PyErr_SetString(pYAPError, e.text().c_str());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
/* turn on director wrapping Callback */
|
||||
//%feature("director") YAPCallback;
|
||||
|
||||
@ -341,4 +355,8 @@ X_API extern Term YAP_MkCharPTerm( char *n);
|
||||
};
|
||||
|
||||
%init %{
|
||||
PyObject * pYAPError = PyErr_NewException("_yap.YAPError", NULL, NULL);
|
||||
Py_INCREF(pYAPError);
|
||||
PyModule_AddObject(m, "YAPError", pYAPError);
|
||||
|
||||
%}
|
||||
|
@ -307,9 +307,12 @@ load_files(Files0,Opts) :-
|
||||
'$load_files__'(Files, M, Opts, Call).
|
||||
'$load_files__'(Files, M, Opts, Call) :-
|
||||
'$lf_option'(last_opt, LastOpt),
|
||||
( '__NB_getval__'('$lf_status', OldTOpts, fail),
|
||||
nonvar(OldTOpts)
|
||||
'$show_consult_level'(LC),
|
||||
writeln(user_error,innbbbbbb),
|
||||
( LC > 0
|
||||
->
|
||||
'__NB_getval__'('$lf_status', OldTOpts, fail),
|
||||
nonvar(OldTOpts),
|
||||
'$lf_opt'(autoload, OldTOpts, OldAutoload),
|
||||
'$lf_opt'('$context_module', OldTOpts, OldContextModule)
|
||||
;
|
||||
|
@ -62,6 +62,75 @@
|
||||
'$get_undefined_predicates'(G, ImportingMod, G0, ExportingMod),
|
||||
ExportingMod \= ImportingMod.
|
||||
|
||||
|
||||
% be careful here not to generate an undefined exception.
|
||||
'$generate_imported_predicate'(G, ImportingMod, G0, ExportingMod) :-
|
||||
(
|
||||
recorded('$import','$import'(ExportingModI,ImportingMod,G0I,G,_,_),_)
|
||||
;
|
||||
'$parent_module'(ImportingMod,ExportingModI),
|
||||
\+ recorded('$import','$import'(ExportingModI,ImportingMod,G0I,G,_,_),_)
|
||||
),
|
||||
ImportingMod \= ExportingModI,
|
||||
(
|
||||
'$undefined'(G, ExportingModI)
|
||||
->
|
||||
'$generate_imported_predicate'(G, ExportingModI, G0, ExportingMod)
|
||||
;
|
||||
G=G0,
|
||||
ExportingModI=ExportingMod
|
||||
).
|
||||
|
||||
/**
|
||||
*
|
||||
* @pred '$continue_imported'(+ModIn, +ModOut, +PredIn ,+PredOut)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
'$continue_imported'(Mod,Mod,Pred,Pred) :-
|
||||
'$pred_exists'(Pred, Mod),
|
||||
!.
|
||||
'$continue_imported'(FM,Mod,FPred,Pred) :-
|
||||
recorded('$import','$import'(IM,Mod,IPred,Pred,_,_),_),
|
||||
'$continue_imported'(FM, IM, FPred, IPred), !.
|
||||
'$continue_imported'(FM,Mod,FPred,Pred) :-
|
||||
prolog:'$parent_module'(Mod,IM),
|
||||
'$continue_imported'(FM, IM, FPred, Pred).
|
||||
|
||||
|
||||
'$autoload'(G, _ImportingMod, ExportingMod, Dialect) :-
|
||||
functor(G, Name, Arity),
|
||||
'$pred_exists'(index(Name,Arity,ExportingMod,_),Dialect),
|
||||
call(Dialect:index(Name,Arity,ExportingMod,_)),
|
||||
!.
|
||||
'$autoload'(G, ImportingMod, ExportingMod, _Dialect) :-
|
||||
functor(G, N, K),
|
||||
functor(G0, N, K),
|
||||
'$autoloader_find_predicate'(G0,ExportingMod),
|
||||
ExportingMod \= ImportingMod,
|
||||
(recordzifnot('$import','$import'(ExportingMod,ImportingMod,G0,G0, N ,K),_) -> true ; true ).
|
||||
|
||||
|
||||
'$autoloader_find_predicate'(G,ExportingModI) :-
|
||||
'__NB_getval__'('$autoloader_set', true, false), !,
|
||||
autoloader:find_predicate(G,ExportingModI).
|
||||
'$autoloader_find_predicate'(G,ExportingModI) :-
|
||||
yap_flag(autoload, true, false),
|
||||
yap_flag( unknown, Unknown, fail),
|
||||
yap_flag(debug, Debug, false), !,
|
||||
load_files([library(autoloader),
|
||||
autoloader:library('INDEX'),
|
||||
swi:library('dialect/swi/INDEX')],
|
||||
[autoload(true),if(not_loaded)]),
|
||||
nb_setval('$autoloader_set', true),
|
||||
yap_flag(autoload, _, true),
|
||||
yap_flag( unknown, _, Unknown),
|
||||
yap_flag( debug, _, Debug),
|
||||
autoloader:find_predicate(G,ExportingModI).
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @}
|
||||
|
@ -244,7 +244,7 @@ compose_message(style_check(What,FILE,Line,Clause), Level)-->
|
||||
main_message(style_check(What,FILE,Line,Clause) , Level, LC ).
|
||||
compose_message(yes, _Level) --> !,
|
||||
[ 'yes'- [] ].
|
||||
compose_message(Throw, _Leve) -->
|
||||
compose_message(Throw, _Level) -->
|
||||
!,
|
||||
[ 'UNHANDLED EXCEPTION - message ~w unknown' - [Throw] ].
|
||||
|
||||
|
@ -339,52 +339,6 @@ system_module(Mod) :-
|
||||
tell(F),fail.
|
||||
'$trace_module'(_,_).
|
||||
|
||||
/**
|
||||
*
|
||||
* @pred '$continue_imported'(+ModIn, +ModOut, +PredIn ,+PredOut)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
'$continue_imported'(Mod,Mod,Pred,Pred) :-
|
||||
'$pred_exists'(Pred, Mod),
|
||||
!.
|
||||
'$continue_imported'(FM,Mod,FPred,Pred) :-
|
||||
recorded('$import','$import'(IM,Mod,IPred,Pred,_,_),_),
|
||||
'$continue_imported'(FM, IM, FPred, IPred), !.
|
||||
'$continue_imported'(FM,Mod,FPred,Pred) :-
|
||||
prolog:'$parent_module'(Mod,IM),
|
||||
'$continue_imported'(FM, IM, FPred, Pred).
|
||||
|
||||
|
||||
'$autoload'(G, _ImportingMod, ExportingMod, Dialect) :-
|
||||
functor(G, Name, Arity),
|
||||
'$pred_exists'(index(Name,Arity,ExportingMod,_),Dialect),
|
||||
call(Dialect:index(Name,Arity,ExportingMod,_)),
|
||||
!.
|
||||
'$autoload'(G, ImportingMod, ExportingMod, _Dialect) :-
|
||||
functor(G, N, K),
|
||||
functor(G0, N, K),
|
||||
'$autoloader_find_predicate'(G0,ExportingMod),
|
||||
ExportingMod \= ImportingMod,
|
||||
(recordzifnot('$import','$import'(ExportingMod,ImportingMod,G0,G0, N ,K),_) -> true ; true ).
|
||||
|
||||
|
||||
'$autoloader_find_predicate'(G,ExportingModI) :-
|
||||
'__NB_getval__'('$autoloader_set', true, false), !,
|
||||
autoloader:find_predicate(G,ExportingModI).
|
||||
'$autoloader_find_predicate'(G,ExportingModI) :-
|
||||
yap_flag(autoload, true, false),
|
||||
yap_flag( unknown, Unknown, fail),
|
||||
yap_flag(debug, Debug, false), !,
|
||||
load_files([library(autoloader),
|
||||
autoloader:library('INDEX'),
|
||||
swi:library('dialect/swi/INDEX')],
|
||||
[autoload(true),if(not_loaded)]),
|
||||
nb_setval('$autoloader_set', true),
|
||||
yap_flag(autoload, _, true),
|
||||
yap_flag( unknown, _, Unknown),
|
||||
yap_flag( debug, _, Debug),
|
||||
autoloader:find_predicate(G,ExportingModI).
|
||||
|
||||
|
||||
/**
|
||||
|
55
pl/preds.yap
55
pl/preds.yap
@ -491,39 +491,17 @@ or built-in.
|
||||
|
||||
*/
|
||||
predicate_property(Pred,Prop) :-
|
||||
strip_module(Pred, Mod, TruePred),
|
||||
'$predicate_property2'(TruePred,Prop,Mod).
|
||||
|
||||
'$predicate_property2'(Pred, Prop, Mod) :-
|
||||
var(Mod), !,
|
||||
'$all_current_modules'(Mod),
|
||||
'$predicate_property2'(Pred, Prop, Mod).
|
||||
'$predicate_property2'(Pred,Prop,M0) :-
|
||||
var(Pred), !,
|
||||
(M = M0 ;
|
||||
M0 \= prolog, M = prolog ;
|
||||
M0 \= user, M = user), % prolog and user modules are automatically incorporate in every other module
|
||||
'$generate_all_preds_from_mod'(Pred, SourceMod, M),
|
||||
'$predicate_property'(Pred,SourceMod,M,Prop).
|
||||
'$predicate_property2'(M:Pred,Prop,_) :- !,
|
||||
'$predicate_property2'(Pred,Prop,M).
|
||||
'$predicate_property2'(Pred,Prop,Mod) :-
|
||||
'$pred_exists'(Pred,Mod), !,
|
||||
'$predicate_property'(Pred,Mod,Mod,Prop).
|
||||
'$predicate_property2'(Pred,Prop,Mod) :-
|
||||
'$get_undefined_pred'(Pred, Mod, NPred, M),
|
||||
current_predicate(_,Pred),
|
||||
'$yap_strip_module'(Pred, Mod, TruePred),
|
||||
(
|
||||
Prop = imported_from(M)
|
||||
'$pred_exists'(TruePred, Mod)
|
||||
->
|
||||
M = Mod,
|
||||
NPred = TruePred
|
||||
;
|
||||
'$predicate_property'(NPred,M,M,Prop),
|
||||
Prop \= exported
|
||||
).
|
||||
|
||||
'$generate_all_preds_from_mod'(Pred, M, M) :-
|
||||
'$current_predicate'(_Na,M,Pred,_).
|
||||
'$generate_all_preds_from_mod'(Pred, SourceMod, Mod) :-
|
||||
recorded('$import','$import'(SourceMod, Mod, Orig, Pred,_,_),_),
|
||||
'$pred_exists'(Orig, SourceMod).
|
||||
'$get_undefined_pred'(TruePred, Mod, NPred, M)
|
||||
),
|
||||
'$predicate_property'(NPred,M,Mod,Prop).
|
||||
|
||||
'$predicate_property'(P,M,_,built_in) :-
|
||||
'$is_system_predicate'(P,M).
|
||||
@ -551,6 +529,8 @@ predicate_property(Pred,Prop) :-
|
||||
functor(P,N,A),
|
||||
once(recorded('$module','$module'(_TFN,M,_S,Publics,_L),_)),
|
||||
lists:memberchk(N/A,Publics).
|
||||
'$predicate_property'(P,M,M0,imported_from(M0)) :-
|
||||
M \= M0.
|
||||
'$predicate_property'(P,Mod,_,number_of_clauses(NCl)) :-
|
||||
'$number_of_clauses'(P,Mod,NCl).
|
||||
'$predicate_property'(P,Mod,_,file(F)) :-
|
||||
@ -606,11 +586,22 @@ Defines the relation: _P_ is a currently defined predicate whose name is the at
|
||||
*/
|
||||
current_predicate(A,T0) :-
|
||||
'$yap_strip_module'(T0, M, T),
|
||||
( var(Mod)
|
||||
->
|
||||
'$all_current_modules'(M)
|
||||
;
|
||||
true
|
||||
),
|
||||
(nonvar(T) -> functor(T, A, _) ; true ),
|
||||
(
|
||||
'$current_predicate'(A,M, T, user)
|
||||
;
|
||||
'$imported_predicate'(T, M, T1, M1),
|
||||
(nonvar(T)
|
||||
->
|
||||
'$imported_predicate'(T, M, T1, M1)
|
||||
;
|
||||
'$generate_imported_predicate'(T, M, T1, M1)
|
||||
),
|
||||
functor(T1, A, _),
|
||||
\+ '$is_system_predicate'(T1,M1)
|
||||
).
|
||||
|
Reference in New Issue
Block a user