diff --git a/src/lib/charsio.pl b/src/lib/charsio.pl index 7ac67c91..afe745a2 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). 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). 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/src/toplevel.pl b/src/toplevel.pl index 820d91d0..67408cd2 100644 --- a/src/toplevel.pl +++ b/src/toplevel.pl @@ -40,23 +40,36 @@ 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. 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, [c(Mod)|Goals0]) + ). print_help :- write('Usage: scryer-prolog [OPTIONS] [FILES] [-- ARGUMENTS]'), @@ -96,6 +109,7 @@ ignore_machine_arg. arg_type(g). arg_type(t). +arg_type(c(_)). arg_type(g(_)). arg_type(t(_)). @@ -132,6 +146,14 @@ run_goals([g(Gs0)|Goals]) :- !, write_term(Goal, [variable_names(VNs),double_quotes(DQ)]), nl ), run_goals(Goals). +run_goals([c(Mod)|Goals]) :- !, + ( catch(consult(Mod), E, print_exception(E)) -> + true + ; write('% Warning: initialization failed for: '), + double_quotes_option(DQ), + write_term(consult(Mod), [double_quotes(DQ)]), nl + ), + run_goals(Goals). run_goals([Goal|_]) :- loader:write_error(error(domain_error(arg_type, Goal), run_goals/1)), nl, 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"]