mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-19 03:13:40 +00:00
tests/invalid/*.{m,err_exp}:
tests/misc_tests/*.m:
tests/mmc_make/*.m:
tests/par_conj/*.m:
tests/purity/*.m:
tests/stm/*.m:
tests/string_format/*.m:
tests/structure_reuse/*.m:
tests/submodules/*.m:
tests/tabling/*.m:
tests/term/*.m:
tests/trailing/*.m:
tests/typeclasses/*.m:
tests/valid/*.m:
tests/warnings/*.{m,exp}:
Make these tests use four-space indentation, and ensure that
each module is imported on its own line. (I intend to use the latter
to figure out which subdirectories' tests can be executed in parallel.)
These changes usually move code to different lines. For the tests
that check compiler error messages, expect the new line numbers.
browser/cterm.m:
browser/tree234_cc.m:
Import only one module per line.
tests/hard_coded/boyer.m:
Fix something I missed.
88 lines
2.1 KiB
Mathematica
88 lines
2.1 KiB
Mathematica
% Test that the state variable transformation works on an atomic goal that
|
|
% doesn't mention the inner state variable (e.g. try_put_mvar).
|
|
|
|
:- module atomic_mvar.
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is cc_multi.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module bool.
|
|
:- import_module maybe.
|
|
:- import_module stm_builtin.
|
|
|
|
:- type mvar(T)
|
|
---> mvar(
|
|
stm_var(maybe(T))
|
|
).
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
main(!IO) :-
|
|
new_mvar(MVar, !IO),
|
|
atomic [outer(!IO), inner(!STM)] (
|
|
put_mvar(MVar, "one", !STM)
|
|
),
|
|
atomic [outer(!IO), inner(!STM)] (
|
|
try_put_mvar(MVar, "two", Success, !STM)
|
|
),
|
|
io.write(Success, !IO),
|
|
io.nl(!IO).
|
|
|
|
:- pred new_mvar(mvar(T)::out, io::di, io::uo) is det.
|
|
|
|
new_mvar(mvar(TVar), !IO) :-
|
|
new_stm_var(no, TVar, !IO).
|
|
|
|
:- pred take_mvar(mvar(T)::in, T::out, stm::di, stm::uo) is det.
|
|
|
|
take_mvar(mvar(TVar), T, !STM) :-
|
|
read_stm_var(TVar, Maybe, !STM),
|
|
(
|
|
Maybe = yes(T),
|
|
write_stm_var(TVar, no, !STM)
|
|
;
|
|
Maybe = no,
|
|
retry(!.STM)
|
|
).
|
|
|
|
:- pred put_mvar(mvar(T)::in, T::in, stm::di, stm::uo) is det.
|
|
|
|
put_mvar(mvar(TVar), T, !STM) :-
|
|
read_stm_var(TVar, Maybe, !STM),
|
|
(
|
|
Maybe = yes(_),
|
|
retry(!.STM)
|
|
;
|
|
Maybe = no,
|
|
write_stm_var(TVar, yes(T), !STM)
|
|
).
|
|
|
|
:- pred try_put_mvar(mvar(T)::in, T::in, bool::out, stm::di, stm::uo) is cc_multi.
|
|
|
|
try_put_mvar(MVar, T, Success, !STM) :-
|
|
atomic [outer(!STM), inner(!STM1)] (
|
|
put_mvar(MVar, T, !STM1),
|
|
Success = yes
|
|
or_else
|
|
% !STM1 not mentioned.
|
|
Success = no
|
|
).
|
|
|
|
:- pred nonsense(io::di, io::uo) is det.
|
|
|
|
nonsense(!IO) :-
|
|
atomic [outer(!IO), inner(!STM)] (
|
|
% !STM not mentioned
|
|
true
|
|
).
|
|
|
|
%---------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=8 sts=4 sw=4 et
|