[m-rev.] diff: put arities on typenames for .NET backend

Tyson Dowd trd at cs.mu.OZ.AU
Tue May 8 23:33:08 AEST 2001


Hi,

Another diff required for --high-level-data and .NET.

===================================================================

Estimated hours taken: 0.5
Branches: main, dotnet-foreign

Add arity when outputting types.  This lets us distinguish types that
have the same name but different arity, which is a bit of a problem in
high-level data grades.

Also add a minor fix for mapping Mercury arrays into System.Array.

compiler/mlds_to_il.m:
	Append _arity to the type name.
	Translate arrays into System.Array.
	Re-use a little duplicated code.

compiler/type_util.m:
	Add type_id_is_array for detecting arrays.


Index: compiler/mlds_to_il.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_il.m,v
retrieving revision 1.23
diff -u -r1.23 mlds_to_il.m
--- compiler/mlds_to_il.m	2001/05/02 16:34:36	1.23
+++ compiler/mlds_to_il.m	2001/05/08 13:09:53
@@ -495,7 +495,9 @@
 	{ ClassName = mlds_module_name_to_class_name(ModuleName) },
 	{ MLDSDefn = mlds__defn(EntityName, _Context, _DeclFlags, Entity) }, 
 	{ term__type_to_term(MLDSDefn, MLDSDefnTerm) },
-	( { EntityName = type(TypeName, _Arity) },
+	( { EntityName = type(TypeName0, Arity) },
+		{ TypeName = string__format("%s_%d",
+			[s(TypeName0), i(Arity)]) },
 		{ FullClassName = append_class_name(ClassName, [TypeName]) },
 		( 
 			{ Entity = mlds__class(ClassDefn) }
@@ -677,7 +679,9 @@
 defn_to_class_decl(mlds__defn(EntityName, _Context, _DeclFlags,
 		mlds__class(ClassDefn)), ILClassDecl) -->
 	DataRep =^ il_data_rep,
-	( { EntityName = type(TypeName, _Arity) } ->
+	( { EntityName = type(TypeName0, Arity) } ->
+		{ TypeName = string__format("%s_%d",
+			[s(TypeName0), i(Arity)]) },
 		{ ClassDefn = mlds__class_defn(_ClassType, _Imports, 
 			Inherits, _Implements, Defns) },
 		{ FullClassName = structured_name("", [TypeName]) },
@@ -1884,8 +1888,9 @@
 	% see comments about function types above.
 mlds_type_to_ilds_type(_, mlds__cont_type(_ArgTypes)) = ilds__type([], int32).
 
-mlds_type_to_ilds_type(_, mlds__class_type(Class, _Arity, _Kind)) = 
-	ilds__type([], class(mlds_class_name_to_ilds_class_name(Class))).
+mlds_type_to_ilds_type(_, mlds__class_type(Class, Arity, _Kind)) = 
+	ilds__type([], class(
+		mlds_class_name_to_ilds_class_name(Class, Arity))).
 
 mlds_type_to_ilds_type(_, mlds__commit_type) = il_commit_type.
 
@@ -1929,9 +1934,17 @@
 :- func mercury_type_to_highlevel_class_type(mercury_type) = ilds__type.
 mercury_type_to_highlevel_class_type(MercuryType) = ILType :-
 	( type_to_type_id(MercuryType, TypeId, _Args) ->
-		ml_gen_type_name(TypeId, ClassName, _Arity),
-		ILType = ilds__type([], class(
-			mlds_class_name_to_ilds_class_name(ClassName)))
+
+		(
+			type_id_is_array(TypeId)
+		->
+			ILType = il_array_type
+		;
+			ml_gen_type_name(TypeId, ClassName, Arity),
+			ILType = ilds__type([], class(
+				mlds_class_name_to_ilds_class_name(
+					ClassName, Arity)))
+		)
 	;
 		unexpected(this_file, "type_to_type_id failed")
 	).
@@ -1942,10 +1955,14 @@
 	unexpected(this_file, "mlds_type_to_ilds_type: unknown_type").
 
 
-:- func mlds_class_name_to_ilds_class_name(mlds__class) = ilds__class_name.
+:- func mlds_class_name_to_ilds_class_name(mlds__class, arity) =
+	ilds__class_name.
 
-mlds_class_name_to_ilds_class_name(qual(MldsModuleName, MldsClassName)) = 
-	append_class_name(mlds_module_name_to_class_name(MldsModuleName),
+mlds_class_name_to_ilds_class_name(
+		qual(MldsModuleName, MldsClassName0), Arity) = IldsClassName :-
+	MldsClassName = string__format("%s_%d", [s(MldsClassName0), i(Arity)]),
+	IldsClassName = append_class_name(
+		mlds_module_name_to_class_name(MldsModuleName),
 		[MldsClassName]).
 
 mlds_type_to_ilds_class_name(DataRep, MldsType) = 
@@ -2057,17 +2074,7 @@
 :- mode mangle_dataname_module(in, in, out) is det.
 
 mangle_dataname_module(no, ModuleName0, ModuleName) :-
-	SymName0 = mlds_module_name_to_sym_name(ModuleName0),
-	( 
-		SymName0 = qualified(Q, M0),
-		string__append(M0, "__c_code", M),
-		SymName = qualified(Q, M)
-	; 
-		SymName0 = unqualified(M0),
-		string__append(M0, "__c_code", M),
-		SymName = unqualified(M)
-	),
-	ModuleName = mercury_module_name_to_mlds(SymName).
+	mangle_foreign_code_module(ModuleName0, managed_cplusplus, ModuleName).
 
 mangle_dataname_module(yes(DataName), ModuleName0, ModuleName) :-
 	( 
Index: compiler/type_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/type_util.m,v
retrieving revision 1.94
diff -u -r1.94 type_util.m
--- compiler/type_util.m	2001/03/18 23:09:59	1.94
+++ compiler/type_util.m	2001/05/08 13:09:53
@@ -79,6 +79,9 @@
 :- pred type_is_aditi_state(type).
 :- mode type_is_aditi_state(in) is semidet.
 
+:- pred type_id_is_array(type_id).
+:- mode type_id_is_array(in) is semidet.
+
 	% Remove an `aditi:state' from the given list if one is present.
 :- pred type_util__remove_aditi_state(list(type), list(T), list(T)).
 :- mode type_util__remove_aditi_state(in, in, out) is det.
@@ -469,6 +472,8 @@
 	BuiltinType \= tuple_type,
 	BuiltinType \= pred_type,
 	BuiltinType \= user_type.
+
+type_id_is_array(qualified(unqualified("array"), "array") - 1).
 
 type_util__var(term__variable(Var), Var).
 


-- 
       Tyson Dowd           # 
                            #  Surreal humour isn't everyone's cup of fur.
     trd at cs.mu.oz.au        # 
http://www.cs.mu.oz.au/~trd #
--------------------------------------------------------------------------
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