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

View File

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