mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-21 12:23:44 +00:00
extras/curs/curs.m:
extras/curs/curs.panel.m:
Make panel a separate submodule of curs, not a nested submodule.
extras/base64/base64.m:
extras/curses/mcurses.basics.m:
extras/curses/mcurses.m:
extras/curses/mcurses.misc.m:
extras/curses/mcurses.user.m:
extras/gator/evolve.m:
extras/gator/genotype.m:
extras/gator/phenotype.m:
extras/gator/tausworthe3.m:
extras/monte/dots.m:
extras/monte/geom.m:
extras/monte/hg.m:
extras/monte/monte.m:
extras/monte/rnd.m:
extras/moose/grammar.m:
extras/moose/moose.m:
extras/mopenssl/mopenssl.m:
extras/net/echo.m:
extras/net/errno.m:
extras/net/getaddrinfo.m:
extras/net/net.m:
extras/net/netdb.m:
extras/net/sockets.m:
extras/net/streams.m:
extras/net/tcp.m:
extras/net/test_lookups.m:
extras/net/types.m:
extras/odbc/odbc.m:
extras/odbc/odbc_test.m:
extras/references/README:
extras/references/reference.m:
extras/references/scoped_update.m:
extras/solver_types/library/any.m:
extras/solver_types/library/any_array.m:
extras/solver_types/library/any_assoc_list.m:
extras/solver_types/library/any_list.m:
extras/solver_types/library/any_map.m:
extras/solver_types/library/any_tree234.m:
extras/solver_types/library/any_util.m:
extras/trail/trail.m:
extras/trailed_update/samples/interpreter.m:
extras/trailed_update/samples/vqueens.m:
extras/trailed_update/tests/var_test.m:
extras/trailed_update/tr_array.m:
extras/trailed_update/tr_store.m:
extras/trailed_update/trailed_update.m:
extras/trailed_update/unsafe.m:
extras/trailed_update/var.m:
Bring programming style up to date.
94 lines
3.3 KiB
Mathematica
94 lines
3.3 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
|
|
%---------------------------------------------------------------------------%
|
|
% Copyright (C) 1997, 2004-2006 The University of Melbourne.
|
|
% Copyright (C) 2018 The Mercury team.
|
|
% This file is distributed under the terms specified in COPYING.LIB.
|
|
%---------------------------------------------------------------------------%
|
|
%
|
|
% File: unsafe.m.
|
|
% Author: fjh.
|
|
% Stability: low.
|
|
%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
% WARNING: the procedures defined in this module are non-logical.
|
|
% They may have side effects, they may violate type safety,
|
|
% they may interfere with certain memory management strategies,
|
|
% and in general they may do lots of nasty things.
|
|
% They may not work with future release of the Mercury compiler,
|
|
% or with other Mercury implementations.
|
|
% Use only as a last resort, and only with great care!
|
|
%
|
|
% You have been warned.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module unsafe.
|
|
:- interface.
|
|
:- import_module io.
|
|
|
|
% unsafe_perform_io/1 performs I/O, in an unsafe manner.
|
|
% It can be used to call a goal that does I/O or has
|
|
% side effects from a context where you do not have an io__state.
|
|
% It can be useful for printf-style debugging.
|
|
% But backtracking over a call to `unsafe_perform_io'
|
|
% can be very dangerous indeed, because with certain
|
|
% memory allocation policies, it can result in dangling pointers.
|
|
% If at all possible, use trace goals instead of this predicate.
|
|
%
|
|
:- impure pred unsafe_perform_io(pred(io__state, io__state)).
|
|
:- mode unsafe_perform_io(pred(di, uo) is det) is det.
|
|
:- mode unsafe_perform_io(pred(di, uo) is cc_multi) is det.
|
|
|
|
% The function unsafe_promise_ground/1 can be used to assert to the
|
|
% compiler that a particular value of inst `any' is in fact ground.
|
|
% The assertion is *not* checked. If it is false, all hell may break out.
|
|
%
|
|
:- func unsafe_promise_ground(T::in(any)) = (T::out) is det.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- pragma foreign_proc("C",
|
|
unsafe_promise_ground(X::in(any)) = (Y::out),
|
|
[will_not_call_mercury, promise_pure],
|
|
"
|
|
Y = X;
|
|
").
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- pragma foreign_proc("C",
|
|
unsafe_perform_io(P::(pred(di, uo) is det)),
|
|
[may_call_mercury],
|
|
"
|
|
call_io_pred_det(P);
|
|
").
|
|
|
|
:- pragma foreign_proc("C",
|
|
unsafe_perform_io(P::(pred(di, uo) is cc_multi)),
|
|
[may_call_mercury],
|
|
"
|
|
call_io_pred_cc_multi(P);
|
|
").
|
|
|
|
:- pred call_io_pred(pred(io, io), io, io).
|
|
:- mode call_io_pred(pred(di, uo) is det, di, uo) is det.
|
|
:- mode call_io_pred(pred(di, uo) is cc_multi, di, uo) is cc_multi.
|
|
|
|
:- pragma foreign_export("C",
|
|
call_io_pred(pred(di, uo) is det, di, uo),
|
|
"call_io_pred_det").
|
|
:- pragma foreign_export("C",
|
|
call_io_pred(pred(di, uo) is cc_multi, di, uo),
|
|
"call_io_pred_cc_multi").
|
|
|
|
call_io_pred(P, !IO) :- P(!IO).
|
|
|
|
%---------------------------------------------------------------------------%
|