From 7573c64087a1ca1b54138fcff388326a606bc707 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 2 Feb 2024 10:54:28 -0700 Subject: [PATCH 1/9] load .scryerrc before files and goals (#1775, #2313) --- src/toplevel.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/toplevel.pl b/src/toplevel.pl index 820d91d0..a3cee9a0 100644 --- a/src/toplevel.pl +++ b/src/toplevel.pl @@ -28,6 +28,7 @@ load_scryerrc :- '$repl' :- asserta('$toplevel':started), + (\+ disabled_init_file -> load_scryerrc ; true), raw_argv(Args0), ( append(Args1, ["--"|_], Args0) -> Args = Args1 @@ -37,7 +38,6 @@ load_scryerrc :- delegate_task(TaskArgs, []) ; true ), - (\+ disabled_init_file -> load_scryerrc ; true), repl. delegate_task([], []). From 75a94fd0b359f9b9d1992207243ed1b4fb7bdc92 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 2 Feb 2024 11:49:02 -0700 Subject: [PATCH 2/9] fmt --- src/machine/streams.rs | 2 +- src/machine/system_calls.rs | 2 +- src/rcu.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/machine/streams.rs b/src/machine/streams.rs index 53269bf4..e05ad983 100644 --- a/src/machine/streams.rs +++ b/src/machine/streams.rs @@ -1875,7 +1875,7 @@ impl MachineState { }; if path.extension().is_none() { - if let Some(metadata) = file.metadata().ok() { + if let Ok(metadata) = file.metadata() { if metadata.is_dir() { path.set_extension("pl"); continue; diff --git a/src/machine/system_calls.rs b/src/machine/system_calls.rs index 5a10358d..73bf62f2 100644 --- a/src/machine/system_calls.rs +++ b/src/machine/system_calls.rs @@ -5629,7 +5629,7 @@ impl Machine { #[inline(always)] pub(crate) fn inference_count(&mut self, count_var: HeapCellValue, count: Integer) { - if let Some(value) = <&Integer as TryInto>::try_into(&count).ok() { + if let Ok(value) = <&Integer as TryInto>::try_into(&count) { self.machine_st .unify_fixnum(Fixnum::build_with(value), count_var); } else { diff --git a/src/rcu.rs b/src/rcu.rs index 5c7c3201..a3e8d2ab 100644 --- a/src/rcu.rs +++ b/src/rcu.rs @@ -22,7 +22,7 @@ thread_local! { // odd value means the current thread is about to access the active_epoch of an Rcu // a thread has a single epoch counter for all Rcu it accesses, // as a thread can only access one Rcu at a time - static THREAD_EPOCH_COUNTER: OnceCell> = OnceCell::new(); + static THREAD_EPOCH_COUNTER: OnceCell> = const { OnceCell::new() }; } pub struct Rcu { From de6c460a51ddf0d72eb6fe929ff0ed5c587d734d Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 2 Feb 2024 15:35:00 -0700 Subject: [PATCH 3/9] treat consultation of command line modules as regular goals (#2314) --- src/toplevel.pl | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/toplevel.pl b/src/toplevel.pl index a3cee9a0..86ba085f 100644 --- a/src/toplevel.pl +++ b/src/toplevel.pl @@ -28,7 +28,6 @@ load_scryerrc :- '$repl' :- asserta('$toplevel':started), - (\+ disabled_init_file -> load_scryerrc ; true), raw_argv(Args0), ( append(Args1, ["--"|_], Args0) -> Args = Args1 @@ -38,6 +37,7 @@ load_scryerrc :- delegate_task(TaskArgs, []) ; true ), + (\+ disabled_init_file -> load_scryerrc ; true), repl. delegate_task([], []). @@ -48,15 +48,17 @@ delegate_task([], Goals0) :- repl. delegate_task([Arg0|Args], Goals0) :- - ( member(Arg0, ["-h", "--help"]) -> print_help - ; member(Arg0, ["-v", "--version"]) -> print_version - ; member(Arg0, ["-g", "--goal"]) -> gather_goal(g, Args, Goals0) - ; member(Arg0, ["-f"]) -> disable_init_file - ; member(Arg0, ["--no-add-history"]) -> ignore_machine_arg + ( ( member(Arg0, ["-h", "--help"]) -> print_help + ; member(Arg0, ["-v", "--version"]) -> print_version + ; member(Arg0, ["-g", "--goal"]) -> gather_goal(g, Args, Goals0) + ; member(Arg0, ["-f"]) -> disable_init_file + ; member(Arg0, ["--no-add-history"]) -> ignore_machine_arg + ), + !, + delegate_task(Args, Goals0) ; atom_chars(Mod, Arg0), - catch(consult(Mod), E, print_exception(E)) - ), - delegate_task(Args, Goals0). + delegate_task(Args, [t(consult(Mod))|Goals0]) + ). print_help :- write('Usage: scryer-prolog [OPTIONS] [FILES] [-- ARGUMENTS]'), @@ -132,6 +134,14 @@ run_goals([g(Gs0)|Goals]) :- !, write_term(Goal, [variable_names(VNs),double_quotes(DQ)]), nl ), run_goals(Goals). +run_goals([t(Goal)|Goals]) :- !, + ( catch(user:Goal, E, print_exception(E)) -> + true + ; write('% Warning: initialization failed for: '), + double_quotes_option(DQ), + write_term(Goal, [double_quotes(DQ)]), nl + ), + run_goals(Goals). run_goals([Goal|_]) :- loader:write_error(error(domain_error(arg_type, Goal), run_goals/1)), nl, From 6a421dd8b0af7ef63de9e9566f06988bb4f16bce Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 2 Feb 2024 17:04:47 -0700 Subject: [PATCH 4/9] fix broken tests --- tests/scryer/cli/issues/goals_compound_goal.toml | 2 +- tests/scryer/cli/issues/goals_multiple_goals.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/scryer/cli/issues/goals_compound_goal.toml b/tests/scryer/cli/issues/goals_compound_goal.toml index 4fd7d5ba..6cc3d16c 100644 --- a/tests/scryer/cli/issues/goals_compound_goal.toml +++ b/tests/scryer/cli/issues/goals_compound_goal.toml @@ -1,2 +1,2 @@ # issue 820 -args = ["-f", "--no-add-history", "-g", "test,halt", "goals.pl"] +args = ["-f", "--no-add-history", "goals.pl", "-g", "test,halt"] diff --git a/tests/scryer/cli/issues/goals_multiple_goals.toml b/tests/scryer/cli/issues/goals_multiple_goals.toml index 25e739dd..676c61dc 100644 --- a/tests/scryer/cli/issues/goals_multiple_goals.toml +++ b/tests/scryer/cli/issues/goals_multiple_goals.toml @@ -1,2 +1,2 @@ # issue 820 -args = ["-f", "--no-add-history", "-g", "test", "-g", "halt", "goals.pl"] +args = ["-f", "--no-add-history", "goals.pl", "-g", "test", "-g", "halt"] From 673329ddb7cfd1f4e1ee45b65ec08078dcee970c Mon Sep 17 00:00:00 2001 From: Mark Date: Sat, 3 Feb 2024 11:49:26 -0700 Subject: [PATCH 5/9] fix reverted tests, ensure files are loaded before goals (#2315) --- src/toplevel.pl | 22 ++++++++++++++----- .../cli/issues/goals_compound_goal.toml | 2 +- .../cli/issues/goals_multiple_goals.toml | 2 +- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/toplevel.pl b/src/toplevel.pl index 86ba085f..67408cd2 100644 --- a/src/toplevel.pl +++ b/src/toplevel.pl @@ -40,10 +40,21 @@ load_scryerrc :- (\+ disabled_init_file -> load_scryerrc ; true), repl. +args_consults_goals([], [], []). +args_consults_goals([Arg|Args], Consults, Goals) :- + arg_consults_goals(Arg, Args, Consults, Goals). + +arg_consults_goals(c(Mod), Args, [c(Mod)|Consults], Goals) :- + args_consults_goals(Args, Consults, Goals). +arg_consults_goals(g(Goal), Args, Consults, [g(Goal)|Goals]) :- + args_consults_goals(Args, Consults, Goals). + delegate_task([], []). delegate_task([], Goals0) :- - reverse(Goals0, Goals), (\+ disabled_init_file -> load_scryerrc ; true), + reverse(Goals0, Goals1), + args_consults_goals(Goals1, Consults, Goals), + run_goals(Consults), run_goals(Goals), repl. @@ -57,7 +68,7 @@ delegate_task([Arg0|Args], Goals0) :- !, delegate_task(Args, Goals0) ; atom_chars(Mod, Arg0), - delegate_task(Args, [t(consult(Mod))|Goals0]) + delegate_task(Args, [c(Mod)|Goals0]) ). print_help :- @@ -98,6 +109,7 @@ ignore_machine_arg. arg_type(g). arg_type(t). +arg_type(c(_)). arg_type(g(_)). arg_type(t(_)). @@ -134,12 +146,12 @@ run_goals([g(Gs0)|Goals]) :- !, write_term(Goal, [variable_names(VNs),double_quotes(DQ)]), nl ), run_goals(Goals). -run_goals([t(Goal)|Goals]) :- !, - ( catch(user:Goal, E, print_exception(E)) -> +run_goals([c(Mod)|Goals]) :- !, + ( catch(consult(Mod), E, print_exception(E)) -> true ; write('% Warning: initialization failed for: '), double_quotes_option(DQ), - write_term(Goal, [double_quotes(DQ)]), nl + write_term(consult(Mod), [double_quotes(DQ)]), nl ), run_goals(Goals). run_goals([Goal|_]) :- diff --git a/tests/scryer/cli/issues/goals_compound_goal.toml b/tests/scryer/cli/issues/goals_compound_goal.toml index 6cc3d16c..4fd7d5ba 100644 --- a/tests/scryer/cli/issues/goals_compound_goal.toml +++ b/tests/scryer/cli/issues/goals_compound_goal.toml @@ -1,2 +1,2 @@ # issue 820 -args = ["-f", "--no-add-history", "goals.pl", "-g", "test,halt"] +args = ["-f", "--no-add-history", "-g", "test,halt", "goals.pl"] diff --git a/tests/scryer/cli/issues/goals_multiple_goals.toml b/tests/scryer/cli/issues/goals_multiple_goals.toml index 676c61dc..25e739dd 100644 --- a/tests/scryer/cli/issues/goals_multiple_goals.toml +++ b/tests/scryer/cli/issues/goals_multiple_goals.toml @@ -1,2 +1,2 @@ # issue 820 -args = ["-f", "--no-add-history", "goals.pl", "-g", "test", "-g", "halt"] +args = ["-f", "--no-add-history", "-g", "test", "-g", "halt", "goals.pl"] From ec4a8745e76e02f60ef3dd4ba3ac33d93263e91a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Arroyo=20Calle?= Date: Sun, 4 Feb 2024 21:04:02 +0100 Subject: [PATCH 6/9] Add all_mdoules test and fix library(csv) --- src/lib/csv.pl | 2 +- tests/scryer/cli/src_tests/all_modules.stderr | 0 tests/scryer/cli/src_tests/all_modules.stdin | 48 +++++++++++++++++++ tests/scryer/cli/src_tests/all_modules.stdout | 47 ++++++++++++++++++ tests/scryer/cli/src_tests/all_modules.toml | 1 + 5 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 tests/scryer/cli/src_tests/all_modules.stderr create mode 100644 tests/scryer/cli/src_tests/all_modules.stdin create mode 100644 tests/scryer/cli/src_tests/all_modules.stdout create mode 100644 tests/scryer/cli/src_tests/all_modules.toml diff --git a/src/lib/csv.pl b/src/lib/csv.pl index d6ad8f73..2cf6ea56 100644 --- a/src/lib/csv.pl +++ b/src/lib/csv.pl @@ -221,7 +221,7 @@ row([X | Y], Opt) --> !, ( separator(Opt) -> row(Y, Opt) - ; end_token -> + ; end_token, { Y = [] }). diff --git a/tests/scryer/cli/src_tests/all_modules.stderr b/tests/scryer/cli/src_tests/all_modules.stderr new file mode 100644 index 00000000..e69de29b diff --git a/tests/scryer/cli/src_tests/all_modules.stdin b/tests/scryer/cli/src_tests/all_modules.stdin new file mode 100644 index 00000000..c61818fe --- /dev/null +++ b/tests/scryer/cli/src_tests/all_modules.stdin @@ -0,0 +1,48 @@ +use_module(library(arithmetic)). +use_module(library(assoc)). +use_module(library(atts)). +use_module(library(between)). +use_module(library(charsio)). +use_module(library(clpb)). +use_module(library(clpz)). +use_module(library(cont)). +use_module(library(crypto)). +use_module(library(csv)). +use_module(library(dcgs)). +use_module(library(debug)). +use_module(library(diag)). +use_module(library(dif)). +use_module(library(error)). +use_module(library(ffi)). +use_module(library(files)). +use_module(library(format)). +use_module(library(freeze)). +use_module(library(gensym)). +use_module(library(http/http_open)). +use_module(library(http/http_server)). +use_module(library(iso_ext)). +use_module(library(lambda)). +use_module(library(lists)). +use_module(library(ordsets)). +use_module(library(os)). +use_module(library(pairs)). +use_module(library(pio)). +use_module(library(queues)). +use_module(library(random)). +use_module(library(reif)). +use_module(library(serialization/abnf)). +use_module(library(serialization/json)). +use_module(library(sgml)). +use_module(library(si)). +use_module(library(simplex)). +use_module(library(sockets)). +use_module(library(tabling)). +use_module(library(terms)). +use_module(library(time)). +use_module(library(tls)). +use_module(library(ugraphs)). +use_module(library(uuid)). +use_module(library(wasm)). +use_module(library(when)). +use_module(library(xpath)). +halt. diff --git a/tests/scryer/cli/src_tests/all_modules.stdout b/tests/scryer/cli/src_tests/all_modules.stdout new file mode 100644 index 00000000..4e32a715 --- /dev/null +++ b/tests/scryer/cli/src_tests/all_modules.stdout @@ -0,0 +1,47 @@ + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. + true. diff --git a/tests/scryer/cli/src_tests/all_modules.toml b/tests/scryer/cli/src_tests/all_modules.toml new file mode 100644 index 00000000..8198ecb9 --- /dev/null +++ b/tests/scryer/cli/src_tests/all_modules.toml @@ -0,0 +1 @@ +args = ["-f", "--no-add-history"] From aa98a7e7d69ec58edac155bf6f8bcf8aeea3c90f Mon Sep 17 00:00:00 2001 From: Markus Triska Date: Tue, 6 Feb 2024 19:05:29 +0100 Subject: [PATCH 7/9] ADDED: clpz_t/2, generalizing support for use with library(reif) This was suggested and contributed by @librarianmage in: https://github.com/mthom/scryer-prolog/issues/2225#issuecomment-1890801923 Many thanks! If anyone can find a better predicate name, please let us know any time! --- src/lib/clpz.pl | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/lib/clpz.pl b/src/lib/clpz.pl index 07768da5..6834a379 100644 --- a/src/lib/clpz.pl +++ b/src/lib/clpz.pl @@ -102,6 +102,7 @@ fd_dom/2, % for use in predicates from library(reif) + clpz_t/2, (#=)/3, (#<)/3 @@ -7981,13 +7982,13 @@ coeff_var_term(C-V, T) :- ( C =:= 1 -> T = #V ; T = C * #V ). Reified predicates for use with predicates from library(reif). - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ -#=(X, Y, T) :- - X #= Y #<==> #B, +clpz_t(Expr, T) :- + Expr #<==> #B, zo_t(B, T). -#<(X, Y, T) :- - X #< Y #<==> #B, - zo_t(B, T). +#=(X, Y, T) :- clpz_t(X #= Y, T). + +#<(X, Y, T) :- clpz_t(X #< Y, T). zo_t(0, false). zo_t(1, true). From 53b7d9eec92e0568b5d0d28622abb62dd535f774 Mon Sep 17 00:00:00 2001 From: Markus Triska Date: Wed, 7 Feb 2024 20:05:07 +0100 Subject: [PATCH 8/9] ENHANCED: Bidirectional char_type/2, addressing #2321. Suggested by @librarianmage, many thanks! --- src/lib/charsio.pl | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/lib/charsio.pl b/src/lib/charsio.pl index 7ac67c91..7a4186a5 100644 --- a/src/lib/charsio.pl +++ b/src/lib/charsio.pl @@ -20,6 +20,7 @@ read and write chars. :- use_module(library(iso_ext)). :- use_module(library(error)). :- use_module(library(lists)). +:- use_module(library(between)). :- use_module(library(iso_ext), [partial_string/1,partial_string/3]). fabricate_var_name(VarType, VarName, N) :- @@ -74,9 +75,10 @@ extend_var_list_([V|Vs], N, VarList, NewVarList, VarType) :- ). -%% char_type(+Char, -Type). +%% char_type(?Char, ?Type). % -% Given a Char, Type is one of the categories that char fits in. +% Type is one of the categories that Char fits in. +% At least one of the arguments must be ground. % Possible categories are: % % - `alnum` @@ -132,17 +134,32 @@ extend_var_list_([V|Vs], N, VarList, NewVarList, VarType) :- % Note that uppercase and lowercase transformations use a string. This is because % some characters do not map 1:1 between lowercase and uppercase. char_type(Char, Type) :- - must_be(character, Char), - ( ground(Type) -> - ( ctype(Type) -> - '$char_type'(Char, Type) - ; domain_error(char_type, Type, char_type/2) - ) - ; ctype(Type), + can_be(character, Char), + ( \+ ctype(Type) -> + domain_error(char_type, Type, char_type/2) + ; true + ), + ( ground(Char) -> + ctype(Type), '$char_type'(Char, Type) + ; ground(Type) -> + max_char_code(Max), + between(0, Max, Code), + char_code(Char, Code), + '$char_type'(Char, Type) + ; must_be(character, Char) ). +max_char_code(Max) :- + catch((length(_, Code), + catch(char_code(Char, Code), + error(representation_error(_),_), + throw(max_char_code(Code))), + false), + max_char_code(Code), + Max is Code - 1). + ctype(alnum). ctype(alpha). ctype(alphabetic). From 539a1aee2c61ffb4e6357d98d2550ecbef266db8 Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 7 Feb 2024 21:46:32 -0700 Subject: [PATCH 9/9] fix tests broken by singleton --- src/lib/charsio.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/charsio.pl b/src/lib/charsio.pl index 7a4186a5..afe745a2 100644 --- a/src/lib/charsio.pl +++ b/src/lib/charsio.pl @@ -153,7 +153,7 @@ char_type(Char, Type) :- max_char_code(Max) :- catch((length(_, Code), - catch(char_code(Char, Code), + catch(char_code(_Char, Code), error(representation_error(_),_), throw(max_char_code(Code))), false),