swi compatibility support

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@2294 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2008-08-01 21:44:25 +00:00
parent 437fda3c61
commit a3983fa820
6 changed files with 1273 additions and 36 deletions

View File

@ -10,8 +10,11 @@
* File: c_interface.c * * File: c_interface.c *
* comments: c_interface primitives definition * * comments: c_interface primitives definition *
* * * *
* Last rev: $Date: 2008-07-24 16:02:00 $,$Author: vsc $ * * Last rev: $Date: 2008-08-01 21:44:24 $,$Author: vsc $ *
* $Log: not supported by cvs2svn $ * $Log: not supported by cvs2svn $
* Revision 1.121 2008/07/24 16:02:00 vsc
* improve C-interface and SWI comptaibility a bit.
*
* Revision 1.120 2008/07/11 17:02:07 vsc * Revision 1.120 2008/07/11 17:02:07 vsc
* fixes by Bart and Tom: mostly libraries but nasty one in indexing * fixes by Bart and Tom: mostly libraries but nasty one in indexing
* compilation. * compilation.
@ -476,6 +479,7 @@ X_API void *STD_PROTO(YAP_ExtraSpaceCut,(void));
#endif #endif
X_API Term STD_PROTO(YAP_CurrentModule,(void)); X_API Term STD_PROTO(YAP_CurrentModule,(void));
X_API Term STD_PROTO(YAP_CreateModule,(Atom)); X_API Term STD_PROTO(YAP_CreateModule,(Atom));
X_API Term STD_PROTO(YAP_StripModule,(Term, Term *));
X_API int STD_PROTO(YAP_ThreadSelf,(void)); X_API int STD_PROTO(YAP_ThreadSelf,(void));
X_API int STD_PROTO(YAP_GetThreadRefCount,(int)); X_API int STD_PROTO(YAP_GetThreadRefCount,(int));
X_API void STD_PROTO(YAP_SetThreadRefCount,(int,int)); X_API void STD_PROTO(YAP_SetThreadRefCount,(int,int));
@ -2288,6 +2292,39 @@ YAP_CreateModule(Atom at)
} }
X_API Term
YAP_StripModule(Term t, Term *modp)
{
Term tmod;
tmod = CurrentModule;
restart:
if (IsVarTerm(t)) {
return 0L;
} else if (IsAtomTerm(t)) {
*modp = tmod;
return t;
} else if (IsApplTerm(t)) {
Functor fun = FunctorOfTerm(t);
if (fun == FunctorModule) {
tmod = ArgOfTerm(1, t);
if (IsVarTerm(tmod) ) {
return 0L;
}
if (!IsAtomTerm(tmod) ) {
return 0L;
}
t = ArgOfTerm(2, t);
goto restart;
}
*modp = tmod;
return t;
}
return 0L;
}
X_API int X_API int
YAP_ThreadSelf(void) YAP_ThreadSelf(void)
{ {

View File

@ -941,7 +941,8 @@ directory.
@section Running Prolog Files @section Running Prolog Files
YAP can also be used to run Prolog files as scripts, at least in YAP can also be used to run Prolog files as scripts, at least in
Unix-like environments. A simple example is shown next: Unix-like environments. A simple example is shown next (do not forget
that the shell comments are very important):
@example @example
@cartouche @cartouche

View File

@ -104,6 +104,19 @@ typedef void *PL_engine_t;
#define PL_INT (20) /* int */ #define PL_INT (20) /* int */
#define PL_LONG (21) /* long */ #define PL_LONG (21) /* long */
#define PL_DOUBLE (22) /* double */ #define PL_DOUBLE (22) /* double */
#define PL_NCHARS (23) /* unsigned, const char * */
#define PL_UTF8_CHARS (24) /* const char * */
#define PL_UTF8_STRING (25) /* const char * */
#define PL_INT64 (26) /* int64_t */
#define PL_NUTF8_CHARS (27) /* unsigned, const char * */
#define PL_NUTF8_CODES (29) /* unsigned, const char * */
#define PL_NUTF8_STRING (30) /* unsigned, const char * */
#define PL_NWCHARS (31) /* unsigned, const wchar_t * */
#define PL_NWCODES (32) /* unsigned, const wchar_t * */
#define PL_NWSTRING (33) /* unsigned, const wchar_t * */
#define PL_MBCHARS (34) /* const char * */
#define PL_MBCODES (35) /* const char * */
#define PL_MBSTRING (36) /* const char * */
#define CVT_ATOM 0x0001 #define CVT_ATOM 0x0001
#define CVT_STRING 0x0002 #define CVT_STRING 0x0002
@ -143,6 +156,21 @@ typedef void *PL_engine_t;
/* end from pl-itf.h */ /* end from pl-itf.h */
/*******************************
* CALL-BACK *
*******************************/
#ifdef PL_KERNEL
#define PL_Q_DEBUG 0x01 /* = TRUE for backward compatibility */
#endif
#define PL_Q_NORMAL 0x02 /* normal usage */
#define PL_Q_NODEBUG 0x04 /* use this one */
#define PL_Q_CATCH_EXCEPTION 0x08 /* handle exceptions in C */
#define PL_Q_PASS_EXCEPTION 0x10 /* pass to parent environment */
#ifdef PL_KERNEL
#define PL_Q_DETERMINISTIC 0x20 /* call was deterministic */
#endif
/* copied from old SICStus/SWI interface */ /* copied from old SICStus/SWI interface */
typedef void install_t; typedef void install_t;
@ -171,6 +199,8 @@ extern X_API int PL_get_list(term_t, term_t, term_t);
extern X_API int PL_get_long(term_t, long *); extern X_API int PL_get_long(term_t, long *);
extern X_API int PL_get_list_chars(term_t, char **, unsigned); extern X_API int PL_get_list_chars(term_t, char **, unsigned);
extern X_API int PL_get_module(term_t, module_t *); extern X_API int PL_get_module(term_t, module_t *);
extern X_API module_t PL_context(void);
extern X_API int PL_strip_module(term_t, module_t *, term_t);
extern X_API atom_t PL_module_name(module_t); extern X_API atom_t PL_module_name(module_t);
extern X_API module_t PL_new_module(atom_t); extern X_API module_t PL_new_module(atom_t);
extern X_API int PL_get_name_arity(term_t, atom_t *, int *); extern X_API int PL_get_name_arity(term_t, atom_t *, int *);
@ -205,39 +235,41 @@ extern X_API void PL_put_pointer(term_t, void *);
extern X_API void PL_put_string_chars(term_t, const char *); extern X_API void PL_put_string_chars(term_t, const char *);
extern X_API void PL_put_term(term_t, term_t); extern X_API void PL_put_term(term_t, term_t);
extern X_API void PL_put_variable(term_t); extern X_API void PL_put_variable(term_t);
extern X_API int PL_compare(term_t, term_t); extern X_API int PL_compare(term_t, term_t);
/* end PL_put_* functions =============================*/ /* end PL_put_* functions =============================*/
/* begin PL_unify_* functions =============================*/ /* begin PL_unify_* functions =============================*/
extern X_API int PL_unify(term_t, term_t); extern X_API int PL_unify(term_t, term_t);
extern X_API int PL_unify_atom(term_t, atom_t); extern X_API int PL_unify_atom(term_t, atom_t);
extern X_API int PL_unify_atom_chars(term_t, const char *); extern X_API int PL_unify_atom_chars(term_t, const char *);
extern X_API int PL_unify_float(term_t, double); extern X_API int PL_unify_atom_nchars(term_t, size_t len, const char *);
extern X_API int PL_unify_int64(term_t, int64_t); extern X_API int PL_unify_float(term_t, double);
extern X_API int PL_unify_integer(term_t, long); extern X_API int PL_unify_functor(term_t, functor_t);
extern X_API int PL_unify_list(term_t, term_t, term_t); extern X_API int PL_unify_int64(term_t, int64_t);
extern X_API int PL_unify_list_chars(term_t, const char *); extern X_API int PL_unify_integer(term_t, long);
extern X_API int PL_unify_nil(term_t); extern X_API int PL_unify_list(term_t, term_t, term_t);
extern X_API int PL_unify_pointer(term_t, void *); extern X_API int PL_unify_list_chars(term_t, const char *);
extern X_API int PL_unify_string_chars(term_t, const char *); extern X_API int PL_unify_nil(term_t);
extern X_API int PL_unify_term(term_t,...); extern X_API int PL_unify_pointer(term_t, void *);
extern X_API int PL_unify_wchars(term_t, int, size_t, const pl_wchar_t *); extern X_API int PL_unify_string_chars(term_t, const char *);
extern X_API int PL_unify_term(term_t,...);
extern X_API int PL_unify_wchars(term_t, int, size_t, const pl_wchar_t *);
/* end PL_unify_* functions =============================*/ /* end PL_unify_* functions =============================*/
/* begin PL_is_* functions =============================*/ /* begin PL_is_* functions =============================*/
extern X_API int PL_is_atom(term_t); extern X_API int PL_is_atom(term_t);
extern X_API int PL_is_atomic(term_t); extern X_API int PL_is_atomic(term_t);
extern X_API int PL_is_compound(term_t); extern X_API int PL_is_compound(term_t);
extern X_API int PL_is_float(term_t); extern X_API int PL_is_float(term_t);
extern X_API int PL_is_functor(term_t, functor_t); extern X_API int PL_is_functor(term_t, functor_t);
extern X_API int PL_is_integer(term_t); extern X_API int PL_is_integer(term_t);
extern X_API int PL_is_list(term_t); extern X_API int PL_is_list(term_t);
extern X_API int PL_is_number(term_t); extern X_API int PL_is_number(term_t);
extern X_API int PL_is_string(term_t); extern X_API int PL_is_string(term_t);
extern X_API int PL_is_variable(term_t); extern X_API int PL_is_variable(term_t);
extern X_API int PL_term_type(term_t); extern X_API int PL_term_type(term_t);
/* end PL_is_* functions =============================*/ /* end PL_is_* functions =============================*/
extern X_API void PL_halt(int); extern X_API void PL_halt(int);
extern X_API int PL_initialise(int, char **); extern X_API int PL_initialise(int, char **);
extern X_API int PL_is_initialised(int *, char ***); extern X_API int PL_is_initialised(int *, char ***);
extern X_API void PL_close_foreign_frame(fid_t); extern X_API void PL_close_foreign_frame(fid_t);
extern X_API void PL_discard_foreign_frame(fid_t); extern X_API void PL_discard_foreign_frame(fid_t);
extern X_API fid_t PL_open_foreign_frame(void); extern X_API fid_t PL_open_foreign_frame(void);
@ -257,6 +289,7 @@ extern X_API int PL_call(term_t, module_t);
extern X_API void PL_register_foreign_in_module(const char *, const char *, int, foreign_t (*)(void), int); extern X_API void PL_register_foreign_in_module(const char *, const char *, int, foreign_t (*)(void), int);
extern X_API void PL_register_extensions(PL_extension *); extern X_API void PL_register_extensions(PL_extension *);
extern X_API void PL_load_extensions(PL_extension *); extern X_API void PL_load_extensions(PL_extension *);
extern X_API int PL_handle_signals(void);
extern X_API int PL_thread_self(void); extern X_API int PL_thread_self(void);
extern X_API int PL_thread_attach_engine(const PL_thread_attr_t *); extern X_API int PL_thread_attach_engine(const PL_thread_attr_t *);
extern X_API int PL_thread_destroy_engine(void); extern X_API int PL_thread_destroy_engine(void);
@ -274,6 +307,12 @@ extern X_API void PL_free(void *);
extern X_API int Sprintf(char *,...); extern X_API int Sprintf(char *,...);
extern X_API int Sdprintf(char *,...); extern X_API int Sdprintf(char *,...);
#ifdef SIO_MAGIC /* defined from <SWI-Stream.h> */
extern X_API int PL_unify_stream(term_t t, IOSTREAM *s);
extern X_API int PL_open_stream(term_t t, IOSTREAM *s); /* compat */
extern X_API int PL_get_stream_handle(term_t t, IOSTREAM **s);
#endif
void swi_install(void); void swi_install(void);
#endif /* _FLI_H_INCLUDED */ #endif /* _FLI_H_INCLUDED */

View File

@ -10,6 +10,10 @@
#endif #endif
#endif #endif
#ifndef PL_EXPORT
#define PL_EXPORT(type) extern X_API type
#endif
/* This appears to make the wide-character support compile and work /* This appears to make the wide-character support compile and work
on HPUX 11.23. There really should be a cleaner way ... on HPUX 11.23. There really should be a cleaner way ...
*/ */
@ -146,8 +150,78 @@ typedef struct io_stream
intptr_t reserved[3]; /* reserved for extension */ intptr_t reserved[3]; /* reserved for extension */
} IOSTREAM; } IOSTREAM;
#define PL_EXPORT(type) extern X_API type #define SmakeFlag(n) (1<<(n-1))
extern X_API int PL_unify_stream(term_t t, IOSTREAM *s); #define SIO_FBUF SmakeFlag(1) /* full buffering */
#define SIO_LBUF SmakeFlag(2) /* line buffering */
#define SIO_NBUF SmakeFlag(3) /* no buffering */
#define SIO_FEOF SmakeFlag(4) /* end-of-file */
#define SIO_FERR SmakeFlag(5) /* error ocurred */
#define SIO_USERBUF SmakeFlag(6) /* buffer is from user */
#define SIO_INPUT SmakeFlag(7) /* input stream */
#define SIO_OUTPUT SmakeFlag(8) /* output stream */
#define SIO_NOLINENO SmakeFlag(9) /* line no. info is void */
#define SIO_NOLINEPOS SmakeFlag(10) /* line pos is void */
#define SIO_STATIC SmakeFlag(11) /* Stream in static memory */
#define SIO_RECORDPOS SmakeFlag(12) /* Maintain position */
#define SIO_FILE SmakeFlag(13) /* Stream refers to an OS file */
#define SIO_PIPE SmakeFlag(14) /* Stream refers to an OS pipe */
#define SIO_NOFEOF SmakeFlag(15) /* don't set SIO_FEOF flag */
#define SIO_TEXT SmakeFlag(16) /* text-mode operation */
#define SIO_FEOF2 SmakeFlag(17) /* attempt to read past eof */
#define SIO_FEOF2ERR SmakeFlag(18) /* Sfpasteof() */
#define SIO_NOCLOSE SmakeFlag(19) /* Do not close on abort */
#define SIO_APPEND SmakeFlag(20) /* opened in append-mode */
#define SIO_UPDATE SmakeFlag(21) /* opened in update-mode */
#define SIO_ISATTY SmakeFlag(22) /* Stream is a tty */
#define SIO_CLOSING SmakeFlag(23) /* We are closing the stream */
#define SIO_TIMEOUT SmakeFlag(24) /* We had a timeout */
#define SIO_NOMUTEX SmakeFlag(25) /* Do not allow multi-thread access */
#define SIO_ADVLOCK SmakeFlag(26) /* File locked with advisory lock */
#define SIO_WARN SmakeFlag(27) /* Pending warning */
#define SIO_CLEARERR SmakeFlag(28) /* Clear error after reporting */
#define SIO_REPXML SmakeFlag(29) /* Bad char --> XML entity */
#define SIO_REPPL SmakeFlag(30) /* Bad char --> Prolog \hex\ */
#define SIO_BOM SmakeFlag(31) /* BOM was detected/written */
#define SIO_SEEK_SET 0 /* From beginning of file. */
#define SIO_SEEK_CUR 1 /* From current position. */
#define SIO_SEEK_END 2 /* From end of file. */
#define Sinput (&S__iob[0]) /* Stream Sinput */
#define Soutput (&S__iob[1]) /* Stream Soutput */
#define Serror (&S__iob[2]) /* Stream Serror */
#define Sgetchar() Sgetc(Sinput)
#define Sputchar(c) Sputc((c), Soutput)
#define S__updatefilepos_getc(s, c) \
((s)->position ? S__fupdatefilepos_getc((s), (c)) \
: (c))
#define Snpgetc(s) ((s)->bufp < (s)->limitp ? (int)(*(s)->bufp++)&0xff \
: S__fillbuf(s))
#define Sgetc(s) S__updatefilepos_getc((s), Snpgetc(s))
/* Control-operations */
#define SIO_GETSIZE (1) /* get size of underlying object */
#define SIO_GETFILENO (2) /* get underlying file (if any) */
#define SIO_SETENCODING (3) /* modify encoding of stream */
/* Sread_pending() */
#define SIO_RP_BLOCK 0x1 /* wait for new input */
PL_EXPORT(void) Sseterr(IOSTREAM *s, int which, const char *message);
PL_EXPORT(int) S__fillbuf(IOSTREAM *s);
PL_EXPORT(IOSTREAM *) Snew(void *handle, int flags, IOFUNCTIONS *functions);
PL_EXPORT(int) Sfileno(IOSTREAM *s);
PL_EXPORT(int) Sgetcode(IOSTREAM *s);
PL_EXPORT(int) Sungetc(int c, IOSTREAM *s);
PL_EXPORT(int) Sputcode(int c, IOSTREAM *s);
PL_EXPORT(int) Sfeof(IOSTREAM *s);
PL_EXPORT(int) Sfpasteof(IOSTREAM *s);
PL_EXPORT(int) Sferror(IOSTREAM *s);
PL_EXPORT(void) Sclearerr(IOSTREAM *s);
PL_EXPORT(void) Sseterr(IOSTREAM *s, int which, const char *message);
#endif /*_PL_STREAM_H*/ #endif /*_PL_STREAM_H*/

View File

@ -439,6 +439,9 @@ extern X_API YAP_Module PROTO(YAP_CurrentModule,(void));
/* int YAP_CurrentModule() */ /* int YAP_CurrentModule() */
extern X_API YAP_Module PROTO(YAP_CreateModule,(YAP_Atom)); extern X_API YAP_Module PROTO(YAP_CreateModule,(YAP_Atom));
/* int YAP_StripModule() */
extern X_API YAP_Term PROTO(YAP_StripModule,(YAP_Term, YAP_Module *));
/* int YAP_AtomGetHold(YAP_Atom) */ /* int YAP_AtomGetHold(YAP_Atom) */
extern X_API int PROTO(YAP_AtomGetHold,(YAP_Atom)); extern X_API int PROTO(YAP_AtomGetHold,(YAP_Atom));

File diff suppressed because it is too large Load Diff