From da79af201b58ab2a4588bb2d78aeaa8bc8ae567e Mon Sep 17 00:00:00 2001 From: Costa Vitor Date: Tue, 12 Feb 2013 12:47:30 -0600 Subject: [PATCH 1/4] top-level more SWI style. --- pl/boot.yap | 21 +++++++++++---------- pl/messages.yap | 2 ++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/pl/boot.yap b/pl/boot.yap index 3c1ddd51a..a47a30679 100755 --- a/pl/boot.yap +++ b/pl/boot.yap @@ -497,11 +497,11 @@ true :- true. '$write_answer'(NV, LGs, Written), '$write_query_answer_true'(Written), ( - '$prompt_alternatives_on'(determinism), CP = NCP, DCP = 0 -> - nl(user_error), + '$prompt_alternatives_on'(determinism), CP = NCP, DCP = 0 + -> + format(user_error, '.~n', []), ! ; - '$another', ! ), @@ -517,8 +517,9 @@ true :- true. '$delayed_goals'(G, [], NV, LGs, _), '$write_answer'(NV, LGs, Written), ( Written = [] -> - !,'$present_answer'(C, yes); - '$another', ! + !,'$present_answer'(C, true) + ; + '$another', ! ), fail. '$yes_no'(_,_) :- @@ -546,9 +547,9 @@ true :- true. '$out_neg_answer' :- ( '$undefined'(print_message(_,_),prolog) -> - '$present_answer'(user_error,"no~n", []) + '$present_answer'(user_error,'false.~n', []) ; - print_message(help,no) + print_message(help,false) ), fail. @@ -559,7 +560,7 @@ true :- true. ( '$enter_system_mode' ; '$exit_system_mode', fail). '$write_query_answer_true'([]) :- !, - format(user_error,'~ntrue',[]). + format(user_error,'true',[]). '$write_query_answer_true'(_). @@ -579,7 +580,7 @@ true :- true. write_term(user_error,Answ,Opts) ; format(user_error,'~w',[Answ]) ), - format(user_error,'~n', []). + format(user_error,'.~n', []). '$another' :- format(user_error,' ? ',[]), @@ -588,7 +589,7 @@ true :- true. '$do_another'(C) :- ( C== 0'; -> skip(user_input,10), %' - '$add_nl_outside_console', + % '$add_nl_outside_console', fail ; C== 10 -> '$add_nl_outside_console', diff --git a/pl/messages.yap b/pl/messages.yap index 45efbc58c..b8d3cd9cc 100644 --- a/pl/messages.yap +++ b/pl/messages.yap @@ -37,6 +37,8 @@ file_position(FileName,LN,MsgCodes) --> generate_message(halt) --> !, ['YAP execution halted']. +generate_message(false) --> !, + ['false.']. generate_message('$abort') --> !, ['YAP execution aborted']. generate_message(abort(user)) --> !, From 268bca2330e2a9190b8edb66a5294170268d388d Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Tue, 12 Feb 2013 12:50:01 -0600 Subject: [PATCH 2/4] use current LD_LIBRARY_PATH --- configure.in | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/configure.in b/configure.in index 22a8722bc..99756ccac 100755 --- a/configure.in +++ b/configure.in @@ -1227,14 +1227,13 @@ case "$target_os" in then YAPLIB_LD="\$(CC) -shared" EXTRA_LIBS_FOR_DLLS="$EXTRA_LIBS_FOR_DLLS -L\$(abs_top_builddir) -lYap -Wl,-R,\$(YAPLIBDIR) -Wl,-R,\$(LIBDIR)" - INSTALL_ENV="LD_LIBRARY_PATH=\$(DESTDIR)\$(LIBDIR):\$(DESTDIR)\$(YAPLIBDIR): YAPSHAREDIR=\$(DESTDIR)\$(SHAREDIR) YAPLIBDIR=\$(DESTDIR)\$(YAPLIBDIR)" - PRE_INSTALL_ENV="LD_LIBRARY_PATH=\$(abs_top_builddir)" + INSTALL_ENV="LD_LIBRARY_PATH=:\$(DESTDIR)\$(LIBDIR):\$(DESTDIR)\$(YAPLIBDIR): YAPSHAREDIR=\$(DESTDIR)\$(SHAREDIR) YAPLIBDIR=\$(DESTDIR)\$(YAPLIBDIR)" else YAPLIB_LD="\$(CC)" EXTRA_LIBS_FOR_DLLS="$EXTRA_LIBS_FOR_DLLS -Wl,-R,\$(YAPLIBDIR) -Wl,-R,\$(LIBDIR)" INSTALL_ENV="YAPSHAREDIR=\$(DESTDIR)\$(SHAREDIR) YAPLIBDIR=\$(DESTDIR)\$(YAPLIBDIR)" - PRE_INSTALL_ENV="" fi + PRE_INSTALL_ENV="LD_LIBRARY_PATH=$LD_LIBRARY_PATH:\$(abs_top_builddir):\$(abs_top_builddir)/lib/sys" ;; *sunos4*) M4="/usr/5bin/m4" From 9fb63762dc90dcb037b0f008aac9fc218f3b3aea Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Tue, 12 Feb 2013 16:21:26 -0600 Subject: [PATCH 3/4] delete_file should be SICStus compatible --- H/pl-incl.h | 2 ++ library/system.yap | 70 ++++++++++++++++++++++++++++++++++++++++++++++ os/pl-files.c | 4 +-- 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/H/pl-incl.h b/H/pl-incl.h index 261c8563d..1dbb03586 100755 --- a/H/pl-incl.h +++ b/H/pl-incl.h @@ -46,6 +46,8 @@ #define PLVERSION YAP_VERSION #define PLNAME "yap" +#define SWIP "swi_" + /* try not to pollute the SWI space */ #ifdef P #undef P diff --git a/library/system.yap b/library/system.yap index c6262291a..bd30d8c5f 100644 --- a/library/system.yap +++ b/library/system.yap @@ -88,7 +88,77 @@ check_int(I, Inp) :- throw(error(type_error(integer,I),Inp)). % file operations +% file operations +delete_file(IFile) :- + true_file_name(IFile, File), + delete_file(File, off, on, off). + +delete_file(IFile, Opts) :- + true_file_name(IFile, File), + process_delete_file_opts(Opts, Dir, Recurse, Ignore, delete_file(File,Opts)), + delete_file(File, Dir, Recurse, Ignore). + +process_delete_file_opts(V, _, _, _, T) :- var(V), !, + throw(error(instantiation_error,T)). +process_delete_file_opts([], off, off, off, _) :- !. +process_delete_file_opts([V|_], _, _, _, T) :- var(V), !, + throw(error(instantiation_error,T)). +process_delete_file_opts([directory|Opts], on, Recurse, Ignore, T) :- !, + process_delete_file_opts(Opts, _, Recurse, Ignore, T). +process_delete_file_opts([recursive|Opts], Dir, on, Ignore, T) :- !, + process_delete_file_opts(Opts, Dir, _, Ignore, T). +process_delete_file_opts([ignore|Opts], Dir, Recurse, on, T) :- !, + process_delete_file_opts(Opts, Dir, Recurse, _, T). +process_delete_file_opts(Opts, _, _, _, T) :- + throw(error(domain_error(delete_file_option,Opts),T)). + +delete_file(IFile, Dir, Recurse, Ignore) :- + true_file_name(IFile, File), + file_property(File, Type, _, _, _Permissions, _, Ignore), + delete_file(Type, File, Dir, Recurse, Ignore). + +delete_file(N, File, _Dir, _Recurse, Ignore) :- number(N), !, % error. + handle_system_error(N, Ignore, delete_file(File)). +delete_file(directory, File, Dir, Recurse, Ignore) :- + delete_directory(Dir, File, Recurse, Ignore). +delete_file(_, File, _Dir, _Recurse, Ignore) :- + unlink_file(File, Ignore). + +unlink_file(IFile, Ignore) :- + true_file_name(IFile, File), + unlink(File, N), + handle_system_error(N, Ignore, delete_file(File)). + +delete_directory(on, File, _Recurse, Ignore) :- + rm_directory(File, Ignore). +delete_directory(off, File, Recurse, Ignore) :- + delete_directory(Recurse, File, Ignore). + +rm_directory(File, Ignore) :- + rmdir(File, Error), + handle_system_error(Error, Ignore, delete_file(File)). + +delete_directory(on, File, Ignore) :- + directory_files(File, FileList, Ignore), + path_separator(D), + atom_concat(File, D, FileP), + delete_dirfiles(FileList, FileP, Ignore), + rmdir(File, Ignore). + +delete_dirfiles([], _, _). +delete_dirfiles(['.'|Fs], File, Ignore) :- !, + delete_dirfiles(Fs, File, Ignore). +delete_dirfiles(['..'|Fs], File, Ignore) :- !, + delete_dirfiles(Fs, File, Ignore). +delete_dirfiles([F|Fs], File, Ignore) :- + atom_concat(File,F,TrueF), + delete_file(TrueF, off, on, Ignore), + delete_dirfiles(Fs, File, Ignore). + +directory_files(File, FileList, Ignore) :- + list_directory(File, FileList, Error), + handle_system_error(Error, Ignore, directory_files(File, FileList)). handle_system_error(Error, _Ignore, _G) :- var(Error), !. handle_system_error(Error, off, G) :- atom(Error), !, diff --git a/os/pl-files.c b/os/pl-files.c index 2c290d6e1..4642b8e68 100644 --- a/os/pl-files.c +++ b/os/pl-files.c @@ -828,7 +828,7 @@ PRED_IMPL("tmp_file_stream", 3, tmp_file_stream, 0) static -PRED_IMPL("delete_file", 1, delete_file, 0) +PRED_IMPL("swi_delete_file", 1, delete_file, 0) { PRED_LD char *n; atom_t aname; @@ -1125,7 +1125,7 @@ BeginPredDefs(files) PRED_DEF("exists_directory", 1, exists_directory, 0) PRED_DEF("tmp_file", 2, tmp_file, 0) PRED_DEF("tmp_file_stream", 3, tmp_file_stream, 0) - PRED_DEF("delete_file", 1, delete_file, 0) + PRED_DEF("swi_delete_file", 1, delete_file, 0) PRED_DEF("delete_directory", 1, delete_directory, 0) PRED_DEF("make_directory", 1, make_directory, 0) PRED_DEF("same_file", 2, same_file, 0) From 60969b9601a794a6d312e80dae5adf71d36e3107 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Tue, 12 Feb 2013 16:45:03 -0600 Subject: [PATCH 4/4] rem and mod used code from div :( (Robrto Bagnara) --- C/arith2.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/C/arith2.c b/C/arith2.c index 805b36ffa..1623929e6 100644 --- a/C/arith2.c +++ b/C/arith2.c @@ -51,12 +51,7 @@ p_mod(Term t1, Term t2) { if (i2 == 0) return Yap_ArithError(EVALUATION_ERROR_ZERO_DIVISOR, t2, "X is " Int_FORMAT " mod 0", i1); if (i1 == Int_MIN && i2 == -1) { -#ifdef USE_GMP - return Yap_gmp_add_ints(Int_MAX, 1); -#else - return Yap_ArithError(EVALUATION_ERROR_INT_OVERFLOW, t1, - "// /2 with %d and %d", i1, i2); -#endif + return MkIntTerm(0); } mod = i1%i2; if (mod && (mod ^ i2) < 0) @@ -181,12 +176,7 @@ p_rem(Term t1, Term t2) { if (i2 == 0) return Yap_ArithError(EVALUATION_ERROR_ZERO_DIVISOR, t2, "X is " Int_FORMAT " rem 0", i1); if (i1 == Int_MIN && i2 == -1) { -#ifdef USE_GMP - return Yap_gmp_add_ints(Int_MAX, 1); -#else - return Yap_ArithError(EVALUATION_ERROR_INT_OVERFLOW, t1, - "rem/2 with %d and %d", i1, i2); -#endif + return MkIntTerm(0); } RINT(i1%i2); }