[m-rev.] for review: break up std_util (part 1.5)
Julien Fischer
juliensf at cs.mu.OZ.AU
Tue Mar 28 20:00:31 AEDT 2006
There are a few alternatives to the following diff:
(1) Leave things as they are and have the Java implementation of
stores use the mutvars in solutions.m.
(2) Define a separate Mutvar class for use by the Java backend to
implement stores (e.g. mercury.store.Mutvar)
(3) Move the definition of mutvars to private_builtin (or a submodule
of private_builtin).
(4) Do what the following diff does.
Does anyone have any opinions, or alternative ideas, on this?
Julien.
Estimated hours taken: 1.5
Branches: main
Factor out the mutvars used to implement the all-solutions predicates
into their own module. They are also (currently) used by the Java
backend to implement stores.
library/solutions.m:
Delete the definition of the mutvar type and supporting predicates
from this module.
library/mutvar.m:
New module. This module provides the mutvar type that currently
lives in solutions.m (and formerly lived in std_util.m).
XXX we should eventually make this a private submodule of the
standard library.
library/store.m:
Fix the definition of generic_mutvars for the Java backend. This
has been broken since the change that moved the all-solutions
predicate to solutions.m.
Replace ':' as a module qualifier.
library/library.m:
Add the new module.
compiler/ml_util.m:
mutvars are handled specially in the IL backend.
doc/Mmakefile:
Don't include the mutvar module in the library reference manual.
Index: compiler/ml_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_util.m,v
retrieving revision 1.42
diff -u -r1.42 ml_util.m
--- compiler/ml_util.m 24 Mar 2006 04:40:46 -0000 1.42
+++ compiler/ml_util.m 28 Mar 2006 07:02:52 -0000
@@ -622,6 +622,7 @@
mercury_private_builtin_module(PrivateBuiltin),
RttiImplementation = unqualified("rtti_implementation"),
StdUtil = unqualified("std_util"),
+ MutVar = unqualified("mutvar"),
TypeDesc = unqualified("type_desc"),
( TypeName = qualified(PrivateBuiltin, "base_typeclass_info")
; TypeName = qualified(PrivateBuiltin, "type_ctor_info")
@@ -647,7 +648,7 @@
% for the moment.
; TypeName = qualified(Builtin, "comparison_result")
; TypeName = qualified(StdUtil, "univ")
- ; TypeName = qualified(StdUtil, "mutvar")
+ ; TypeName = qualified(MutVar, "mutvar")
).
%-----------------------------------------------------------------------------%
Index: doc/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/Mmakefile,v
retrieving revision 1.39
diff -u -r1.39 Mmakefile
--- doc/Mmakefile 16 Aug 2005 15:51:29 -0000 1.39
+++ doc/Mmakefile 28 Mar 2006 08:39:05 -0000
@@ -259,6 +259,8 @@
;; \
$(LIBRARY_DIR)/term_size_prof_builtin.m) \
;; \
+ $(LIBRARY_DIR)/mutvar.m) \
+ ;; \
*) \
echo "* `basename $$filename .m`::"; \
;; \
@@ -285,6 +287,8 @@
;; \
$(LIBRARY_DIR)/term_size_prof_builtin.m) \
;; \
+ $(LIBRARY_DIR)/mutvar.m) \
+ ;; \
*) \
file="`basename $$filename .m`"; \
echo "@node $$file"; \
Index: library/library.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/library.m,v
retrieving revision 1.93
diff -u -r1.93 library.m
--- library/library.m 24 Mar 2006 04:40:52 -0000 1.93
+++ library/library.m 28 Mar 2006 06:38:27 -0000
@@ -130,6 +130,7 @@
:- import_module version_types.
% The modules intended for Mercury system implementors.
+:- import_module mutvar.
:- import_module private_builtin.
:- import_module profiling_builtin.
:- import_module rtti_implementation.
@@ -217,6 +218,7 @@
mercury_std_library_module("map").
mercury_std_library_module("math").
mercury_std_library_module("multi_map").
+mercury_std_library_module("mutvar").
mercury_std_library_module("ops").
mercury_std_library_module("parser").
mercury_std_library_module("pprint").
Index: library/mutvar.m
===================================================================
RCS file: library/mutvar.m
diff -N library/mutvar.m
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ library/mutvar.m 28 Mar 2006 06:37:42 -0000
@@ -0,0 +1,187 @@
+%-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+%-----------------------------------------------------------------------------%
+% Copyright (C) 1994-2006 The University of Melbourne.
+% This file may only be copied under the terms of the GNU Library General
+% Public License - see the file COPYING.LIB in the Mercury distribution.
+%-----------------------------------------------------------------------------%
+
+% File: mutvar.m.
+
+% This module is used in the implementation of all-solutions predicates
+% (solutions.m) and stores (store.m). This module is a private part of the
+% Mercury implementation; user modules should never explicitly import this
+% module. The interface for this module does not get included in the Mercury
+% library reference manual.
+
+% XXX When we move to use submodules in the standard library, we should
+% make this module a private submodule.
+
+%-----------------------------------------------------------------------------%
+
+:- module mutvar.
+:- interface.
+
+ % A non-backtrackably destructively modifiable reference type.
+ %
+:- type mutvar(T).
+
+ % Create a new mutvar given a term for it to reference.
+ %
+:- impure pred new_mutvar(T, mutvar(T)).
+:- mode new_mutvar(in, out) is det.
+:- mode new_mutvar(di, uo) is det.
+
+ % Get the value currently referred to by a reference.
+ %
+:- impure pred get_mutvar(mutvar(T), T) is det.
+:- mode get_mutvar(in, uo) is det. % XXX this is a work-around
+/*
+XXX `ui' modes don't work yet
+:- mode get_mutvar(in, uo) is det.
+:- mode get_mutvar(ui, uo) is det. % unsafe, but we use it safely
+*/
+
+ % Destructively modify a reference to refer to a new object.
+ %
+:- impure pred set_mutvar(mutvar(T), T) is det.
+:- mode set_mutvar(in, in) is det.
+/*
+XXX `ui' modes don't work yet
+:- pred set_mutvar(ui, di) is det.
+*/
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- implementation.
+
+:- pragma inline(new_mutvar/2).
+:- pragma inline(get_mutvar/2).
+:- pragma inline(set_mutvar/2).
+
+%-----------------------------------------------------------------------------%
+%
+% C implementation
+%
+
+ % This type is a builtin type whose operations are implemented in C.
+ %
+:- type mutvar(T)
+ ---> mutvar(private_builtin.ref(T)).
+
+:- pragma foreign_proc("C",
+ new_mutvar(X::in, Ref::out),
+ [will_not_call_mercury, thread_safe],
+"
+ MR_offset_incr_hp_msg(Ref, MR_SIZE_SLOT_SIZE, MR_SIZE_SLOT_SIZE + 1,
+ MR_PROC_LABEL, ""mutvar.mutvar/1"");
+ MR_define_size_slot(0, Ref, 1);
+ * (MR_Word *) Ref = X;
+").
+:- pragma foreign_proc("C",
+ new_mutvar(X::di, Ref::uo),
+ [will_not_call_mercury, thread_safe],
+"
+ MR_offset_incr_hp_msg(Ref, MR_SIZE_SLOT_SIZE, MR_SIZE_SLOT_SIZE + 1,
+ MR_PROC_LABEL, ""mutvar.mutvar/1"");
+ MR_define_size_slot(0, Ref, 1);
+ * (MR_Word *) Ref = X;
+").
+
+:- pragma foreign_proc("C",
+ get_mutvar(Ref::in, X::uo),
+ [will_not_call_mercury, thread_safe],
+"
+ X = * (MR_Word *) Ref;
+").
+
+:- pragma foreign_proc("C",
+ set_mutvar(Ref::in, X::in),
+ [will_not_call_mercury, thread_safe],
+"
+ *(MR_Word *) Ref = X;
+").
+
+%-----------------------------------------------------------------------------%
+%
+% C# implementation
+%
+
+:- pragma foreign_proc("C#",
+ new_mutvar(X::in, Ref::out),
+ [will_not_call_mercury, thread_safe],
+"
+ Ref = new object[1];
+ Ref[0] = X;
+").
+:- pragma foreign_proc("C#",
+ new_mutvar(X::di, Ref::uo),
+ [will_not_call_mercury, thread_safe],
+"
+ Ref = new object[1];
+ Ref[0] = X;
+").
+
+:- pragma foreign_proc("C#",
+ get_mutvar(Ref::in, X::uo),
+ [will_not_call_mercury, thread_safe],
+"
+ X = Ref[0];
+").
+
+:- pragma foreign_proc("C#",
+ set_mutvar(Ref::in, X::in),
+ [will_not_call_mercury, thread_safe],
+"
+ Ref[0] = X;
+").
+
+%-----------------------------------------------------------------------------%
+%
+% Java implementation
+%
+
+:- pragma foreign_code("Java",
+"
+ public static class Mutvar {
+ public Object object;
+
+ public Mutvar(Object init) {
+ object = init;
+ }
+ }
+").
+
+:- pragma foreign_type("Java", mutvar(T), "mercury.mutvar.Mutvar").
+
+:- pragma foreign_proc("Java",
+ new_mutvar(X::in, Ref::out),
+ [will_not_call_mercury, thread_safe],
+"
+ Ref = new mercury.mutvar.Mutvar(X);
+").
+:- pragma foreign_proc("Java",
+ new_mutvar(X::di, Ref::uo),
+ [will_not_call_mercury, thread_safe],
+"
+ Ref = new mercury.mutvar.Mutvar(X);
+").
+
+:- pragma foreign_proc("Java",
+ get_mutvar(Ref::in, X::uo),
+ [will_not_call_mercury, thread_safe],
+"
+ X = Ref.object;
+").
+
+:- pragma foreign_proc("Java",
+ set_mutvar(Ref::in, X::in),
+ [will_not_call_mercury, thread_safe],
+"
+ Ref.object = X;
+").
+
+%-----------------------------------------------------------------------------%
+:- end_module mutvar.
+%-----------------------------------------------------------------------------%
Index: library/solutions.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/solutions.m,v
retrieving revision 1.1
diff -u -r1.1 solutions.m
--- library/solutions.m 24 Mar 2006 04:40:52 -0000 1.1
+++ library/solutions.m 28 Mar 2006 06:39:53 -0000
@@ -166,6 +166,8 @@
:- implementation.
+:- import_module mutvar.
+
%-----------------------------------------------------------------------------%
solutions(Pred, List) :-
@@ -762,148 +764,5 @@
end_all_soln_neg_context_no_more.
%-----------------------------------------------------------------------------%
-
-%%% :- module mutvar.
-%%% :- interface.
-
-% A non-backtrackably destructively modifiable reference type
-:- type mutvar(T).
-
-% Create a new mutvar given a term for it to reference.
-:- impure pred new_mutvar(T, mutvar(T)).
-:- mode new_mutvar(in, out) is det.
-:- mode new_mutvar(di, uo) is det.
-
-% Get the value currently referred to by a reference.
-:- impure pred get_mutvar(mutvar(T), T) is det.
-:- mode get_mutvar(in, uo) is det. % XXX this is a work-around
-/*
-XXX `ui' modes don't work yet
-:- mode get_mutvar(in, uo) is det.
-:- mode get_mutvar(ui, uo) is det. % unsafe, but we use it safely
-*/
-
-% destructively modify a reference to refer to a new object.
-:- impure pred set_mutvar(mutvar(T), T) is det.
-:- mode set_mutvar(in, in) is det.
-/*
-XXX `ui' modes don't work yet
-:- pred set_mutvar(ui, di) is det.
-*/
-
-%%% :- implementation.
-
-% This type is a builtin-in type whose operations are implemented in C.
-:- type mutvar(T)
- ---> mutvar(private_builtin.ref(T)).
-
-:- pragma inline(new_mutvar/2).
-:- pragma inline(get_mutvar/2).
-:- pragma inline(set_mutvar/2).
-
-:- pragma foreign_proc("C",
- new_mutvar(X::in, Ref::out),
- [will_not_call_mercury, thread_safe],
-"
- MR_offset_incr_hp_msg(Ref, MR_SIZE_SLOT_SIZE, MR_SIZE_SLOT_SIZE + 1,
- MR_PROC_LABEL, ""solutions.mutvar/1"");
- MR_define_size_slot(0, Ref, 1);
- * (MR_Word *) Ref = X;
-").
-:- pragma foreign_proc("C",
- new_mutvar(X::di, Ref::uo),
- [will_not_call_mercury, thread_safe],
-"
- MR_offset_incr_hp_msg(Ref, MR_SIZE_SLOT_SIZE, MR_SIZE_SLOT_SIZE + 1,
- MR_PROC_LABEL, ""solutions.mutvar/1"");
- MR_define_size_slot(0, Ref, 1);
- * (MR_Word *) Ref = X;
-").
-
-:- pragma foreign_proc("C",
- get_mutvar(Ref::in, X::uo),
- [will_not_call_mercury, thread_safe],
-"
- X = * (MR_Word *) Ref;
-").
-
-:- pragma foreign_proc("C",
- set_mutvar(Ref::in, X::in),
- [will_not_call_mercury, thread_safe],
-"
- *(MR_Word *) Ref = X;
-").
-
-:- pragma foreign_proc("C#",
- new_mutvar(X::in, Ref::out),
- [will_not_call_mercury, thread_safe],
-"
- Ref = new object[1];
- Ref[0] = X;
-").
-:- pragma foreign_proc("C#",
- new_mutvar(X::di, Ref::uo),
- [will_not_call_mercury, thread_safe],
-"
- Ref = new object[1];
- Ref[0] = X;
-").
-
-:- pragma foreign_proc("C#",
- get_mutvar(Ref::in, X::uo),
- [will_not_call_mercury, thread_safe],
-"
- X = Ref[0];
-").
-
-:- pragma foreign_proc("C#",
- set_mutvar(Ref::in, X::in),
- [will_not_call_mercury, thread_safe],
-"
- Ref[0] = X;
-").
-
-:- pragma foreign_code("Java",
-"
- public static class Mutvar {
- public Object object;
-
- public Mutvar(Object init) {
- object = init;
- }
- }
-").
-:- pragma foreign_type(java, mutvar(T), "mercury.solutions.Mutvar").
-
-:- pragma foreign_proc("Java",
- new_mutvar(X::in, Ref::out),
- [will_not_call_mercury, thread_safe],
-"
- Ref = new mercury.solutions.Mutvar(X);
-").
-:- pragma foreign_proc("Java",
- new_mutvar(X::di, Ref::uo),
- [will_not_call_mercury, thread_safe],
-"
- Ref = new mercury.solutions.Mutvar(X);
-").
-
-:- pragma foreign_proc("Java",
- get_mutvar(Ref::in, X::uo),
- [will_not_call_mercury, thread_safe],
-"
- X = Ref.object;
-").
-
-:- pragma foreign_proc("Java",
- set_mutvar(Ref::in, X::in),
- [will_not_call_mercury, thread_safe],
-"
- Ref.object = X;
-").
-
-%%% end_module mutvar.
-
-%-----------------------------------------------------------------------------%
:- end_module solutions.
%-----------------------------------------------------------------------------%
Index: library/store.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/store.m,v
retrieving revision 1.55
diff -u -r1.55 store.m
--- library/store.m 22 Mar 2006 02:56:19 -0000 1.55
+++ library/store.m 28 Mar 2006 06:51:14 -0000
@@ -311,7 +311,7 @@
[will_not_call_mercury, promise_pure, will_not_modify_trail],
"
MR_offset_incr_hp_msg(Mutvar, MR_SIZE_SLOT_SIZE, MR_SIZE_SLOT_SIZE + 1,
- MR_PROC_LABEL, ""store:mutvar/2"");
+ MR_PROC_LABEL, ""store.mutvar/2"");
MR_define_size_slot(0, Mutvar, 1);
* (MR_Word *) Mutvar = Val;
S = S0;
@@ -333,13 +333,13 @@
S = S0;
").
-:- pragma foreign_type(java, generic_mutvar(T, S), "mercury.std_util.Mutvar").
+:- pragma foreign_type(java, generic_mutvar(T, S), "mercury.mutvar.Mutvar").
:- pragma foreign_proc("Java",
new_mutvar(Val::in, Mutvar::out, _S0::di, _S::uo),
[will_not_call_mercury, promise_pure],
"
- Mutvar = new mercury.std_util.Mutvar(Val);
+ Mutvar = new mercury.mutvar.Mutvar(Val);
").
:- pragma foreign_proc("Java",
@@ -368,7 +368,7 @@
[will_not_call_mercury, promise_pure, will_not_modify_trail],
"
MR_offset_incr_hp_msg(Mutvar, MR_SIZE_SLOT_SIZE, MR_SIZE_SLOT_SIZE + 1,
- MR_PROC_LABEL, ""store:mutvar/2"");
+ MR_PROC_LABEL, ""store.mutvar/2"");
MR_define_size_slot(0, Mutvar, 1);
S = S0;
").
@@ -377,7 +377,7 @@
unsafe_new_uninitialized_mutvar(Mutvar::out, _S0::di, _S::uo),
[will_not_call_mercury, promise_pure],
"
- Mutvar = new mercury.std_util.Mutvar(null);
+ Mutvar = new mercury.mutvar.Mutvar(null);
").
store.new_cyclic_mutvar(Func, MutVar, !Store) :-
--------------------------------------------------------------------------
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