bunch of fixes for YAP's own IO

This commit is contained in:
Vítor Santos Costa 2015-07-22 19:33:30 -05:00
parent 91d6faabc1
commit f3b84af062
20 changed files with 191 additions and 128 deletions

View File

@ -18,6 +18,8 @@
*/
#include <stdlib.h>
#include <string>
// Bad export from Python
#ifdef HAVE_STAT
#undef HAVE_STAT
@ -67,25 +69,19 @@ extern "C" {
// taken from yap_structs.h
#include "iopreds.h"
extern void YAP_UserCPredicate(const char *, YAP_UserCPred, YAP_Arity arity);
extern void YAP_UserCPredicate(const char *, YAP_UserCPred, YAP_Arity arity);
/* void UserCPredicateWithArgs(const char *name, int *fn(), unsigned int arity) */
extern void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred, YAP_Arity, YAP_Term);
/* void UserCPredicateWithArgs(const char *name, int *fn(), unsigned int arity) */
extern void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred, YAP_Arity, YAP_Term);
/* void UserBackCPredicate(const char *name, int *init(), int *cont(), int
/* void UserBackCPredicate(const char *name, int *init(), int *cont(), int
arity, int extra) */
extern void YAP_UserBackCPredicate(const char *, YAP_UserCPred, YAP_UserCPred, YAP_Arity, unsigned int);
extern Term Yap_StringToTerm(const char *s, size_t len, encoding_t enc, int prio, Term *bindings_p);
extern void YAP_UserBackCPredicate(const char *, YAP_UserCPred, YAP_UserCPred, YAP_Arity, unsigned int);
extern Term Yap_StringToTerm(const char *s, size_t len, encoding_t enc, int prio, Term *bindings_p);
}
//#include <vector>
class YAPEngine;
class YAPAtom;
class YAPFunctor;

View File

@ -118,6 +118,12 @@ public:
};
/// current module for the engine
YAPModule currentModule( ) { return YAPModule( ) ; }
/// current directory for the engine
const char *currentDir( ) {
char dir[1024];
std::string s = Yap_getcwd(dir, 1024-1);
return s.c_str();
}
};
#endif /* YAPQ_HH */

View File

@ -59,6 +59,7 @@ INLINE_ONLY inline EXTERN Term ArgOfTerm (int i, Term t);
INLINE_ONLY inline EXTERN Term
ArgOfTerm (int i, Term t)
{
return (Term) (Derefa (RepAppl (t) + (i)));
}

View File

@ -218,6 +218,7 @@ CELL *Yap_GetFromArena(Term *,UInt,UInt);
void Yap_InitGlobals(void);
Term Yap_SaveTerm(Term);
Term Yap_SetGlobalVal(Atom, Term);
Term Yap_GetGlobal(Atom);
Int Yap_DeleteGlobal(Atom);
void Yap_AllocateDefaultArena(Int, Int, int);
@ -327,8 +328,8 @@ void Yap_InitMPE(void);
/* other.c */
Term Yap_MkApplTerm(Functor,unsigned int,Term *);
Term Yap_MkNewApplTerm(Functor,unsigned int);
Term Yap_MkApplTerm(Functor,arity_t,const Term *);
Term Yap_MkNewApplTerm(Functor,arity_t);
Term Yap_MkNewPairTerm(void);
Term Yap_Globalise(Term);

View File

