allow SWI Interface to send/receive wide characters.

This commit is contained in:
Vítor Santos Costa 2010-07-21 10:58:24 +01:00
parent 1f3455a656
commit b61d69ffe8
9 changed files with 71 additions and 29 deletions

View File

@ -828,6 +828,30 @@ IOSWIGetc(int sno)
return i; return i;
} }
/* static */
static int
IOSWIWidePutc(int sno, int ch)
{
int i;
Yap_StartSlots();
i = (SWIWidePutc)(ch, Stream[sno].u.swi_stream.swi_ptr);
Yap_CloseSlots();
YENV = ENV;
return i;
}
/* static */
static int
IOSWIWideGetc(int sno)
{
int i;
Yap_StartSlots();
i = (SWIWideGetc)(Stream[sno].u.swi_stream.swi_ptr);
Yap_CloseSlots();
YENV = ENV;
return i;
}
#if USE_SOCKET #if USE_SOCKET
/* static */ /* static */
static int static int
@ -1271,7 +1295,10 @@ EOFGetc(int sno)
s->stream_getc = PlGetc; s->stream_getc = PlGetc;
s->stream_gets = PlGetsFunc(); s->stream_gets = PlGetsFunc();
} }
s->stream_wgetc = get_wchar; if (s->status & SWI_Stream_f)
s->stream_wgetc = IOSWIWideGetc;
else
s->stream_wgetc = get_wchar;
if (CharConversionTable != NULL) if (CharConversionTable != NULL)
s->stream_wgetc_for_read = ISOWGetc; s->stream_wgetc_for_read = ISOWGetc;
else else
@ -3156,13 +3183,13 @@ LookupSWIStream (struct io_stream *swi_s)
Stream[i].encoding = DefaultEncoding(); Stream[i].encoding = DefaultEncoding();
Stream[i].stream_getc = IOSWIGetc; Stream[i].stream_getc = IOSWIGetc;
Stream[i].stream_putc = IOSWIPutc; Stream[i].stream_putc = IOSWIPutc;
Stream[i].stream_wputc = put_wchar; Stream[i].stream_wputc = IOSWIWidePutc;
Stream[i].stream_wgetc = get_wchar; Stream[i].stream_wgetc = IOSWIWideGetc;
Stream[i].stream_gets = DefaultGets; Stream[i].stream_gets = DefaultGets;
if (CharConversionTable != NULL) if (CharConversionTable != NULL)
Stream[i].stream_wgetc_for_read = ISOWGetc; Stream[i].stream_wgetc_for_read = ISOWGetc;
else else
Stream[i].stream_wgetc_for_read = get_wchar; Stream[i].stream_wgetc_for_read = IOSWIWideGetc;
return i; return i;
} }
@ -4575,9 +4602,9 @@ p_get (void)
Yap_Error(PERMISSION_ERROR_INPUT_BINARY_STREAM, ARG1, "get/2"); Yap_Error(PERMISSION_ERROR_INPUT_BINARY_STREAM, ARG1, "get/2");
return FALSE; return FALSE;
} }
while ((ch = get_wchar(sno)) <= 32 && ch >= 0); while ((ch = Stream[sno].stream_wgetc(sno)) <= 32 && ch >= 0);
UNLOCK(Stream[sno].streamlock); UNLOCK(Stream[sno].streamlock);
return (Yap_unify_constant (ARG2, MkIntTerm (ch))); return (Yap_unify_constant (ARG2, MkIntegerTerm (ch)));
} }
static Int static Int
@ -4595,7 +4622,7 @@ p_get0 (void)
Yap_Error(PERMISSION_ERROR_INPUT_BINARY_STREAM, ARG1, "get0/2"); Yap_Error(PERMISSION_ERROR_INPUT_BINARY_STREAM, ARG1, "get0/2");
return FALSE; return FALSE;
} }
out = get_wchar(sno); out = Stream[sno].stream_wgetc(sno);
UNLOCK(Stream[sno].streamlock); UNLOCK(Stream[sno].streamlock);
return (Yap_unify_constant (ARG2, MkIntegerTerm (out)) ); return (Yap_unify_constant (ARG2, MkIntegerTerm (out)) );
} }
@ -5698,7 +5725,7 @@ p_skip (void)
UNLOCK(Stream[sno].streamlock); UNLOCK(Stream[sno].streamlock);
return (FALSE); return (FALSE);
} }
while ((ch = get_wchar(sno)) != n && ch != -1); while ((ch = Stream[sno].stream_wgetc(sno)) != n && ch != -1);
UNLOCK(Stream[sno].streamlock); UNLOCK(Stream[sno].streamlock);
return (TRUE); return (TRUE);
} }

