[m-rev.] for review: namespace changes
Peter Ross
petdr at cs.mu.OZ.AU
Thu May 3 01:36:30 AEST 2001
Hi,
For Tyson to review.
===================================================================
Estimated hours taken: 2
Branches: main
Merge the changes from the dotnet-foreign branch which deal with
namespaces.
compiler/ilasm.m:
compiler/ilds.m:
compiler/mlds_to_il.m:
compiler/mlds_to_mcpp.m:
For the module foo.m, place all the code in a type called
mercury_code in the namespace foo rather than in the type foo and no
namespace. This helps avoid problems where you have a type and a
namespace at the top level with the same name.
library/array.m:
library/builtin.m:
library/private_builtin.m:
library/std_util.m:
Change to using the new convention for namespaces.
Index: compiler/ilasm.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ilasm.m,v
retrieving revision 1.8
diff -u -r1.8 ilasm.m
--- compiler/ilasm.m 2001/04/23 12:24:33 1.8
+++ compiler/ilasm.m 2001/05/02 15:13:00
@@ -318,11 +318,15 @@
ilasm__write_list(Contents, "\n", output_classdecl, Info2, Info),
io__write_string("\n}").
ilasm__output_decl(namespace(DottedName, Contents), Info0, Info) -->
- io__write_string(".namespace "),
- output_dotted_name(DottedName),
- io__write_string(" {\n"),
- output(Contents, Info0, Info),
- io__write_string("}\n").
+ ( { DottedName \= [] } ->
+ io__write_string(".namespace "),
+ output_dotted_name(DottedName),
+ io__write_string(" {\n"),
+ output(Contents, Info0, Info),
+ io__write_string("}\n")
+ ;
+ output(Contents, Info0, Info)
+ ).
ilasm__output_decl(method(MethodHead, MethodDecls), Info0, Info) -->
io__write_string(".method "),
output_methodhead(MethodHead, Info0, Info1),
Index: compiler/ilds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ilds.m,v
retrieving revision 1.3
diff -u -r1.3 ilds.m
--- compiler/ilds.m 2001/04/11 10:17:22 1.3
+++ compiler/ilds.m 2001/05/02 15:13:00
@@ -340,6 +340,10 @@
:- func get_class_namespace(ilds__class_name) = ilds__namespace_qual_name.
+ % Get the non-namespace portion of a class name.
+
+:- func get_class_suffix(ilds__class_name) = ilds__id.
+
% Add an extra identifier to the end of an IL class name, e.g.
% append Foo to [mercury]mercury.runtime to make
% [mercury]mercury.runtime.Foo
@@ -351,6 +355,16 @@
:- import_module error_util.
+get_class_suffix(structured_name(_, FullName)) = SuffixName :-
+ (
+ list__last(FullName, Last)
+ ->
+ SuffixName = Last
+ ;
+ % This class has no name whatsoever.
+ unexpected(this_file, "get_class_namespace: class has no name")
+ ).
+
get_class_namespace(structured_name(_, FullName)) = NamespaceName :-
(
list__last(FullName, Last),
@@ -359,7 +373,7 @@
NamespaceName0 = NamespaceName
;
% This class has no name whatsoever.
- unexpected(this_file, "get_class_namespace: list__drop failed")
+ unexpected(this_file, "get_class_namespace: class has no name")
).
append_class_name(structured_name(Assembly, ClassName), ExtraClass) =
Index: compiler/mlds_to_il.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_il.m,v
retrieving revision 1.21
diff -u -r1.21 mlds_to_il.m
--- compiler/mlds_to_il.m 2001/05/02 11:36:38 1.21
+++ compiler/mlds_to_il.m 2001/05/02 15:13:03
@@ -253,15 +253,21 @@
% The declarations in this class.
MethodDecls = [AllocDoneField, CCtor | ClassDecls],
+ SimpleClassName = get_class_suffix(ClassName),
+ NamespaceName = get_class_namespace(ClassName),
+
% The class that corresponds to this MLDS module.
- MainClass = [class([public], AssemblyName, extends_nothing,
+ MainClass = [class([public], SimpleClassName, extends_nothing,
implements([]), MethodDecls)],
+ MainNamespace = [namespace(NamespaceName, MainClass)],
% A namespace to contain all the other declarations that
- % are created as a result of this MLDS code.
- MainNamespace = [namespace([AssemblyName], OtherDecls)],
+ % are created as a result of this MLDS code (currently
+ % this is not much).
+ OtherNamespace = [namespace([AssemblyName], OtherDecls)],
ILAsm = list__condense(
- [ExternAssemblies, ThisAssembly, MainClass, MainNamespace]).
+ [ExternAssemblies, ThisAssembly, MainNamespace,
+ OtherNamespace]).
%-----------------------------------------------------------------------------
@@ -2183,17 +2189,19 @@
structured_name(AssemblyName, ClassName) :-
SymName = mlds_module_name_to_sym_name(MldsModuleName),
sym_name_to_class_name(SymName, ClassName),
- ( ClassName = [A0 | _] ->
- AssemblyName = A0
+ (
+ ClassName = ["mercury" | _]
+ ->
+ AssemblyName = "mercury"
;
- AssemblyName = ""
+ mlds_to_il__sym_name_to_string(SymName, AssemblyName)
).
:- pred sym_name_to_class_name(sym_name, list(ilds__id)).
:- mode sym_name_to_class_name(in, out) is det.
sym_name_to_class_name(SymName, Ids) :-
sym_name_to_class_name_2(SymName, Ids0),
- list__reverse(Ids0, Ids).
+ list__reverse(["mercury_code" | Ids0], Ids).
:- pred sym_name_to_class_name_2(sym_name, list(ilds__id)).
:- mode sym_name_to_class_name_2(in, out) is det.
Index: compiler/mlds_to_mcpp.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_mcpp.m,v
retrieving revision 1.1
diff -u -r1.1 mlds_to_mcpp.m
--- compiler/mlds_to_mcpp.m 2001/05/02 11:36:39 1.1
+++ compiler/mlds_to_mcpp.m 2001/05/02 15:13:03
@@ -112,7 +112,12 @@
"extern ""C"" int _fltused=0;\n",
"\n"]),
- { Namespace = get_class_namespace(ClassName) },
+ { Namespace0 = get_class_namespace(ClassName) },
+ { list__reverse(Namespace0) = [Head | Tail] ->
+ Namespace = list__reverse([Head ++ "__c_code" | Tail])
+ ;
+ Namespace = Namespace0
+ },
io__write_list(Namespace, "\n",
(pred(N::in, di, uo) is det -->
@@ -123,7 +128,7 @@
ForeignCode),
io__write_strings([
- "\n__gc public class ", ModuleNameStr, "__c_code\n",
+ "\n__gc public class mercury_code",
"{\n",
"public:\n"]),
Index: library/array.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/array.m,v
retrieving revision 1.88
diff -u -r1.88 array.m
--- library/array.m 2001/03/15 07:42:20 1.88
+++ library/array.m 2001/05/02 15:13:11
@@ -533,7 +533,7 @@
static int
do_unify__array_1_0(MR_Word type_info, MR_Box x, MR_Box y)
{
- return mercury::array__c_code::__Unify____array_1_0(
+ return mercury::array__c_code::mercury_code::__Unify____array_1_0(
type_info,
dynamic_cast<MR_Array>(x),
dynamic_cast<MR_Array>(y));
@@ -543,7 +543,7 @@
do_compare__array_1_0(
MR_Word type_info, MR_Word_Ref result, MR_Box x, MR_Box y)
{
- mercury::array__c_code::__Compare____array_1_0(
+ mercury::array__c_code::mercury_code::__Compare____array_1_0(
type_info, result,
dynamic_cast<MR_Array>(x),
dynamic_cast<MR_Array>(y));
Index: library/builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/builtin.m,v
retrieving revision 1.52
diff -u -r1.52 builtin.m
--- library/builtin.m 2001/03/15 07:42:21 1.52
+++ library/builtin.m 2001/05/02 15:13:11
@@ -785,7 +785,7 @@
static int
do_unify__int_0_0(MR_Box x, MR_Box y)
{
- return mercury::builtin__c_code::__Unify____int_0_0(
+ return mercury::builtin__c_code::mercury_code::__Unify____int_0_0(
mercury::runtime::Convert::ToInt32(x),
mercury::runtime::Convert::ToInt32(y));
}
@@ -793,7 +793,7 @@
static int
do_unify__string_0_0(MR_Box x, MR_Box y)
{
- return mercury::builtin__c_code::__Unify____string_0_0(
+ return mercury::builtin__c_code::mercury_code::__Unify____string_0_0(
dynamic_cast<MR_String>(x),
dynamic_cast<MR_String>(y));
}
@@ -801,7 +801,7 @@
static int
do_unify__float_0_0(MR_Box x, MR_Box y)
{
- return mercury::builtin__c_code::__Unify____float_0_0(
+ return mercury::builtin__c_code::mercury_code::__Unify____float_0_0(
mercury::runtime::Convert::ToDouble(x),
mercury::runtime::Convert::ToDouble(y));
}
@@ -809,7 +809,7 @@
static int
do_unify__character_0_0(MR_Box x, MR_Box y)
{
- return mercury::builtin__c_code::__Unify____character_0_0(
+ return mercury::builtin__c_code::mercury_code::__Unify____character_0_0(
mercury::runtime::Convert::ToChar(x),
mercury::runtime::Convert::ToChar(y));
}
@@ -825,7 +825,7 @@
static int
do_unify__c_pointer_0_0(MR_Box x, MR_Box y)
{
- return mercury::builtin__c_code::__Unify____c_pointer_0_0(
+ return mercury::builtin__c_code::mercury_code::__Unify____c_pointer_0_0(
dynamic_cast<MR_Word>(x),
dynamic_cast<MR_Word>(y));
}
@@ -854,7 +854,7 @@
static void
do_compare__int_0_0(MR_Word_Ref result, MR_Box x, MR_Box y)
{
- mercury::builtin__c_code::__Compare____int_0_0(result,
+ mercury::builtin__c_code::mercury_code::__Compare____int_0_0(result,
mercury::runtime::Convert::ToInt32(x),
mercury::runtime::Convert::ToInt32(y));
}
@@ -862,7 +862,7 @@
static void
do_compare__string_0_0(MR_Word_Ref result, MR_Box x, MR_Box y)
{
- mercury::builtin__c_code::__Compare____string_0_0(result,
+ mercury::builtin__c_code::mercury_code::__Compare____string_0_0(result,
dynamic_cast<MR_String>(x),
dynamic_cast<MR_String>(y));
}
@@ -870,7 +870,7 @@
static void
do_compare__float_0_0(MR_Word_Ref result, MR_Box x, MR_Box y)
{
- mercury::builtin__c_code::__Compare____float_0_0(result,
+ mercury::builtin__c_code::mercury_code::__Compare____float_0_0(result,
mercury::runtime::Convert::ToDouble(x),
mercury::runtime::Convert::ToDouble(y));
}
@@ -879,7 +879,7 @@
do_compare__character_0_0(
MR_Word_Ref result, MR_Box x, MR_Box y)
{
- mercury::builtin__c_code::__Compare____character_0_0(
+ mercury::builtin__c_code::mercury_code::__Compare____character_0_0(
result,
mercury::runtime::Convert::ToChar(x),
mercury::runtime::Convert::ToChar(y));
@@ -896,7 +896,7 @@
do_compare__c_pointer_0_0(
MR_Word_Ref result, MR_Box x, MR_Box y)
{
- mercury::builtin__c_code::__Compare____c_pointer_0_0(
+ mercury::builtin__c_code::mercury_code::__Compare____c_pointer_0_0(
result,
dynamic_cast<MR_Word>(x),
dynamic_cast<MR_Word>(y));
Index: library/private_builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/private_builtin.m,v
retrieving revision 1.72
diff -u -r1.72 private_builtin.m
--- library/private_builtin.m 2001/04/10 15:26:35 1.72
+++ library/private_builtin.m 2001/05/02 15:13:12
@@ -643,7 +643,7 @@
do_unify__type_ctor_info_1_0(
MR_Word type_info, MR_Box x, MR_Box y)
{
- return mercury::private_builtin__c_code::__Unify____type_ctor_info_1_0(
+ return mercury::private_builtin__c_code::mercury_code::__Unify____type_ctor_info_1_0(
type_info,
dynamic_cast<MR_Word>(x),
dynamic_cast<MR_Word>(y));
@@ -653,7 +653,7 @@
do_unify__type_info_1_0(
MR_Word type_info, MR_Box x, MR_Box y)
{
- return mercury::private_builtin__c_code::__Unify____type_info_1_0(
+ return mercury::private_builtin__c_code::mercury_code::__Unify____type_info_1_0(
type_info,
dynamic_cast<MR_Word>(x),
dynamic_cast<MR_Word>(y));
@@ -663,7 +663,7 @@
do_unify__typeclass_info_1_0(
MR_Word type_info, MR_Box x, MR_Box y)
{
- return mercury::private_builtin__c_code::__Unify____typeclass_info_1_0(
+ return mercury::private_builtin__c_code::mercury_code::__Unify____typeclass_info_1_0(
type_info,
dynamic_cast<MR_Word>(x),
dynamic_cast<MR_Word>(y));
@@ -674,7 +674,7 @@
MR_Word type_info, MR_Box x, MR_Box y)
{
return
- mercury::private_builtin__c_code::__Unify____base_typeclass_info_1_0(
+ mercury::private_builtin__c_code::mercury_code::__Unify____base_typeclass_info_1_0(
type_info,
dynamic_cast<MR_Word>(x),
dynamic_cast<MR_Word>(y));
@@ -684,7 +684,7 @@
do_compare__type_ctor_info_1_0(
MR_Word type_info, MR_Word_Ref result, MR_Box x, MR_Box y)
{
- mercury::private_builtin__c_code::__Compare____type_ctor_info_1_0(
+ mercury::private_builtin__c_code::mercury_code::__Compare____type_ctor_info_1_0(
type_info, result,
dynamic_cast<MR_Word>(x),
dynamic_cast<MR_Word>(y));
@@ -694,7 +694,7 @@
do_compare__type_info_1_0(
MR_Word type_info, MR_Word_Ref result, MR_Box x, MR_Box y)
{
- mercury::private_builtin__c_code::__Compare____type_info_1_0(
+ mercury::private_builtin__c_code::mercury_code::__Compare____type_info_1_0(
type_info, result,
dynamic_cast<MR_Word>(x),
dynamic_cast<MR_Word>(y));
@@ -704,7 +704,7 @@
do_compare__typeclass_info_1_0(
MR_Word type_info, MR_Word_Ref result, MR_Box x, MR_Box y)
{
- mercury::private_builtin__c_code::__Compare____typeclass_info_1_0(
+ mercury::private_builtin__c_code::mercury_code::__Compare____typeclass_info_1_0(
type_info, result,
dynamic_cast<MR_Word>(x),
dynamic_cast<MR_Word>(y));
@@ -714,7 +714,7 @@
do_compare__base_typeclass_info_1_0(
MR_Word type_info, MR_Word_Ref result, MR_Box x, MR_Box y)
{
- mercury::private_builtin__c_code::__Compare____base_typeclass_info_1_0(
+ mercury::private_builtin__c_code::mercury_code::__Compare____base_typeclass_info_1_0(
type_info, result,
dynamic_cast<MR_Word>(x),
dynamic_cast<MR_Word>(y));
Index: library/std_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/std_util.m,v
retrieving revision 1.227
diff -u -r1.227 std_util.m
--- library/std_util.m 2001/04/29 18:21:49 1.227
+++ library/std_util.m 2001/05/02 15:13:17
@@ -1343,7 +1343,7 @@
static int
do_unify__type_desc_0_0(MR_Box x, MR_Box y)
{
- return mercury::std_util__c_code::__Unify____type_desc_0_0(
+ return mercury::std_util__c_code::mercury_code::__Unify____type_desc_0_0(
dynamic_cast<MR_Word>(x),
dynamic_cast<MR_Word>(y));
}
@@ -1352,7 +1352,7 @@
do_compare__type_desc_0_0(
MR_Word_Ref result, MR_Box x, MR_Box y)
{
- mercury::std_util__c_code::__Compare____type_desc_0_0(
+ mercury::std_util__c_code::mercury_code::__Compare____type_desc_0_0(
result,
dynamic_cast<MR_Word>(x),
dynamic_cast<MR_Word>(y));
----
Peter Ross
PhD Student University of Melbourne
http://www.cs.mu.oz.au/~petdr/
--------------------------------------------------------------------------
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