@ -59,9 +59,6 @@ include_directories(../../CXX)
qt5_use_modules(qtyap Widgets)
qt5_use_modules(qtyap Core SerialPort)
#target_link_libraries(qtyap QtSerialPort)
install(TARGETS qtyap
RUNTIME DESTINATION ${bindir}

View File

@ -100,18 +100,19 @@ void SettingsDialog::apply()
void SettingsDialog::checkCustomBaudRatePolicy(int idx)
{
bool isCustomBaudRate = !ui->baudRateBox->itemData(idx).isValid();
/* bool isCustomBaudRate = !ui->baudRateBox->itemData(idx).isValid();
ui->baudRateBox->setEditable(isCustomBaudRate);
if (isCustomBaudRate) {
ui->baudRateBox->clearEditText();
QLineEdit *edit = ui->baudRateBox->lineEdit();
edit->setValidator(intValidator);
}
*/
}
void SettingsDialog::checkCustomDevicePathPolicy(int idx)
{
bool isCustomPath = !ui->serialPortInfoListBox->itemData(idx).isValid();
bool isCustomPath = !ui->serialPortInfoListBox->itemData(idx).isValid();
ui->serialPortInfoListBox->setEditable(isCustomPath);
if (isCustomPath)
ui->serialPortInfoListBox->clearEditText();
@ -119,7 +120,7 @@ void SettingsDialog::checkCustomDevicePathPolicy(int idx)
void SettingsDialog::fillPortsParameters()
{
ui->baudRateBox->addItem(QStringLiteral("9600"), QSerialPort::Baud9600);
/* ui->baudRateBox->addItem(QStringLiteral("9600"), QSerialPort::Baud9600);
ui->baudRateBox->addItem(QStringLiteral("19200"), QSerialPort::Baud19200);
ui->baudRateBox->addItem(QStringLiteral("38400"), QSerialPort::Baud38400);
ui->baudRateBox->addItem(QStringLiteral("115200"), QSerialPort::Baud115200);
@ -146,11 +147,12 @@ void SettingsDialog::fillPortsParameters()
ui->flowControlBox->addItem(tr("None"), QSerialPort::NoFlowControl);
ui->flowControlBox->addItem(tr("RTS/CTS"), QSerialPort::HardwareControl);
ui->flowControlBox->addItem(tr("XON/XOFF"), QSerialPort::SoftwareControl);
*/
}
void SettingsDialog::fillPortsInfo()
{
ui->serialPortInfoListBox->clear();
/* ui->serialPortInfoListBox->clear();
QString description;
QString manufacturer;
QString serialNumber;
@ -171,12 +173,13 @@ void SettingsDialog::fillPortsInfo()
}
ui->serialPortInfoListBox->addItem(tr("Custom"));
*/
}
void SettingsDialog::updateSettings()
{
currentSettings.name = ui->serialPortInfoListBox->currentText();
/*
if (ui->baudRateBox->currentIndex() == 4) {
currentSettings.baudRate = ui->baudRateBox->currentText().toInt();
} else {
@ -201,5 +204,5 @@ void SettingsDialog::updateSettings()
ui->flowControlBox->itemData(ui->flowControlBox->currentIndex()).toInt());
currentSettings.stringFlowControl = ui->flowControlBox->currentText();
currentSettings.localEchoEnabled = ui->localEchoCheckBox->isChecked();
currentSettings.localEchoEnabled = ui->localEchoCheckBox->isChecked();*/
}

View File

@ -80,6 +80,9 @@ struct swi_mutex* WithMutex void
// streams
struct stream_desc* Stream void
#if defined(THREADS)
lockvar StreamDescLock MkLock
#endif
// access to yap initial arguments
char** argv void

View File

@ -190,6 +190,7 @@ struct pred_entry *wake_up_code WakeUpCode MkPred AtomWakeUpGoal 2 PROLOG_MODU
#endif
struct pred_entry *pred_goal_expansion PredGoalExpansion MkPred FunctorGoalExpansion USER_MODULE
struct pred_entry *pred_meta_call PredMetaCall MkPred FunctorMetaCall PROLOG_MODULE
struct pred_entry *pred_trace_meta_call PredTraceMetaCall MkPred FunctorTraceMetaCall PROLOG_MODULE
struct pred_entry *pred_dollar_catch PredDollarCatch MkPred FunctorCatch PROLOG_MODULE
struct pred_entry *pred_recorded_with_key PredRecordedWithKey MkPred FunctorRecordedWithKey PROLOG_MODULE
struct pred_entry *pred_log_upd_clause PredLogUpdClause MkPred FunctorDoLogUpdClause PROLOG_MODULE

View File

@ -1,6 +1,6 @@
:- use_module(library(lineutils),
[file_filter_with_initialization/5,
[file_filter_with_init/5,
split/3,
glue/3]).
@ -16,6 +16,9 @@
:- style_check(all).
file_filter_with_initialization(A,B,C,D,E) :-
file_filter_with_init(A,B,C,D,E).
main :-
warning(Warning),
%file_filter_with_initialization('misc/HEAPFIELDS','H/hstruct.h',gen_struct,Warning,['hstruct.h','HEAPFIELDS']),

View File

@ -267,8 +267,9 @@ Yap_DeleteAliases (int sno)
break; /* just put something here */
}
new_aliasp++;
} else {
} else {
LOCAL_NOfFileAliases--;
// printf("RM %p at %d/%d %d\n", new_aliasp->name, new_aliasp-LOCAL_FileAliases, new_aliasp->alias_stream, sno);
}
} else {
/* avoid holes in alias array */
@ -279,7 +280,7 @@ Yap_DeleteAliases (int sno)
new_aliasp++;
}
aliasp++;
}
}/////
}
/* check if name is an alias */
@ -365,10 +366,11 @@ Yap_RemoveAlias (Atom arg, int sno)
}
aliasp++;
}
//printf("RM %p at %d\n", arg, aliasp-LOCAL_FileAliases);
/* we have not found an alias neither a hole */
if (aliasp == LOCAL_FileAliases+LOCAL_SzOfFileAliases)
ExtendAliasArray();
LOCAL_NOfFileAliases++;
LOCAL_NOfFileAliases--;
aliasp->name = arg;
aliasp->alias_stream = sno;
return(TRUE);
@ -393,6 +395,7 @@ Yap_AddAlias (Atom arg, int sno)
if (aliasp == LOCAL_FileAliases+LOCAL_SzOfFileAliases)
ExtendAliasArray();
LOCAL_NOfFileAliases++;
// printf("ADD %p at %d\n", arg, aliasp-LOCAL_FileAliases);
aliasp->name = arg;
aliasp->alias_stream = sno;
return true;