View File

@ -24,6 +24,8 @@
typedef int (*SWI_PutFunction)(int, void *); typedef int (*SWI_PutFunction)(int, void *);
typedef int (*SWI_GetFunction)(void *); typedef int (*SWI_GetFunction)(void *);
typedef int (*SWI_PutWideFunction)(int, void *);
typedef int (*SWI_GetWideFunction)(void *);
typedef int (*SWI_CloseFunction)(void *); typedef int (*SWI_CloseFunction)(void *);
#include "../include/dswiatoms.h" #include "../include/dswiatoms.h"

View File

@ -91,10 +91,6 @@
#define TotGcRecovered WL->tot_gc_recovered #define TotGcRecovered WL->tot_gc_recovered
#define LastGcTime WL->last_gc_time #define LastGcTime WL->last_gc_time
#define LastSSTime WL->last_ss_time #define LastSSTime WL->last_ss_time
#define FSWIStream WL->f_swi_stream
#define SWIGetc WL->swi_getc
#define SWIPutc WL->swi_putc
#define SWIClose WL->swi_close
#if defined(YAPOR) || defined(THREADS) #if defined(YAPOR) || defined(THREADS)
#define SignalLock WL->signal_lock #define SignalLock WL->signal_lock
@ -177,6 +173,12 @@
#define BGL Yap_global->bgl #define BGL Yap_global->bgl
#endif #endif
#define FSWIStream Yap_global->f_swi_stream
#define SWIGetc Yap_global->swi_getc
#define SWIPutc Yap_global->swi_putc
#define SWIWideGetc Yap_global->swi_wgetc
#define SWIWidePutc Yap_global->swi_wputc
#define SWIClose Yap_global->swi_close
#define Yap_AllowLocalExpansion Yap_global->allow_local_expansion #define Yap_AllowLocalExpansion Yap_global->allow_local_expansion
#define Yap_AllowGlobalExpansion Yap_global->allow_global_expansion #define Yap_AllowGlobalExpansion Yap_global->allow_global_expansion

View File

