fix calling of Write and Read for new SWI style interface.

This commit is contained in:
Vitor Santos Costa 2011-07-22 15:49:40 +01:00
parent eea7f83e09
commit a16a7d5b1c
9 changed files with 51 additions and 35 deletions

View File

@ -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();
}

View File

@ -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

View File

@ -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}

View File

@ -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

View File

@ -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);

View File

@ -30,7 +30,6 @@ static char *rcsid = "$Header: /Users/vitor/Yap/yap-cvsbackup/library/mpi/mpi.c,
#include <string.h>
#include <mpi.h>
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);
}
}

View File

@ -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)
{

@ -1 +1 @@
Subproject commit 9a96f8ebb751b169132aef0591cb1863ebcf4e26
Subproject commit e3c7eb9a9a54d6a9069396ecd1c3b537a8f6165a

View File

@ -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).