View File

@ -105,12 +105,12 @@ char *
if (sno < 0)
return NULL;
LOCK(GLOBAL_Stream[sno].streamlock);
LOCAL_c_output_stream = sno;
if (encp)
GLOBAL_Stream[sno].encoding = encp;
Yap_plwrite (t, GLOBAL_Stream+sno, 0, flags, 1200);
s[GLOBAL_Stream[sno].u.mem_string.pos] = '\0';
LOCK(GLOBAL_Stream[sno].streamlock);
GLOBAL_Stream[sno].status = Free_Stream_f;
UNLOCK(GLOBAL_Stream[sno].streamlock);
LOCAL_c_output_stream = old_output_stream;

View File

@ -935,6 +935,7 @@ if (IsVarTerm(tin)) {
}
UNLOCK(GLOBAL_Stream[output_stream].streamlock);
out = Yap_Execute( Deref(ARG2) PASS_REGS);
LOCK(GLOBAL_Stream[output_stream].streamlock);
LOCAL_c_output_stream = old_out;
if (mem_stream) {
Term tat;

View File

@ -266,8 +266,8 @@ Term Yap_StreamUserName(int sno)
return (s->user_name);
}
if ((atname = StreamName(sno)))
return atname;
return 0;
return atname;
return TermNil;
}
static void
@ -409,7 +409,7 @@ void
Yap_DebugPlWrite(Term t)
{
if (t != 0)
Yap_plwrite(t, NULL, 0, 0, 1200);
Yap_plwrite(t,GLOBAL_Stream+2, 0, 0, 1200);
}
void
@ -1671,7 +1671,9 @@ Yap_OpenStream(FILE *fd, char *name, Term file_name, int flags)
sname = AtomUserOut;
}
}
LOCK(GLOBAL_StreamDescLock);
if ((sno = Yap_CheckAlias(sname)) == -1) {
UNLOCK(GLOBAL_StreamDescLock);
Yap_Error(EXISTENCE_ERROR_STREAM, arg, msg);
return -1;
}
@ -1684,18 +1686,20 @@ Yap_OpenStream(FILE *fd, char *name, Term file_name, int flags)
if (sno < 0)
{
Yap_Error(DOMAIN_ERROR_STREAM_OR_ALIAS, arg, msg);
UNLOCK(GLOBAL_StreamDescLock);
return (-1);
}
if (GLOBAL_Stream[sno].status & Free_Stream_f)
{
PlIOError(EXISTENCE_ERROR_STREAM, arg, msg);
UNLOCK(GLOBAL_StreamDescLock);
return (-1);
}
LOCK(GLOBAL_Stream[sno].streamlock);
if (GLOBAL_Stream[sno].status & Free_Stream_f)
{
UNLOCK(GLOBAL_Stream[sno].streamlock);
PlIOError(EXISTENCE_ERROR_STREAM, arg, msg);
return (-1);
}
UNLOCK(GLOBAL_StreamDescLock);
if ((GLOBAL_Stream[sno].status & kind) == 0)
{
UNLOCK(GLOBAL_Stream[sno].streamlock);
UNLOCK(GLOBAL_Stream[sno].streamlock);
if (kind & Input_Stream_f)
PlIOError(PERMISSION_ERROR_INPUT_STREAM, arg, msg);
else

View File

@ -160,6 +160,9 @@ typedef struct stream_desc
Atom name;
Term user_name;
FILE* file;
// useful in memory streams
char *nbuf;
size_t nsize;
union {
struct {
#define PLGETC_BUF_SIZE 4096
@ -405,8 +408,8 @@ CACHE_REGS
cpos--;
}
sargs[0] = MkIntegerTerm (cpos);
sargs[1] = MkIntegerTerm (LOCAL_StartLine = GLOBAL_Stream[sno].linecount);
sargs[2] = MkIntegerTerm (GLOBAL_Stream[sno].linepos);
sargs[1] = MkIntegerTerm (LOCAL_StartLineCount = GLOBAL_Stream[sno].linecount);
sargs[2] = MkIntegerTerm (LOCAL_StartLinePos = GLOBAL_Stream[sno].linepos);
sargs[3] = sargs[4] = MkIntTerm (0);
return Yap_MkApplTerm (FunctorStreamPos, 5, sargs);
}

View File

@ -265,7 +265,7 @@ Yap_open_buf_write_stream(char **nbufp, size_t *ncharsp)
st->linecount = 1;
Yap_DefaultStreamOps( st );
#if MAY_WRITE
st->file = open_memstream(&nbuf, &nchars);
st->file = open_memstream(&st->nbuf, &st->nsize);
st->status = Output_Stream_f | InMemory_Stream_f|Seekable_Stream_f;
#else
st->u.mem_string.pos = 0;
@ -319,7 +319,15 @@ open_mem_write_stream (USES_REGS1) /* $open_mem_write_stream(-Stream) */
memHandle *
Yap_MemExportStreamPtrs( int sno )
{
return &GLOBAL_Stream[sno].u.mem_string;
#if MAY_WRITE
if (fflush(GLOBAL_Stream[sno].file) == 0) {
GLOBAL_Stream[sno].nbuf[GLOBAL_Stream[sno].nsize] = '\0';
return (memHandle *)GLOBAL_Stream[sno].nbuf;
}
return NULL;
#else
return &GLOBAL_Stream[sno].u.mem_string;
#endif
}
@ -327,17 +335,28 @@ static Int
peek_mem_write_stream ( USES_REGS1 )
{ /* '$peek_mem_write_stream'(+GLOBAL_Stream,?S0,?S) */
Int sno = Yap_CheckStream (ARG1, (Output_Stream_f | InMemory_Stream_f), "close/2");
Int i = GLOBAL_Stream[sno].u.mem_string.pos;
Int i;
Term tf = ARG2;
CELL *HI;
const char *ptr;
if (sno < 0)
return (FALSE);
restart:
HI = HR;
#if MAY_WRITE
if (fflush(GLOBAL_Stream[sno].file) == 0) {
ptr = GLOBAL_Stream[sno].nbuf;
i = GLOBAL_Stream[sno].nsize;
}
#else
size_t pos;
ptr = GLOBAL_Stream[sno].u.mem_string.buf;
i = GLOBAL_Stream[sno].u.mem_string.pos;
#endif
while (i > 0) {
--i;
tf = MkPairTerm(MkIntTerm(GLOBAL_Stream[sno].u.mem_string.buf[i]),tf);
tf = MkPairTerm(MkIntTerm(ptr[i]),tf);
if (HR + 1024 >= ASP) {
UNLOCK(GLOBAL_Stream[sno].streamlock);
HR = HI;

View File

@ -1,8 +1,7 @@
/*************************************************************************
* *
* YAP Prolog *
* *
* *
* Yap Prolog was developed at NCCUP - Universidade do Porto *
* *
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
@ -348,7 +347,7 @@ Yap_syntax_error (TokEntry * tokptr, int sno)
t[2] = endline;
tf[1] = Yap_MkApplTerm(Yap_MkFunctor(AtomBetween,3),3,t);
}
tf[2] = TermDot;
tf[2] = tf[3] = TermDot;
tf[4] = MkIntegerTerm(count);
tf[5] = out;
tf[6] = Yap_StreamUserName(sno);
@ -475,7 +474,7 @@ Int
Yap_FirstLineInParse ( void )
{
CACHE_REGS
return LOCAL_StartLine;
return LOCAL_StartLineCount;
}
static void
@ -540,21 +539,10 @@ complete_processing( FEnv *fe, TokEntry *tokstart )
reset_regs(tokstart, fe);
}
}
if (!Yap_unify(v, fe->np))
if (!Yap_unify(v, fe->sp))
return false;
}
if (fe->tp) {
while (TRUE) {
fe->old_H = HR;
if (setjmp(LOCAL_IOBotch) == 0) {
v = fe->tpos;
break;
} else {
reset_regs( tokstart, fe);
}
}
if (!Yap_unify(v, fe->tp))
}
if (fe->tp && !Yap_unify(fe->tpos, fe->tp)) {
return false;
}
@ -603,14 +591,21 @@ scanEOF( FEnv *fe, int inp_stream)
// return end_of_file
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
fe->t = MkAtomTerm (AtomEof);
if (fe->np && !Yap_unify(TermNil, fe->np))
fe->t = 0;
if (fe->sp && !Yap_unify(TermNil, fe->sp))
fe->t = 0;
if (fe->vp && !Yap_unify(TermNil, fe->vp))
fe->t = 0;
if (fe->tp && !Yap_unify(fe->tp , fe->tpos))
fe->t = 0;
post_process_eof(GLOBAL_Stream + inp_stream);
#if DEBUG
if (GLOBAL_Option['p' - 'a' + 1] || true) {
fprintf(stderr, "[ end_of_file %p ]", GLOBAL_Stream[inp_stream].name);
Yap_DebugPlWrite(fe->t);
Yap_DebugPutc(stderr, ' ]\n');
if (GLOBAL_Option['p' - 'a' + 1]) {
fprintf(stderr, "[ end_of_file %p ]\n", GLOBAL_Stream[inp_stream].name);
}
#endif
TR = (tr_fr_ptr)LOCAL_ScannerStack;
return YAP_PARSING_FINISHED;
}
@ -624,7 +619,6 @@ initParser(Term opts, FEnv *fe, REnv *re, int inp_stream, int nargs)
LOCAL_ErrorMessage = NULL;
fe->old_TR = TR;
LOCAL_Error_TYPE = YAP_NO_ERROR;
fe->tpos = StreamPosition(inp_stream);
LOCAL_SourceFileName = GLOBAL_Stream[inp_stream].name;
LOCAL_eot_before_eof = false;
fe->tpos = StreamPosition(inp_stream);
@ -669,7 +663,6 @@ static parser_state_t
scanError(REnv *re, FEnv *fe, int inp_stream)
{
CACHE_REGS
fe->t = 0;
// running out of memory
if (LOCAL_Error_TYPE == OUT_OF_TRAIL_ERROR) {
@ -712,11 +705,11 @@ scanError(REnv *re, FEnv *fe, int inp_stream)
return YAP_SCANNING;
}
static parser_state_t
parseError(REnv *re, FEnv *fe, int inp_stream)
{
CACHE_REGS
fe->t = 0;
TokEntry * tokstart =
LOCAL_tokptr;
@ -738,7 +731,7 @@ parseError(REnv *re, FEnv *fe, int inp_stream)
return YAP_PARSING_FINISHED;
} else {
Yap_PrintWarning(terr);
if (ParserErrorStyle ==TermDec10);
if (ParserErrorStyle == TermDec10);
return YAP_SCANNING;
}
}
@ -749,16 +742,19 @@ static parser_state_t
parse(REnv *re, FEnv *fe, int inp_stream)
{
CACHE_REGS
TokEntry * tokstart =
TokEntry * tokstart =
LOCAL_tokptr;
fe->t = Yap_Parse(re->prio);
if (fe->t == 0 || LOCAL_ErrorMessage)
return YAP_SCANNING_ERROR;
return YAP_PARSING_ERROR;
TR = (tr_fr_ptr)LOCAL_ScannerStack;
if (fe->reading_clause)
complete_clause_processing( fe, tokstart, fe->t );
else
complete_processing( fe, tokstart );
if (fe->reading_clause &&
!complete_clause_processing( fe, tokstart, fe-> t ))
fe->t = 0;
else if (!fe->reading_clause &&
!complete_processing( fe, tokstart ))
fe->t = 0;
#if EMACS
first_char = tokstart->TokPos;
#endif /* EMACS */
@ -785,7 +781,7 @@ parse(REnv *re, FEnv *fe, int inp_stream)
Term Yap_read_term(int inp_stream, Term opts, int nargs)
{
CACHE_REGS
FEnv fe;
REnv re;
tr_fr_ptr tr0 = TR;
@ -793,7 +789,6 @@ Term Yap_read_term(int inp_stream, Term opts, int nargs)
int emacs_cares = FALSE;
#endif
parser_state_t state = YAP_START_PARSING;
while (state != YAP_PARSING_FINISHED)
{
@ -906,8 +901,8 @@ static xarg * setClauseReadEnv( Term opts, FEnv *fe, struct renv *re, int inp_s
re->sy = TermDec10;
}
fe->vp = 0;
if (args[READ_VARIABLE_NAMES].used) {
fe->np = args[READ_VARIABLE_NAMES].tvalue;
if (args[READ_CLAUSE_VARIABLE_NAMES].used) {
fe->np = args[READ_CLAUSE_VARIABLE_NAMES].tvalue;
} else {
fe->np = 0;
}
@ -959,7 +954,6 @@ complete_clause_processing( FEnv *fe, TokEntry *tokstart, Term t )
singls[0] = v;
singls[1] = fe->tpos;
singls[2] = t;
jmp_deb(1);
if (Yap_PrintWarning(Yap_MkApplTerm(Yap_MkFunctor(AtomSingleton,3),3,singls)))
break;
} else {
@ -989,7 +983,7 @@ complete_clause_processing( FEnv *fe, TokEntry *tokstart, Term t )
/**
* @pred read_clause( +_Stream_, -_Clause_, ?_Opts) is det
*
* Same as read_clause/3, but from the standard input stream.
u* Same as read_clause/3, but from the standard input stream.
*
*/
static Int
@ -1389,4 +1383,3 @@ Yap_InitReadTPreds(void)
Yap_InitCPred ("$style_checker", 1, style_checker, SyncPredFlag|HiddenPredFlag);
}

View File

@ -125,6 +125,7 @@ FILE *Yap_GetOutputStream(Term t, const char *msg)
return rc;
}
int
GetFreeStreamD(void)
{
@ -521,24 +522,19 @@ eof_action ( int sno, Term t2 USES_REGS )
static bool
do_stream_property (int sno, Term opts USES_REGS)
do_stream_property (int sno, xarg *args USES_REGS)
{ /* Init current_stream */
xarg *args;
stream_property_choices_t i;
bool rc = true;
args = Yap_ArgListToVector ( opts, stream_property_defs, STREAM_PROPERTY_END );
if (args == NULL) {
return false;
}
for (i=0; i < STREAM_PROPERTY_END; i ++) {
if (args[i].used) {
switch (i) {
case STREAM_PROPERTY_ALIAS:
rc = rc &&
Yap_FetchStreamAlias ( sno, args[STREAM_PROPERTY_ALIAS].tvalue PASS_REGS);
break;
rc = rc &
Yap_FetchStreamAlias ( sno, args[STREAM_PROPERTY_ALIAS].tvalue PASS_REGS);
break;
case STREAM_PROPERTY_BOM:
rc = rc &&
has_bom ( sno, args[STREAM_PROPERTY_BOM].tvalue PASS_REGS);
@ -605,53 +601,89 @@ do_stream_property (int sno, Term opts USES_REGS)
}
}
}
UNLOCK(GLOBAL_Stream[sno].streamlock);
return rc;
}
static Int
cont_stream_property (USES_REGS1)
{ /* current_stream */
int i = IntOfTerm (EXTRA_CBACK_ARG (2, 1)), i0;
LOCK(GLOBAL_Stream[i].streamlock);
i0=i;
while (i < MaxStreams) {
if (GLOBAL_Stream[i].status & Free_Stream_f) {
++i;
continue;
}
if (i != i0) {
LOCK(GLOBAL_Stream[i].streamlock);
UNLOCK(GLOBAL_Stream[i0].streamlock);
}
++i;
EXTRA_CBACK_ARG (2, 1) = MkIntTerm (i);
if (i == MaxStreams)
do_cut( true );
if ( do_stream_property(i-1, Deref(ARG2) PASS_REGS) ) {
Yap_unify(ARG1, Yap_MkStream(i-1));
return true;
}
bool det;
xarg *args;
int i = IntOfTerm (EXTRA_CBACK_ARG (2, 1));
bool rc;
args = Yap_ArgListToVector ( Deref(ARG2), stream_property_defs, STREAM_PROPERTY_END );
if (args == NULL) {
cut_fail();
}
UNLOCK(GLOBAL_Stream[i0].streamlock);
cut_fail();
LOCK(GLOBAL_StreamDescLock);
if (args[STREAM_PROPERTY_ALIAS].tvalue &&
IsAtomTerm(args[STREAM_PROPERTY_ALIAS].tvalue)) {
// one solution only
det = true;
i = Yap_CheckAlias(AtomOfTerm(args[STREAM_PROPERTY_ALIAS].tvalue));
UNLOCK(GLOBAL_StreamDescLock);
if (i < 0) {
cut_fail();
}
rc = true;
} else {
while (GLOBAL_Stream[i].status & Free_Stream_f) {
++i;
if (i == MaxStreams)
cut_fail();
else
EXTRA_CBACK_ARG (2, 1) = MkIntTerm (i+1);
}
LOCK(GLOBAL_Stream[i].streamlock);
UNLOCK(GLOBAL_StreamDescLock);
rc = do_stream_property(i, args PASS_REGS);
UNLOCK(GLOBAL_Stream[i].streamlock);
}
if (rc)
rc = Yap_unify(ARG1, Yap_MkStream(i));
if (rc) {
if (det)
cut_succeed();
else
return true;
} else if (det)
cut_fail();
else
return false;
}
static Int
stream_property (USES_REGS1)
{ /* Init current_stream */
Term t1 = Deref(ARG1);
//Yap_DebugPlWrite(ARG1);fprintf(stderr,", ");
// Yap_DebugPlWrite(ARG2);fprintf(stderr,"\n");
/* make valgrind happy by always filling in memory */
EXTRA_CBACK_ARG (2, 1) = MkIntTerm (0);
if (!IsVarTerm(t1)) {
Int i;
xarg *args;
i = Yap_CheckStream (t1, Input_Stream_f|Output_Stream_f|Append_Stream_f, "current_stream/3");
do_cut(0);
if (i < 0)
return false;
return do_stream_property( i, Deref(ARG2) PASS_REGS);
if (i < 0) {
cut_fail();
}
args = Yap_ArgListToVector ( Deref(ARG2), stream_property_defs, STREAM_PROPERTY_END );
if (args == NULL) {
UNLOCK(GLOBAL_Stream[i].streamlock);
cut_fail();
}
if ( do_stream_property( i, args PASS_REGS) ) {
UNLOCK(GLOBAL_Stream[i].streamlock);
cut_succeed();
} else {
UNLOCK(GLOBAL_Stream[i].streamlock);
cut_fail();
}
} else {
return (cont_stream_property (PASS_REGS1));
return cont_stream_property( PASS_REGS1);
}
}

View File

@ -445,7 +445,7 @@ write_canonical ( USES_REGS1 )
args[WRITE_IGNORE_OPS].tvalue = TermTrue;
args[WRITE_QUOTED].used = true;
args[WRITE_QUOTED].tvalue = TermTrue;
write_term( output_stream, ARG1, args PASS_REGS);
write_term( output_stream, ARG2, args PASS_REGS);
UNLOCK(GLOBAL_Stream[output_stream].streamlock);
Yap_CloseSlots( mySlots );
if (EX != 0L) {

View File

@ -81,7 +81,7 @@ chtype(Int ch)
#define ParserAuxSp LOCAL_ScannerStack
/* routines in parser.c */
VarEntry *Yap_LookupVar(char *);
VarEntry *Yap_LookupVar(const char *);
Term Yap_VarNames(VarEntry *,Term);
Term Yap_Variables(VarEntry *,Term);
Term Yap_Singletons(VarEntry *,Term);
@ -178,17 +178,17 @@ void Yap_init_socks(char *host, long interface_port);
extern int errno;
#endif
INLINE_ONLY EXTERN UInt inline HashFunction(unsigned char *);
INLINE_ONLY EXTERN UInt inline HashFunction(const char *);
INLINE_ONLY EXTERN UInt inline WideHashFunction(wchar_t *);
INLINE_ONLY EXTERN inline UInt
HashFunction(unsigned char *CHP)
HashFunction(const char *CHP)
{
/* djb2 */
UInt hash = 5381;
UInt c;
while ((c = *CHP++) != '\0') {
while ((c = (UInt)(*CHP++)) != '\0') {
/* hash = ((hash << 5) + hash) + c; hash * 33 + c */
hash = hash * 33 ^ c;
}

View File

@ -6,9 +6,6 @@ ${CMAKE_CURRENT_BINARY_DIR}/SWIGTYPE_p_CELL.java
${CMAKE_CURRENT_BINARY_DIR}/SWIGTYPE_p_CPredicate.java
${CMAKE_CURRENT_BINARY_DIR}/SWIGTYPE_p_Prop.java
${CMAKE_CURRENT_BINARY_DIR}/SWIGTYPE_p_Term.java
${CMAKE_CURRENT_BINARY_DIR}/SWIGTYPE_p_YAP_Arity.java
${CMAKE_CURRENT_BINARY_DIR}/SWIGTYPE_p_YAP_Term.java
${CMAKE_CURRENT_BINARY_DIR}/SWIGTYPE_p_YAP_UserCPred.java
${CMAKE_CURRENT_BINARY_DIR}/SWIGTYPE_p_YAP_tag_t.java
${CMAKE_CURRENT_BINARY_DIR}/SWIGTYPE_p_arity_t.java
${CMAKE_CURRENT_BINARY_DIR}/SWIGTYPE_p_encoding_t.java