@ -93,10 +93,6 @@ typedef struct worker_local {
YAP_ULONG_LONG tot_gc_recovered; YAP_ULONG_LONG tot_gc_recovered;
Int last_gc_time; Int last_gc_time;
Int last_ss_time; Int last_ss_time;
Functor f_swi_stream;
SWI_GetFunction swi_getc;
SWI_PutFunction swi_putc;
SWI_CloseFunction swi_close;
#if defined(YAPOR) || defined(THREADS) #if defined(YAPOR) || defined(THREADS)
lockvar signal_lock; lockvar signal_lock;
@ -179,6 +175,12 @@ typedef struct worker_shared {
lockvar bgl; lockvar bgl;
#endif #endif
Functor f_swi_stream;
SWI_GetFunction swi_getc;
SWI_PutFunction swi_putc;
SWI_GetWideFunction swi_wgetc;
SWI_PutWideFunction swi_wputc;
SWI_CloseFunction swi_close;
int allow_local_expansion; int allow_local_expansion;
int allow_global_expansion; int allow_global_expansion;

View File

@ -91,10 +91,6 @@ static void InitWorker(int wid) {
FOREIGN_WL(wid)->tot_gc_recovered = 0L; FOREIGN_WL(wid)->tot_gc_recovered = 0L;
FOREIGN_WL(wid)->last_gc_time = 0L; FOREIGN_WL(wid)->last_gc_time = 0L;
FOREIGN_WL(wid)->last_ss_time = 0L; FOREIGN_WL(wid)->last_ss_time = 0L;
FOREIGN_WL(wid)->f_swi_stream = NULL;
FOREIGN_WL(wid)->swi_getc = NULL;
FOREIGN_WL(wid)->swi_putc = NULL;
FOREIGN_WL(wid)->swi_close = NULL;
#if defined(YAPOR) || defined(THREADS) #if defined(YAPOR) || defined(THREADS)
INIT_LOCK(FOREIGN_WL(wid)->signal_lock); INIT_LOCK(FOREIGN_WL(wid)->signal_lock);
@ -177,6 +173,12 @@ static void InitGlobal(void) {
INIT_LOCK(Yap_global->bgl); INIT_LOCK(Yap_global->bgl);
#endif #endif
Yap_global->f_swi_stream = NULL;
Yap_global->swi_getc = NULL;
Yap_global->swi_putc = NULL;
Yap_global->swi_wgetc = NULL;
Yap_global->swi_wputc = NULL;
Yap_global->swi_close = NULL;
Yap_global->allow_local_expansion = TRUE; Yap_global->allow_local_expansion = TRUE;
Yap_global->allow_global_expansion = TRUE; Yap_global->allow_global_expansion = TRUE;

View File

@ -92,10 +92,6 @@ static void RestoreWorker(int wid) {
#if defined(YAPOR) || defined(THREADS) #if defined(YAPOR) || defined(THREADS)
REINIT_LOCK(FOREIGN_WL(wid)->signal_lock); REINIT_LOCK(FOREIGN_WL(wid)->signal_lock);
@ -188,6 +184,12 @@ static void RestoreGlobal(void) {
#if HAVE_LIBREADLINE #if HAVE_LIBREADLINE

View File

@ -3097,6 +3097,8 @@ PL_YAP_InitSWIIO(struct SWI_IO *swio)
FSWIStream = SWIFunctorToFunctor(swio->f); FSWIStream = SWIFunctorToFunctor(swio->f);
SWIGetc = swio->get_c; SWIGetc = swio->get_c;
SWIPutc = swio->put_c; SWIPutc = swio->put_c;
SWIWideGetc = swio->get_w;
SWIWidePutc = swio->put_w;
SWIClose = swio->close_s; SWIClose = swio->close_s;
} }

View File

@ -99,11 +99,6 @@ YAP_ULONG_LONG tot_gc_recovered TotGcRecovered =0L
Int last_gc_time LastGcTime =0L Int last_gc_time LastGcTime =0L
Int last_ss_time LastSSTime =0L Int last_ss_time LastSSTime =0L
Functor f_swi_stream FSWIStream =NULL
SWI_GetFunction swi_getc SWIGetc =NULL
SWI_PutFunction swi_putc SWIPutc =NULL
SWI_CloseFunction swi_close SWIClose =NULL
// global variables that cannot be global in a thread/or-p implementation // global variables that cannot be global in a thread/or-p implementation
#if defined(YAPOR) || defined(THREADS) #if defined(YAPOR) || defined(THREADS)
lockvar signal_lock SignalLock MkLock lockvar signal_lock SignalLock MkLock
@ -199,6 +194,13 @@ UInt threads_total_time ThreadsTotalTime =0L
lockvar bgl BGL MkLock lockvar bgl BGL MkLock
#endif #endif
Functor f_swi_stream FSWIStream =NULL
SWI_GetFunction swi_getc SWIGetc =NULL
SWI_PutFunction swi_putc SWIPutc =NULL
SWI_GetWideFunction swi_wgetc SWIWideGetc =NULL
SWI_PutWideFunction swi_wputc SWIWidePutc =NULL
SWI_CloseFunction swi_close SWIClose =NULL
// stack overflow expansion/gc control // stack overflow expansion/gc control
int allow_local_expansion Yap_AllowLocalExpansion =TRUE int allow_local_expansion Yap_AllowLocalExpansion =TRUE
int allow_global_expansion Yap_AllowGlobalExpansion =TRUE int allow_global_expansion Yap_AllowGlobalExpansion =TRUE

View File

@ -4316,6 +4316,7 @@ static void
init_yap_extras() init_yap_extras()
{ {
swi_io_struct swiio; swi_io_struct swiio;
swiio.f = FUNCTOR_dstream1; swiio.f = FUNCTOR_dstream1;
swiio.get_c = pl_Sgetc; swiio.get_c = pl_Sgetc;
swiio.put_c = Sputc; swiio.put_c = Sputc;