View source with raw comments or as raw
    1/*  Part of SWI-Prolog
    2
    3    Author:        Jan Wielemaker
    4    E-mail:        J.Wielemaker@vu.nl
    5    WWW:           http://www.swi-prolog.org
    6    Copyright (c)  2019-2020, VU University Amsterdam
    7                              CWI, Amsterdam
    8    All rights reserved.
    9
   10    Redistribution and use in source and binary forms, with or without
   11    modification, are permitted provided that the following conditions
   12    are met:
   13
   14    1. Redistributions of source code must retain the above copyright
   15       notice, this list of conditions and the following disclaimer.
   16
   17    2. Redistributions in binary form must reproduce the above copyright
   18       notice, this list of conditions and the following disclaimer in
   19       the documentation and/or other materials provided with the
   20       distribution.
   21
   22    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   23    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   24    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
   25    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
   26    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   27    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   28    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   29    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   30    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   31    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
   32    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   33    POSSIBILITY OF SUCH DAMAGE.
   34*/
   35
   36:- module(machine,
   37          [ gc_heap/0,
   38            trimcore/0,
   39
   40            abolish_table_info/0,
   41            close_open_tables/1,          % ?
   42
   43            str_cat/3,
   44
   45            parsort/4,                    % +List, +Spec, +Dupl, -Sorted
   46
   47            term_type/2,
   48
   49            xsb_expand_file_name/2,       % +File, -Expanded
   50            expand_filename_no_prepend/2, % FileName, -ExpandedName
   51            parse_filename/4,             % +FileName, -Dir, -Base, -Extension
   52
   53            conset/2,                     % +Term, +Value
   54            conget/2,                     % +Term, -Value
   55
   56            slash/1,                      % -OSDirSlash
   57
   58            xsb_backtrace/1,              % -Backtrace
   59            xwam_state/2                  % +Id, -Value
   60          ]).   61:- use_module(library(debug)).   62:- use_module(library(error)).   63:- use_module(library(prolog_stack)).
 gc_heap
Explicitly invoke heap garbage collection.
   69gc_heap :-
   70    garbage_collect.
 trimcore
Trim the stacks.
   76trimcore :-
   77    trim_stacks.
 abolish_table_info
Undocumented in the XSB manual.
   83abolish_table_info.
 close_open_tables(?Arg)
Undocumented in the XSB manual. Tables are always closed on exceptions, so it is unclear what this should do?
   90close_open_tables(_).
 str_cat(+Atom1, +Atom2, -Atom3)
   94str_cat(A, B, AB) :-
   95    must_be(atom, A),
   96    must_be(atom, B),
   97    atom_concat(A, B, AB).
 parsort(+List, +Order, +Dupl, -Sorted) is det
parsort/4 is a very general sorting routine.
  103parsort(_List, Spec, _Dupl, _Sorted) :-
  104    var(Spec),
  105    !,
  106    uninstantiation_error(Spec).
  107parsort(_List, _Spec, Dupl, _Sorted) :-
  108    var(Dupl),
  109    !,
  110    uninstantiation_error(Dupl).
  111parsort(List, asc,  0, Sorted) :- !, sort(0, @=<, List, Sorted).
  112parsort(List, asc,  _, Sorted) :- !, sort(0, @<,  List, Sorted).
  113parsort(List, [],   0, Sorted) :- !, sort(0, @=<, List, Sorted).
  114parsort(List, [],   _, Sorted) :- !, sort(0, @<,  List, Sorted).
  115parsort(List, desc, 0, Sorted) :- !, sort(0, @>=, List, Sorted).
  116parsort(List, desc, _, Sorted) :- !, sort(0, @>,  List, Sorted).
  117parsort(List, SortSpec, Dupl, Sorted) :-
  118    must_be(list, SortSpec),
  119    reverse(SortSpec, Rev),
  120    parsort_(Rev, Dupl, List, Sorted).
  121
  122parsort_([], _, List, List).
  123parsort_([H|T], Dupl, List0, List) :-
  124    parsort_1(H, Dupl, List0, List1),
  125    parsort_(T, Dupl, List1, List).
  126
  127parsort_1(asc(I),  0, List, Sorted) :- !, sort(I, @=<, List, Sorted).
  128parsort_1(asc(I),  _, List, Sorted) :- !, sort(I, @<,  List, Sorted).
  129parsort_1(desc(I), 0, List, Sorted) :- !, sort(I, @>=, List, Sorted).
  130parsort_1(desc(I), _, List, Sorted) :- !, sort(I, @>,  List, Sorted).
  131parsort_1(Spec,  _, _, _) :-
  132    domain_error(parsort_spec, Spec).
 term_type(+Term, -Type:integer)
