From a16a7d5b1cd5f56c745dfeed4a36a954503a0684 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Fri, 22 Jul 2011 15:49:40 +0100 Subject: [PATCH] fix calling of Write and Read for new SWI style interface. --- C/c_interface.c | 6 +++--- H/yapio.h | 3 +-- docs/yap.tex | 12 ++++++------ include/yap_structs.h | 5 +++-- library/lammpi/prologterms2c.c | 10 ++-------- library/mpi/mpi.c | 16 +++------------- packages/PLStream/pl-yap.c | 30 ++++++++++++++++++++++++++++++ packages/semweb | 2 +- pl/consult.yap | 2 ++ 9 files changed, 51 insertions(+), 35 deletions(-) diff --git a/C/c_interface.c b/C/c_interface.c index 15797a906..3341277cf 100755 --- a/C/c_interface.c +++ b/C/c_interface.c @@ -465,7 +465,7 @@ X_API IOSTREAM *STD_PROTO(YAP_TermToStream,(Term)); X_API IOSTREAM *STD_PROTO(YAP_InitConsult,(int, char *)); X_API void STD_PROTO(YAP_EndConsult,(IOSTREAM *)); X_API Term STD_PROTO(YAP_Read, (IOSTREAM *)); -X_API void STD_PROTO(YAP_Write, (Term, int (*)(wchar_t), int)); +X_API void STD_PROTO(YAP_Write, (Term, IOSTREAM *, int)); X_API Term STD_PROTO(YAP_CopyTerm, (Term)); X_API Term STD_PROTO(YAP_WriteBuffer, (Term, char *, unsigned int, int)); X_API char *STD_PROTO(YAP_CompileClause, (Term)); @@ -2655,12 +2655,12 @@ YAP_Read(IOSTREAM *inp) } X_API void -YAP_Write(Term t, int (*myputc)(wchar_t), int flags) +YAP_Write(Term t, IOSTREAM *stream, int flags) { BACKUP_MACHINE_REGS(); do_putcf = myputc; /* */ - Yap_plwrite (t, do_yap_putc, flags, 1200); + Yap_dowrite (t, stream, flags, 1200); RECOVER_MACHINE_REGS(); } diff --git a/H/yapio.h b/H/yapio.h index 665181347..57e3008f5 100644 --- a/H/yapio.h +++ b/H/yapio.h @@ -67,6 +67,7 @@ #define YP_FILE FILE int STD_PROTO(YP_putc,(int, int)); +void STD_PROTO(Yap_dowrite, (Term, IOSTREAM *, int, int)); #else @@ -96,8 +97,6 @@ int STD_PROTO(YP_putc,(int, int)); #define fclose ERR_fclose #define fflush ERR_fflush - - /* flags for files in IOSTREAM struct */ #define _YP_IO_WRITE 1 #define _YP_IO_READ 2 diff --git a/docs/yap.tex b/docs/yap.tex index 1c2076b81..77f8eb386 100644 --- a/docs/yap.tex +++ b/docs/yap.tex @@ -17320,9 +17320,9 @@ Associate the term @var{value} with the atom @var{at}. The term @var{value} must be a constant. This functionality is used by YAP as a simple way for controlling and communicating with the Prolog run-time. -@item @code{YAP_Term} YAP_Read(@code{int (*)(void)} @var{GetC}) +@item @code{YAP_Term} YAP_Read(@code{IOSTREAM *Stream}) @findex YAP_Read/1 -Parse a Term using the function @var{GetC} to input characters. +Parse a @var{Term} from the stream @var{Stream}. @item @code{YAP_Term} YAP_Write(@code{YAP_Term} @var{t}) @findex YAP_CopyTerm/1 @@ -17330,13 +17330,13 @@ Copy a Term @var{t} and all associated constraints. May call the garbage collector and returns @code{0L} on error (such as no space being available). -@item @code{void} YAP_Write(@code{YAP_Term} @var{t}, @code{void (*)(int)} -@var{PutC}, @code{int} @var{flags}) +@item @code{void} YAP_Write(@code{YAP_Term} @var{t}, @code{IOSTREAM} +@var{stream}, @code{int} @var{flags}) @findex YAP_Write/3 -Write a Term @var{t} using the function @var{PutC} to output +Write a Term @var{t} using the stream @var{stream} to output characters. The term is written according to a mask of the following flags in the @code{flag} argument: @code{YAP_WRITE_QUOTED}, -@code{YAP_WRITE_HANDLE_VARS}, and @code{YAP_WRITE_IGNORE_OPS}. +@code{YAP_WRITE_HANDLE_VARS}, @code{YAP_WRITE_USE_PORTRAY}, and @code{YAP_WRITE_IGNORE_OPS}. @item @code{void} YAP_WriteBuffer(@code{YAP_Term} @var{t}, @code{char *} @var{buff}, @code{unsigned int} diff --git a/include/yap_structs.h b/include/yap_structs.h index 58a34ba8c..30f77bb9f 100755 --- a/include/yap_structs.h +++ b/include/yap_structs.h @@ -101,9 +101,10 @@ typedef double YAP_Float; #define YAP_FULL_BOOT_FROM_PROLOG 4 #define YAP_BOOT_ERROR -1 -#define YAP_WRITE_QUOTED 0 -#define YAP_WRITE_HANDLE_VARS 1 +#define YAP_WRITE_QUOTED 1 #define YAP_WRITE_IGNORE_OPS 2 +#define YAP_WRITE_HANDLE_VARS 2 +#define YAP_WRITE_USE_PORTRAY 8 #define YAP_CONSULT_MODE 0 #define YAP_RECONSULT_MODE 1 diff --git a/library/lammpi/prologterms2c.c b/library/lammpi/prologterms2c.c index a2af81238..88673202a 100644 --- a/library/lammpi/prologterms2c.c +++ b/library/lammpi/prologterms2c.c @@ -142,12 +142,6 @@ p2c_putc(const int c) { /* * Function used by YAP to read a char from a string */ -static int -p2c_getc(void) { - if( BUFFER_POS < BUFFER_LEN ) - return BUFFER_PTR[BUFFER_POS++]; - return -1; -} /* * Writes a term to a stream. */ @@ -177,7 +171,7 @@ read_term_from_stream(const int fd) { if ( size> BUFFER_SIZE) expand_buffer(size-BUFFER_SIZE); read(fd,BUFFER_PTR,size); // read term from stream - return YAP_Read( p2c_getc ); + return YAP_ReadBuffer( BUFFER_PTR , NULL); } /********************************************************************************************* * Conversion: Prolog Term->char[] and char[]->Prolog Term @@ -229,7 +223,7 @@ string2term(char *const ptr,const size_t *size) { } BUFFER_POS=0; LOCAL_ErrorMessage=NULL; - t = YAP_Read(p2c_getc); + t = YAP_ReadBuffer( BUFFER_PTR , NULL ); if ( t==FALSE ) { write_msg(__FUNCTION__,__FILE__,__LINE__,"FAILED string2term>>>>size:%d %d %s\n",BUFFER_SIZE,strlen(BUFFER_PTR),LOCAL_ErrorMessage); exit(1); diff --git a/library/mpi/mpi.c b/library/mpi/mpi.c index 9c287d5f0..f7cc5b178 100644 --- a/library/mpi/mpi.c +++ b/library/mpi/mpi.c @@ -30,7 +30,6 @@ static char *rcsid = "$Header: /Users/vitor/Yap/yap-cvsbackup/library/mpi/mpi.c, #include #include -Term STD_PROTO(YAP_Read, (int (*)(void))); void STD_PROTO(YAP_Write, (Term, void (*)(int), int)); STATIC_PROTO (Int p_mpi_open, (void)); @@ -105,15 +104,6 @@ mpi_putc(Int ch) } } -static Int -mpi_getc(void) -{ - if( bufptr < bufsize ) return buf[bufptr++]; - else return -1; -} - - - /* * C Predicates @@ -301,7 +291,7 @@ p_mpi_receive() /* mpi_receive(-data, ?orig, ?tag) */ /* parse received string into a Prolog term */ bufptr = 0; - t = YAP_Read( mpi_getc ); + t = YAP_ReadBuffer( buf, NULL ); if( t == TermNil ) { retv = FALSE; @@ -384,7 +374,7 @@ p_mpi_bcast3() /* mpi_bcast( ?data, +root, +max_size ) */ bufptr = 0; /* parse received string into a Prolog term */ - return Yap_unify( YAP_Read(mpi_getc), ARG1 ); + return Yap_unify( YAP_ReadBuffer( buf, NULL ), ARG1 ); } } @@ -464,7 +454,7 @@ p_mpi_bcast2() /* mpi_bcast( ?data, +root ) */ bufstrlen = strlen(buf); bufptr = 0; - return Yap_unify(YAP_Read( mpi_getc ), ARG1); + return Yap_unify(YAP_ReadBuffer( buf, NULL ), ARG1); } } diff --git a/packages/PLStream/pl-yap.c b/packages/PLStream/pl-yap.c index 3d2b63be8..24f517fae 100755 --- a/packages/PLStream/pl-yap.c +++ b/packages/PLStream/pl-yap.c @@ -1121,6 +1121,9 @@ Yap_StreamPosition(IOSTREAM *st) return StreamPosition(st); } +IOSTREAM *STD_PROTO(Yap_Scurin, (void)); +int STD_PROTO(Yap_dowrite, (Term, IOSTREAM *, int, int)); + IOSTREAM * Yap_Scurin(void) { @@ -1128,6 +1131,32 @@ Yap_Scurin(void) return Scurin; } +int +Yap_dowrite(Term t, IOSTREAM *stream, int flags, int priority) + /* term to be written */ + /* consumer */ + /* write options */ +{ + CACHE_REGS + int swi_flags; + int res; + Int slot = Yap_InitSlot(t PASS_REGS); + + swi_flags = 0; + if (flags & Quote_illegal_f) + swi_flags |= PL_WRT_QUOTED; + if (flags & Handle_vars_f) + swi_flags |= PL_WRT_NUMBERVARS; + if (flags & Use_portray_f) + swi_flags |= PL_WRT_PORTRAY; + if (flags & Ignore_ops_f) + swi_flags |= PL_WRT_IGNOREOPS; + + res = PL_write_term(stream, slot, priority, swi_flags); + Yap_RecoverSlots(1 PASS_REGS); + return res; +} + #if THREADS @@ -1178,6 +1207,7 @@ error: return rc; } + int recursiveMutexInit(recursiveMutex *m) { diff --git a/packages/semweb b/packages/semweb index 9a96f8ebb..e3c7eb9a9 160000 --- a/packages/semweb +++ b/packages/semweb @@ -1 +1 @@ -Subproject commit 9a96f8ebb751b169132aef0591cb1863ebcf4e26 +Subproject commit e3c7eb9a9a54d6a9069396ecd1c3b537a8f6165a diff --git a/pl/consult.yap b/pl/consult.yap index 195f32b69..d19412404 100755 --- a/pl/consult.yap +++ b/pl/consult.yap @@ -1050,6 +1050,8 @@ make :- fail. make. +make_library_index(_Directory). + '$file_name'(Stream,F) :- stream_property(Stream, file_name(F)), !. '$file_name'(user_input,user_output).