View source with raw comments or as raw
    1/*  Part of SWI-Prolog
    2
    3    WWW:           http://www.swi-prolog.org
    4    Copyright (c)  2020-2021, SWI-Prolog Solutions b.v.
    5    All rights reserved.
    6
    7    Redistribution and use in source and binary forms, with or without
    8    modification, are permitted provided that the following conditions
    9    are met:
   10
   11    1. Redistributions of source code must retain the above copyright
   12       notice, this list of conditions and the following disclaimer.
   13
   14    2. Redistributions in binary form must reproduce the above copyright
   15       notice, this list of conditions and the following disclaimer in
   16       the documentation and/or other materials provided with the
   17       distribution.
   18
   19    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   20    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   21    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
   22    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
   23    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   24    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   25    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   26    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   27    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   28    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
   29    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   30    POSSIBILITY OF SUCH DAMAGE.
   31*/
   32
   33:- module(sicstus4,
   34	  [ nonmember/2,		% ?Element, ?List
   35	    statistics/2,		% ?Key, ?Value
   36	    op(1100, xfy, (do))
   37	  ]).   38:- reexport(sicstus,
   39	    [ (block)/1,
   40	      if/3,
   41	      use_module/3,
   42	      bb_put/2,
   43	      bb_get/2,
   44	      bb_delete/2,
   45	      bb_update/3,
   46	      is_mutable/1 as mutable,
   47	      create_mutable/2,
   48	      get_mutable/2,
   49	      update_mutable/2,
   50	      sicstus_is_readable_stream/1,
   51	      read_line/1,
   52	      read_line/2,
   53	      trimcore/0,
   54	      prolog_flag/3,
   55	      prolog_flag/2,
   56	      op(1150, fx, (block)),
   57	      op(1150, fx, (mode)),
   58	      op(900, fy, (spy)),
   59	      op(900, fy, (nospy))
   60	    ]).

SICStus 4 compatibility library

This library is intended to be activated using the directive below in files that are designed for use with SICStus Prolog 4. The changes are in effect until the end of the file and in each file loaded from this file.

:- expects_dialect(sicstus4).

This library only provides compatibility with version 4 of SICStus Prolog. For SICStus Prolog 3 compatibility, use library(dialect/sicstus) instead.

