start work on exception handling
This commit is contained in:
parent
6c7a84a942
commit
d8ecd6a202
18
CXX/yapi.cpp
18
CXX/yapi.cpp
@ -379,7 +379,7 @@ YAPPredicate::YAPPredicate(const char *s, Term **outp, term_t &vnames) throw (in
|
|||||||
vnames = Yap_NewSlots(1 PASS_REGS);
|
vnames = Yap_NewSlots(1 PASS_REGS);
|
||||||
Term t = Yap_StringToTerm(s, strlen(s)+1, vnames);
|
Term t = Yap_StringToTerm(s, strlen(s)+1, vnames);
|
||||||
if (t == 0L)
|
if (t == 0L)
|
||||||
throw YAPError::SYNTAX_ERROR;
|
throw SYNTAX_ERROR;
|
||||||
ap = getPred( t, outp );
|
ap = getPred( t, outp );
|
||||||
//{ CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "OUT vnames=%d ap=%p LCL0=%p", vnames, ap, LCL0) ; }
|
//{ CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "OUT vnames=%d ap=%p LCL0=%p", vnames, ap, LCL0) ; }
|
||||||
}
|
}
|
||||||
@ -446,7 +446,7 @@ YAPQuery::initQuery( Term *ts )
|
|||||||
LOCAL_execution = (struct open_query_struct *)this;
|
LOCAL_execution = (struct open_query_struct *)this;
|
||||||
this->q_open=1;
|
this->q_open=1;
|
||||||
this->q_state=0;
|
this->q_state=0;
|
||||||
this->q_flags = 0;
|
this->q_flags = PL_Q_PASS_EXCEPTION;
|
||||||
this->q_g = ts;
|
this->q_g = ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -493,7 +493,7 @@ bool YAPQuery::next()
|
|||||||
return false;
|
return false;
|
||||||
// don't forget, on success these guys must create slots
|
// don't forget, on success these guys must create slots
|
||||||
if (this->q_state == 0) {
|
if (this->q_state == 0) {
|
||||||
extern void toggle_low_level_trace(void);
|
// extern void toggle_low_level_trace(void);
|
||||||
//toggle_low_level_trace();
|
//toggle_low_level_trace();
|
||||||
result = (bool)YAP_EnterGoal((YAP_PredEntryPtr)this->ap, this->q_g, &this->q_h);
|
result = (bool)YAP_EnterGoal((YAP_PredEntryPtr)this->ap, this->q_g, &this->q_h);
|
||||||
} else {
|
} else {
|
||||||
@ -537,7 +537,9 @@ void YAPQuery::close()
|
|||||||
int YAPPredicate::call(YAPTerm t[])
|
int YAPPredicate::call(YAPTerm t[])
|
||||||
{
|
{
|
||||||
YAPQuery q = YAPQuery(*this, t);
|
YAPQuery q = YAPQuery(*this, t);
|
||||||
int ret = q.next();
|
int ret;
|
||||||
|
|
||||||
|
ret = q.next();
|
||||||
q.cut();
|
q.cut();
|
||||||
q.close();
|
q.close();
|
||||||
return ret;
|
return ret;
|
||||||
@ -628,12 +630,14 @@ YAPQuery *YAPEngine::query( char *s ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
YAPQuery *YAPEngine::safeQuery( char *s ) {
|
YAPQuery *YAPEngine::safeQuery( char *s ) {
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
YAPQuery *n = new YAPQuery( s );
|
YAPQuery *n = new YAPQuery( s );
|
||||||
|
n->setFlag( PL_Q_CATCH_EXCEPTION );
|
||||||
|
n->resetFlag( PL_Q_PASS_EXCEPTION );
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
catch (...) {
|
catch (yap_error_number errno) {
|
||||||
|
error = errno;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
21
CXX/yapi.hh
21
CXX/yapi.hh
@ -94,10 +94,6 @@ class YAPApplTerm;
|
|||||||
class YAPPairTerm;
|
class YAPPairTerm;
|
||||||
class YAPQuery;
|
class YAPQuery;
|
||||||
|
|
||||||
#include "yapie.hh"
|
|
||||||
|
|
||||||
class TypeError {};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Generic Prolog Term
|
* @brief Generic Prolog Term
|
||||||
*/
|
*/
|
||||||
@ -425,7 +421,7 @@ public:
|
|||||||
Term t, tp;
|
Term t, tp;
|
||||||
t = YAP_ReadBuffer(s,&tp);
|
t = YAP_ReadBuffer(s,&tp);
|
||||||
if (t == 0L)
|
if (t == 0L)
|
||||||
throw YAPError::SYNTAX_ERROR;
|
throw SYNTAX_ERROR;
|
||||||
ap = getPred( t, (Term **)NULL );
|
ap = getPred( t, (Term **)NULL );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -437,7 +433,7 @@ public:
|
|||||||
Term t, tp;
|
Term t, tp;
|
||||||
t = YAP_ReadBuffer(s,&tp);
|
t = YAP_ReadBuffer(s,&tp);
|
||||||
if (t == 0L)
|
if (t == 0L)
|
||||||
throw YAPError::SYNTAX_ERROR;
|
throw SYNTAX_ERROR;
|
||||||
ap = getPred( t, (Term **)NULL );
|
ap = getPred( t, (Term **)NULL );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -515,6 +511,10 @@ public:
|
|||||||
|
|
||||||
initQuery( ts );
|
initQuery( ts );
|
||||||
}
|
}
|
||||||
|
/// set flags for query execution, currently only for exception handling
|
||||||
|
void setFlag(int flag) {q_flags |= flag; }
|
||||||
|
/// reset flags for query execution, currently only for exception handling
|
||||||
|
void resetFlag(int flag) {q_flags &= ~flag; }
|
||||||
/// first query
|
/// first query
|
||||||
///
|
///
|
||||||
/// actually implemented by calling the next();
|
/// actually implemented by calling the next();
|
||||||
@ -551,6 +551,7 @@ class YAPEngine {
|
|||||||
private:
|
private:
|
||||||
YAPCallback *_callback;
|
YAPCallback *_callback;
|
||||||
YAP_init_args init_args;
|
YAP_init_args init_args;
|
||||||
|
yap_error_number error;
|
||||||
public:
|
public:
|
||||||
YAPEngine(char *savedState = (char *)NULL,
|
YAPEngine(char *savedState = (char *)NULL,
|
||||||
size_t stackSize = 0,
|
size_t stackSize = 0,
|
||||||
@ -569,15 +570,17 @@ public:
|
|||||||
/// remove current callback
|
/// remove current callback
|
||||||
void delYAPCallback() { _callback = 0; }
|
void delYAPCallback() { _callback = 0; }
|
||||||
/// set a new callback
|
/// set a new callback
|
||||||
void setYAPCallback(YAPCallback *cb) { delYAPCallback(); _callback = cb; __android_log_print(ANDROID_LOG_INFO, __FILE__, "after loading startup %p",cb); }
|
void setYAPCallback(YAPCallback *cb) { delYAPCallback(); _callback = cb; }
|
||||||
/// execute the callback.
|
/// execute the callback.
|
||||||
void run() { if (_callback) _callback->run(); }
|
void run() { if (_callback) _callback->run(); }
|
||||||
/// execute the callback with a text argument.
|
/// execute the callback with a text argument.
|
||||||
void run( char *s) { __android_log_print(ANDROID_LOG_INFO, __FUNCTION__, "bef calling disp %s %p",s, _callback); if (_callback) _callback->run(s); }
|
void run( char *s) { if (_callback) _callback->run(s); }
|
||||||
/// build a query on the engine
|
/// build a query on the engine
|
||||||
YAPQuery *query( char *s );
|
YAPQuery *query( char *s );
|
||||||
/// build a query on the engine
|
/// build a query on the engine handling exceptions
|
||||||
YAPQuery *safeQuery( char *s );
|
YAPQuery *safeQuery( char *s );
|
||||||
|
|
||||||
|
yap_error_number hasError( ); //> report whether the engine has found an error
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
22
CXX/yapie.hh
22
CXX/yapie.hh
@ -10,7 +10,27 @@ class YAPPredicate;
|
|||||||
|
|
||||||
class YAPError {
|
class YAPError {
|
||||||
public:
|
public:
|
||||||
static const int SYNTAX_ERROR = 0x10000;
|
static const int SYNTAX_ERROR = 0x10000; //> syntax error
|
||||||
|
static const int DOMAIN_ERROR = 0x20000; //> usually illegal parameter, like asin( 2 )
|
||||||
|
static const int TYPE_ERROR = 0x40000; //> usually illegal parameter in the language, like ( 2 mod 3.0 )
|
||||||
|
static const int PERMISSION_ERROR = 0x80000; //> wrong para,eter
|
||||||
|
static const int EVALUATION_ERROR = 0x100000; //> bad arithmetic expressions
|
||||||
|
static const int RESOURCE_ERROR = 0x200000; //> no resource available, like MEM
|
||||||
|
static const int REPRESENTATION_ERROR = 0x400000; //> bad UTF-8 strings, etc
|
||||||
|
static const int EXISTËNCE_ERROR = 0x400000; //> object not found
|
||||||
|
static const int PROFILER = 0x400000; //> improve profiling support.
|
||||||
|
static const int OTHER_ERROR = 0x800000; //> anything rldr.,,,,,,,,,,,,,,,,,,,,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class YAPErrorClass {
|
||||||
|
public:
|
||||||
|
static const int SYNTAX_ERROR = 0x10000;
|
||||||
|
static const int DOMAIN_ERROR = 0x20000;
|
||||||
|
static const int TYPE_ERROR = 0x40000;
|
||||||
|
static const int PERMISSION_ERROR = 0x80000;
|
||||||
|
static const int EVALUATION_ERROR = 0x100000;
|
||||||
|
static const int RESOURCE_ERROR = 0x200000;
|
||||||
|
static const int REPRESENTATION_ERROR = 0x400000;
|
||||||
|
static const int OTHER_ERROR = 0x800000;
|
||||||
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user