[m-rev.] Fixed extras/trailed_update to use solver types
Ralph Becket
rafe at cs.mu.OZ.AU
Tue Mar 1 16:38:41 AEDT 2005
Estimated hours taken: 0.25
Branches: main, version-0_12-branch
extras/trailed_update/tr_store.m:
Change mutvar and ref to generic_mutvar and generic_ref
throughout.
extras/trailed_update/var.m:
Change the definition of var/1 to use the new solver types
interface.
Index: extras/trailed_update/tr_store.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/trailed_update/tr_store.m,v
retrieving revision 1.12
diff -u -r1.12 tr_store.m
--- extras/trailed_update/tr_store.m 31 Jan 2003 03:32:40 -0000 1.12
+++ extras/trailed_update/tr_store.m 1 Mar 2005 05:33:52 -0000
@@ -15,7 +15,7 @@
% so that updates can be undone on backtracking.
%
% See store.m for documentation, and for the definition of the types
-% `store', `mutvar', and `ref'.
+% `store', `generic_mutvar', and `generic_ref'.
%
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
@@ -31,22 +31,23 @@
% create a new mutable variable,
% initialized with the specified value
-:- pred tr_store__new_mutvar(T, mutvar(T, S), store(S), store(S)).
+:- pred tr_store__new_mutvar(T, generic_mutvar(T, S), store(S), store(S)).
:- mode tr_store__new_mutvar(in, out, mdi, muo) is det.
% copy_mutvar(Mutvar, Copy, S0, S)
% is equivalent to
% get_mutvar(Mutvar, Value, S0, S1),
% new_mutvar(Value, Copy, S1, S )
-:- pred tr_store__copy_mutvar(mutvar(T, S), mutvar(T, S), store(S), store(S)).
+:- pred tr_store__copy_mutvar(generic_mutvar(T, S), generic_mutvar(T, S),
+ store(S), store(S)).
:- mode tr_store__copy_mutvar(in, out, mdi, muo) is det.
% lookup the value stored in a given mutable variable
-:- pred tr_store__get_mutvar(mutvar(T, S), T, store(S), store(S)).
+:- pred tr_store__get_mutvar(generic_mutvar(T, S), T, store(S), store(S)).
:- mode tr_store__get_mutvar(in, out, mdi, muo) is det.
% replace the value stored in a given mutable variable
-:- pred tr_store__set_mutvar(mutvar(T, S), T, store(S), store(S)).
+:- pred tr_store__set_mutvar(generic_mutvar(T, S), T, store(S), store(S)).
:- mode tr_store__set_mutvar(in, in, mdi, muo) is det.
%-----------------------------------------------------------------------------%
@@ -62,13 +63,14 @@
% of the representation of that value.
% It does however allocate one cell to hold the reference;
% you can use new_arg_ref to avoid that.)
-:- pred tr_store__new_ref(T, ref(T, S), store(S), store(S)).
+:- pred tr_store__new_ref(T, generic_ref(T, S), store(S), store(S)).
:- mode tr_store__new_ref(mdi, out, mdi, muo) is det.
% ref_functor(Ref, Functor, Arity):
% Given a reference to a term, return the functor and arity
% of that term.
-:- pred tr_store__ref_functor(ref(T, S), string, int, store(S), store(S)).
+:- pred tr_store__ref_functor(generic_ref(T, S), string, int,
+ store(S), store(S)).
:- mode tr_store__ref_functor(in, out, out, mdi, muo) is det.
% arg_ref(Ref, ArgNum, ArgRef):
@@ -78,7 +80,8 @@
% (argument numbers start from zero).
% It is an error if the argument number is out of range,
% or if the argument reference has the wrong type.
-:- pred tr_store__arg_ref(ref(T, S), int, ref(ArgT, S), store(S), store(S)).
+:- pred tr_store__arg_ref(generic_ref(T, S), int, generic_ref(ArgT, S),
+ store(S), store(S)).
:- mode tr_store__arg_ref(in, in, out, mdi, muo) is det.
% new_arg_ref(Val, ArgNum, ArgRef):
@@ -87,7 +90,8 @@
% except that it is more efficient.
% It is an error if the argument number is out of range,
% or if the argument reference has the wrong type.
-:- pred tr_store__new_arg_ref(T, int, ref(ArgT, S), store(S), store(S)).
+:- pred tr_store__new_arg_ref(T, int, generic_ref(ArgT, S),
+ store(S), store(S)).
:- mode tr_store__new_arg_ref(mdi, in, out, mdi, muo) is det.
% set_ref(Ref, ValueRef):
@@ -96,7 +100,8 @@
% a reference to another term (ValueRef),
% update the store so that the term referred to by Ref
% is replaced with the term referenced by ValueRef.
-:- pred tr_store__set_ref(ref(T, S), ref(T, S), store(S), store(S)).
+:- pred tr_store__set_ref(generic_ref(T, S), generic_ref(T, S),
+ store(S), store(S)).
:- mode tr_store__set_ref(in, in, mdi, muo) is det.
% set_ref_value(Ref, Value):
@@ -104,19 +109,19 @@
% Given a reference to a term (Ref), and a value (Value),
% update the store so that the term referred to by Ref
% is replaced with Value.
-:- pred tr_store__set_ref_value(ref(T, S), T, store(S), store(S)).
+:- pred tr_store__set_ref_value(generic_ref(T, S), T, store(S), store(S)).
:- mode tr_store__set_ref_value(in, mdi, mdi, muo) is det.
% Given a reference to a term, return that term.
% Note that this requires making a copy, so this pred may
% be inefficient if used to return large terms; it
% is most efficient with atomic terms.
-:- pred tr_store__copy_ref_value(ref(T, S), T, store(S), store(S)).
+:- pred tr_store__copy_ref_value(generic_ref(T, S), T, store(S), store(S)).
:- mode tr_store__copy_ref_value(in, uo, mdi, muo) is det.
% Same as above, but without making a copy.
% Destroys the store.
-:- pred tr_store__extract_ref_value(store(S), ref(T, S), T).
+:- pred tr_store__extract_ref_value(store(S), generic_ref(T, S), T).
:- mode tr_store__extract_ref_value(mdi, in, out) is det.
%-----------------------------------------------------------------------------%
@@ -141,11 +146,12 @@
% or if the argument is a `no_tag' type,
% then the behaviour is undefined, and probably harmful.
-:- pred tr_store__unsafe_arg_ref(ref(T, S), int, ref(ArgT, S),
+:- pred tr_store__unsafe_arg_ref(generic_ref(T, S), int, generic_ref(ArgT, S),
store(S), store(S)).
:- mode tr_store__unsafe_arg_ref(in, in, out, mdi, muo) is det.
-:- pred tr_store__unsafe_new_arg_ref(T, int, ref(ArgT, S), store(S), store(S)).
+:- pred tr_store__unsafe_new_arg_ref(T, int, generic_ref(ArgT, S),
+ store(S), store(S)).
:- mode tr_store__unsafe_new_arg_ref(mdi, in, out, mdi, muo) is det.
%-----------------------------------------------------------------------------%
@@ -199,7 +205,7 @@
% refers to, without making a copy; it is unsafe because
% the store could later be modified, changing the returned
% value.
-:- pred tr_store__unsafe_ref_value(ref(T, S), T, store(S), store(S)).
+:- pred tr_store__unsafe_ref_value(generic_ref(T, S), T, store(S), store(S)).
:- mode tr_store__unsafe_ref_value(in, uo, mdi, muo) is det.
:- pragma c_code(unsafe_ref_value(Ref::in, Val::uo, S0::mdi, S::muo),
will_not_call_mercury,
@@ -243,7 +249,8 @@
S = S0;
}").
-:- pragma c_code(new_arg_ref(Val::mdi, ArgNum::in, ArgRef::out, S0::mdi, S::muo),
+:- pragma c_code(new_arg_ref(Val::mdi, ArgNum::in, ArgRef::out,
+ S0::mdi, S::muo),
will_not_call_mercury,
"{
MR_TypeInfo arg_type_info;
@@ -306,7 +313,8 @@
%-----------------------------------------------------------------------------%
-:- pragma c_code(unsafe_arg_ref(Ref::in, Arg::in, ArgRef::out, S0::mdi, S::muo),
+:- pragma c_code(unsafe_arg_ref(Ref::in, Arg::in, ArgRef::out,
+ S0::mdi, S::muo),
will_not_call_mercury,
"{
/* unsafe - does not check type & arity, won't handle no_tag types */
Index: extras/trailed_update/var.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/trailed_update/var.m,v
retrieving revision 1.22
diff -u -r1.22 var.m
--- extras/trailed_update/var.m 25 Jul 2003 02:27:34 -0000 1.22
+++ extras/trailed_update/var.m 1 Mar 2005 05:30:12 -0000
@@ -162,12 +162,14 @@
%
%---------------------------------------------------------------------------%
- % We use '$VAR'/1 as the name for the functor for variable
- % representations simply because that name is "traditional".
% (Note that the representation can be printed out, if you call
% io__write(Var), so this is not entirely hidden from the user.)
-:- solver type var(T) ---> '$VAR'(var_rep(T))
- where equality is (==).
+:- solver type var(T)
+ where representation is var_rep(T),
+ initialisation is init,
+ ground is ground,
+ any is any,
+ equality is (==).
:- type var_rep(T)
---> free
--------------------------------------------------------------------------
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