[m-rev.] Add `:- mutable' declaration to the language.

Julien Fischer juliensf at cs.mu.OZ.AU
Thu Sep 1 17:06:15 AEST 2005




On Thu, 1 Sep 2005, Ralph Becket wrote:

> 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],
> "MR_trail_current_value(&mutable_variable_x); X = x;").
>
> :- pragma foreign_proc("C", set_x(X::in(ground)), [thread_safe],
> "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.
>
Don't you also need to update the list of operators in library/ops.m
and in the reference manual?

Julien.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list