Commit Graph

2 Commits

Author SHA1 Message Date
Peter Wang
d3dc779b89 Add some thread-local mutables to these test cases.
Estimated hours taken: 0
Branches: main

tests/hard_coded/mutable_decl.exp:
tests/hard_coded/mutable_decl.m:
tests/hard_coded/pure_mutable.exp:
tests/hard_coded/pure_mutable.m:
tests/invalid/bad_mutable.err_exp:
tests/invalid/bad_mutable.m:
	Add some thread-local mutables to these test cases.
	(Forgot to commit them earlier.)
2007-01-15 02:24:28 +00:00
Ralph Becket
da2984c507 Add `:- mutable' directives to the language, providing modules with private
Estimated hours taken: 24
Branches: main

Add `:- mutable' directives to the language, providing modules with private
mutable variables.  A directives

:- mutable(x, int, 0, ground, [thread_safe]).

leads to the compiler generating the following:

:- semipure pred get_x(int::out(ground)) is det.
:- impure   pred set_x(int::in(ground)) is det.
:-          pred initialise_mutable_x(io::di, io::uo) is det.
:- initialise initialise_mutable_x/2.

initialise_mutable_x(!IO) :-
	promise_pure(
		impure set_x(0)
	).

:- pragma foreign_decl("C", "MR_Word mutable_variable_x;").

:- pragma foreign_proc("C", get_x(X::out(ground)),
[thread_safe, promise_semipure],
"MR_trail_current_value(&mutable_variable_x); X = mutable_variable_x;").

:- pragma foreign_proc("C", set_x(X::in(ground)),
[thread_safe],
"mutable_variable_x = X;").

Possible attributes for a mutable variable are `thread_safe' and
`untrailed'.



NEWS:
	Mention the new language feature.

compiler/make_hlds_passes.m:
	Handle the new mutable/5 item.

	Pass 1 expands a mutable directives into the pred
	declaration items.

	Pass 2 expands a mutable directives into the initialise
	and foreign_decl declaration items.

	Pass 3 expands a mutable directives into the initialise
	declaration and the clauses for the preds.

compiler/mercury_to_mercury.m:
compiler/mercury_qual.m:
compiler/modules.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
	Cover the new mutable/5 item.

compiler/prog_data.m:
	Add a new mutable/5 program item.

compiler/prog_io.m:
	Parse `:- mutable' directives.

compiler/prog_io_typeclass.m:
compiler/prog_io_util.m:
	Move list_term_to_term_list from prog_io_typeclass to prog_io_util
	(it's a generally useful predicate).

doc/reference_manual.texi:
	Document the new `:- mutable' directive.

tests/hard_coded/Mmakefile:
tests/hard_coded/mutable_decl.m:
tests/hard_coded/mutable_decl.exp:
	Added a test case that only runs in trailing grades.
2005-09-05 02:29:59 +00:00