This commit is contained in:
Vitor Santos Costa 2018-07-17 11:43:57 +01:00
parent 37992c77be
commit e5748f3c9f
23 changed files with 654 additions and 672 deletions

View File

@ -589,7 +589,7 @@ yap_error_descriptor_t *Yap_popErrorContext(bool mdnew, bool pass) {
// last block
LOCAL_ActiveError = ep;
if (e->errorNo && !ep->errorNo && pass) {
yap_error_descriptor_t *epp = ep->top_error;
yap_error_descriptor_t *epp = ep->top_error;
memmove(ep, e, sizeof(*e));
ep->top_error = epp;
}
@ -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 ||

View File

@ -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) {
@ -184,15 +185,15 @@ static bool consult(const char *b_file USES_REGS) {
Term vs = MkVarTerm(), pos = MkVarTerm();
t = YAP_ReadClauseFromStream(c_stream, vs, pos);
// Yap_GetNèwSlot(t);
if (t == TermEof)
break;
if (t == TermEof)
break;
if (t == 0) {
fprintf(stderr, "[ SYNTAX ERROR: while parsing stream %s at line %ld ]\n",
b_file, GLOBAL_Stream[c_stream].linecount);
} else if (IsVarTerm(t) || t == TermNil) {
fprintf(stderr, "[ line: " Int_FORMAT ": term cannot be compiled ]",
GLOBAL_Stream[c_stream].linecount);
} else if (IsApplTerm(t) && (FunctorOfTerm(t) == functor_query ||
} else if (IsApplTerm(t) && (FunctorOfTerm(t) == functor_query ||
FunctorOfTerm(t) == functor_command1)) {
t = ArgOfTerm(1, t);
if (IsApplTerm(t) && FunctorOfTerm(t) == functor_compile2) {
@ -201,13 +202,12 @@ static bool consult(const char *b_file USES_REGS) {
YAP_RunGoalOnce(t);
}
} else {
YAP_CompileClause(t);
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();
@ -216,14 +216,14 @@ static bool consult(const char *b_file USES_REGS) {
pop_text_stack(lvl);
return false;
}
pop_text_stack(lvl);
return true;
pop_text_stack(lvl);
return true;
}
///
///
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)
@ -768,7 +768,7 @@ X_API YAP_file_type_t YAP_parse_yap_arguments(int argc, char *argv[],
argv++;
iap->PrologTopLevelGoal = add_end_dot(*argv);
}
iap->HaltAfterBoot = true;
iap->HaltAfterBoot = true;
break;
case 'n':
if (!strcmp("nosignals", p)) {
@ -941,15 +941,15 @@ static void init_hw(YAP_init_args *yap_init, struct ssz_t *spt) {
if (yap_init->Embedded) {
yap_init->install = false;
GLOBAL_PrologShouldHandleInterrupts =
yap_init->PrologCannotHandleInterrupts = true;
yap_init->PrologCannotHandleInterrupts = true;
} else {
GLOBAL_PrologShouldHandleInterrupts =
!yap_init->PrologCannotHandleInterrupts;
!yap_init->PrologCannotHandleInterrupts;
}
Yap_InitSysbits(0); /* init signal handling and time, required by later
functions */
GLOBAL_argv = yap_init->Argv;
GLOBAL_argc = yap_init->Argc;
Yap_InitSysbits(0); /* init signal handling and time, required by later
functions */
GLOBAL_argv = yap_init->Argv;
GLOBAL_argc = yap_init->Argc;
#if __ANDROID__
@ -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;
}
@ -1022,9 +1023,9 @@ X_API void YAP_Init(YAP_init_args *yap_init) {
CACHE_REGS
if (yap_init->QuietMode) {
setVerbosity(TermSilent);
}
if (yap_init->QuietMode) {
setVerbosity(TermSilent);
}
if (yap_init->PrologRCFile != NULL) {
/*
This must be done before restore, otherwise
@ -1037,15 +1038,15 @@ 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) ) {
&minfo.Heap)) {
init_globals(yap_init);
start_modules();
CurrentModule = PROLOG_MODULE;
TermEof = MkAtomTerm( Yap_LookupAtom("end_of_file"));
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)));
@ -1056,21 +1057,22 @@ X_API void YAP_Init(YAP_init_args *yap_init) {
start_modules();
if (yap_init->install && Yap_OUTPUT_STARTUP) {
setAtomicGlobalPrologFlag(RESOURCE_DATABASE_FLAG,
MkAtomTerm(Yap_LookupAtom(Yap_INPUT_STARTUP)));
setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, true);
}
setAtomicGlobalPrologFlag(RESOURCE_DATABASE_FLAG,
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) {
Term t = MkAtomTerm(Yap_LookupAtom(Yap_OUTPUT_STARTUP));
Term g = Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("qsave_program"), 1),
1, &t);
if (yap_init->install && Yap_OUTPUT_STARTUP) {
Term t = MkAtomTerm(Yap_LookupAtom(Yap_OUTPUT_STARTUP));
Term g = Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("qsave_program"), 1),
1, &t);
YAP_RunGoalOnce(g);
}
YAP_RunGoalOnce(g);
}
end_init(yap_init);
end_init(yap_init);
}
#if (DefTrailSpace < MinTrailSpace)

View File

@ -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
*
@ -91,32 +88,32 @@ 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);
/// auxiliary routine to find a predicate in the current module.
PredEntry *getPred(Term &t, Term &tm, CELL *&outp);
PredEntry *asPred() { return ap; };
/// Empty constructor for predicates
/// Empty constructor for predicates
///
/// Just do nothing.
inline YAPPredicate() {
}
YAPPredicate(Term &to, Term &tmod, CELL * &ts, const char *pname);
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) {
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);
inline YAPPredicate(YAPTerm t) {
CELL *v = nullptr;
Term tp = t.term();
Term tm = Yap_CurrentModule();
ap = getPred(tp, tm, v);
}
/// Cast constructor for predicates,
@ -138,16 +136,14 @@ inline YAPPredicate(YAPTerm t) {
///
inline YAPPredicate(PredEntry *pe) { ap = pe; }
/// Functor constructor for predicates, is given a specific module.
/// Functor constructor for predicates, is given a specific module.
/// This version avoids manufacturing objects
inline YAPPredicate(Functor f, Term mod) {
ap = RepPredProp(PredPropByFunc(f, mod));
}
public:
/// String constructor for predicates
/// String constructor for predicates
///
/// It also communicates the array of arguments t[]
/// and the array of variables
@ -157,25 +153,25 @@ public:
const char *s = (const char *)s0;
Term tnames = MkVarTerm();
tout =
Yap_BufferToTermWithPrioBindings(s, TermNil, tnames, strlen(s0), 1200);
Yap_BufferToTermWithPrioBindings(s, TermNil, tnames, strlen(s0), 1200);
// fprintf(stderr,"ap=%p arity=%d text=%s", ap, ap->ArityOfPE, s);
// Yap_DebugPlWrite(out);
if (tout == 0L) {
return;
return;
throw YAPError();
}
Term tm = Yap_CurrentModule();
ap = getPred(tout, tm, nts);
tout = Yap_SaveTerm(tout);
names = YAPPairTerm(tnames);
}
ap = getPred(tout, nts);
tout = Yap_SaveTerm(tout);
names = YAPPairTerm(tnames);
}
/// Functor constructor for predicates
///
/// Asssumes that we use the current module.
YAPPredicate(YAPFunctor f) {
CACHE_REGS
ap = RepPredProp(PredPropByFunc(f.f, Yap_CurrentModule()));
ap = RepPredProp(PredPropByFunc(f.f, Yap_CurrentModule()));
}
/// Functor constructor for predicates, is given a specific 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,14 +209,14 @@ 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.
///
inline YAPPredicate(const char *at, uintptr_t arity, YAPTerm mod) {
ap = RepPredProp(
PredPropByFunc(Yap_MkFunctor(Yap_LookupAtom(at), arity), mod.term()));
PredPropByFunc(Yap_MkFunctor(Yap_LookupAtom(at), arity), mod.term()));
};
/// 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
@ -279,7 +275,7 @@ public:
YAPPrologPredicate(YAPAtom s, arity_t arity) : YAPPredicate(s, arity){};
/// add a new clause
bool assertClause(YAPTerm clause, bool last = true,
YAPTerm source = YAPTerm());
YAPTerm source = YAPTerm());
/// add a new tuple
bool assertFact(YAPTerm *tuple, bool last = true);
/// retract at least the first clause matching the predicate.
@ -300,10 +296,9 @@ public:
YAPFLIP(YAP_UserCPred call, YAPAtom name, YAP_Arity arity,
YAPModule module = YAPModule(), YAP_UserCPred retry = 0,
YAP_UserCPred cut = 0, YAP_Arity extra = 0, bool test = false)
: YAPPredicate(name, arity, module) {
: 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);
@ -314,7 +309,7 @@ public:
};
YAPFLIP(const char *name, uintptr_t arity, YAPModule module = YAPModule(),
bool backtrackable = false)
: YAPPredicate(YAPAtom(name), arity, module) {
: YAPPredicate(YAPAtom(name), arity, module) {
if (backtrackable) {
Yap_InitCPredBackCut(name, arity, 0, 0, 0, 0, UserCPredFlag);
} else {

View File

@ -519,7 +519,7 @@ bool YAPEngine::mgoal(Term t, Term tmod, bool release) {
#if YAP_PYTHON
// PyThreadState *_save;
//std::cerr << "mgoal " << YAPTerm(t).text() << "\n";
// std::cerr << "mgoal " << YAPTerm(t).text() << "\n";
// _save = PyEval_SaveThread();
#endif
CACHE_REGS
@ -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)) {

View File

@ -96,7 +96,7 @@ public:
inline YAPQuery(const char *s) : YAPPredicate(s, goal, names, (nts = &ARG1)) {
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "got game %ld",
LOCAL_CurSlot);
openQuery();
};
// inline YAPQuery() : YAPPredicate(s, tgoal, tnames)
@ -117,8 +117,8 @@ public:
YAPQuery(YAPTerm t) : YAPPredicate((goal = t.term()), (nts = &ARG1)) {
BACKUP_MACHINE_REGS();
openQuery();
names = YAPPairTerm(TermNil) ;
RECOVER_MACHINE_REGS();
names = YAPPairTerm(TermNil);
RECOVER_MACHINE_REGS();
}
/// set flags for query execution, currently only for exception handling
void setFlag(int flag) { q_flags |= flag; }
@ -177,7 +177,7 @@ public:
YAPEngineArgs() {
// const std::string *s = new std::string("startup.yss");
Embedded = true;
install = false;
install = false;
Yap_InitDefaults(this, nullptr, 0, nullptr);
#if YAP_PYTHON
@ -204,13 +204,13 @@ public:
inline void setMaxTrailSize(bool fl) { MaxTrailSize = fl; };
inline bool getMaxTrailSize() { return MaxTrailSize; };
inline bool getMaxTrailSize() { return MaxTrailSize; };
inline void createSavedState(bool fl) { install = fl; };
inline void createSavedState(bool fl) { install = fl; };
inline bool creatingSavedState() { return install; };
inline bool creatingSavedState() { return install; };
inline void setPLDIR(const char *fl) {
inline void setPLDIR(const char *fl) {
LIBDIR = (const char *)malloc(strlen(fl) + 1);
strcpy((char *)LIBDIR, fl);
};
@ -286,7 +286,7 @@ private:
void doInit(YAP_file_type_t BootMode, YAPEngineArgs *cargs);
YAP_dogoalinfo q;
YAPError e;
PredEntry *rewriteUndefEngineQuery(PredEntry *ap, Term &t, Term tmod);
PredEntry *rewriteUndefEngineQuery(PredEntry *ap, Term &t, Term tmod);
public:
/// construct a new engine; may use a variable number of arguments
@ -326,23 +326,26 @@ 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
/// recovered on backtracking. The release option ensures
/// backtracking is called at the very end.
bool mgoal(Term t, Term tmod, bool release= false);
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

173
H/Yatom.h
View File

@ -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.
@ -273,10 +249,10 @@ INLINE_ONLY bool IsModProperty(int flags) {
#define UNKNOWN_MASK \
(UNKNOWN_ERROR | UNKNOWN_WARNING | UNKNOWN_FAIL | UNKNOWN_FAST_FAIL | \
UNKNOWN_ABORT | UNKNOWN_HALT)
#define SNGQ_CHARS (0x10000) /* 'ab' --> [a, b] */
#define SNGQ_ATOM (0x20000) /* 'ab' --> ab */
#define SNGQ_STRING (0x40000) /* 'ab' --> "ab" */
#define SNGQ_CODES (0x80000) /* 'ab' --> [0'a, 0'b] */
#define SNGQ_CHARS (0x10000) /* 'ab' --> [a, b] */
#define SNGQ_ATOM (0x20000) /* 'ab' --> ab */
#define SNGQ_STRING (0x40000) /* 'ab' --> "ab" */
#define SNGQ_CODES (0x80000) /* 'ab' --> [0'a, 0'b] */
#define SNGQ_MASK (BCKQ_CHARS | BCKQ_ATOM | BCKQ_STRING | BCKQ_CODES)
Term Yap_getUnknownModule(ModEntry *m);
@ -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);
@ -717,8 +678,8 @@ typedef struct DB_STRUCT {
struct DB_STRUCT *p, *n; /* entry's age, negative if from recorda,
positive if it was recordz */
CELL Mask; /* parts that should be cleared */
CELL Key; /* A mask that can be used to check before
you unify */
CELL Key; /* A mask that can be used to check before
you unify */
DBTerm DBT;
} DBStruct;
@ -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,10 +1232,9 @@ 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);
extern Term Yap_BufferToTerm(const char *s, Term opts);
/* cdmgr.c */
extern int Yap_RemoveIndexation(PredEntry *);
@ -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);
@ -1599,17 +1526,17 @@ 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 yap_error_descriptor_t *Yap_GetException();
extern void Yap_PrintException(yap_error_descriptor_t *i);
INLINE_ONLY bool Yap_HasException(void) {
return LOCAL_ActiveError->errorNo != YAP_NO_ERROR;
}
INLINE_ONLY Term MkSysError(yap_error_descriptor_t *i) {
Term et = MkAddressTerm(i);
return Yap_MkApplTerm( FunctorException, 1, &et);
return Yap_MkApplTerm(FunctorException, 1, &et);
}
yap_error_descriptor_t *Yap_UserError( Term t, yap_error_descriptor_t *i);
yap_error_descriptor_t *Yap_UserError(Term t, yap_error_descriptor_t *i);
extern bool Yap_RaiseException(void);

View File

@ -1,4 +1,4 @@
l/****************************************************************************
/****************************************************************************
**
** Copyright (C) 2012 Denis Shienkov <denis.shienkov@gmail.com>
** Copyright (C) 2012 Laszlo Papp <lpapp@kde.org>
@ -37,29 +37,27 @@ l/****************************************************************************
#include <QPlainTextEdit>
class Console : public QPlainTextEdit
{
Q_OBJECT
class Console : public QPlainTextEdit {
Q_OBJECT
signals:
void getData(const QString &data);
void getData(const QString &data);
public:
explicit Console(QWidget *parent = 0);
explicit Console(QWidget *parent = 0);
void putData(const QString &data);
void putData(const QString &data);
void setLocalEchoEnabled(bool set);
void setLocalEchoEnabled(bool set);
protected:
virtual void keyPressEvent(QKeyEvent *e);
virtual void mousePressEvent(QMouseEvent *e);
virtual void mouseDoubleClickEvent(QMouseEvent *e);
virtual void contextMenuEvent(QContextMenuEvent *e);
virtual void keyPressEvent(QKeyEvent *e);
virtual void mousePressEvent(QMouseEvent *e);
virtual void mouseDoubleClickEvent(QMouseEvent *e);
virtual void contextMenuEvent(QContextMenuEvent *e);
private:
bool localEchoEnabled;
bool localEchoEnabled;
};
#endif // CONSOLE_H

View File

@ -1,16 +1,16 @@
/*************************************************************************
* *
* YAP Prolog %W% %G% *
* Yap Prolog was developed at NCCUP - Universidade do Porto *
* *
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
* *
**************************************************************************
* *
* File: YapError.h * mods:
** comments: error header file for YAP *
* version: $Id: Yap.h,v 1.38 2008-06-18 10:02:27 vsc Exp $ *
*************************************************************************/
* *
* YAP Prolog %W% %G% *
* Yap Prolog was developed at NCCUP - Universidade do Porto *
* *
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
* *
**************************************************************************
* *
* File: YapError.h * mods:
** comments: error header file for YAP *
* version: $Id: Yap.h,v 1.38 2008-06-18 10:02:27 vsc Exp $ *
*************************************************************************/
#ifndef YAP_ERROR_H
#define YAP_ERROR_H 1
@ -38,13 +38,12 @@
#define MAX_ERROR_MSG_SIZE 1024
extern void
Yap_InitError__(const char *file, const char *function, int lineno,
yap_error_number e, YAP_Term g, ...);
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, ...)
@ -54,13 +53,13 @@ extern void Yap_ThrowError__(const char *file, const char *function, int lineno,
;
#define Yap_NilError(id, ...) \
Yap_Error__(false,__FILE__, __FUNCTION__, __LINE__, id, TermNil, __VA_ARGS__)
Yap_Error__(false, __FILE__, __FUNCTION__, __LINE__, id, TermNil, __VA_ARGS__)
#define Yap_InitError(id, ...) \
Yap_InitError__(__FILE__, __FUNCTION__, __LINE__, id, TermNil, __VA_ARGS__)
#define Yap_Error(id, inp, ...) \
Yap_Error__(false,__FILE__, __FUNCTION__, __LINE__, id, inp, __VA_ARGS__)
Yap_Error__(false, __FILE__, __FUNCTION__, __LINE__, id, inp, __VA_ARGS__)
#define Yap_ThrowError(id, inp, ...) \
Yap_ThrowError__(__FILE__, __FUNCTION__, __LINE__, id, inp, __VA_ARGS__)
@ -74,18 +73,18 @@ 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))
return t;
if (IsVarTerm(t)) {
Yap_Error__(false,fu, fi, line, INSTANTIATION_ERROR, t, NULL);
Yap_Error__(false, fu, fi, line, INSTANTIATION_ERROR, t, NULL);
} else {
if (IsAtomTerm(t))
return t;
Yap_Error__(false,fu, fi, line, TYPE_ERROR_ATOM, t, NULL);
Yap_Error__(false, fu, fi, line, TYPE_ERROR_ATOM, t, NULL);
return 0L;
}
@ -114,8 +113,8 @@ INLINE_ONLY Term Yap_ensure_atom__(const char *fu, const char *fi,
#define AUX_ERROR(t, n, s, TYPE) \
if (s + (n + 1) > (TYPE *)AuxSp) { \
pop_text_stack(lvl); \
LOCAL_Error_TYPE = RESOURCE_ERROR_AUXILIARY_STACK; \
pop_text_stack(lvl); \
LOCAL_Error_TYPE = RESOURCE_ERROR_AUXILIARY_STACK; \
LOCAL_Error_Size = n * sizeof(TYPE); \
return NULL; \
}
@ -225,7 +224,7 @@ INLINE_ONLY Term Yap_ensure_atom__(const char *fu, const char *fi,
const char *prologParserText;
const char *prologParserFile;
bool prologConsulting;
const char *culprit;
const char *culprit;
YAP_Term errorRawTerm, rawExtraErrorTerm;
char *errorMsg;
size_t errorMsgLen;
@ -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 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 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_prolog_add_culprit(yap_error_descriptor_t *t);
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_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

View File

@ -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) :- !.

View File

@ -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;

View File

@ -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}'],

View File

@ -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)

