Codebase list swi-prolog / 7c63afa
New upstream version 8.2.4+dfsg Lev Lamberov 3 years ago
72 changed file(s) with 799 addition(s) and 347 deletion(s). Raw diff Collapse all Expand all
7373 include(QLF)
7474 include(PackageSelection)
7575 include(Dependencies)
76 include(DocDepends)
7677
7778 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
7879 set_install_prefix()
0 8.2.3
0 8.2.4
13791379 sub_atom(Name, 0, _, _, '__aux_meta_call_').
13801380
13811381 compile_meta(CallIn, CallOut, M, Term, (CallOut :- Body)) :-
1382 term_variables(Term, AllVars),
1382 replace_subterm(CallIn, true, Term, Term2),
1383 term_variables(Term2, AllVars),
13831384 term_variables(CallIn, InVars),
13841385 intersection_eq(InVars, AllVars, HeadVars),
1385 variant_sha1(CallIn+HeadVars, Hash),
1386 copy_term_nat(CallIn+HeadVars, NAT),
1387 variant_sha1(NAT, Hash),
13861388 atom_concat('__aux_meta_call_', Hash, AuxName),
13871389 expand_goal(CallIn, _Pos0, Body, _Pos, M, [], (CallOut:-CallIn), []),
13881390 length(HeadVars, Arity),
13911393 ; HeadArgs = HeadVars
13921394 ),
13931395 CallOut =.. [AuxName|HeadArgs].
1396
1397 %! replace_subterm(From, To, TermIn, TermOut)
1398 %
1399 % Replace instances (==/2) of From inside TermIn by To.
1400
1401 replace_subterm(From, To, TermIn, TermOut) :-
1402 From == TermIn,
1403 !,
1404 TermOut = To.
1405 replace_subterm(From, To, TermIn, TermOut) :-
1406 compound(TermIn),
1407 compound_name_arity(TermIn, Name, Arity),
1408 Arity > 0,
1409 !,
1410 compound_name_arity(TermOut, Name, Arity),
1411 replace_subterm_compound(1, Arity, From, To, TermIn, TermOut).
1412 replace_subterm(_, _, Term, Term).
1413
1414 replace_subterm_compound(I, Arity, From, To, TermIn, TermOut) :-
1415 I =< Arity,
1416 !,
1417 arg(I, TermIn, A1),
1418 arg(I, TermOut, A2),
1419 replace_subterm(From, To, A1, A2),
1420 I2 is I+1,
1421 replace_subterm_compound(I2, Arity, From, To, TermIn, TermOut).
1422 replace_subterm_compound(_I, _Arity, _From, _To, _TermIn, _TermOut).
1423
13941424
13951425 %! intersection_eq(+Small, +Big, -Shared) is det.
13961426 %
301301 ; var(Goal)
302302 -> ( Arity == 0
303303 -> ( atom(Name)
304 -> Goal = Name
305 ; Name == []
304306 -> Goal = Name
305307 ; blob(Name, closure)
306308 -> Goal = Name
10711073 ; Dirs = Defaults
10721074 ),
10731075 '$member'(Dir, Dirs),
1076 Dir \== '',
10741077 exists_directory(Dir).
10751078
10761079 '$path_sep'(Char) :-
9494 translate_message2(error(resource_error(tripwire(Wire, Context)), _)) -->
9595 !,
9696 tripwire_message(Wire, Context).
97 translate_message2(error(existence_error(reset, Ball), SWI)) -->
98 swi_location(SWI),
99 tabling_existence_error(Ball, SWI).
97100 translate_message2(error(ISO, SWI)) -->
98101 swi_location(SWI),
99102 term_message(ISO),
314317 domain(Domain) -->
315318 ['`~w\''-[Domain] ].
316319
320 %! tabling_existence_error(+Ball, +Context)//
321 %
322 % Called on invalid shift/1 calls. Track those that result from
323 % tabling errors.
324
325 tabling_existence_error(Ball, Context) -->
326 { table_shift_ball(Ball) },
327 [ 'Tabling dependency error' ],
328 swi_extra(Context).
329
330 table_shift_ball(dependency(_Head)).
331 table_shift_ball(dependency(_Skeleton, _Trie, _Mono)).
332 table_shift_ball(call_info(_Skeleton, _Status)).
333 table_shift_ball(call_info(_GenSkeleton, _Skeleton, _Status)).
334
335 %! dwim_predicates(+PI, -Dwims)
336 %
337 % Find related predicate indicators.
338
317339 dwim_predicates(Module:Name/_Arity, Dwims) :-
318340 !,
319341 findall(Dwim, dwim_predicate(Module:Name, Dwim), Dwims).
0 if(INSTALL_DOCUMENTATION OR WARN_NO_DOCUMENTATION)
1
2 # Verify all packages required to build the HTML documentation are
3 # present.
4
5 function(check_doc_dependencies)
6 set(doc_depends pldoc ltx2htm archive)
7 set(missing)
8
9 foreach(pkg ${doc_depends})
10 has_package(${pkg} has_pkg)
11 if(NOT has_pkg)
12 set(missing "${missing} ${pkg}")
13 list(APPEND SWIPL_PACKAGE_LIST ${pkg})
14 endif()
15 endforeach()
16
17 if(missing)
18 set(INSTALL_DOCUMENTATION OFF CACHE BOOL "Install the HTML documentation files" FORCE)
19 set(WARN_NO_DOCUMENTATION ON CACHE BOOL "Re-check documentation" FORCE)
20 message(
21 "WARNING: Dropped building the documentation because the following \
22 packages are missing: ${missing}")
23 else()
24 set(INSTALL_DOCUMENTATION ON CACHE BOOL "Install the HTML documentation files" FORCE)
25 set(WARN_NO_DOCUMENTATION OFF CACHE BOOL "Re-check documentation" FORCE)
26 endif()
27 endfunction()
28
29 check_doc_dependencies()
30
31 endif()
343343 clpr_dual_linsum(Coeff, Name, Coeff*Name).
344344
345345 clpr_constraint_coefficient(c(_, Left, _, _), Coeff) :-
346 maplist(coeff_, Left, Coeff).
346 maplist(all_coeffs, Left, Coeff).
347347
348348 all_coeffs(Coeff*_, Coeff).
349349
8080
8181 %% environ(?Name, ?Value) is nondet.
8282 %
83 % True if Value an atom associated with the environment variable
84 % Name.
85 %
86 % @tbd Mode -Name is not supported
83 % True if Value is an atom associated with the environment variable
84 % or system property Name.
85 %
86 % @tbd Mode -Name is not supported.
87 %
88 % Because SWI-Prolog doesn't have an obvious equivalent to
89 % SICStus system properties, this predicate currently
90 % behaves as if no system properties are defined,
91 % i. e. only environment variables are returned.
92 %
93 % @compat sicstus
8794
8895 environ(Name, Value) :-
8996 getenv(Name, Value).
4343 %% term_variables_bag(+Term, -Variables) is det.
4444 %
4545 % Variables is a list of variables that appear in Term. The
46 % variables are ordered according to depth-first lef-right walking
46 % variables are ordered according to depth-first left-right walking
4747 % of the term. Variables contains no duplicates. This is the same
48 % as SWI-Prolog's term_variables.
48 % as SWI-Prolog's term_variables/2.
4949
5050 term_variables_bag(Term, Variables) :-
5151 term_variables(Term, Variables).
5151 git_show/4, % +Dir, +Hash, -Commit, +Options
5252 git_commit_data/3 % +Field, +Record, -Value
5353 ]).
54 :- use_module(library(record),[record/1,current_record/2, op(_,_,record)]).
54 :- use_module(library(record),[(record)/1,current_record/2, op(_,_,record)]).
5555
5656 :- autoload(library(apply),[maplist/3]).
5757 :- autoload(library(error),[must_be/2,existence_error/2]).
308308 directory(Directory)
309309 ]),
310310 Status == exit(0),
311 string_codes(".\n", Codes).
311 string_codes(GitDir0, Codes),
312 split_string(GitDir0, "", " \n", [GitDir]),
313 sub_string(GitDir, B, _, A, "/.git/modules/"),
314 !,
315 sub_string(GitDir, 0, B, _, Main),
316 sub_string(GitDir, _, A, 0, Below),
317 directory_file_path(Main, Below, Dir),
318 same_file(Dir, Directory).
312319
313320 %! git_describe(-Version, +Options) is semidet.
314321 %
385385 option(right_margin(RM), Options),
386386 Indent + Width < RM % fits on a line, simply write
387387 -> pprint(Term, Ctx, Options)
388 ; Term =.. [Name|Args],
388 ; compound_name_arguments(Term, Name, Args),
389389 format(atom(Buf2), '~q(', [Name]),
390390 write(Out, Buf2),
391391 atom_length(Buf2, FunctorIndent),
438438 ).
439439
440440
441 pp_compound_args([], _, _).
441442 pp_compound_args([H|T], Ctx, Options) :-
442443 pp(H, Ctx, Options),
443444 ( T == []
570570 '$get_predicate_attribute'(Module:Head, defined, 1).
571571 walk_called(ClosureCall, _, _, _) :-
572572 compound(ClosureCall),
573 functor(ClosureCall, Closure, _),
573 compound_name_arity(ClosureCall, Closure, _),
574574 blob(Closure, closure),
575575 !,
576576 '$closure_predicate'(Closure, Module:Name/Arity),
10451045
10461046
10471047 hidden_predicate(Name, _) :-
1048 atom(Name), % []/N is not hidden
10481049 sub_atom(Name, 0, _, _, '$wrap$').
10491050
10501051
17861786 var_or_nonneg(X) :- integer(X), X >= 0, !.
17871787
17881788 pi_to_term(Name/Arity, Term) :-
1789 atom(Name), integer(Arity), Arity >= 0,
1789 (atom(Name)->true;Name==[]), integer(Arity), Arity >= 0,
17901790 !,
17911791 functor(Term, Name, Arity).
17921792 pi_to_term(Name//Arity0, Term) :-
4141 :- autoload(library(apply),[maplist/3]).
4242 :- autoload(library(lists),[append/3,member/2,subtract/3]).
4343 :- autoload(library(make),[make/0]).
44 :- autoload(library(pldoc/man_index), [save_man_index/0]).
4445
4546
4647 /** <module> Installation support predicates
148149 % Create swi('doc/manindex.db') during the build process.
149150
150151 cmake_save_man_index :-
151 use_module(library(pldoc/man_index)),
152152 save_man_index.
153153
154154
512512 safe_primitive(compound(_)).
513513 safe_primitive(callable(_)).
514514 safe_primitive(ground(_)).
515 safe_primitive(system:nonground(_,_)).
515516 safe_primitive(system:cyclic_term(_)).
516517 safe_primitive(acyclic_term(_)).
517518 safe_primitive(system:is_stream(_)).
7777 \secref{metapred} for mode flags to label meta-predicate arguments in
7878 module export declarations.
7979
80 \subsection{Redicate indicators} \label{sec:predicate_indic}
80 \subsection{Predicate indicators} \label{sec:predicate-indic}
8181
8282 \index{predicate indicator}%
8383 Referring to a predicate in running text is done using a
8686 generally omitted if it is irrelevant (case of a built-in predicate) or if it
8787 can be inferred from context.
8888
89 \subsubsection{Non-terminal indicatora} \label{sec:nonterminal_indic}
89 \subsubsection{Non-terminal indicators} \label{sec:nonterminal-indic}
9090
9191 \index{non-terminal indicator}%
9292 Compliant to the ISO standard draft on Definite Clause Grammars (see
791791 constraint symbol.
792792 \end{itemlist}
793793
794 \section{CHR Compiler Errors and Warnings} \label{sec:chr-errors}
794 \section{CHR Compiler Errors and Warnings} \label{sec:chr-warnings-and-errors}
795795 %==================
796796
797797 In this section we summarize the most important error and warning messages
1414
1515 Most implementations of the Prolog language are designed to serve a
1616 limited set of use cases. SWI-Prolog is no exception to this rule.
17 SWI-Prolog positions itself primarily as a Prolog environment for
17 SWI-Prolog positions itself primarily as a Prolog environment for
1818 `programming in the large' and use cases where it plays a central role
1919 in an application, i.e., where it acts as `glue' between components. At
2020 the same time, SWI-Prolog aims at providing a productive rapid
2424 and interfaces to a large number of document formats, protocols and
2525 programming languages. Prototyping is facilitated by good development
2626 tools, both for command line usage and for usage with graphical
27 development tools. Demand loading of predicates from the library and a
27 development tools. Demand loading of predicates from the library and a
2828 `make' facility avoids the \emph{requirement} for using declarations and
2929 reduces typing.
3030
3535 Note that these positions do not imply that the system cannot be used
3636 with other scenarios. SWI-Prolog is used as an embedded language where
3737 it serves as a small rule subsystem in a large application. It is also
38 used as a deductive database. In some cases this is the right choice
38 used as a deductive database. In some cases, this is the right choice
3939 because SWI-Prolog has features that are required in the application,
40 such as threading or Unicode support. In general though, for example,
40 such as threading or Unicode support. In general though, for example:
4141 GNU-Prolog is more suited for embedding because it is small and can
42 compile to native code, XSB is better for deductive databases because it
42 compile to native code; XSB is better for deductive databases because it
4343 provides a mature implementation of \jargon{tabling} including support
4444 for incremental updates and \jargon{Well Founded
4545 Semantics}\footnote{Sponsored by Kyndi and with help from the XSB
4646 developers Theresa Swift and David S. Warren, SWI-Prolog now supports
47 many of the XSB features.}, and ECLiPSe is better at constraint
47 many of the XSB features.}; and ECLiPSe is better at constraint
4848 handling.
4949
5050 The syntax and set of built-in predicates is based on the ISO standard
5353 The infrastructure for constraint programming is based on hProlog
5454 \cite{Demoen:CW350}. Some libraries are copied from the
5555 YAP\footnote{\url{http://www.dcc.fc.up.pt/\~{}vsc/Yap/}} system.
56 Together with YAP we developed a portability framework (see
56 Together with YAP, we developed a portability framework (see
5757 \secref{dialect}). This framework has been filled for SICStus Prolog,
5858 YAP, IF/Prolog and Ciao. SWI-Prolog version~7 introduces various
5959 extensions to the Prolog language (see \secref{extensions}). The
7474 than one million lines of Prolog code.
7575
7676 SWI-Prolog has two development tracks. \emph{Stable} releases have an
77 even \emph{minor} version number (e.g., 6.2.1) and are released as a
77 even \emph{minor} version number (e.g., 6.2.1) and are released as a
7878 branch from the development version when the development
7979 version is considered stable and there is sufficient new functionality
8080 to justify a stable release. Stable releases often get a few patch
102102 Users requiring more support should ensure access to knowledgeable developers.
103103
104104 \item [Performance is your first concern]
105 Various free and commercial systems have better performance. But,
105 Various free and commercial systems have better performance. But,
106106 `standard' Prolog benchmarks disregard many factors that are often
107107 critical to the performance of large applications. SWI-Prolog is not
108108 good at fast calling of simple predicates, but it is fast with dynamic
210210
211211 SWI-Prolog started back in 1986 with the requirement for a Prolog that
212212 could handle recursive interaction with the C-language: Prolog calling C
213 and C calling Prolog recursively. In those days Prolog systems were not
213 and C calling Prolog recursively. In those days, Prolog systems were not
214214 very aware of their environment and we needed such a system to support
215215 interactive applications. Since then, SWI-Prolog's development has been
216 guided by requests from the user community, especially focussing on (in
216 guided by requests from the user community, especially focusing on (in
217217 arbitrary order) interaction with the environment, scalability, (I/O)
218218 performance, standard compliance, teaching and the program development
219219 environment.
5858
5959 \newcommand{\vmajor}{8}
6060 \newcommand{\vminor}{2}
61 \newcommand{\vpatch}{3}
61 \newcommand{\vpatch}{4}
6262 \newcommand{\vtag}{}
63 \newcommand{\vmonth}{November}
64 \newcommand{\vyear}{2020}
63 \newcommand{\vmonth}{January}
64 \newcommand{\vyear}{2021}
6565
6666 #ifdef BOOK
6767 \newcommand{\versionshort}{\vmajor}
13901390 \end{itemize}
13911391
13921392 \prologflagitem{compile_meta_arguments}{atom}{rw}
1393 Experimental flag that controls compilation of arguments passed to
1394 meta-calls marked `0' or `\chr{^}' (see meta_predicate/1). Supported
1395 values are:
1393 This flag controls compilation of arguments passed to meta-calls marked
1394 `0' or `\chr{^}' (see meta_predicate/1). Supported values are:
13961395
13971396 \begin{description}
13981397 \termitem{false}{}
1399 (default). Meta-arguments are passed verbatim.
1398 (default). Meta-arguments are passed verbatim. If the argument is a
1399 control structure ((A,B), (A;B), (A->B;C), etc.) it is compile to an
1400 temporary clause allocated on the environment stack when the
1401 meta-predicate is called.
1402
14001403 \termitem{control}{}
1401 Compile meta-arguments that contain control structures ((A,B), (A;B),
1402 (A->B;C), etc.). If not compiled at compile time, such arguments are
1403 compiled to a temporary clause before execution. Using this option
1404 enhances performance of processing complex meta-goals that are known
1405 at compile time.
1406 \termitem{true}{}
1407 Also compile references to normal user predicates. This harms
1408 performance (a little), but enhances the power of poor-mens consistency
1409 check used by make/0 and implemented by list_undefined/0.
1404 Compile meta-arguments that contain control structures to an auxiliary
1405 predicate. This generally improves performance as well as the debugging
1406 experience.
1407
14101408 \termitem{always}{}
1411 Always create an intermediate clause, even for system predicates. This
1412 prepares for replacing the normal head of the generated predicate with
1413 a special reference (similar to database references as used by, e.g.,
1414 assert/2) that provides direct access to the executable code, thus
1415 avoiding runtime lookup of predicates for meta-calling.
1409 Always create an intermediate clause, even for system
1410 predicates.\footnote{This may be used in the future for
1411 replacing the normal head of the generated predicate with a special
1412 reference (similar to database references as used by, e.g., assert/2)
1413 that provides direct access to the executable code, thus avoiding
1414 runtime lookup of predicates for meta-calling.}
14161415 \end{description}
14171416
14181417 \prologflagitem{compiled_at}{atom}{r}
34063405
34073406 \begin{table}
34083407 \begin{center}
3409 \begin{tabular}{|c|l|p{5cm}|}
3408 \begin{tabular}{|l|p{5cm}|}
34103409 \hline
3411 Option & Area name & Description \\
3410 Area name & Description \\
34123411 \hline
3413 \cmdlineoption{-L} & \bf local stack & The local stack is used to store
3412 \bf local stack & The local stack is used to store
34143413 the execution environments of procedure
34153414 invocations. The space for an environment is
34163415 reclaimed when it fails, exits without leaving
34183417 the !/0 predicate or no choice points have
34193418 been created since the invocation and the last
34203419 subclause is started (last call optimisation). \\
3421 \cmdlineoption{-G} & \bf global stack & The global stack is used
3420 \bf global stack & The global stack is used
34223421 to store terms created during Prolog's
34233422 execution. Terms on this stack will be reclaimed
34243423 by backtracking to a point before the term
34253424 was created or by garbage collection (provided the
34263425 term is no longer referenced). \\
3427 \cmdlineoption{-T} & \bf trail stack & The trail stack is used to store
3426 \bf trail stack & The trail stack is used to store
34283427 assignments during execution. Entries on this
34293428 stack remain alive until backtracking before the
34303429 point of creation or the garbage collector
22 Author: Jan Wielemaker
33 E-mail: J.Wielemaker@vu.nl
44 WWW: http://www.swi-prolog.org
5 Copyright (c) 2000-2020, University of Amsterdam
5 Copyright (c) 2000-2021, University of Amsterdam
66 VU University Amsterdam
77 CWI, Amsterdam
8 SWI-Prolog Solutions b.v.
89 All rights reserved.
910
1011 Redistribution and use in source and binary forms, with or without
9091 static atom_t ATOM_timeout;
9192 static atom_t ATOM_release;
9293 static atom_t ATOM_infinite;
94 static atom_t ATOM_text;
95 static atom_t ATOM_binary;
96 static atom_t ATOM_octet;
97 static atom_t ATOM_utf8;
98 static atom_t ATOM_ascii;
99 static atom_t ATOM_iso_latin_1;
100 static atom_t ATOM_unicode_be;
101 static atom_t ATOM_unicode_le;
102
93103 static functor_t FUNCTOR_error2;
94104 static functor_t FUNCTOR_process_error2;
95105 static functor_t FUNCTOR_system_error2;
96106 static functor_t FUNCTOR_pipe1;
107 static functor_t FUNCTOR_pipe2;
97108 static functor_t FUNCTOR_stream1;
98109 static functor_t FUNCTOR_exit1;
99110 static functor_t FUNCTOR_killed1;
100111 static functor_t FUNCTOR_eq2; /* =/2 */
112 static functor_t FUNCTOR_type1;
113 static functor_t FUNCTOR_encoding1;
101114
102115 #define MAYBE 2
103116
149162 typedef struct p_stream
150163 { term_t term; /* P in pipe(P) */
151164 std_type type; /* type of stream */
165 IOENC encoding; /* Encoding for the stream */
152166 #ifdef __WINDOWS__
153167 HANDLE fd[2]; /* pipe handles */
154168 #else
279293
280294 #ifndef __WINDOWS__
281295 static int
282 already_in_env(const char *env, const char *e)
283 { for(; *env; env += strlen(env)+1)
296 already_in_env(const char *env, int count, const char *e)
297 { for(; count-- > 0; env += strlen(env)+1)
284298 { const char *s, *q;
285299
286300 for(s=env, q=e; *s && *q && *s == *q && *s != '=' && *q != '='; s++,q++)
332346 if ( !PL_get_nil_ex(tail) )
333347 return FALSE;
334348
349 if ( pass && count == 0 )
350 return TRUE; /* environment([]) is a no-op */
351
335352 #ifndef __WINDOWS__
336353 if ( pass )
337354 {
341358 extern char **environ;
342359 #endif
343360 char **e;
361 int count0 = count;
344362
345363 for(e=environ; e && *e; e++)
346 { if ( !already_in_env(eb->buffer, *e) )
364 { if ( !already_in_env(eb->buffer, count0, *e) )
347365 { add_ecbuf(eb, *e, strlen(*e));
348366 add_ecbuf(eb, ECHARS("\0"), 1);
349367 count++;
366384 #endif
367385
368386 return TRUE;
387 }
388
389
390 static int
391 get_type(term_t head, IOENC *enc)
392 { atom_t a;
393
394 if ( PL_get_atom_ex(head, &a) )
395 { if ( a == ATOM_text )
396 *enc = ENC_ANSI;
397 else if ( a == ATOM_binary )
398 *enc = ENC_OCTET;
399 else
400 return PL_domain_error("stream_type", head);
401
402 return TRUE;
403 }
404
405 return FALSE;
406 }
407
408 /* TBD: provide a public API for translating encoding names to
409 * the IOENC enum
410 */
411
412 static int
413 get_encoding(term_t head, IOENC *enc)
414 { atom_t a;
415
416 if ( PL_get_atom_ex(head, &a) )
417 { if ( a == ATOM_octet )
418 *enc = ENC_OCTET;
419 else if ( a == ATOM_ascii )
420 *enc = ENC_ASCII;
421 else if ( a == ATOM_iso_latin_1 )
422 *enc = ENC_ISO_LATIN_1;
423 else if ( a == ATOM_text )
424 *enc = ENC_ANSI;
425 else if ( a == ATOM_utf8 )
426 *enc = ENC_UTF8;
427 else if ( a == ATOM_unicode_be )
428 *enc = ENC_UNICODE_BE;
429 else if ( a == ATOM_unicode_le )
430 *enc = ENC_UNICODE_LE;
431 else
432 return PL_domain_error("encoding", head);
433
434 return TRUE;
435 }
436
437 return FALSE;
369438 }
370439
371440
383452 } else
384453 { return PL_domain_error("process_stream", t);
385454 }
386 } else if ( PL_is_functor(t, FUNCTOR_pipe1) )
455 } else if ( PL_is_functor(t, FUNCTOR_pipe1) ||
456 PL_is_functor(t, FUNCTOR_pipe2) )
387457 { stream->term = PL_new_term_ref();
458 stream->encoding = ENC_ANSI;
388459 _PL_get_arg(1, t, stream->term);
389460 if ( !PL_is_variable(stream->term) )
390461 { for (i = 0; i < info->pipes; i++)
393464 }
394465 if (i == info->pipes)
395466 return PL_uninstantiation_error(stream->term);
467 }
468 if ( PL_is_functor(t, FUNCTOR_pipe2) )
469 { term_t tail = PL_new_term_ref();
470 term_t head = PL_new_term_ref();
471
472 _PL_get_arg(2, t, tail);
473 while(PL_get_list_ex(tail, head, tail))
474 { if ( PL_is_functor(head, FUNCTOR_type1) )
475 { _PL_get_arg(1, head, head);
476 if ( !get_type(head, &stream->encoding) )
477 return FALSE;
478 } else if ( PL_is_functor(head, FUNCTOR_encoding1) )
479 { _PL_get_arg(1, head, head);
480 if ( !get_encoding(head, &stream->encoding) )
481 return FALSE;
482 } else
483 return PL_domain_error("pipe_option", head);
484 }
485 if ( !PL_get_nil_ex(tail) )
486 return FALSE;
396487 }
397488 stream->type = std_pipe;
398489 info->pipes++;
681772
682773
683774 static IOSTREAM *
775 open_process_pipe(process_context *pc, p_options *info, int which, int fdn)
776 { void *handle;
684777 #ifdef __WINDOWS__
685 open_process_pipe(process_context *pc, int which, HANDLE fd)
778 HANDLE fd = info->streams[which].fd[fdn];
686779 #else
687 open_process_pipe(process_context *pc, int which, int fd)
688 #endif
689 { void *handle;
690 int flags;
780 int fd = info->streams[which].fd[fdn];
781 #endif
782 int flags = SIO_RECORDPOS|SIO_FBUF;
783 IOSTREAM *s;
691784
692785 pc->open_mask |= (1<<which);
693786 #ifdef __WINDOWS__
696789 pc->pipes[which] = fd;
697790 #endif
698791
699 #define ISO_FLAGS (SIO_RECORDPOS|SIO_FBUF|SIO_TEXT)
792 if ( info->streams[which].encoding != ENC_OCTET )
793 flags |= SIO_TEXT;
700794
701795 if ( which == 0 )
702 flags = SIO_OUTPUT|ISO_FLAGS;
796 flags |= SIO_OUTPUT;
703797 else
704 flags = SIO_INPUT|ISO_FLAGS;
798 flags |= SIO_INPUT;
705799
706800 handle = (void *)((uintptr_t)pc | (uintptr_t)which);
707801
708 return Snew(handle, flags, &Sprocessfunctions);
802 if ( (s=Snew(handle, flags, &Sprocessfunctions)) )
803 s->encoding = info->streams[which].encoding;
804
805 return s;
709806 }
710807
711808
12361333
12371334 if ( info->streams[0].type == std_pipe )
12381335 { CloseHandle(info->streams[0].fd[0]);
1239 if ( (s = open_process_pipe(pc, 0, info->streams[0].fd[1])) )
1336 if ( (s = open_process_pipe(pc, info, 0, 1)) )
12401337 rc = PL_unify_stream(info->streams[0].term, s);
12411338 else
12421339 CloseHandle(info->streams[0].fd[1]);
12431340 }
12441341 if ( info->streams[1].type == std_pipe )
12451342 { CloseHandle(info->streams[1].fd[1]);
1246 if ( rc && (s = open_process_pipe(pc, 1, info->streams[1].fd[0])) )
1343 if ( rc && (s = open_process_pipe(pc, info, 1, 0)) )
12471344 PL_unify_stream(info->streams[1].term, s);
12481345 else
12491346 CloseHandle(info->streams[1].fd[0]);
12511348 if ( info->streams[2].type == std_pipe &&
12521349 ( !info->streams[1].term || PL_compare(info->streams[1].term, info->streams[2].term) != 0 ) )
12531350 { CloseHandle(info->streams[2].fd[1]);
1254 if ( rc && (s = open_process_pipe(pc, 2, info->streams[2].fd[0])) )
1351 if ( rc && (s = open_process_pipe(pc, info, 2, 0)) )
12551352 rc = PL_unify_stream(info->streams[2].term, s);
12561353 else
12571354 CloseHandle(info->streams[2].fd[0]);
15551652 return rc;
15561653 }
15571654
1655 static IOSTREAM *
1656 p_fdopen(p_options *info, int which, int fdn, char *mode)
1657 { IOSTREAM *s;
1658 char m[10];
1659 char *mp = m;
1660
1661 *mp++ = mode[0];
1662 if ( info->streams[which].encoding == ENC_OCTET )
1663 *mp++ = 'b';
1664 *mp = 0;
1665
1666 if ( (s=Sfdopen(info->streams[which].fd[fdn], m)) )
1667 s->encoding = info->streams[which].encoding;
1668
1669 return s;
1670 }
1671
15581672
15591673 static int
15601674 process_parent_side(p_options *info, int pid)
15731687
15741688 if ( info->streams[0].type == std_pipe )
15751689 { close_ok(info->streams[0].fd[0]);
1576 if ( (s = open_process_pipe(pc, 0, info->streams[0].fd[1])) )
1690 if ( (s = open_process_pipe(pc, info, 0, 1)) )
15771691 rc = PL_unify_stream(info->streams[0].term, s);
15781692 else
15791693 close_ok(info->streams[0].fd[1]);
15801694 }
15811695 if ( info->streams[1].type == std_pipe )
15821696 { close_ok(info->streams[1].fd[1]);
1583 if ( rc && (s = open_process_pipe(pc, 1, info->streams[1].fd[0])) )
1697 if ( rc && (s = open_process_pipe(pc, info, 1, 0)) )
15841698 rc = PL_unify_stream(info->streams[1].term, s);
15851699 else
15861700 close_ok(info->streams[1].fd[0]);
15881702 if ( info->streams[2].type == std_pipe &&
15891703 ( !info->streams[1].term || PL_compare(info->streams[1].term, info->streams[2].term) != 0 ) )
15901704 { close_ok(info->streams[2].fd[1]);
1591 if ( rc && (s = open_process_pipe(pc, 2, info->streams[2].fd[0])) )
1705 if ( rc && (s = open_process_pipe(pc, info, 2, 0)) )
15921706 rc = PL_unify_stream(info->streams[2].term, s);
15931707 else
15941708 close_ok(info->streams[2].fd[0]);
16001714
16011715 if ( info->streams[0].type == std_pipe )
16021716 { close_ok(info->streams[0].fd[0]);
1603 if ( (s = Sfdopen(info->streams[0].fd[1], "w")) )
1717 if ( (s = p_fdopen(info, 0, 1, "w")) )
16041718 rc = PL_unify_stream(info->streams[0].term, s);
16051719 else
16061720 close_ok(info->streams[0].fd[1]);
16071721 }
16081722 if ( info->streams[1].type == std_pipe )
16091723 { close_ok(info->streams[1].fd[1]);
1610 if ( rc && (s = Sfdopen(info->streams[1].fd[0], "r")) )
1724 if ( rc && (s = p_fdopen(info, 1, 0, "r")) )
16111725 rc = PL_unify_stream(info->streams[1].term, s);
16121726 else
16131727 close_ok(info->streams[1].fd[0]);
16151729 if ( info->streams[2].type == std_pipe &&
16161730 ( !info->streams[1].term || PL_compare(info->streams[1].term, info->streams[2].term) != 0 ) )
16171731 { close_ok(info->streams[2].fd[1]);
1618 if ( rc && (s = Sfdopen(info->streams[2].fd[0], "r")) )
1732 if ( rc && (s = p_fdopen(info, 2, 0, "r")) )
16191733 PL_unify_stream(info->streams[2].term, s);
16201734 else
16211735 close_ok(info->streams[2].fd[0]);
21412255 MKATOM(timeout);
21422256 MKATOM(release);
21432257 MKATOM(infinite);
2258 MKATOM(text);
2259 MKATOM(binary);
2260 MKATOM(octet);
2261 MKATOM(utf8);
2262 MKATOM(ascii);
2263 MKATOM(iso_latin_1);
2264 MKATOM(unicode_be);
2265 MKATOM(unicode_le);
21442266
21452267 MKFUNCTOR(pipe, 1);
2268 MKFUNCTOR(pipe, 2);
2269 MKFUNCTOR(type, 1);
2270 MKFUNCTOR(encoding, 1);
21462271 MKFUNCTOR(stream, 1);
21472272 MKFUNCTOR(error, 2);
21482273 MKFUNCTOR(process_error, 2);
9494 distinction. This implies that is_process/1 is incomplete and
9595 unreliable.
9696
97 * SICStus only supports ISO 8859-1 (latin-1). This implementation
98 supports arbitrary OS multibyte interaction using the default
99 locale.
100
10197 * It is unclear what the detached(true) option is supposed to do. Disable
10298 signals in the child? Use setsid() to detach from the session? The
10399 current implementation uses setsid() on Unix systems.
135131 % Bind the standard streams of the new process. Spec is one of
136132 % the terms below. If pipe(Pipe) is used, the Prolog stream is
137133 % a stream in text-mode using the encoding of the default
138 % locale. The encoding can be changed using set_stream/2.
134 % locale. The encoding can be changed using set_stream/2,
135 % or by using the two-argument form of =pipe=, which accepts an
136 % encoding(Encoding) option.
139137 % The options =stdout= and =stderr= may use the same stream,
140138 % in which case both output streams are connected to the same
141139 % Prolog stream.
149147 % Bind to a _null_ stream. Reading from such a stream
150148 % returns end-of-file, writing produces no output
151149 % * pipe(-Stream)
150 % * pipe(-Stream, +StreamOptions)
152151 % Attach input and/or output to a Prolog stream.
152 % The optional StreamOptions argument is a list of options
153 % that affect the stream. Currently only the options
154 % type(+Type) and encoding(+Encoding) are supported,
155 % which have the same meaning as the stream properties
156 % of the same name (see stream_property/2).
157 % StreamOptions is provided mainly for SICStus compatibility -
158 % the SWI-Prolog predicate set_stream/2 can be used
159 % for the same purpose.
153160 % * stream(+Stream)
154161 % Attach input or output to an existing Prolog stream.
155162 % This stream must be associated with an OS file
478478 status_has_content(created(_Location)).
479479 status_has_content(moved(_To)).
480480 status_has_content(moved_temporary(_To)).
481 status_has_content(gone(_URL)).
481482 status_has_content(see_other(_To)).
482483 status_has_content(bad_request(_ErrorTerm)).
483484 status_has_content(authorise(_Method)).
584585 [ h1('Moved Temporary'),
585586 p(['The document is currently ',
586587 a(href(To), ' Here')
588 ]),
589 \address
590 ]),
591 HTML).
592 status_page_hook(gone(URL), html_tokens(HTML), _Options) :-
593 phrase(page([ title('410 Resource Gone')
594 ],
595 [ h1('Resource Gone'),
596 p(['The document has been removed ',
597 a(href(URL), ' from here')
587598 ]),
588599 \address
589600 ]),
13151326 [ location(To) ]).
13161327 status_reply_headers(moved_temporary(To, Body), Body,
13171328 [ location(To) ]).
1329 status_reply_headers(gone(_URL, Body), Body, []).
13181330 status_reply_headers(see_other(To, Body), Body,
13191331 [ location(To) ]).
13201332 status_reply_headers(authorise(Method, Body), Body,
24362448 { atom_codes(Value, Chars)
24372449 }.
24382450
2451 chars_to_semicolon_or_blank([]), ";" -->
2452 ";",
2453 !.
2454 chars_to_semicolon_or_blank([]) -->
2455 " ",
2456 blanks,
2457 eos,
2458 !.
24392459 chars_to_semicolon_or_blank([H|T]) -->
24402460 [H],
2441 { H \== 32, H \== 0'; },
24422461 !,
24432462 chars_to_semicolon_or_blank(T).
24442463 chars_to_semicolon_or_blank([]) -->
638638 ; domain_error(method, M)
639639 ).
640640
641 %! map_method(+MethodID, -Method)
642 %
643 % Support additional ``METHOD`` keywords. Default are the official
644 % HTTP methods as defined by the various RFCs.
645
646 :- multifile
647 map_method/2.
648
641649 map_method(delete, 'DELETE').
642650 map_method(get, 'GET').
643651 map_method(head, 'HEAD').
8383 a websocket inside the HTTP server infrastructure and
8484 http_open_websocket/3 as a layer over http_open/3 to realise a client
8585 connection. After establishing a connection, ws_send/2 and ws_receive/2
86 can be used to send and receive messages. The predicate ws_close/2 is
86 can be used to send and receive messages. The predicate ws_close/3 is
8787 provided to perform the closing handshake and dispose of the stream
8888 objects.
8989
2828 if(PROG_JAVA_HOME)
2929 message("-- Find Java home using ${PROG_JAVA_HOME}")
3030
31 if(CMAKE_SIZEOF_VOID_P EQUAL 8)
32 set(jdatamodel -d64)
33 else()
34 set(jdatamodel -d32)
31 if(NOT APPLE)
32 if(CMAKE_SIZEOF_VOID_P EQUAL 8)
33 set(jdatamodel -d64)
34 else()
35 set(jdatamodel -d32)
36 endif()
3537 endif()
3638
3739 exec_program(${PROG_JAVA_HOME} ARGS ${jdatamodel}
3840 OUTPUT_VARIABLE jhome
41 OUTPUT_STRIP_TRAILING_WHITESPACE
3942 RETURN_VALUE jhome_ret)
4043 if(jhome_ret EQUAL 0)
4144 set(JAVA_HOME ${jhome} CACHE FILEPATH "Home of Java")
22 Author: Jan Wielemaker
33 E-mail: J.Wielemaker@vu.nl
44 WWW: http://www.swi-prolog.org
5 Copyright (c) 2002-2018, University of Amsterdam,
5 Copyright (c) 2002-2020, University of Amsterdam,
66 VU University Amsterdam
77 All rights reserved.
88
5656 #include <sqlext.h>
5757 #include <time.h>
5858 #include <limits.h> /* LONG_MAX, etc. */
59 #include <math.h>
5960
6061 #ifndef HAVE_SQLLEN
6162 #define SQLLEN DWORD
34203421
34213422 return TRUE;
34223423 #if defined(HAVE_LOCALTIME) || defined(HAVE_GMTIME)
3423 } else if ( PL_get_float(t, &tf) && tf <= LONG_MAX && tf >= LONG_MIN )
3424 } else if ( PL_get_float(t, &tf) )
34243425 { time_t t = (time_t)tf;
34253426 long ns = (long)((tf - (double)t) * 1000000000.0);
34263427 #if defined(HAVE_GMTIME) && defined USE_UTC
34283429 #else
34293430 struct tm *tm = localtime(&t);
34303431 #endif
3432
3433 if ( fabs(tf - (double)t) > 1.0 )
3434 return FALSE; /* out of range */
34313435
34323436 stamp->year = tm->tm_year + 1900;
34333437 stamp->month = tm->tm_mon + 1;
4242 print_html_head/1, % +Stream
4343 predref//1, % +PI //
4444 predref//2, % +PI, Options //
45 nopredref//1, % +PI //
4546 module_info/3, % +File, +Options0, -Options
4647 doc_hide_private/3, % +Doc0, -Doc, +Options
4748 edit_button//2, % +File, +Options, //
7071 tags//1, % +Tags, //
7172 term//3, % +Text, +Term, +Bindings, //
7273 file_header//2, % +File, +Options, //
74 flagref//1, % +Flag
7375 objects//2, % +Objects, +Options, //
7476 object_ref//2, % +Object, +Options, //
7577 object_name//2, % +Object, +Object
7880 object_page//2, % +Object, +Options, //
7981 object_page_header//2, % +File, +Options, //
8082 object_synopsis//2, % +Object, +Options, //
81 object_page_footer//2 % +Object, +Options, //
83 object_footer//2, % +Object, +Options, //
84 object_page_footer//2, % +Object, +Options, //
85 cite//1 % +Citations
8286 ]).
8387 :- use_module(library(lists)).
8488 :- use_module(library(option)).
10191023 html([ div(a(href(location_by_id(pldoc_doc)+File), File))
10201024 ]).
10211025
1026 %! object_footer(+Obj, +Options)// is det.
1027 %
1028 % Call the hook prolog:doc_object_footer//2. This hook will be used to
1029 % deal with examples.
1030
1031 object_footer(Obj, Options) -->
1032 prolog:doc_object_footer(Obj, Options),
1033 !.
1034 object_footer(_, _) --> [].
1035
1036
10221037 %! object_page_footer(+Obj, +Options)// is det.
10231038 %
10241039 % Call the hook prolog:doc_object_page_footer//2. This hook will
10251040 % be used to deal with annotations.
10261041
10271042 object_page_footer(Obj, Options) -->
1028 prolog:doc_object_page_footer(Obj, Options).
1043 prolog:doc_object_page_footer(Obj, Options),
1044 !.
10291045 object_page_footer(_, _) --> [].
10301046
10311047
112112 blocked('/swipl-lfr.pl').
113113 blocked('/dcg_basics.pl'). % deprecated file
114114 blocked('/readline.pl'). % conflicts with editline.pl
115 blocked('/win_menu.pl'). % Leads to warnings without a console.
22 Author: Jan Wielemaker
33 E-mail: J.Wielemaker@vu.nl
44 WWW: http://www.swi-prolog.org
5 Copyright (c) 2006-2018, University of Amsterdam
5 Copyright (c) 2006-2020, University of Amsterdam
66 VU University Amsterdam
77 CWI, Amsterdam
88 All rights reserved.
4545
4646 :- autoload(doc_html,
4747 [ object_tree/5, private/2, object_page_header/4, objects/4,
48 object_href/2, object_synopsis/4, object_page_footer/4,
48 object_href/2, object_synopsis/4, object_footer/4,
49 object_page_footer/4,
4950 object_ref/4, object_page/4,
5051 object_source_button//2
5152 ]).
5354 :- autoload(doc_search,[search_form/3]).
5455 :- autoload(doc_util,[atom_to_object/2,atom_pi/2]).
5556 :- autoload(man_index,[manual_object/5]).
56 :- autoload(library(apply),[maplist/2,maplist/3]).
57 :- autoload(library(apply),[maplist/2,maplist/3,convlist/3]).
5758 :- autoload(library(debug),[assertion/1,debug/3]).
5859 :- autoload(library(error),[permission_error/3,existence_error/2]).
5960 :- autoload(library(filesex),
752753 man_match(root, root, _) -->
753754 !,
754755 man_overview([]).
755 man_match((Parent+Path)-(Obj+[element(dt,A,C0)|DD]), Obj, Options) -->
756 man_match((Parent+Path)-(Obj+DOM), Obj, Options) -->
756757 { \+ option(synopsis(false), Options),
758 DOM = [element(dt,A,C0)|DD],
759 convlist(dt_obj, DOM, Objs),
757760 option(link_source(Link), Options, true),
758761 man_qualified_object(Obj, Parent, LibOpt, QObj, Section),
759762 !,
765768 dom_list([ element(dt,[],[\man_synopsis(QObj, Section, LibOpt)]),
766769 element(dt,A,C)
767770 | DD
768 ], Path, Options).
771 ], Path, Options),
772 object_footer(Objs, Options).
769773 man_match((_Parent+Path)-(Obj+DOM), Obj, Options) -->
770774 dom_list(DOM, Path, Options).
771775
776 dt_obj(element(dt,_,C), Obj) :-
777 xpath(C, //a(@id=Atom), _),
778 atom_to_object(Atom, Obj).
772779
773780 :- html_meta
774781 dom_list(html, +, +, ?, ?).
4444 prolog:doc_search_field//1, % +Options
4545 prolog:doc_places_menu//1, % +Dir
4646 prolog:doc_directory/1, % ?Dir
47 prolog:doc_object_footer//2, % +Object, +Options
4748 prolog:doc_object_page_footer//2, % +Object, +Options
4849 prolog:doc_page_header//2, % +File, +Options
4950 prolog:doc_links//2, % +Directory, +Options
3737
3838 Version~2 of PlDoc extends the syntax with
3939 \href{http://en.wikipedia.org/wiki/Markdown}{Markdown} markup as
40 specified by \href{http://www.stack.nl/~dimitri/doxygen/}{Docygen}.
40 specified by \href{http://www.stack.nl/~dimitri/doxygen/}{Doxygen}.
4141 Based on experience with version~1, PlDoc~2 both tightens some rules
4242 to avoid misinterpretations and relaxes others that were considered
4343 too conservative.
10701070 that is widely accepted and not tied to a single system. In PlDoc~2,
10711071 we have adopted markdown, including many of the limitations and
10721072 extensions introduced by
1073 \href{http://www.stack.nl/~dimitri/doxygen/}{Docygen}. Limitations are
1073 \href{http://www.stack.nl/~dimitri/doxygen/}{Doxygen}. Limitations are
10741074 needed to avoid ambiguities due to the common use of symbol charaters
10751075 in programming languages. Extensions are desirable to make use of
10761076 already existing conventions and to support requirements of program
43994399
44004400 if ( keep_gen == db->gc.last_gen )
44014401 { garbage -= db->gc.uncollectable;
4402 assert((int64_t)garbage >= 0);
4402 if ( (int64_t)garbage < 0 )
4403 garbage = 0;
44034404 }
44044405
44054406 return PL_unify_term(info,
628628 test('Certificate is not issued by trusted CA'):-
629629 do_verification_test(14, try_ssl_client('www.example.com', test_verify_hook), VerificationResults, Status),
630630 ( VerificationResults:Status == [unknown_issuer]:true ->
631 % OpenSSL 1.0.2 and above
631 % OpenSSL 1.0.2 - 1.1.1h
632632 true
633633 ; VerificationResults:Status == [unknown_issuer, not_trusted]:true ->
634634 % OpenSSL 1.0.1 and below
635 true
636 ; VerificationResults:Status == [unknown_issuer, verified]:true ->
637 % OpenSSL 1.1.1i and above
635638 true
636639 ).
637640
3535 tipc_paxos_get/2, % ?Term, +Options
3636 tipc_paxos_set/1, % ?Term
3737 tipc_paxos_set/2, % ?Term, +Options
38 tipc_paxos_replicate/1, % ?Term
3938 tipc_paxos_on_change/2, % ?Term, +Goal
4039 tipc_initialize/0
4140 ]).
5756 %! tipc_paxos_get(?Term) is semidet.
5857 %! tipc_paxos_get(?Term, +Options) is semidet.
5958 %! tipc_paxos_set(?Term, +Options) is semidet.
60 %! tipc_paxos_replicate(?Term) is det.
6159 %! tipc_paxos_on_change(?Term, :Goal) is det.
6260
6361 tipc_paxos_set(Term) :- paxos_set(Term, []).
6462 tipc_paxos_set(Term, Options) :- paxos_set(Term, Options).
6563 tipc_paxos_get(Term) :- paxos_get(Term, []).
6664 tipc_paxos_get(Term, Options) :- paxos_get(Term, Options).
67 tipc_paxos_replicate(X) :- paxos_replicate(X).
6865 tipc_paxos_on_change(Term, Goal) :- paxos_on_change(Term, Goal).
6966
7067 :- multifile
199199 default_emacs_mode('.*\\.yaml~?$', yaml).
200200 default_emacs_mode('.*\\.cmake~?$|CMakeLists.txt', cmake).
201201 default_emacs_mode('.*\\.txt~?$', text).
202 default_emacs_mode('.*\\.md~?$', text).
203 default_emacs_mode('.*\\.eml~?$', text).
202204 default_emacs_mode('[Cc]ompose|README|\\.article', text).
203205 default_emacs_mode(Pattern, prolog) :-
204206 user:prolog_file_type(Ext, prolog),
00 /* Part of XPCE --- The SWI-Prolog GUI toolkit
11
22 Author: Jan Wielemaker and Anjo Anjewierden
3 E-mail: jan@swi.psy.uva.nl
4 WWW: http://www.swi.psy.uva.nl/projects/xpce/
5 Copyright (c) 1985-2002, University of Amsterdam
3 E-mail: jan@swi-prolog.org
4 WWW: https://www.swi-prolog.org
5 Copyright (c) 1985-2020, University of Amsterdam
6 SWI-Prolog Solutions b.v.
67 All rights reserved.
78
89 Redistribution and use in source and binary forms, with or without
3435 :- module(emacs_text_mode, []).
3536 :- use_module(library(pce)).
3637
37 :- emacs_begin_mode(text, fundamental,
38 "Edit plain text (sets fillmode",
38 :- emacs_begin_mode(text, language,
39 "Edit plain text (sets fillmode)",
3940 [],
40 []).
41 [ '"' = string_quote('\\'),
42 '''' = string_quote('\\'),
43 '>' = comment_start, % use comment-region for quoting
44 '\n' + comment_end
45 ]).
4146
4247 setup_mode(E) :->
4348 "Switch editor into fill-mode"::
8484 ]) :-
8585 xsb_module_file(Module, File),
8686 xsb_imports(Preds, File, Imports).
87 prolog_colour:goal_colours(dynamic(_Preds as Options),
88 xsb-[ keyword(as)-[ predicates,
89 OptColours
90 ]
91 ]) :-
92 dyn_option_colours(Options, OptColours).
9387
9488 xsb_module_file(usermod, module(user)) :-
9589 !.
123117 xsb_imports(A, From, CA),
124118 xsb_imports(B, From, CB).
125119 xsb_imports(_, file(Path), import(Path)).
126
127 dyn_option_colours(Var, error(instantiation_error)) :-
128 var(Var),
129 !.
130 dyn_option_colours((A,B), functor-[CA, CB]) :-
131 dyn_option_colours(A, CA),
132 dyn_option_colours(B, CB).
133 dyn_option_colours(Opt, identifier) :-
134 valid_dyn_option(Opt),
135 !.
136 dyn_option_colours(_Opt, error(type_error(xsb_dynamic_option))).
137
138 valid_dyn_option(incremental).
139 valid_dyn_option(abstract(_)).
140120
141121 prolog_colour:style(goal(xsb, _), [colour(blue), underline(true)]).
142122
22 Author: Jan Wielemaker and Anjo Anjewierden
33 E-mail: wielemak@science.uva.nl
44 WWW: http://www.swi-prolog.org/packages/xpce/
5 Copyright (c) 2006-2015, University of Amsterdam
5 Copyright (c) 2006-2020, University of Amsterdam
6 SWI-Prolog Solutions b.v.
67 All rights reserved.
78
89 Redistribution and use in source and binary forms, with or without
6970 format_time/3,
7071 maplist/3,
7172 strip_module/3,
72 xref_called/4
73 xref_called/4,
74 head_name_arity/3
7375 ]).
7476
7577 gxref_version('0.1.1').
19191921 predicate_indicator(Goal, Name/Arity) :-
19201922 callable(Goal),
19211923 !,
1922 functor(Goal, Name, Arity).
1924 head_name_arity(Goal, Name, Arity).
19231925 predicate_indicator(Goal, Goal).
19241926
19251927 hidden_module(user) :- !.
21042106 ).
21052107
21062108 generated_callable(M:Term) :-
2107 functor(Term, Name, Arity),
2109 head_name_arity(Term, Name, Arity),
21082110 prolog:generated_predicate(M:Name/Arity).
21092111
21102112 %! xref_called(?Source, ?Callable) is nondet.
136136
137137
138138 status
139 ws_legal_display_name(char *s)
139 ws_legal_display_name(const char *s)
140140 { succeed;
141141 }
142142
562562
563563 if ( ca )
564564 { PceString s = &ca->data;
565 HGLOBAL mem = ws_string_to_global_mem(s);
565 HGLOBAL mem = ws_string_to_global_mem(s);
566566
567567 if ( mem )
568568 SetClipboardData(CF_UNICODETEXT, mem);
2727 COMMON(void) ws_activate_screen_saver(DisplayObj d);
2828 COMMON(void) ws_deactivate_screen_saver(DisplayObj d);
2929 COMMON(void) ws_init_display(DisplayObj d);
30 COMMON(status) ws_legal_display_name(char *s);
30 COMMON(status) ws_legal_display_name(const char *s);
3131 COMMON(status) ws_opened_display(DisplayObj d);
3232 COMMON(void) ws_open_display(DisplayObj d);
3333 COMMON(void) ws_quit_display(DisplayObj d);
00 /* Part of XPCE --- The SWI-Prolog GUI toolkit
11
22 Author: Jan Wielemaker and Anjo Anjewierden
3 E-mail: jan@swi.psy.uva.nl
3 E-mail: jan@swi-prolog.org
44 WWW: http://www.swi.psy.uva.nl/projects/xpce/
5 Copyright (c) 1985-2002, University of Amsterdam
5 Copyright (c) 1985-2020, University of Amsterdam
6 SWI-Prolog Solutions b.v.
67 All rights reserved.
78
89 Redistribution and use in source and binary forms, with or without
176177 }
177178
178179
180 const char *
181 skipint(const char *s)
182 { const char *s0 = s;
183
184 while ( *s && isdigit(*s) )
185 s++;
186
187 return s > s0 ? s : NULL;
188 }
189
179190 status
180 ws_legal_display_name(char *s)
181 { char host[LINESIZE];
182 int display, screen;
183
184 if ( sscanf(s, "%[a-zA-Z0-9.]:%d.%d", host, &display, &screen) >= 2 )
185 succeed;
186
187 fail;
191 ws_legal_display_name(const char *s)
192 { while( *s && (isalnum(*s) || *s == '.') )
193 s++;
194 if ( *s != ':' )
195 fail;
196 s++;
197 if ( !(s = skipint(s)) )
198 fail;
199 if ( *s == '.' )
200 { s++;
201 if ( !(s = skipint(s)) )
202 fail;
203 }
204
205 return *s == '\0';
188206 }
189207
190208
228246 char *theaddress = XDisplayName(address);
229247
230248 if ( isDefault(d->address) && !getenv("DISPLAY") )
231 sprintf(problem, "no DISPLAY environment variable");
249 strcpy(problem, "no DISPLAY environment variable");
232250 else if ( !ws_legal_display_name(theaddress) )
233 sprintf(problem, "malformed address: %s", theaddress);
251 snprintf(problem, sizeof(problem), "malformed DISPLAY address: %s",
252 theaddress);
234253 else
235254 strcpy(problem, "No permission to contact X-server?");
236255
1111 ## Publishing
1212
1313 snapcraft login (Ubuntu one credentials)
14 snapcraft push swi-prolog_<version>.snap
14 snapcraft upload swi-prolog_<version>.snap
1515 snapcraft list-revisions swi-prolog
16 snapcraft release swi-prolog 1 beta,edge
16
17 snapcraft release swi-prolog 1 edge
18 OR
19 snapcraft release swi-prolog 1 stable,candidate,beta
1720
1821 Channels is a list of `stable`, `candidate`, `beta` or `edge`
1922
6767 /* PLVERSION_TAG: a string, normally "", but for example "rc1" */
6868
6969 #ifndef PLVERSION
70 #define PLVERSION 80203
70 #define PLVERSION 80204
7171 #endif
7272 #ifndef PLVERSION_TAG
7373 #define PLVERSION_TAG ""
22 Author: Jan Wielemaker
33 E-mail: J.Wielemaker@vu.nl
44 WWW: http://www.swi-prolog.org
5 Copyright (c) 2008-2016, University of Amsterdam
5 Copyright (c) 2008-2020, University of Amsterdam
6 SWI-Prolog Solutions b.v.
67 All rights reserved.
78
89 Redistribution and use in source and binary forms, with or without
4344 */
4445
4546 test_attvar :-
46 run_tests([ attvar,
47 freeze
48 ]).
47 run_tests([ attvar,
48 freeze,
49 attvar_with_occurs_check
50 ]).
4951
5052 :- begin_tests(attvar).
5153
5254 test(s_list, L==Codes) :- % Verify wakeup on S_LIST
53 string_codes("hello", Codes),
54 freeze(X, X=Codes),
55 append(X, [], L).
55 string_codes("hello", Codes),
56 freeze(X, X=Codes),
57 append(X, [], L).
5658 test(true_ndet, error(existence_error(procedure,_))) :-
57 freeze(X, wake(X)),
58 between(-2, 2, X).
59 freeze(X, wake(X)),
60 between(-2, 2, X).
5961
6062 wake(2) :-
6163 i_am_undefined.
6567 :- begin_tests(freeze).
6668
6769 test(freeze_and, true) :-
68 freeze(X, true),
69 freeze(Y, true),
70 X=Y,
71 freeze(X, true),
72 X=a.
70 freeze(X, true),
71 freeze(Y, true),
72 X=Y,
73 freeze(X, true),
74 X=a.
7375
7476 :- end_tests(freeze).
77
78 :- begin_tests(attvar_with_occurs_check).
79
80 test(occurs_check, fail) :-
81 freeze(A, writeln(A)),
82 freeze(B, writeln(B)),
83 Q=[[[A],[B]],x],
84 P=[A|B],
85 unify_with_occurs_check(P, Q).
86
87 :- end_tests(attvar_with_occurs_check).
111111 test(create, true) :-
112112 forall(between(1, 100, S),
113113 test_create(S)).
114 test(convert, error(type_error('dict-key',a(x)))) :-
115 A = [a(x):1, b:2].a,
116 writeln(A).
114117
115118 :- end_tests(dict_create).
116119
141144 test('dict_pairs/3') :-
142145 dict_pairs(D, a, [k1-v1, k2-v2]),
143146 D == a{k1:v1, k2:v2}.
147 test('dict_pairs/3', error(type_error('dict-key', "k1"))) :-
148 dict_pairs(_, a, ["k1"-v1, "k2"-v2]).
144149 test('get_dict/3') :-
145150 get_dict(k1, a{k1:v1}, V),
146151 V == v1.
535535
536536 static int
537537 utf8_exists_file(const char *name ARG_LD)
538 { PL_chars_t txt;
538 {
539 #ifndef __WINDOWS__
540 PL_chars_t txt;
539541 int rc;
540542
541543 PL_STRINGS_MARK();
545547 txt.storage = PL_CHARS_HEAP;
546548 txt.canonical = FALSE;
547549 rc = ( PL_canonicalise_text(&txt) &&
548 PL_mb_text(&txt, REP_MB) &&
550 PL_mb_text(&txt, REP_FN) &&
549551 AccessFile(txt.text.t, ACCESS_EXIST) );
550552 PL_free_text(&txt);
551553 PL_STRINGS_RELEASE();
552554
553555 return rc;
556 #else
557 return AccessFile(name, ACCESS_EXIST);
558 #endif
554559 }
555560
556561 static DIR*
557562 utf8_opendir(const char *name ARG_LD)
558 { PL_chars_t txt;
563 {
564 #ifndef __WINDOWS__
565 PL_chars_t txt;
559566 DIR *rc;
560567
561568 PL_STRINGS_MARK();
565572 txt.storage = PL_CHARS_HEAP;
566573 txt.canonical = FALSE;
567574 if ( PL_canonicalise_text(&txt) &&
568 PL_mb_text(&txt, REP_MB) )
575 PL_mb_text(&txt, REP_FN) )
569576 rc = opendir(txt.text.t);
570577 else
571578 rc = NULL;
573580 PL_STRINGS_RELEASE();
574581
575582 return rc;
583 #else
584 return opendir(name);
585 #endif
576586 }
577587
578588 static int
837837 }
838838 }
839839 /* set the flag value */
840 if ( f->index > 0 )
840 if ( f->index > 0 && rval )
841841 { unsigned int mask = (unsigned int)1 << (f->index-1);
842842
843843 if ( val )
26142614 { functor = functorTerm(*arg);
26152615 fdef = valueFunctor(functor);
26162616
2617 if ( !isTextAtom(fdef->name) )
2617 if ( !isTextAtom(fdef->name) && fdef->name != ATOM_nil )
26182618 return NOT_CALLABLE;
26192619
26202620 if ( true(fdef, ARITH_F) && !ci->islocal )
6464 active non-Prolog slots.
6565 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
6666
67 static term_t
68 findReset(LocalFrame fr, term_t ball ARG_LD)
67 #define FRESET_NO_FRAME -1
68 #define FRESET_FINDALL -2
69
70 static int
71 findReset(LocalFrame fr, term_t ball, term_t *rframe ARG_LD)
6972 { Definition reset3 = PROCEDURE_reset3->definition;
7073
7174 for(; fr; fr = fr->parent)
7275 { int rc;
7376 term_t tref;
77 static Procedure proc_fl = NULL;
78
79 if ( !proc_fl )
80 proc_fl = PL_predicate("findall_loop", 4, "$bags");
81
82 if ( fr->predicate == proc_fl->definition )
83 return FRESET_FINDALL;
7484
7585 if ( fr->predicate != reset3 )
7686 continue;
8090 fr = (LocalFrame)valTermRef(tref);
8191
8292 if ( rc )
83 { return consTermRef(fr);
84 }
85 }
86
87 return 0;
93 { *rframe = consTermRef(fr);
94 return TRUE;
95 }
96 }
97
98 return FRESET_NO_FRAME;
8899 }
89100
90101
340351 Code
341352 shift(term_t ball ARG_LD)
342353 { term_t reset;
343
344 if ( (reset=findReset(environment_frame, ball PASS_LD)) )
354 int rc;
355
356 if ( (rc=findReset(environment_frame, ball, &reset PASS_LD)) == TRUE )
345357 { term_t cont = PL_new_term_ref();
346358 LocalFrame resetfr;
347359 LocalFrame fr;
385397 return resetfr->programPointer;
386398 }
387399
388 PL_existence_error("reset/3", ball);
389 return NULL;
400 { static const char *msg[] =
401 { "No matching reset/3 call",
402 "Cannot catch continuation through findall/3"
403 };
404
405 return PL_error("shift", 1, msg[-1-rc],
406 ERR_EXISTENCE, ATOM_reset, ball),NULL;
407 }
390408 }
391409
392410
22 Author: Jan Wielemaker
33 E-mail: J.Wielemaker@vu.nl
44 WWW: http://www.swi-prolog.org
5 Copyright (c) 2013-2017, VU University Amsterdam
5 Copyright (c) 2013-2020, VU University Amsterdam
6 SWI-Prolog Solutions b.v.
67 All rights reserved.
78
89 Redistribution and use in source and binary forms, with or without
596597
597598
598599 static int
599 get_name_value(Word p, Word name, Word value, Word mark, int flags ARG_LD)
600 get_name_value(Word p, Word name, Word value, mark *m, int flags ARG_LD)
600601 { const char *type;
601602
602603 deRef(p);
617618
618619 return TRUE;
619620 } else
620 { gTop = mark;
621 { Undo(*m);
621622 PL_type_error("dict-key", pushWordAsTermRef(np));
622623 popTermRef();
623624
639640 else
640641 type = "key-value";
641642
642 gTop = mark;
643 Undo(*m);
643644 PL_type_error(type, pushWordAsTermRef(p));
644645 popTermRef();
645646
683684
684685 if ( PL_is_list(data) )
685686 { intptr_t len = lengthList(data, TRUE);
686 Word m, ap, tail;
687 Word ap, dp, tail;
688 mark m;
689 int rc;
687690
688691 if ( len < 0 )
689692 return FALSE; /* not a proper list */
690 retry:
691 if ( !(m = allocGlobal(len*2+2)) )
692 return FALSE; /* global overflow */
693 ap = m;
693
694 if ( unlikely(tTop+1 >= tMax) )
695 { if ( !makeMoreStackSpace(TRAIL_OVERFLOW, ALLOW_GC|ALLOW_SHIFT) )
696 return FALSE;
697 }
698 if ( (rc=ensureGlobalSpace(len*2+2, ALLOW_GC)) != TRUE )
699 return raiseStackOverflow(rc);
700 ap = gTop;
701 Mark(m);
702 dp = ap;
694703 *ap++ = dict_functor(len);
695704 if ( tag )
696705 { Word cp = valTermRef(tag);
697706
698707 *ap = linkVal(cp); /* TBD: maybe move to another function */
699708 if ( tagex(*ap) == (TAG_REFERENCE|STG_LOCAL) )
700 { if ( unlikely(tTop+1 >= tMax) )
701 { if ( !makeMoreStackSpace(TRAIL_OVERFLOW, ALLOW_GC|ALLOW_SHIFT) )
702 return FALSE;
703 gTop = m;
704 goto retry;
705 }
706 deRef(cp)
709 { deRef(cp)
707710 setVar(*ap);
708711 Trail(cp, makeRef(ap));
709712 }
717720 while( isList(*tail) )
718721 { Word head = HeadList(tail);
719722
720 if ( !get_name_value(head, ap+1, ap, m, flags PASS_LD) )
721 {
723 if ( !get_name_value(head, ap+1, ap, &m, flags PASS_LD) )
722724 return FALSE;
723 }
724725 ap += 2;
725726 tail = TailList(tail);
726727 deRef(tail);
727728 }
728729
729 if ( dict_order(m, TRUE PASS_LD) )
730 if ( dict_order(dp, TRUE PASS_LD) )
730731 { gTop = ap;
731 *valTermRef(dict) = consPtr(m, TAG_COMPOUND|STG_GLOBAL);
732 *valTermRef(dict) = consPtr(dp, TAG_COMPOUND|STG_GLOBAL);
732733 DEBUG(CHK_SECURE, checkStacks(NULL));
733734 return TRUE;
734735 } else
538538 PL_meta_predicate(PL_predicate("prolog_listen", 3, "system"), "+:+");
539539 PL_meta_predicate(PL_predicate("prolog_unlisten", 2, "system"), "+:");
540540 PL_meta_predicate(PL_predicate("with_tty_raw", 1, "system"), "0");
541 PL_meta_predicate(PL_predicate("$sig_atomic", 1, "system"), "0");
541542
542543 for( ecell = ext_head; ecell; ecell = ecell->next )
543544 bindExtensions(ecell->module, ecell->extensions);
47074707
47084708 int
47094709 PL_pending__LD(int sig ARG_LD)
4710 { if ( sig > 0 && sig <= MAXSIGNAL && HAS_LD )
4711 { int off = (sig-1)/32;
4712 int mask = 1 << ((sig-1)%32);
4713
4714 return (LD->signal.pending[off] & mask) ? TRUE : FALSE;
4715 }
4716
4717 return -1;
4710 { return pendingSignal(LD, sig);
47184711 }
47194712
47204713
7070 COMMON(int) foreignWakeup(term_t ex ARG_LD);
7171 COMMON(void) updateAlerted(PL_local_data_t *ld);
7272 COMMON(int) raiseSignal(PL_local_data_t *ld, int sig);
73 COMMON(int) pendingSignal(PL_local_data_t *ld, int sig);
7374 COMMON(Module) contextModule(LocalFrame fr);
7475 COMMON(void) setContextModule(LocalFrame fr, Module context);
7576 COMMON(int) existingChoice(Choice ch ARG_LD);
17761776 var-VAROFFSET(0), (PC-state->c0)-1));
17771777 #ifdef O_DEBUG
17781778 if ( DEBUGGING(CHK_SECURE) )
1779 { Word vp = varFrameP(fr, PC[0]);
1779 { Word vp = varFrameP(fr, var);
17801780
17811781 if ( !isVar(*vp & ~MARK_MASK) )
17821782 { Sdprintf("ERROR: [%ld] %s: Wrong clear of var %d, PC=%d\n",
451451 { int pending[2]; /* PL_raise() pending signals */
452452 int current; /* currently processing signal */
453453 int is_sync; /* current signal is synchronous */
454 #ifndef __unix__
455 int forced; /* Forced signal */
456 #endif
454457 } signal;
455458
456459 struct
678681
679682 #ifdef O_LIMIT_DEPTH
680683 struct
681 { uintptr_t limit;
682 uintptr_t reached;
684 { size_t limit;
685 size_t reached;
683686 } depth_info;
684687 #endif
685688
788791 #define exception_printed (LD->exception.printed)
789792 #define gc_status (LD->gc.status)
790793 #define debugstatus (LD->_debugstatus)
791 #define depth_limit (LD->depth_info.limit)
792 #define depth_reached (LD->depth_info.reached)
793794 #define base_addresses (LD->bases)
794795 #define Suser_input (LD->IO.streams[0])
795796 #define Suser_output (LD->IO.streams[1])
16451645 } registers;
16461646 LocalFrame next_environment; /* See D_BREAK and get_vmi_state() */
16471647 #ifdef O_LIMIT_DEPTH
1648 uintptr_t saved_depth_limit; /* saved values of these */
1649 uintptr_t saved_depth_reached;
1648 size_t saved_depth_limit; /* saved values of these */
1649 size_t saved_depth_reached;
16501650 #endif
16511651 #if O_CATCHTHROW
16521652 term_t exception; /* Exception term */
24442444 #define SYSTEM_MODE (LD->prolog_flag.access_level == ACCESS_LEVEL_SYSTEM)
24452445
24462446 #ifdef O_LIMIT_DEPTH
2447 #define DEPTH_NO_LIMIT (~(uintptr_t)0x0) /* Highest value */
2447 #define DEPTH_NO_LIMIT ((size_t)-1) /* Highest value */
24482448 #endif
24492449
24502450 #ifdef O_INFERENCE_LIMIT
402402
403403 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
404404 When detected to run under a GNU-Emacs shell or using M-x run-prolog
405 from GNU-Emacs, don't pretend we can manipulate the TTY settings.
405 from GNU-Emacs, don't pretend we can manipulate the TTY settings. On
406 Windows, do pretend we have a tty, so the prompt is displayed.
406407 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
407408
408409 static void
409 setupGNUEmacsInferiorMode()
410 { char envbuf[4];
410 setupGNUEmacsInferiorMode(void)
411 { char envbuf[80];
411412 char *s;
412413 int val;
413414
418419
419420 clearPrologFlagMask(PLFLAG_TTY_CONTROL);
420421 val = TRUE;
422 #ifdef __WINDOWS__
423 Sinput->flags |= SIO_ISATTY;
424 Soutput->flags |= SIO_ISATTY;
425 Serror->flags |= SIO_ISATTY;
426 #endif
421427 } else
422428 { val = FALSE;
423429 }
582582 int
583583 setSuperModule(Module m, Module s)
584584 { if ( s == m )
585 cannotSetSuperModule(m, s);
585 return cannotSetSuperModule(m, s);
586586
587587 if ( m->supers && !m->supers->next )
588588 { if ( (Module)m->supers->value != s )
12831283 clearHTable(module->public);
12841284 }
12851285 if ( super )
1286 setSuperModule(module, _lookupModule(super PASS_LD));
1286 rc = setSuperModule(module, _lookupModule(super PASS_LD));
12871287
12881288 PL_UNLOCK(L_MODULE);
12891289
12911291 { if ( !PL_unify_nil(rtail) )
12921292 return FALSE;
12931293
1294 rc = printMessage(ATOM_warning,
1295 PL_FUNCTOR_CHARS, "declare_module", 2,
1296 PL_ATOM, name,
1297 PL_FUNCTOR_CHARS, "abolish", 1,
1298 PL_TERM, rdef);
1294 if ( rc )
1295 rc = printMessage(ATOM_warning,
1296 PL_FUNCTOR_CHARS, "declare_module", 2,
1297 PL_ATOM, name,
1298 PL_FUNCTOR_CHARS, "abolish", 1,
1299 PL_TERM, rdef);
12991300 }
13001301
13011302 return rc;
221221 while( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) )
222222 { TranslateMessage(&msg);
223223 DispatchMessage(&msg);
224 if ( PL_exception(0) )
225 return FALSE;
224226 }
225227
226228 if ( PL_handle_signals() < 0 )
650650 }
651651
652652 Mark(m);
653 LD->mark_bar = NO_MARK_BAR; /* see also unify_all_trail_ptrs() */
653654 rc = do_unify(t1, t2 PASS_LD);
654655 DiscardMark(m);
655656
43194320 return rc;
43204321 }
43214322
4323 discardBuffer(&b);
4324
43224325 split:
43234326 if ( !sep || st.length == 0 )
43244327 { if ( !sep )
43264329
43274330 return PL_domain_error("non_empty_atom", sep);
43284331 }
4329 discardBuffer(&b);
4332
43304333 return split_atom(list, &st, atom PASS_LD);
43314334 }
43324335
49104913 /* $depth_limit(+Limit, -OldLimit, -DepthReached)
49114914 */
49124915
4916 static int
4917 unify_depth_LD(term_t t, size_t depth ARG_LD)
4918 { if ( depth == DEPTH_NO_LIMIT )
4919 return PL_unify_atom(t, ATOM_inf);
4920 else
4921 return PL_unify_uint64(t, depth);
4922 }
4923
4924 static int
4925 get_depth_LD(term_t t, size_t *depth ARG_LD)
4926 { atom_t a;
4927
4928 if ( PL_get_atom(t, &a) && a == ATOM_inf )
4929 { *depth = DEPTH_NO_LIMIT;
4930 return TRUE;
4931 }
4932
4933 return PL_get_size_ex(t, depth);
4934 }
4935
4936 #define unify_depth(t, d) unify_depth_LD(t, d PASS_LD)
4937 #define get_depth(t, d) get_depth_LD(t, d PASS_LD)
4938
49134939 static
49144940 PRED_IMPL("$depth_limit", 3, pl_depth_limit, 0)
49154941 { GET_LD
4916 long levels;
4917 long clevel = levelFrame(environment_frame) - 1;
4918
4919 if ( PL_get_long_ex(A1, &levels) )
4920 { if ( PL_unify_integer(A2, depth_limit) &&
4921 PL_unify_integer(A3, depth_reached) )
4922 { depth_limit = clevel + levels + 1; /* 1 for the catch/3 */
4923 depth_reached = clevel;
4942 size_t levels;
4943 size_t clevel = levelFrame(environment_frame) - 1;
4944
4945 if ( PL_get_size_ex(A1, &levels) )
4946 { if ( unify_depth(A2, LD->depth_info.limit) &&
4947 unify_depth(A3, LD->depth_info.reached) )
4948 { size_t newlimit = clevel + levels + 1; /* 1 for the catch/3 */
4949
4950 if ( newlimit < clevel )
4951 return PL_representation_error("depth_limit");
4952
4953 LD->depth_info.limit = newlimit;
4954 LD->depth_info.reached = clevel;
49244955
49254956 updateAlerted(LD);
4926 succeed;
4927 }
4928 }
4929
4930 fail;
4957 return TRUE;
4958 }
4959 }
4960
4961 return FALSE;
49314962 }
49324963
49334964
49344965 static
49354966 PRED_IMPL("$depth_limit_true", 5, pl_depth_limit_true, PL_FA_NONDETERMINISTIC)
4936 { term_t limit = A1;
4967 { PRED_LD
4968 term_t limit = A1;
49374969 term_t olimit = A2;
49384970 term_t oreached = A3;
49394971 term_t res = A4;
49414973
49424974 switch( CTX_CNTRL )
49434975 { case FRG_FIRST_CALL:
4944 { GET_LD
4945 long l, ol, or;
4946
4947 if ( PL_get_long_ex(limit, &l) &&
4948 PL_get_long_ex(olimit, &ol) &&
4949 PL_get_long_ex(oreached, &or) )
4976 { size_t l, ol, or;
4977
4978 if ( get_depth(limit, &l) &&
4979 get_depth(olimit, &ol) &&
4980 get_depth(oreached, &or) )
49504981 { intptr_t clevel = levelFrame(environment_frame) - 1;
4951 intptr_t used = depth_reached - clevel - 1;
4952
4953 depth_limit = ol;
4954 depth_reached = or;
4982 intptr_t used = LD->depth_info.reached - clevel - 1;
4983
4984 LD->depth_info.limit = ol;
4985 LD->depth_info.reached = or;
49554986 updateAlerted(LD);
49564987
49574988 if ( used < 1 )
49584989 used = 1;
49594990 if ( !PL_unify_integer(res, used) )
4960 fail;
4991 return FALSE;
49614992
49624993 return unify_det(cut PASS_LD);
49634994 }
49654996 break;
49664997 }
49674998 case FRG_REDO:
4968 { GET_LD
4969 long levels;
4970 long clevel = levelFrame(environment_frame) - 1;
4971
4972 PL_get_long_ex(limit, &levels);
4973 depth_limit = clevel + levels + 1; /* 1 for catch/3 */
4974 depth_reached = clevel;
4999 { size_t levels;
5000 size_t clevel = levelFrame(environment_frame) - 1;
5001
5002 if ( !get_depth(limit, &levels) )
5003 return FALSE;
5004 LD->depth_info.limit = clevel + levels + 1; /* 1 for catch/3 */
5005 LD->depth_info.reached = clevel;
49755006 updateAlerted(LD);
49765007
4977 fail; /* backtrack to goal */
5008 return FALSE; /* backtrack to goal */
49785009 }
49795010 case FRG_CUTTED:
4980 succeed;
4981 }
4982
4983 fail;
5011 return TRUE;
5012 }
5013
5014 return FALSE;
49845015 }
49855016
49865017
49875018 static
49885019 PRED_IMPL("$depth_limit_false", 3, depth_limit_false, 0)
49895020 { PRED_LD
4990 long ol, or;
4991
4992 if ( PL_get_long_ex(A1, &ol) &&
4993 PL_get_long_ex(A2, &or) )
4994 { int exceeded = (depth_reached > depth_limit);
4995
4996 depth_limit = ol;
4997 depth_reached = or;
5021 size_t ol, or;
5022
5023 if ( get_depth(A1, &ol) &&
5024 get_depth(A2, &or) )
5025 { int exceeded = (LD->depth_info.reached > LD->depth_info.limit);
5026
5027 LD->depth_info.limit = ol;
5028 LD->depth_info.reached = or;
49985029 updateAlerted(LD);
49995030
50005031 if ( exceeded )
50015032 return PL_unify_atom(A3, ATOM_depth_limit_exceeded);
50025033 }
50035034
5004 fail;
5035 return FALSE;
50055036 }
50065037
50075038
50085039 static
50095040 PRED_IMPL("$depth_limit_except", 3, depth_limit_except, 0)
50105041 { PRED_LD
5011 long ol, or;
5012
5013 if ( PL_get_long_ex(A1, &ol) &&
5014 PL_get_long_ex(A2, &or) )
5015 { depth_limit = ol;
5016 depth_reached = or;
5042 size_t ol, or;
5043
5044 if ( get_depth(A1, &ol) &&
5045 get_depth(A2, &or) )
5046 { LD->depth_info.limit = ol;
5047 LD->depth_info.reached = or;
50175048 updateAlerted(LD);
50185049
50195050 return PL_raise_exception(A3);
7474 }
7575
7676 #ifdef O_LIMIT_DEPTH
77 depth_limit = (uintptr_t)DEPTH_NO_LIMIT;
77 LD->depth_info.limit = DEPTH_NO_LIMIT;
7878 #endif
7979
8080 LD->autoload.nesting = NULL;
125125 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
126126 lingerDefinition() deals with (undefined) definitions that are replaced
127127 due to importing. These definitions can be in use with other threads.
128 This needs be be improved, possibly using a technique similar to the RDF
128 This needs to be improved, possibly using a technique similar to the RDF
129129 database. For now, we merely collect them in a single place, so we know
130130 what is going on. In addition, we can collect lingering definitions when
131131 destroying a module, resulting in leak-free temporary modules.
14281428 retractClauseDefinition(Definition def, Clause clause)
14291429 { GET_LD
14301430 size_t size = sizeofClause(clause->code_size) + SIZEOF_CREF_CLAUSE;
1431 gen_t egen;
14311432
14321433 if ( def->events &&
14331434 !predicate_update_event(def, ATOM_retract, clause PASS_LD) )
14471448 if ( false(clause, UNIT_CLAUSE) )
14481449 def->impl.clauses.number_of_rules--;
14491450 #ifdef O_LOGICAL_UPDATE
1450 clause->generation.erased = next_global_generation();
1451 do
1452 { egen = global_generation()+1;
1453 clause->generation.erased = egen;
1454 } while (egen < next_global_generation());
14511455 setLastModifiedPredicate(def, clause->generation.erased);
14521456 #endif
14531457 DEBUG(CHK_SECURE, checkDefinition(def));
23762380 { DEBUG(MSG_PROC_COUNT, Sdprintf("Delayed unalloc %s\n", predicateName(def)));
23772381 assert(def->module == NULL);
23782382 if ( def->impl.clauses.first_clause == NULL )
2379 { if ( def->lingering )
2380 { static int done = FALSE;
2381 if ( !done )
2382 { Sdprintf("maybeUnregisterDirtyDefinition(%s): lingering data\n",
2383 predicateName(def));
2384 done = TRUE;
2385 }
2386 }
2383 { DEBUG(0,
2384 if ( def->lingering )
2385 { Sdprintf("maybeUnregisterDirtyDefinition(%s): lingering data\n",
2386 predicateName(def));
2387 });
23872388 unregisterDirtyDefinition(def);
23882389 deleteIndexes(&def->impl.clauses, TRUE);
23892390 freeHeap(def->impl.any.args, sizeof(arg_info)*def->functor->arity);
29422943 ForeignRedoPtr(ctx);
29432944 } else
29442945 { setGenerationFrame(environment_frame);
2945 assert(dref);
2946 dref->generation = generationFrame(environment_frame);
29472946 DEBUG(MSG_CGC_RETRACT,
29482947 Sdprintf("Retract: first clause deleted; set gen to %lld\n",
29492948 generationFrame(environment_frame)));
159159 initPrologLocalData(ARG1_LD)
160160 {
161161 #ifdef O_LIMIT_DEPTH
162 depth_limit = DEPTH_NO_LIMIT;
162 LD->depth_info.limit = DEPTH_NO_LIMIT;
163163 #endif
164164 #ifdef O_INFERENCE_LIMIT
165165 LD->inference_limit.limit = INFERENCE_NO_LIMIT;
506506 { term_t sigterm = PL_new_term_ref();
507507 qid_t qid;
508508 #ifdef O_LIMIT_DEPTH
509 uintptr_t olimit = depth_limit;
510 depth_limit = DEPTH_NO_LIMIT;
509 size_t olimit = LD->depth_info.limit;
510 LD->depth_info.limit = DEPTH_NO_LIMIT;
511511 #endif
512512
513513 PL_put_atom_chars(sigterm, signal_name(sig));
518518 if ( PL_next_solution(qid) ) {}; /* cannot ignore return */
519519 PL_cut_query(qid);
520520 #ifdef O_LIMIT_DEPTH
521 depth_limit = olimit;
521 LD->depth_info.limit = olimit;
522522 #endif
523523 } else if ( true(sh, PLSIG_THROW) )
524524 { char *predname;
536536 } else if ( sh->handler )
537537 { int ex_pending = (exception_term && !sync);
538538 #ifdef O_LIMIT_DEPTH
539 uintptr_t olimit = depth_limit;
540 depth_limit = DEPTH_NO_LIMIT;
539 uintptr_t olimit = LD->depth_info.limit;
540 LD->depth_info.limit = DEPTH_NO_LIMIT;
541541 #endif
542542 (*sh->handler)(sig);
543543 #ifdef O_LIMIT_DEPTH
544 depth_limit = olimit;
544 LD->depth_info.limit = olimit;
545545 #endif
546546
547547 DEBUG(MSG_SIGNAL,
10601060 PL_handle_signals(void)
10611061 { GET_LD
10621062
1063 if ( !HAS_LD || LD->critical || !is_signalled(PASS_LD1) )
1063 if ( !is_signalled(PASS_LD1) )
10641064 return 0;
1065 if ( exception_term )
1066 return -1;
1067
1068 return handleSignals(PASS_LD1);
1069 }
1070
1065 else
1066 return handleSignals(PASS_LD1);
1067 }
1068
1069 #ifndef __unix__
1070 static int
1071 handleSigInt(ARG1_LD)
1072 { int intmask = 1<<(SIGINT-1);
1073
1074 if ( LD->signal.forced == SIGINT && LD->signal.pending[0] & intmask )
1075 { ATOMIC_AND(&LD->signal.pending[0], ~intmask);
1076
1077 LD->signal.forced = 0;
1078 dispatch_signal(SIGINT, TRUE);
1079
1080 if ( exception_term )
1081 return -1;
1082 updateAlerted(LD);
1083
1084 return 1;
1085 }
1086
1087 return 0;
1088 }
1089 #endif
10711090
10721091 int
10731092 handleSignals(ARG1_LD)
10741093 { int done = 0;
10751094 int i;
10761095
1077 if ( !HAS_LD || LD->critical )
1096 if ( !is_signalled(PASS_LD1) )
1097 return 0;
1098 if ( !HAS_LD )
1099 return 0;
1100 if ( exception_term )
1101 return -1;
1102 #ifndef __unix__ /* on Unix we ask to signal twice */
1103 if ( (done=handleSigInt(PASS_LD1)) )
1104 return done;
1105 #endif
1106 if ( LD->critical )
10781107 return 0;
10791108
10801109 for(i=0; i<2; i++)
14631463 { PL_thread_info_t *info = GD->thread.threads[i];
14641464
14651465 if ( info && info->w32id == id && info->thread_data )
1466 { raiseSignal(info->thread_data, sig);
1467 if ( info->w32id )
1468 PostThreadMessage(info->w32id, WM_SIGNALLED, 0, 0L);
1466 { PL_local_data_t *ld = info->thread_data;
1467
14691468 PL_UNLOCK(L_THREAD);
1469 if ( pendingSignal(ld, sig) )
1470 ld->signal.forced = sig;
1471 else
1472 raiseSignal(ld, sig);
1473 PostThreadMessage(id, WM_SIGNALLED, 0, 0L);
14701474 DEBUG(MSG_THREAD, Sdprintf("Signalled %d to thread %d\n", sig, i));
14711475 return TRUE;
14721476 }
30343038 if ( rval )
30353039 {
30363040 #ifdef O_LIMIT_DEPTH
3037 uintptr_t olimit = depth_limit;
3038 depth_limit = DEPTH_NO_LIMIT;
3041 size_t olimit = LD->depth_info.limit;
3042 LD->depth_info.limit = DEPTH_NO_LIMIT;
30393043 #endif
30403044 rval = callProlog(gm, goal, PL_Q_CATCH_EXCEPTION, &ex);
30413045 #ifdef O_LIMIT_DEPTH
3042 depth_limit = olimit;
3046 LD->depth_info.limit = olimit;
30433047 #endif
30443048 } else
30453049 { rval = raiseStackOverflow(GLOBAL_OVERFLOW);
214214 { GET_LD
215215
216216 #ifdef O_PLMT
217 if ( PL_thread_self() > 1 )
217 if ( PL_thread_self() > 1 && !LD->exit_requested )
218218 { Sfprintf(Sdout, "%sexit session\n", msg);
219219 LD->exit_requested = EXIT_REQ_THREAD;
220220 return ACTION_ABORT;
950950 if ( debugstatus.showContext )
951951 Sfprintf(out, "[%s] ", stringAtom(contextModule(frame)->name));
952952 #ifdef O_LIMIT_DEPTH
953 if ( levelFrame(frame) > depth_limit )
953 if ( levelFrame(frame) > LD->depth_info.limit )
954954 Sfprintf(out, "[depth-limit exceeded] ");
955955 #endif
956956
16351635 return;
16361636 }
16371637 } else
1638 { safe = TRUE;
1639 }
1640 #else
1641 safe = !LD->critical;
16381642 #endif /* no async signals; always safe */
1639 { safe = TRUE;
1640 }
16411643
16421644 Sreset();
16431645 again:
975975
976976 stats->nodes++;
977977 stats->bytes += sizeof(*n);
978 if ( n->value )
978 if ( n->value && true(n, TN_PRIMARY) )
979979 stats->values++;
980980
981981 if ( children.any )
12821282 void
12831283 trie_delete(trie *trie, trie_node *node, int prune)
12841284 { if ( node->value )
1285 { clear(node, (TN_PRIMARY|TN_SECONDARY));
1285 { if ( true(node, TN_PRIMARY) )
1286 ATOMIC_DEC(&trie->value_count);
1287
1288 clear(node, (TN_PRIMARY|TN_SECONDARY));
12861289 if ( prune && trie->references == 0 )
12871290 { prune_node(trie, node);
12881291 } else
12961299 release_value(v);
12971300 }
12981301 }
1299 ATOMIC_DEC(&trie->value_count);
13001302 trie_discard_clause(trie);
13011303 }
13021304 }
23542356 stat_trie(trie, &stats);
23552357 if ( stats.nodes != trie->node_count )
23562358 Sdprintf("OOPS: trie_property/2: counted %zd nodes, admin says %zd\n",
2357 stats.nodes, trie->node_count);
2359 (size_t)stats.nodes, (size_t)trie->node_count);
23582360 if ( stats.values != trie->value_count )
23592361 Sdprintf("OOPS: trie_property/2: counted %zd values, admin says %zd\n",
2360 stats.values, trie->value_count);
2362 (size_t)stats.values, (size_t)trie->value_count);
23612363 // assert(stats.nodes == trie->node_count);
23622364 // assert(stats.values == trie->value_count);
23632365 return PL_unify_int64(arg, stats.bytes);
15881588 if ( unlikely(LD->alerted) )
15891589 { /* play safe */
15901590 lTop = (LocalFrame) argFrameP(FR, DEF->functor->arity);
1591 PC = DEF->codes;
15911592
15921593 /* we need the autoloader and get back */
15931594 if ( DEF->codes[0] == encode(S_VIRGIN) &&
16231624 Profile(FR->prof_node = profCall(DEF PASS_LD));
16241625
16251626 #ifdef O_LIMIT_DEPTH
1626 { unsigned int depth = levelFrame(FR);
1627
1628 if ( depth > depth_reached )
1629 depth_reached = depth;
1630 if ( depth > depth_limit )
1627 { size_t depth = levelFrame(FR);
1628
1629 if ( depth > LD->depth_info.reached )
1630 LD->depth_info.reached = depth;
1631 if ( depth > LD->depth_info.limit )
16311632 { DEBUG(2, Sdprintf("depth-limit\n"));
16321633
16331634 if ( debugstatus.debugging )
312312 }
313313
314314 return FALSE;
315 }
316
317
318 int
319 pendingSignal(PL_local_data_t *ld, int sig)
320 { if ( sig > 0 && sig <= MAXSIGNAL && ld )
321 { int off = (sig-1)/32;
322 int mask = 1 << ((sig-1)%32);
323
324 return (ld->signal.pending[off] & mask) ? TRUE : FALSE;
325 }
326
327 return -1;
315328 }
316329
317330
25382551 qf->flags_saved = (LD->prolog_flag.mask.flags & NDEBUG_SAVE_FLAGS);
25392552 setPrologFlagMask(PLFLAG_LASTCALL);
25402553 #ifdef O_LIMIT_DEPTH
2541 qf->saved_depth_limit = depth_limit;
2542 qf->saved_depth_reached = depth_reached;
2543 depth_limit = DEPTH_NO_LIMIT;
2554 qf->saved_depth_limit = LD->depth_info.limit;
2555 qf->saved_depth_reached = LD->depth_info.reached;
2556 LD->depth_info.limit = DEPTH_NO_LIMIT;
25442557 #endif
25452558 }
25462559 fr->predicate = def;
26172630 LD->prolog_flag.mask.flags &= (~NDEBUG_SAVE_FLAGS);
26182631 LD->prolog_flag.mask.flags |= qf->flags_saved;
26192632 #ifdef O_LIMIT_DEPTH
2620 depth_limit = qf->saved_depth_limit;
2621 depth_reached = qf->saved_depth_reached;
2633 LD->depth_info.limit = qf->saved_depth_limit;
2634 LD->depth_info.reached = qf->saved_depth_reached;
26222635 #endif /*O_LIMIT_DEPTH*/
26232636 }
26242637 updateAlerted(LD);
26802680 run_scripts(T).
26812681
26822682 script_failed(File, fail) :-
2683 !,
26832684 format(user_error, '~NScript ~w failed~n', [File]),
26842685 assert(failed(script(File))).
26852686 script_failed(File, Except) :-
11221122 if ( rlc_kill(b) )
11231123 return 0;
11241124 break;
1125 }
1126
1127 if ( (name = lookupMenuId(item)) )
1128 { if ( _rlc_menu_hook )
1129 { (*_rlc_menu_hook)(b, name);
1130 }
1131
1132 return 0;
1125 default:
1126 if ( (name = lookupMenuId(item)) )
1127 { if ( _rlc_menu_hook )
1128 { (*_rlc_menu_hook)(b, name);
1129 }
1130
1131 return 0;
1132 }
11331133 }
11341134
11351135 break;
14271427 static int
14281428 rlc_get_message(MSG *msg, HWND hwnd, UINT low, UINT high)
14291429 { int rc;
1430
14301431 again:
1431 if ( (rc=GetMessage(msg, hwnd, low, high)) )
1432 if ( (rc=PeekMessage(msg, hwnd, low, WM_RLC_INPUT, PM_REMOVE)) )
1433 { if ( _rlc_message_hook &&
1434 (*_rlc_message_hook)(msg->hwnd, msg->message,
1435 msg->wParam, msg->lParam) )
1436 goto again;
1437 } else if ( (rc=GetMessage(msg, hwnd, low, high)) )
14321438 { if ( _rlc_message_hook &&
14331439 (*_rlc_message_hook)(msg->hwnd, msg->message,
14341440 msg->wParam, msg->lParam) )
23212327 b->imodeswitch = FALSE;
23222328 b->lhead = NULL;
23232329 b->ltail = NULL;
2330 InitializeCriticalSection(&b->lock);
23242331
23252332 memset(b->lines, 0, sizeof(text_line) * h);
23262333 for(i=0; i<h; i++)
34253432 if ( !b )
34263433 return -1;
34273434
3435 EnterCriticalSection(&b->lock);
34283436 for(s=buf, e=&buf[count]; s<e; s++)
34293437 { if ( *s == '\n' )
34303438 b->promptlen = 0;
34313439 else if ( b->promptlen < MAXPROMPT-1 )
34323440 b->promptbuf[b->promptlen++] = *s;
34333441 }
3442 LeaveCriticalSection(&b->lock);
34343443
34353444 if ( b->window )
34363445 { if ( SendMessageTimeout(b->window,
34673476 }
34683477 if ( b->read_buffer.line )
34693478 free(b->read_buffer.line);
3479 DeleteCriticalSection(&b->lock);
34703480
34713481 free(b);
34723482 }
171171 DWORD console_thread_id; /* I/O thread id */
172172 DWORD application_thread_id;
173173 HWND kill_window; /* window in app thread for destroy */
174 CRITICAL_SECTION lock; /* Serialized actions */
174175
175176 user_data values[MAX_USER_VALUES]; /* associated user data */
176177 } rlc_data, *RlcData;