Emulation of internal XSB predicate
  138term_type(Term, Type) :-
  139    (   atom(Term)
  140    ->  Type = 5
  141    ;   compound(Term)
  142    ->  (   Term = [_|_]
  143        ->  Type = 3
  144        ;   Type = 1
  145        )
  146    ;   integer(Term)
  147    ->  Type = 2
  148    ;   float(Term)
  149    ->  Type = 6
  150    ;   var(Term)
  151    ->  Type = 0
  152    ;   assertion(fail)
  153    ).
  154
  155		 /*******************************
  156		 *              FILES		*
  157		 *******************************/
 xsb_expand_file_name(+File, -Expanded)
  163xsb_expand_file_name(File, Expanded) :-
  164    absolute_file_name(File, Expanded, [expand(true)]).
 expand_filename_no_prepend(+FileName, -ExpandedName)
  170expand_filename_no_prepend(File, Expanded) :-
  171    expand_file_name(File, Absolute),
  172    working_directory(Dir0, Dir0),
  173    ensure_slash(Dir0, Dir),
  174    (   atom_concat(Dir, Ex0, Absolute)
  175    ->  Expanded = Ex0
  176    ;   Expanded = Absolute
  177    ).
 parse_filename(+FileName, -Dir, -Base, -Extension)
  183parse_filename(FileName, Dir, Base, Extension) :-
  184    sub_atom(FileName, 0, _, _, '~'),
  185    !,
  186    expand_file_name(FileName, Absolute),
  187    parse_filename_2(Absolute, Dir, Base, Extension).
  188parse_filename(FileName, Dir, Base, Extension) :-
  189    parse_filename_2(FileName, Dir, Base, Extension).
  190
  191parse_filename_2(FileName, Dir, Base, Extension) :-
  192    file_directory_name(FileName, Dir0),
  193    (   Dir0 == '.'
  194    ->  Dir = ''
  195    ;   ensure_slash(Dir0, Dir)
  196    ),
  197    file_base_name(FileName, File),
  198    file_name_extension(Base, Extension, File).
  199
  200ensure_slash(Dir, DirS) :-
  201    sub_atom(Dir, _, _, 0, '/'),
  202    !,
  203    DirS = Dir.
  204ensure_slash(Dir, DirS) :-
  205    atom_concat(Dir, '/', DirS).
 conset(+Term, +Value) is det
 conget(+Term, -Value) is det
Cheap set/get integer value associated with an atom. Seems this is a subset of what SWI-Prolog flags can do.
  214conset(Name, Value) :-
  215    set_flag(Name, Value).
  216
  217conget(Name, Value) :-
  218    get_flag(Name, Value).
 slash(-Slash)
Return the directory separator for the platform
  224slash(Slash) :-
  225    (   current_prolog_flag(windows, true)
  226    ->  Slash = '\\'
  227    ;   Slash = '/'
  228    ).
 xsb_backtrace(-Backtrace)
Upon success Backtrace is bound to a structure indicating the forward continuations for a point of execution. This structure should be treated as opaque.
  236xsb_backtrace(Backtrace) :-
  237    get_prolog_backtrace(25, Backtrace).
 xwam_state(+Id, -Value)
Low-level query. Used by the XSB test suite.
  243xwam_state(2, DelayReg) :-
  244    !,
  245    (   '$tbl_delay_list'([_|_])
  246    ->  DelayReg = 1
  247    ;   DelayReg = 0
  248    ).
  249xwam_state(Id, _Value) :-
  250    domain_error(xwam_state, Id)