remove some more duplicated code

This commit is contained in:
Vitor Santos Costa 2013-11-22 15:18:03 +00:00
parent de606255bb
commit f6f183c0f6
16 changed files with 162 additions and 186 deletions

3
.gitmodules vendored
View File

@ -49,3 +49,6 @@
[submodule "packages/ltx2htm"]
path = packages/ltx2htm
url = git://git.code.sf.net/p/yap/ltx2htm
[submodule "packages/raptor"]
path = packages/raptor
url = https://github.com/davidvaz/yap-raptor.git

View File

@ -2088,10 +2088,12 @@ YAP_ReadBuffer(char *s, Term *tp)
{
CACHE_REGS
Term t;
Int sl;
BACKUP_H();
sl = Yap_NewSlots(1 PASS_REGS);
LOCAL_ErrorMessage=NULL;
while ((t = Yap_StringToTerm(s,tp)) == 0L) {
while (!PL_chars_to_term(s,sl)) {
if (LOCAL_ErrorMessage) {
if (!strcmp(LOCAL_ErrorMessage,"Stack Overflow")) {
if (!Yap_dogc( 0, NULL PASS_REGS )) {
@ -2115,8 +2117,8 @@ YAP_ReadBuffer(char *s, Term *tp)
return 0L;
}
} else {
*tp = MkAtomTerm(Yap_LookupAtom(LOCAL_ErrorMessage));
LOCAL_ErrorMessage = NULL;
// get from slot has an exception
*tp = Yap_GetFromSlot(sl PASS_REGS);
RECOVER_H();
return 0L;
}
@ -2127,7 +2129,7 @@ YAP_ReadBuffer(char *s, Term *tp)
}
}
RECOVER_H();
return t;
return Yap_GetFromSlot(sl PASS_REGS);
}
/* copy a string to a buffer */

View File

@ -389,49 +389,6 @@ GenerateSyntaxError(Term *tp, TokEntry *tokstart, IOSTREAM *sno, Term msg USES_R
}
}
Term
Yap_StringToTerm(char *s,Term *tp)
{
CACHE_REGS
IOSTREAM *sno = Sopenmem(&s, NULL, "r");
Term t;
TokEntry *tokstart;
tr_fr_ptr TR_before_parse;
Term tpos = TermNil;
if (sno == NULL)
return FALSE;
TR_before_parse = TR;
tokstart = LOCAL_tokptr = LOCAL_toktide = Yap_tokenizer(sno, FALSE, &tpos);
if (tokstart == NIL || tokstart->Tok == Ord (eot_tok)) {
if (tp) {
*tp = MkAtomTerm(AtomEOFBeforeEOT);
}
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments);
Sclose(sno);
return FALSE;
} else if (LOCAL_ErrorMessage) {
if (tp) {
*tp = MkAtomTerm(Yap_LookupAtom(LOCAL_ErrorMessage));
}
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments);
Sclose(sno);
return FALSE;
}
t = Yap_Parse();
TR = TR_before_parse;
if (!t || LOCAL_ErrorMessage) {
GenerateSyntaxError(tp, tokstart, sno, MkAtomTerm(Yap_LookupAtom(LOCAL_ErrorMessage)) PASS_REGS);
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments);
Sclose(sno);
return FALSE;
}
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments);
Sclose(sno);
return t;
}
Int
Yap_FirstLineInParse (void)
{
@ -748,10 +705,6 @@ p_disable_char_conversion( USES_REGS1 )
{
int i;
for (i = 0; i < MaxStreams; i++) {
if (!(Stream[i].status & Free_Stream_f))
Stream[i].stream_wgetc_for_read = Stream[i].stream_wgetc;
}
CharConversionTable = NULL;
return(TRUE);
}
@ -923,8 +876,6 @@ p_write_string( USES_REGS1 )
void
Yap_InitIOPreds(void)
{
if (!Stream)
Stream = (StreamDesc *)Yap_AllocCodeSpace(sizeof(StreamDesc)*MaxStreams);
/* here the Input/Output predicates */
Yap_InitCPred ("$set_read_error_handler", 1, p_set_read_error_handler, SafePredFlag|SyncPredFlag);
Yap_InitCPred ("$get_read_error_handler", 1, p_get_read_error_handler, SafePredFlag|SyncPredFlag);

View File

@ -233,23 +233,24 @@ static Term
float_send(char *s, int sign)
{
GET_LD
Float f = (Float)atof(s);
Float f = (Float)(sign*atof(s));
printf("buf=%s && f= %f\n", s, f);
#if HAVE_ISFINITE
if (truePrologFlag(PLFLAG_ISO)) { /* iso */
if (!isfinite(f)) {
LOCAL_ErrorMessage = "Float overflow while scanning";
return(MkEvalFl(0.0));
return(MkEvalFl(f));
}
}
#elif HAVE_FINITE
if (truePrologFlag(PLFLAG_ISO)) { /* iso */
if (!finite(f)) {
LOCAL_ErrorMessage = "Float overflow while scanning";
return(MkEvalFl(0.0));
return(MkEvalFl(f));
}
}
#endif
return (MkEvalFl(f*sign));
return (MkEvalFl(f));
}
/* we have an overflow at s */

View File

@ -6,6 +6,7 @@ typedef enum TokenKinds {
WString_tok,
Ponctuation_tok,
Error_tok,
QuasiQuotes_tok,
eot_tok
} tkinds;

View File

@ -270,16 +270,6 @@
#define OpList Yap_heap_regs->op_list
#define Stream Yap_heap_regs->yap_streams
#define NOfFileAliases Yap_heap_regs->n_of_file_aliases
#define SzOfFileAliases Yap_heap_regs->sz_of_file_aliases
#define FileAliases Yap_heap_regs->file_aliases
#define AtPrompt Yap_heap_regs->atprompt
#define YapPrompt Yap_heap_regs->_prompt
#define CharConversionTable Yap_heap_regs->char_conversion_table
#define CharConversionTable2 Yap_heap_regs->char_conversion_table2

View File

@ -270,16 +270,6 @@
struct operator_entry *op_list;
struct stream_desc *yap_streams;
UInt n_of_file_aliases;
UInt sz_of_file_aliases;
struct AliasDescS *file_aliases;
Atom atprompt;
char _prompt[MAX_PROMPT];
char *char_conversion_table;
char *char_conversion_table2;

View File

@ -270,16 +270,6 @@
OpList = NULL;
Stream = NULL;
NOfFileAliases = 0;
SzOfFileAliases = 0;
FileAliases = NULL;
AtPrompt = AtomNil;
CharConversionTable = NULL;
CharConversionTable2 = NULL;

View File

@ -45,67 +45,6 @@ FILE *rl_instream, *rl_outstream;
typedef int (*GetsFunc)(int, UInt, char *);
typedef struct stream_desc
{
union {
struct {
struct io_stream *swi_ptr;
} swi_stream;
struct {
Atom name;
Term user_name;
#if defined(__MINGW32__) || defined(_MSC_VER)
#define PLGETC_BUF_SIZE 4096
char *buf, *ptr;
int left;
#endif
YP_File file;
} file;
} u;
Int charcount, linecount, linepos;
Int status;
int och;
#if defined(YAPOR) || defined(THREADS)
lockvar streamlock; /* protect stream access */
#endif
int (* stream_putc)(int, int); /* function the stream uses for writing */
int (* stream_getc)(int); /* function the stream uses for reading */
GetsFunc stream_gets; /* function the stream uses for reading a sequence of characters */
/* function the stream uses for parser. It may be different if the ISO
character conversion is on */
int (* stream_wgetc_for_read)(int);
int (* stream_wgetc)(int);
int (* stream_wputc)(int,wchar_t);
mbstate_t mbstate;
}
StreamDesc;
#define YAP_ERROR NIL
#define MaxStreams 64
#define Free_Stream_f 0x000001
#define Output_Stream_f 0x000002
#define Input_Stream_f 0x000004
#define Append_Stream_f 0x000008
#define Eof_Stream_f 0x000010
#define Tty_Stream_f 0x000040
#define Binary_Stream_f 0x000100
#define Eof_Error_Stream_f 0x000200
#define Reset_Eof_Stream_f 0x000400
#define Past_Eof_Stream_f 0x000800
#define Push_Eof_Stream_f 0x001000
#define Seekable_Stream_f 0x002000
#define Promptable_Stream_f 0x004000
#define Popen_Stream_f 0x080000
#define User_Stream_f 0x100000
#define HAS_BOM_f 0x200000
#define RepError_Prolog_f 0x400000
#define RepError_Xml_f 0x800000
#define SWI_Stream_f 0x1000000
#define EXPAND_FILENAME 0x000080
#define StdInStream 0
#define StdOutStream 1
#define StdErrStream 2

View File

@ -982,16 +982,6 @@ RestoreDBErasedIList__( USES_REGS1 )
}
}
static void
RestoreStreams(void)
{
}
static void
RestoreAliases(void)
{
}
static void
RestoreForeignCode__( USES_REGS1 )
{

View File

@ -270,16 +270,6 @@
OpList = OpListAdjust(OpList);
RestoreStreams();
RestoreAliases();
AtPrompt = AtomAdjust(AtPrompt);
CharConversionTable = CodeCharPAdjust(CharConversionTable);
CharConversionTable2 = CodeCharPAdjust(CharConversionTable2);

View File

@ -732,6 +732,7 @@ all: startup.yss
@ENABLE_CPLINT@ (cd packages/cplint/slipcase; $(MAKE))
@ENABLE_PRISM@ @INSTALL_DLLS@ (cd packages/prism/src/c; $(MAKE))
@ENABLE_BDDLIB@ @INSTALL_DLLS@ (cd packages/bdd; $(MAKE))
@ENABLE_RAPTOR@ @INSTALL_DLLS@ (cd packages/raptor; $(MAKE))
@ENABLE_CUDD@ (cd packages/ProbLog/simplecudd; $(MAKE))
@ENABLE_CUDD@ (cd packages/ProbLog/simplecudd_lfi; $(MAKE))
@ENABLE_JPL@ @INSTALL_DLLS@ (cd packages/jpl; $(MAKE))
@ -820,6 +821,7 @@ install_unix: startup.yss @YAPLIB@
@ENABLE_PRISM@ @INSTALL_DLLS@ (cd packages/prism/src/c; $(MAKE) install)
@ENABLE_PRISM@ @INSTALL_DLLS@ (cd packages/prism/src/prolog; $(MAKE) install)
@ENABLE_BDDLIB@ @INSTALL_DLLS@ (cd packages/bdd; $(MAKE) install)
@ENABLE_RAPTOR@ @INSTALL_DLLS@ (cd packages/raptor; $(MAKE) install)
@ENABLE_CUDD@ (cd packages/ProbLog/simplecudd; $(MAKE) install)
@ENABLE_CUDD@ (cd packages/ProbLog/simplecudd_lfi; $(MAKE) install)
@ENABLE_CUDA@ @INSTALL_DLLS@ (cd packages/cuda; $(MAKE) install)
@ -878,6 +880,7 @@ install_win32: startup.yss @ENABLE_WINCONSOLE@ yap-win@EXEC_SUFFIX@
@ENABLE_PRISM@ (cd packages/prism/src/c; $(MAKE) install)
@ENABLE_PRISM@ (cd packages/prism/src/prolog; $(MAKE) install)
@ENABLE_BDDLIB@ (cd packages/bdd; $(MAKE) install)
@ENABLE_RAPTOR@ (cd packages/raptor; $(MAKE) install)
@ENABLE_CUDD@ (cd packages/ProbLog/simplecudd; $(MAKE) install)
@ENABLE_CUDD@ (cd packages/ProbLog/simplecudd_lfi; $(MAKE) install)
@ENABLE_CUDA@ @INSTALL_DLLS@ (cd packages/cuda; $(MAKE) install)
@ -947,6 +950,7 @@ clean: clean_docs
@ENABLE_CPLINT@ (cd packages/cplint/approx/simplecuddLPADs; $(MAKE) clean)
@ENABLE_CPLINT@ (cd packages/cplint; $(MAKE) clean)
@ENABLE_BDDLIB@ (cd packages/bdd; $(MAKE) clean)
@ENABLE_RAPTOR@ (cd packages/raptor; $(MAKE) clean)
@ENABLE_LIBARCHIVE@ (cd packages/archive; $(MAKE) clean)
@ENABLE_ODBC@ (cd packages/odbc; $(MAKE) clean)
@ENABLE_CUDD@ (cd packages/ProbLog/simplecudd; $(MAKE) clean)

131
configure vendored
View File

@ -636,6 +636,9 @@ PYTHON
MPICF
MPILDF
YAPMPILIB
RAPTOR_CPPFLAGS
RAPTOR_LDFLAGS
ENABLE_RAPTOR
GECODE_EXTRALIBS
GECODE_VERSION
GECODE_MAJOR
@ -873,6 +876,7 @@ with_odbc
with_cudd
with_junit
enable_gecode
with_raptor
with_mpi
with_mpe
with_python
@ -1554,6 +1558,7 @@ Optional Packages:
--with-odbc=<dir> Location of ODBC include/lib
--with-cudd=DIR use CUDD package in DIR
--with-junit=PATH Specify location of the junit JAR file
--with-raptor=DIR use RAPTOR package in DIR
--with-mpi=DIR use LAM/MPI library in DIR
--with-mpe=DIR use MPE library in DIR
--with-python=DIR interface to R language
@ -6521,6 +6526,12 @@ else
ENABLE_ZLIB="@# "
fi
if test -e "$srcdir"/packages/raptor/Makefile.in; then
ENABLE_RAPTOR=""
else
ENABLE_RAPTOR="@# "
fi
if test "$cross_compiling" = "yes"
then
YAP_EXTRAS=
@ -11710,7 +11721,7 @@ else
JAVA_TEST=Test.java
CLASS_TEST=Test.class
cat << \EOF > $JAVA_TEST
/* #line 11713 "configure" */
/* #line 11724 "configure" */
public class Test {
}
EOF
@ -11886,7 +11897,7 @@ EOF
if uudecode$EXEEXT Test.uue; then
ac_cv_prog_uudecode_base64=yes
else
echo "configure: 11889: uudecode had trouble decoding base 64 file 'Test.uue'" >&5
echo "configure: 11900: uudecode had trouble decoding base 64 file 'Test.uue'" >&5
echo "configure: failed file was:" >&5
cat Test.uue >&5
ac_cv_prog_uudecode_base64=no
@ -12017,7 +12028,7 @@ else
JAVA_TEST=Test.java
CLASS_TEST=Test.class
cat << \EOF > $JAVA_TEST
/* #line 12020 "configure" */
/* #line 12031 "configure" */
public class Test {
}
EOF
@ -12052,7 +12063,7 @@ JAVA_TEST=Test.java
CLASS_TEST=Test.class
TEST=Test
cat << \EOF > $JAVA_TEST
/* [#]line 12055 "configure" */
/* [#]line 12066 "configure" */
public class Test {
public static void main (String args[]) {
System.exit (0);
@ -12910,6 +12921,112 @@ fi
if test "$ENABLE_RAPTOR" = ""
then
# Check whether --with-raptor was given.
if test "${with_raptor+set}" = set; then :
withval=$with_raptor; yap_cv_raptor="$withval"
else
yap_cv_raptor=yes
fi
if test "$yap_cv_raptor" = no
then
ENABLE_RAPTOR="@# "
else
ENABLE_RAPTOR=""
fi
if test "$yap_cv_raptor" != no; then
oldlibs="$LIBS"
oldCPPFLAGS="$CPPFLAGS"
if test "$yap_cv_raptor" != "NONE" -a "$yap_cv_raptor" != "yes"; then
CPPFLAGS="-I $yap_cv_raptor/include"
elif test -d /usr/include/raptor2; then
CPPFLAGS="-I /usr/include/raptor2"
elif test -d /usr/local/include/raptor2; then
CPPFLAGS="-I /usr/local/include/raptor2"
elif test "$prefix" != "NONE"; then
CPPFLAGS="-I $prefix/include"
else
CPPFLAGS="-I /usr/local/include"
fi
for ac_header in raptor.h
do :
ac_fn_c_check_header_mongrel "$LINENO" "raptor.h" "ac_cv_header_raptor_h" "$ac_includes_default"
if test "x$ac_cv_header_raptor_h" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_RAPTOR_H 1
_ACEOF
fi
done
oldlibs="$LIBS"
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for main in -lraptor2" >&5
$as_echo_n "checking for main in -lraptor2... " >&6; }
if ${ac_cv_lib_raptor2_main+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-lraptor2 $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
return main ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_raptor2_main=yes
else
ac_cv_lib_raptor2_main=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_raptor2_main" >&5
$as_echo "$ac_cv_lib_raptor2_main" >&6; }
if test "x$ac_cv_lib_raptor2_main" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_LIBRAPTOR2 1
_ACEOF
LIBS="-lraptor2 $LIBS"
fi
RAPTOR_LDFLAGS="$LIBS"
RAPTOR_CPPFLAGS="$CPPFLAGS"
LIBS="$oldlibs"
CPPFLAGS="$oldCPPFLAGS"
fi
fi
# Check whether --with-mpi was given.
if test "${with_mpi+set}" = set; then :
@ -13601,6 +13718,11 @@ ac_config_files="$ac_config_files packages/gecode/Makefile"
fi
if test "$ENABLE_RAPTOR" = ""; then
ac_config_files="$ac_config_files packages/raptor/Makefile"
fi
if test "$ENABLE_PRISM" = ""; then
ac_config_files="$ac_config_files packages/prism/src/c/Makefile"
@ -14361,6 +14483,7 @@ do
"packages/real/Makefile") CONFIG_FILES="$CONFIG_FILES packages/real/Makefile" ;;
"packages/CLPBN/horus/Makefile") CONFIG_FILES="$CONFIG_FILES packages/CLPBN/horus/Makefile" ;;
"packages/gecode/Makefile") CONFIG_FILES="$CONFIG_FILES packages/gecode/Makefile" ;;
"packages/raptor/Makefile") CONFIG_FILES="$CONFIG_FILES packages/raptor/Makefile" ;;
"packages/prism/src/c/Makefile") CONFIG_FILES="$CONFIG_FILES packages/prism/src/c/Makefile" ;;
"packages/prism/src/prolog/Makefile") CONFIG_FILES="$CONFIG_FILES packages/prism/src/prolog/Makefile" ;;
"packages/yap-lbfgs/Makefile") CONFIG_FILES="$CONFIG_FILES packages/yap-lbfgs/Makefile" ;;

