cleanups
This commit is contained in:
parent
03d9fdd45a
commit
705a6e9b7f
@ -1,5 +1,13 @@
|
||||
|
||||
add_library (Yap++ SHARED yapi.cpp)
|
||||
add_library (Yap++ SHARED
|
||||
yapa.hh
|
||||
yapdb.hh
|
||||
yapi.cpp
|
||||
yapi.hh
|
||||
yapie.hh
|
||||
yapq.hh
|
||||
yapt.hh
|
||||
)
|
||||
|
||||
include_directories (H include ${CMAKE_BINARY_DIR} ${GMP_INCLUDE_DIR})
|
||||
|
||||
|
@ -128,7 +128,7 @@ protected:
|
||||
// Yap_DebugPlWrite(out);
|
||||
// delete [] ns;
|
||||
if (out == 0L)
|
||||
throw YAPError::YAP_SYNTAX_ERROR;
|
||||
throw YAPError(SYNTAX_ERROR);
|
||||
ap = getPred( out, outp);
|
||||
RECOVER_MACHINE_REGS();
|
||||
}
|
||||
|
37
CXX/yapi.cpp
37
CXX/yapi.cpp
@ -327,9 +327,15 @@ YAPTerm *YAPTerm::vars()
|
||||
}
|
||||
*/
|
||||
|
||||
YAPTerm::YAPTerm(void *ptr) { CACHE_REGS mk( MkIntegerTerm( (Int)ptr ) );}
|
||||
YAPTerm::YAPTerm(void *ptr) {
|
||||
CACHE_REGS
|
||||
mk( MkIntegerTerm( (Int)ptr ) );
|
||||
}
|
||||
|
||||
YAPTerm::YAPTerm(intptr_t i) { CACHE_REGS Term tn = MkIntegerTerm( i ); mk( tn ); }
|
||||
YAPTerm::YAPTerm(intptr_t i) {
|
||||
CACHE_REGS Term tn = MkIntegerTerm( i );
|
||||
mk( tn );
|
||||
}
|
||||
|
||||
YAPTerm YAPListTerm::car()
|
||||
{
|
||||
@ -338,10 +344,13 @@ YAPTerm YAPListTerm::car()
|
||||
if (IsPairTerm(to))
|
||||
return YAPTerm(HeadOfTerm(to));
|
||||
else
|
||||
throw YAPError::YAP_DOMAIN_ERROR;
|
||||
throw YAPError(TYPE_ERROR_LIST);
|
||||
}
|
||||
|
||||
YAPVarTerm::YAPVarTerm() { CACHE_REGS mk( MkVarTerm( ) ); }
|
||||
YAPVarTerm::YAPVarTerm() {
|
||||
CACHE_REGS
|
||||
mk( MkVarTerm( ) );
|
||||
}
|
||||
|
||||
|
||||
char *YAPAtom::getName(void) {
|
||||
@ -381,6 +390,19 @@ void YAPQuery::initOpenQ() {
|
||||
q_cp = CP;
|
||||
}
|
||||
|
||||
int
|
||||
YAPError::get( )
|
||||
{
|
||||
return errNo;
|
||||
}
|
||||
|
||||
const char *
|
||||
YAPError::text()
|
||||
{
|
||||
return "YAP Error";
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
YAPQuery::initQuery( Term t )
|
||||
{
|
||||
@ -590,11 +612,12 @@ YAPEngine::YAPEngine( char *savedState,
|
||||
init_args.YapPrologTopLevelGoal = topLevel;
|
||||
init_args.HaltAfterConsult = script;
|
||||
init_args.FastBoot = fastBoot;
|
||||
yerror = YAPError();
|
||||
delYAPCallback();
|
||||
if (cb) setYAPCallback(cb);
|
||||
curren = this;
|
||||
if (YAP_Init( &init_args ) == YAP_BOOT_ERROR)
|
||||
throw(YAPError::YAP_OTHER_ERROR);
|
||||
throw(YAPError(INTERNAL_ERROR));
|
||||
}
|
||||
|
||||
|
||||
@ -619,7 +642,7 @@ PredEntry *YAPPredicate::getPred( Term &t, Term* &outp ) {
|
||||
Term m = Yap_CurrentModule() ;
|
||||
t = Yap_StripModule(t, &m);
|
||||
if (IsVarTerm(t) || IsNumTerm(t)) {
|
||||
throw YAPError::YAP_TYPE_ERROR;
|
||||
throw YAPError(TYPE_ERROR_NUMBER);
|
||||
}
|
||||
if (IsAtomTerm(t)) {
|
||||
ap = RepPredProp(PredPropByAtom(AtomOfTerm(t), m));
|
||||
@ -633,7 +656,7 @@ PredEntry *YAPPredicate::getPred( Term &t, Term* &outp ) {
|
||||
}
|
||||
Functor f = FunctorOfTerm(t);
|
||||
if (IsExtensionFunctor(f)) {
|
||||
throw YAPError::YAP_TYPE_ERROR;
|
||||
throw YAPError(TYPE_ERROR_NUMBER);
|
||||
} else {
|
||||
ap = RepPredProp(PredPropByFunc(f, m));
|
||||
outp = RepAppl(t)+1;
|
||||
|
15
CXX/yapie.hh
15
CXX/yapie.hh
@ -1,16 +1,11 @@
|
||||
|
||||
|
||||
class YAPError {
|
||||
int errNo;
|
||||
public:
|
||||
static const int YAP_SYNTAX_ERROR = 0x10000; //> syntax error
|
||||
static const int YAP_DOMAIN_ERROR = 0x20000; //> usually illegal parameter, like asin( 2 )
|
||||
static const int YAP_TYPE_ERROR = 0x40000; //> usually illegal parameter in the language, like ( 2 mod 3.0 )
|
||||
static const int YAP_PERMISSION_ERROR = 0x80000; //> wrong para,eter
|
||||
static const int YAP_EVALUATION_ERROR = 0x100000; //> bad arithmetic expressions
|
||||
static const int YAP_RESOURCE_ERROR = 0x200000; //> no resource available, like MEM
|
||||
static const int YAP_REPRESENTATION_ERROR = 0x400000; //> bad UTF-8 strings, etc
|
||||
static const int YAP_EXISTENCE_ERROR = 0x800000; //> object not found
|
||||
static const int YAP_PROFILER = 0x100000; //> improve profiling support.
|
||||
static const int YAP_OTHER_ERROR = 0x2000000; //> anything
|
||||
YAPError() { errNo = YAP_NO_ERROR; };
|
||||
YAPError(int err) { errNo = err; };
|
||||
int get();
|
||||
const char *text();
|
||||
};
|
||||
|
||||
|
@ -111,7 +111,7 @@ public:
|
||||
/// execute the callback with a text argument.
|
||||
void run( char *s) { if (_callback) _callback->run(s); }
|
||||
/// execute the callback with a text argument.
|
||||
YAPError hasError( ) { return yerror; }
|
||||
YAPError hasError( ) { return yerror.get(); }
|
||||
/// build a query on the engine
|
||||
YAPQuery *query( const char *s ) {
|
||||
return new YAPQuery( s );
|
||||
|
@ -230,7 +230,7 @@ public:
|
||||
else if ( to == TermNil)
|
||||
return YAPListTerm( );
|
||||
/* error */
|
||||
throw YAPError::YAP_TYPE_ERROR;
|
||||
throw YAPError(TYPE_ERROR_LIST);
|
||||
}
|
||||
|
||||
/// Check if the list is empty.
|
||||
|
@ -14,6 +14,9 @@
|
||||
|
||||
#define NO_DYN 1
|
||||
|
||||
#ifndef FOREIGN_H
|
||||
#define FOREIGN_H
|
||||
|
||||
/* Currently load_foreign_files works for the following machines:
|
||||
|
||||
AIX: should work for 3.2 and 4.1 at least, using ECOFF;
|
||||
@ -110,3 +113,5 @@ void Yap_ShutdownLoadForeign(void);
|
||||
|
||||
#define EAGER_LOADING 1
|
||||
#define GLOBAL_LOADING 2
|
||||
|
||||
#endif
|
||||
|
@ -4,7 +4,8 @@ typedef enum TokenKinds {
|
||||
Var_tok,
|
||||
String_tok,
|
||||
WString_tok,
|
||||
StringTerm_tok,
|
||||
BQString_tok,
|
||||
WBQString_tok,
|
||||
Ponctuation_tok,
|
||||
Error_tok,
|
||||
QuasiQuotes_tok,
|
||||
|
119
H/YapText.h
119
H/YapText.h
@ -14,9 +14,8 @@
|
||||
* comments: Term conversion C implemented support *
|
||||
* *
|
||||
*************************************************************************/
|
||||
#ifdef SCCS
|
||||
static char SccsId[] = "%W% %G%";
|
||||
#endif
|
||||
#ifndef YAP_TEXT_H
|
||||
#define YAP_TEXT_H
|
||||
|
||||
#if SIZEOF_WCHAR_T == 2
|
||||
#define CHARCODE_MAX 0xffff
|
||||
@ -59,7 +58,7 @@ typedef enum {
|
||||
|
||||
typedef UInt seq_type_t;
|
||||
|
||||
#define YAP_TYPE_MASK 0xFFFF
|
||||
#define YAP_TYPE_MASK 0x0FFF
|
||||
|
||||
typedef union {
|
||||
Float f;
|
||||
@ -114,12 +113,6 @@ mod_to_type( Term mod USES_REGS )
|
||||
{
|
||||
|
||||
// see pl-incl.h
|
||||
#ifndef DBLQ_CHARS
|
||||
#define DBLQ_CHARS (0x0004) /* "ab" --> ['a', 'b'] */
|
||||
#define DBLQ_ATOM (0x0008) /* "ab" --> 'ab' */
|
||||
#define DBLQ_STRING (0x0010) /* "ab" --> "ab" */
|
||||
#define DBLQ_MASK (DBLQ_CHARS|DBLQ_ATOM|DBLQ_STRING)
|
||||
#endif
|
||||
unsigned int flags = Yap_GetModuleEntry(mod)->flags;
|
||||
if (flags & DBLQ_ATOM) {
|
||||
return YAP_STRING_ATOM;
|
||||
@ -131,6 +124,23 @@ mod_to_type( Term mod USES_REGS )
|
||||
return YAP_STRING_CODES;
|
||||
}
|
||||
|
||||
// string type depends on current module
|
||||
static inline seq_type_t
|
||||
mod_to_bqtype( Term mod USES_REGS )
|
||||
{
|
||||
|
||||
// see pl-incl.h
|
||||
unsigned int flags = Yap_GetModuleEntry(mod)->flags;
|
||||
if (flags & BCKQ_ATOM) {
|
||||
return YAP_STRING_ATOM;
|
||||
} else if (flags & BCKQ_STRING) {
|
||||
return YAP_STRING_STRING;
|
||||
} else if (flags & BCKQ_CHARS) {
|
||||
return YAP_STRING_ATOMS;
|
||||
}
|
||||
return YAP_STRING_CODES;
|
||||
}
|
||||
|
||||
// the routines
|
||||
|
||||
extern void *Yap_readText( void *buf, seq_tv_t *inp, encoding_t *enc, int *minimal, size_t *lengp USES_REGS);
|
||||
@ -310,6 +320,22 @@ Yap_AtomicToTDQ(Term t0, Term mod USES_REGS)
|
||||
return out.val.t;
|
||||
}
|
||||
|
||||
static inline Term
|
||||
Yap_AtomicToTBQ(Term t0, Term mod USES_REGS)
|
||||
{
|
||||
seq_tv_t inp, out;
|
||||
|
||||
inp.val.t = t0;
|
||||
inp.type = YAP_STRING_STRING|YAP_STRING_ATOM|YAP_STRING_INT|YAP_STRING_FLOAT|YAP_STRING_BIG|YAP_STRING_TERM;
|
||||
out.type = mod_to_bqtype(mod PASS_REGS);
|
||||
|
||||
if (!Yap_CVT_Text(&inp, &out PASS_REGS))
|
||||
return 0L;
|
||||
if (out.type == YAP_STRING_ATOM)
|
||||
return MkAtomTerm( out.val.a);
|
||||
return out.val.t;
|
||||
}
|
||||
|
||||
static inline Atom
|
||||
Yap_CharsToAtom( const char *s USES_REGS )
|
||||
{
|
||||
@ -360,7 +386,7 @@ Yap_CharsToDiffListOfCodes( const char *s, Term tail USES_REGS )
|
||||
inp.val.c = s;
|
||||
inp.sz = 0;
|
||||
inp.type = YAP_STRING_CHARS;
|
||||
out.type = YAP_STRING_DIFF;
|
||||
out.type = YAP_STRING_DIFF|YAP_STRING_CODES;
|
||||
out.dif = tail;
|
||||
if (!Yap_CVT_Text(&inp, &out PASS_REGS))
|
||||
return 0L;
|
||||
@ -398,6 +424,23 @@ Yap_CharsToTDQ( const char *s, Term mod USES_REGS )
|
||||
return out.val.t;
|
||||
}
|
||||
|
||||
static inline Term
|
||||
Yap_CharsToTBQ( const char *s, Term mod USES_REGS )
|
||||
{
|
||||
seq_tv_t inp, out;
|
||||
|
||||
inp.val.c = s;
|
||||
inp.sz = 0;
|
||||
inp.type = YAP_STRING_CHARS;
|
||||
inp.mod = mod;
|
||||
out.type = mod_to_bqtype(mod PASS_REGS);
|
||||
if (!Yap_CVT_Text(&inp, &out PASS_REGS))
|
||||
return 0L;
|
||||
if (out.type == YAP_STRING_ATOM)
|
||||
return MkAtomTerm( out.val.a );
|
||||
return out.val.t;
|
||||
}
|
||||
|
||||
static inline Atom
|
||||
Yap_ListOfAtomsToAtom(Term t0 USES_REGS)
|
||||
{
|
||||
@ -556,6 +599,23 @@ YapListToTDQ(Term t0, Term mod USES_REGS)
|
||||
return out.val.t;
|
||||
}
|
||||
|
||||
static inline Term
|
||||
YapListToTBQ(Term t0, Term mod USES_REGS)
|
||||
{
|
||||
seq_tv_t inp, out;
|
||||
|
||||
inp.val.t = t0;
|
||||
inp.type = YAP_STRING_STRING|YAP_STRING_ATOMS_CODES|YAP_STRING_TERM;
|
||||
out.type = mod_to_bqtype(mod PASS_REGS);
|
||||
|
||||
if (!Yap_CVT_Text(&inp, &out PASS_REGS))
|
||||
return 0L;
|
||||
if (out.type == YAP_STRING_ATOM) {
|
||||
return MkAtomTerm( out.val.a);
|
||||
}
|
||||
return out.val.t;
|
||||
}
|
||||
|
||||
static inline Atom
|
||||
Yap_NCharsToAtom( const char *s, size_t len USES_REGS )
|
||||
{
|
||||
@ -634,6 +694,24 @@ Yap_NCharsToTDQ( const char *s, size_t len, Term mod USES_REGS )
|
||||
return out.val.t;
|
||||
}
|
||||
|
||||
static inline Term
|
||||
Yap_NCharsToTBQ( const char *s, size_t len, Term mod USES_REGS )
|
||||
{
|
||||
seq_tv_t inp, out;
|
||||
|
||||
inp.val.c = s;
|
||||
inp.type = YAP_STRING_CHARS|YAP_STRING_NCHARS;
|
||||
inp.sz = len;
|
||||
inp.mod = mod;
|
||||
out.type = mod_to_bqtype(mod PASS_REGS);
|
||||
out.max = len;
|
||||
if (!Yap_CVT_Text(&inp, &out PASS_REGS))
|
||||
return 0L;
|
||||
if (out.type == YAP_STRING_ATOM)
|
||||
return MkAtomTerm( out.val.a );
|
||||
return out.val.t;
|
||||
}
|
||||
|
||||
static inline Atom
|
||||
Yap_NumberToAtom(Term t0 USES_REGS)
|
||||
{
|
||||
@ -888,6 +966,23 @@ Yap_WCharsToTDQ( wchar_t *s, Term mod USES_REGS )
|
||||
return out.val.t;
|
||||
}
|
||||
|
||||
static inline Term
|
||||
Yap_WCharsToTBQ( wchar_t *s, Term mod USES_REGS )
|
||||
{
|
||||
seq_tv_t inp, out;
|
||||
|
||||
inp.val.w = s;
|
||||
inp.type = YAP_STRING_WCHARS;
|
||||
inp.sz = 0;
|
||||
inp.mod = mod;
|
||||
out.type = mod_to_bqtype(mod PASS_REGS);
|
||||
if (!Yap_CVT_Text(&inp, &out PASS_REGS))
|
||||
return 0L;
|
||||
if (out.type == YAP_STRING_ATOM)
|
||||
return MkAtomTerm( out.val.a);
|
||||
return out.val.t;
|
||||
}
|
||||
|
||||
static inline Term
|
||||
Yap_WCharsToString(const wchar_t *s USES_REGS)
|
||||
{
|
||||
@ -1062,4 +1157,4 @@ Yap_SubtractTailString(Term t1, Term th USES_REGS)
|
||||
return outv[0].val.t;
|
||||
}
|
||||
|
||||
|
||||
#endif // ≈YAP_TEXT_H
|
||||
|
@ -168,6 +168,7 @@ Yap_PrintPredName( struct pred_entry *ap );
|
||||
void Yap_RestartYap(int);
|
||||
void Yap_exit(int);
|
||||
bool Yap_Warning( const char *s, ... );
|
||||
bool Yap_PrintWarning( Term t );
|
||||
yamop *Yap_Error(yap_error_number,Term,const char *msg, ...);
|
||||
yamop *Yap_NilError(yap_error_number,const char *msg, ...);
|
||||
int Yap_HandleError( const char *msg, ... );
|
||||
@ -191,6 +192,8 @@ void Yap_PrepGoal(UInt, CELL *, choiceptr USES_REGS);
|
||||
int Yap_execute_pred(struct pred_entry *ppe, CELL *pt, bool pass_exception USES_REGS);
|
||||
int Yap_dogc( int extra_args, Term *tp USES_REGS );
|
||||
Term Yap_PredicateIndicator(Term t, Term mod);
|
||||
bool Yap_Execute(Term t USES_REGS);
|
||||
|
||||
/* exo.c */
|
||||
void Yap_InitExoPreds(void);
|
||||
void Yap_udi_Interval_init(void);
|
||||
|
13
H/Yatom.h
13
H/Yatom.h
@ -427,12 +427,17 @@ IsModProperty (int flags)
|
||||
#define DBLQ_CHARS (0x0004) /* "ab" --> ['a', 'b'] */
|
||||
#define DBLQ_ATOM (0x0008) /* "ab" --> 'ab' */
|
||||
#define DBLQ_STRING (0x0010) /* "ab" --> "ab" */
|
||||
#define DBLQ_CODES (0x0020) /* "ab" --> [0'a, 0'b] */
|
||||
#define DBLQ_MASK (DBLQ_CHARS|DBLQ_ATOM|DBLQ_STRING|DBLQ_CODES)
|
||||
#define UNKNOWN_FAIL (0x0020) /* module */
|
||||
#define UNKNOWN_WARNING (0x0040) /* module */
|
||||
#define UNKNOWN_ERROR (0x0080) /* module */
|
||||
#define BCKQ_CHARS (0x0040) /* `ab` --> ['a', 'b'] */
|
||||
#define BCKQ_ATOM (0x0080) /* `ab` --> 'ab' */
|
||||
#define BCKQ_STRING (0x0100) /* `ab` --> "ab" */
|
||||
#define BCKQ_CODES (0x0200) /* `ab` --> [0'a, 0'b] */
|
||||
#define BCKQ_MASK (BCKQ_CHARS|BCKQ_ATOM|BCKQ_STRING|BCKQ_CODES)
|
||||
#define UNKNOWN_FAIL (0x0400) /* module */
|
||||
#define UNKNOWN_WARNING (0x0800) /* module */
|
||||
#define UNKNOWN_ERROR (0x1000) /* module */
|
||||
#define UNKNOWN_MASK (UNKNOWN_ERROR|UNKNOWN_WARNING|UNKNOWN_FAIL)
|
||||
#define DBLQ_CODES (0x0008) /* "ab" --> [0'a, 0'b] */
|
||||
|
||||
Term Yap_getUnknownModule(ModEntry *m);
|
||||
void Yap_setModuleFlags(ModEntry *n, ModEntry *o);
|
||||
|
@ -15,6 +15,9 @@
|
||||
* *
|
||||
*************************************************************************/
|
||||
|
||||
#ifndef CLAUSE_H
|
||||
#define CLAUSE_H 1
|
||||
|
||||
#include "Yatom.h"
|
||||
#include "YapHeap.h"
|
||||
|
||||
@ -453,3 +456,5 @@ void Yap_dump_code_area_for_profiler(void);
|
||||
#else
|
||||
#define Yap_InformOfRemoval(X)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -19,6 +19,8 @@
|
||||
#define REMOTE_c_error_stream(wid) REMOTE(wid)->c_error_stream_
|
||||
#define LOCAL_sockets_io LOCAL->sockets_io_
|
||||
#define REMOTE_sockets_io(wid) REMOTE(wid)->sockets_io_
|
||||
#define LOCAL_within_print_message LOCAL->within_print_message_
|
||||
#define REMOTE_within_print_message(wid) REMOTE(wid)->within_print_message_
|
||||
|
||||
|
||||
|
||||
|
@ -12,6 +12,7 @@ typedef struct worker_local {
|
||||
int c_output_stream_;
|
||||
int c_error_stream_;
|
||||
bool sockets_io_;
|
||||
bool within_print_message_;
|
||||
|
||||
|
||||
|
||||
|
@ -337,6 +337,7 @@
|
||||
AtomSwi = Yap_LookupAtom("swi");
|
||||
AtomSymbolChar = Yap_LookupAtom("symbol_char");
|
||||
AtomSyntaxError = Yap_LookupAtom("syntax_error");
|
||||
AtomSyntaxErrors = Yap_LookupAtom("syntax_errors");
|
||||
AtomSyntaxErrorHandler = Yap_LookupAtom("syntax_error_handler");
|
||||
AtomSystem = Yap_LookupAtom("system");
|
||||
AtomSystemError = Yap_LookupAtom("system_error");
|
||||
|
@ -12,6 +12,7 @@ static void InitWorker(int wid) {
|
||||
REMOTE_c_output_stream(wid) = 1;
|
||||
REMOTE_c_error_stream(wid) = 2;
|
||||
REMOTE_sockets_io(wid) = false;
|
||||
REMOTE_within_print_message(wid) = false;
|
||||
|
||||
|
||||
|
||||
|
@ -337,6 +337,7 @@
|
||||
AtomSwi = AtomAdjust(AtomSwi);
|
||||
AtomSymbolChar = AtomAdjust(AtomSymbolChar);
|
||||
AtomSyntaxError = AtomAdjust(AtomSyntaxError);
|
||||
AtomSyntaxErrors = AtomAdjust(AtomSyntaxErrors);
|
||||
AtomSyntaxErrorHandler = AtomAdjust(AtomSyntaxErrorHandler);
|
||||
AtomSystem = AtomAdjust(AtomSystem);
|
||||
AtomSystemError = AtomAdjust(AtomSystemError);
|
||||
|
@ -1628,6 +1628,7 @@ RestoreEntries(PropEntry *pp, int int_key USES_REGS)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
RestoreAtom(AtomEntry *at USES_REGS)
|
||||
{
|
||||
|
@ -66,6 +66,7 @@ static void RestoreWorker(int wid USES_REGS) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
REMOTE_GlobalArena(wid) = TermToGlobalOrAtomAdjust(REMOTE_GlobalArena(wid));
|
||||
|
@ -672,6 +672,8 @@
|
||||
#define AtomSymbolChar Yap_heap_regs->AtomSymbolChar_
|
||||
Atom AtomSyntaxError_;
|
||||
#define AtomSyntaxError Yap_heap_regs->AtomSyntaxError_
|
||||
Atom AtomSyntaxErrors_;
|
||||
#define AtomSyntaxErrors Yap_heap_regs->AtomSyntaxErrors_
|
||||
Atom AtomSyntaxErrorHandler_;
|
||||
#define AtomSyntaxErrorHandler Yap_heap_regs->AtomSyntaxErrorHandler_
|
||||
Atom AtomSystem_;
|
||||
|
Reference in New Issue
Block a user