View File

@ -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

View File

@ -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) ).

View File

@ -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).
open_esh(_Errors , Text, Stream) :-
open_mem_read_stream( Text, Stream ).
esh(Errors , Stream) :-
repeat,
catch(
read_clause(Stream, Cl, [term_position(_Pos), syntax_errors(fail)] ),
Error,
syntax(Errors , Error)
),
Cl == end_of_file,
!.
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(Engine , Text, Stream, Name) :-
Engine.errors := [],
b_setval( jupyter, Engine),
Name := Engine.stream_name,
open_mem_read_stream( Text, Stream ).
esh(Engine , Name, Stream) :-
repeat,
catch(
read_clause(Stream, Cl,[]),
E=error(C,E),
p_message(C,E)
),
Cl == end_of_file,
!.
close_esh( _Engine , Stream ) :-
close(Stream).
close_esh( _Errors , 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( _ ).

View File

@ -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

View File

@ -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:

View File

@ -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,135 +104,30 @@ 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;
YAPPycatch(e);
SWIG_fail;
}
}
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());
}
}
%typecheck(2) Int { $1 = PyLong_Check($input); }
%typecheck(3) double { $1 = PyFloat_Check($input); }
%typecheck(2) const char * { $1 = PyUnicode_Check($input); }
#else
%typecheck(1) Term { $1 = !PyUnicode_Check($input); }
%typecheck(1) YAP_Term { $1 = PyUnicode_Check($input); }
%typecheck(0) YAPTerm { $1 = !PyUnicode_Check($input); }
#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); }
%typecheck(1) Term { $1 = !PyUnicode_Check($input); }
%typecheck(1) YAP_Term { $1 = PyUnicode_Check($input); }
%typecheck(0) YAPTerm { $1 = !PyUnicode_Check($input); }
%typemap(in) jlong %{
@ -288,16 +152,16 @@ X_API extern Term YAP_MkCharPTerm( char *n);
}
}
#endif
#endif
%{
/* Put header files here or function declarations like below */
%{
/* 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);
%}

View File

@ -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)
;

View File

@ -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).
/**
*
* @}

View File

@ -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] ].

View File

@ -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).
/**

View File

@ -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),
(
Prop = imported_from(M)
;
'$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).
current_predicate(_,Pred),
'$yap_strip_module'(Pred, Mod, TruePred),
(
'$pred_exists'(TruePred, Mod)
->
M = Mod,
NPred = TruePred
;
'$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),
(nonvar(T) -> functor(T, A, _) ; true ),
( 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)
).