View File

@ -736,6 +736,12 @@ else
ENABLE_ZLIB="@# "
fi
if test -e "$srcdir"/packages/raptor/Makefile.in; then
ENABLE_RAPTOR=""
else
ENABLE_RAPTOR="@# "
fi
if test "$cross_compiling" = "yes"
then
YAP_EXTRAS=
@ -1878,6 +1884,11 @@ fi
m4_include([packages/gecode/configure.in])
if test "$ENABLE_RAPTOR" = ""
then
m4_include([packages/raptor/configure.in])
fi
m4_include([library/lammpi/configure.in])
m4_include([packages/python/configure.in])
@ -2066,6 +2077,10 @@ if test "$ENABLE_GECODE" = ""; then
AC_CONFIG_FILES([packages/gecode/Makefile])
fi
if test "$ENABLE_RAPTOR" = ""; then
AC_CONFIG_FILES([packages/raptor/Makefile])
fi
if test "$ENABLE_PRISM" = ""; then
AC_CONFIG_FILES([packages/prism/src/c/Makefile])
AC_CONFIG_FILES([packages/prism/src/prolog/Makefile])

View File

@ -300,20 +300,6 @@ Int yap_flags_field[NUMBER_OF_YAP_FLAGS] yap_flags InitFlags() void
/* Operators */
struct operator_entry *op_list OpList =NULL OpListAdjust
/* Input/Output */
/* stream array */
struct stream_desc *yap_streams Stream =NULL RestoreStreams()
/* stream aliases */
UInt n_of_file_aliases NOfFileAliases =0 void
UInt sz_of_file_aliases SzOfFileAliases =0 void
struct AliasDescS *file_aliases FileAliases =NULL RestoreAliases()
/* prompting */
Atom atprompt AtPrompt =AtomNil AtomAdjust
char _prompt[MAX_PROMPT] YapPrompt void void
/* ISO char conversion: I will make no comments */
char *char_conversion_table CharConversionTable =NULL CodeCharPAdjust
char *char_conversion_table2 CharConversionTable2 =NULL CodeCharPAdjust

1
packages/raptor Submodule

@ -0,0 +1 @@
Subproject commit 099c16227d951355965cabd6afc1a94f3a98bf19