To be done
- The dialect-compatibility packages are developed in a `demand-driven' fashion. Please contribute to this package. */
   79% Note: Although the do operator is declared here, do loops currently
   80% aren't emulated by library(dialect/sicstus4).
   81:- op(1100, xfy, user:(do)).   82
   83
   84		 /*******************************
   85		 *	    LIBRARY SETUP	*
   86		 *******************************/
 push_sicstus4_library
Pushes searching for dialect/sicstus4 in front of every library directory that contains such as sub-directory.
   93push_sicstus4_library :-
   94	(   absolute_file_name(library(dialect/sicstus4), Dir,
   95			       [ file_type(directory),
   96				 access(read),
   97				 solutions(all),
   98				 file_errors(fail)
   99			       ]),
  100	    asserta((user:file_search_path(library, Dir) :-
  101		    prolog_load_context(dialect, sicstus4))),
  102	    fail
  103	;   true
  104	).
  105
  106
  107:- push_sicstus4_library.
 setup_dialect
Further dialect initialization.

sicstus4 currently performs the same initialization as the sicstus (SICStus 3) dialect.

  117setup_dialect :- sicstus:setup_dialect.
  118
  119
  120		 /*******************************
  121		 *	  LIBRARY MODULES	*
  122		 *******************************/
 rename_module(?SICStus4Module, ?RenamedSICStus4Module) is nondet
True if RenamedSICStus4Module is the name that we use for the SICStus 4 native module SICStus4Module. We do this in places where the module-name conflicts. All explicitly qualified goals are mapped to the SICStus 4 equivalent of the module.
  131:- multifile
  132	rename_module/2.  133
  134system:goal_expansion(M:Goal, SicstusM:Goal) :-
  135	atom(M),
  136	rename_module(M, SicstusM),
  137	prolog_load_context(dialect, sicstus4).
 nonmember(?Element, ?List) is semidet
True if Element doesn't unify with any element in List. No variables are bound.
  145nonmember(Element, List) :- \+ memberchk(Element, List).
  146
  147% As of SICStus 4.6.0, the following statistics/2 keys are still missing:
  148% Introduced in SICStus 4.0:
  149% * defragmentation
  150% Introduced in SICStus 4.1:
  151% * choice_used, choice_free
  152% * defrag_count, defrag_time
  153% * dpgc_count, dpgc_time
  154% * memory_culprit
  155% * memory_buckets
  156% Introduced in SICStus 4.3:
  157% * jit_count, jit_time
  158
  159statistics(total_runtime, Stats) :- !, system:statistics(runtime, Stats).
  160% The following keys were introduced with SICStus Prolog 4.1.
  161statistics(memory_used, BytesUsed) :- !, system:statistics(memory, [BytesUsed, _]).
  162statistics(memory_free, BytesFree) :- !, system:statistics(memory, [_, BytesFree]).
  163statistics(global_stack_used, BytesUsed) :- !, system:statistics(global_stack, [BytesUsed, _]).
  164statistics(global_stack_free, BytesFree) :- !, system:statistics(global_stack, [_, BytesFree]).
  165statistics(local_stack_used, BytesUsed) :- !, system:statistics(local_stack, [BytesUsed, _]).
  166statistics(local_stack_free, BytesFree) :- !, system:statistics(local_stack, [_, BytesFree]).
  167statistics(trail_used, BytesUsed) :- !, system:statistics(trail, [BytesUsed, _]).
  168statistics(trail_free, BytesFree) :- !, system:statistics(trail, [_, BytesFree]).
  169statistics(atoms_used, BytesUsed) :- !, system:statistics(atom_space, BytesUsed).
  170statistics(atoms_nbused, CountUsed) :- !, system:statistics(atoms, CountUsed).
  171statistics(atoms_nbfree, CountFree) :- !, CountFree = 0.
  172statistics(ss_global, Count) :- !, system:statistics(stack_shifts, [Count, _, _]).
  173statistics(ss_local, Count) :- !, system:statistics(stack_shifts, [_, Count, _]).
  174statistics(ss_time, Time) :- !, system:statistics(stack_shifts, [_, _, Time]).
  175statistics(gc_count, Count) :- !, system:statistics(garbage_collection, [Count, _, _|_]).
  176statistics(gc_freed, BytesFreed) :- !, system:statistics(garbage_collection, [_, BytesFreed, _|_]).
  177statistics(gc_time, Time) :- !, system:statistics(garbage_collection, [_, _, Time|_]).
  178statistics(agc_count, Count) :- !, system:statistics(atom_garbage_collection, [Count, _, _]).
  179statistics(agc_freed, BytesFreed) :- !, system:statistics(atom_garbage_collection, [_, BytesFreed, _]).
  180statistics(agc_time, Time) :- !, system:statistics(atom_garbage_collection, [_, _, Time]).
  181statistics(dcgc_count, Count) :- !, system:statistics(clause_garbage_collection, [Count, _, _]).
  182statistics(dcgc_time, Time) :- !, system:statistics(clause_garbage_collection, [_, _, Time]).
  183
  184:- use_module(sicstus, [statistics/2 as sicstus3_statistics]).  185statistics(Keyword, Value) :- sicstus3_statistics(Keyword, Value).
  186
  187% Provide (\)/2 as arithmetic function.  Ideally, we should be able to
  188% bind multiple names to built-in functions.  This is rather slow.  We
  189% could also consider adding \ internally, but not turning it into an
  190% operator.
  191
  192:- arithmetic_function(user:(\)/2).  193
  194user:(\(X,Y,R)) :-
  195	R is xor(X,Y)