error handling

This commit is contained in:
Vitor Santos Costa 2018-03-24 22:56:52 +00:00
parent 0b67a66533
commit e02884a94f
2 changed files with 40 additions and 40 deletions

View File

@ -437,6 +437,7 @@ bool YAPEngine::call(YAPPredicate ap, YAPTerm ts[]) {
LOCAL_RestartEnv = &buf;
if (sigsetjmp(*LOCAL_RestartEnv, false)) {
std::cerr << "Restart\n";
throw *new YAPError();
//q.e = new YAPError();
}
// don't forget, on success these bindings will still be there);
@ -490,7 +491,7 @@ bool YAPEngine::mgoal(Term t, Term tmod) {
if (sigsetjmp(*LOCAL_RestartEnv, false)) {
// PyEval_RestoreThread(_save);
std::cerr << "Restart\n";
//throw new YAPError();
throw *new YAPError();
}
// don't forget, on success these guys may create slots
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec ");
@ -567,10 +568,7 @@ Term YAPEngine::fun(Term t) {
sigjmp_buf buf, *oldp = LOCAL_RestartEnv;
LOCAL_RestartEnv = &buf;
if (sigsetjmp(*LOCAL_RestartEnv, false)) {
// throw new YAPError();
LOCAL_RestartEnv = oldp;
RECOVER_MACHINE_REGS();
return 0;
throw *new YAPError();
}
// don't forget, on success these guys may create slots
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec ");
@ -693,7 +691,7 @@ bool YAPQuery::next() {
return false;
LOCAL_RestartEnv = &buf;
if (sigsetjmp(*LOCAL_RestartEnv, false)) {
//e = new YAPError();
throw *new YAPError();
}
// don't forget, on success these guys may create slots
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec ");
@ -712,10 +710,9 @@ bool YAPQuery::next() {
}
q_state = 1;
if ((terr = Yap_PeekException())) {
LOCAL_RestartEnv = &buf;
throw * new YAPError();
result = false;
}
}
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "out %d", result);
if (!result) {

View File

@ -144,38 +144,41 @@ class YAPShell:
# if not isinstance(eq[0],str):
# print( "Error: Variable Name matches a Python Symbol")
# return
self.do_ask = True
engine = self.engine
bindings = []
g = python_query(self, query)
if not self.q:
self.q = Query( engine, g )
for bind in self.q:
bindings += [bind]
if self.do_ask:
print(bindings)
bindings = []
try:
engine = self.engine
bindings = []
loop = False
g = python_query(self, query)
if not self.q:
self.q = Query( engine, g )
for bind in self.q:
bindings += [bind]
if loop:
continue
if not self.q:
break
s = input("more(;), all(*), no(\\n), python(#) ?").lstrip()
else:
s = ";"
if s.startswith(';') or s.startswith('y'):
continue
elif s.startswith('#'):
try:
exec(s.lstrip('#'))
except:
raise
elif s.startswith('*') or s.startswith('a'):
self.do_ask = False
continue
else:
break
if self.q:
self.os = query
if bindings:
return True,bindings
print("No (more) answers")
return False, None
if s.startswith(';') or s.startswith('y'):
continue
elif s.startswith('#'):
try:
exec(s.lstrip('#'))
except:
raise
elif s.startswith('*') or s.startswith('a'):
loop = True
continue
else:
break
if self.q:
self.os = query
if bindings:
return True,bindings
print("No (more) answers")
return False, None
except e:
print("Exception")
print(e)
def live(self, engine, **kwargs):