[m-rev.] [dotnet-foreign] diff: distinguish between mercury and foreign imports

Peter Ross petdr at miscrit.be
Fri May 4 19:50:14 AEST 2001


Hi,


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


Estimated hours taken: 1
Branches: dotnet-foreign

Add information to MLDS imports which indicates whether the import of
some code originally written in mercury.

compiler/ml_code_gen.m:
    Imports which are due to foreign_type pragmas have the new field set
    to no.

compiler/mlds.m:
    Change the mlds__import type so that it contains an indicator of
    whether or not the import was originally written in mercury or not.

compiler/mlds_to_c.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
    Changes to handle the new field.

Index: ml_code_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_code_gen.m,v
retrieving revision 1.80.2.4
diff -u -r1.80.2.4 ml_code_gen.m
--- ml_code_gen.m	2001/05/03 13:04:42	1.80.2.4
+++ ml_code_gen.m	2001/05/03 17:15:21
@@ -821,12 +821,12 @@
 	list__filter_map((pred(TypeDefn::in, Import::out) is semidet :-
 			hlds_data__get_type_defn_body(TypeDefn, Body),
 			Body = foreign_type(_, Location),
-			Import = mercury_module_name_to_mlds(
-					unqualified(Location))
+			Import = import(mercury_module_name_to_mlds(
+					unqualified(Location)), no)
 		), map__values(Types), ForeignTypeImports),
+	P = (func(Name) = import(mercury_module_name_to_mlds(Name), yes)),
 	MLDS_ImportList = ForeignTypeImports ++ 
-			list__map(mercury_module_name_to_mlds,
-					set__to_sorted_list(AllImports)).
+			list__map(P, set__to_sorted_list(AllImports)).
 
 :- pred ml_gen_defns(module_info, mlds__defns, io__state, io__state).
 :- mode ml_gen_defns(in, out, di, uo) is det.
Index: mlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds.m,v
retrieving revision 1.49.4.3
diff -u -r1.49.4.3 mlds.m
--- mlds.m	2001/05/03 13:04:50	1.49.4.3
+++ mlds.m	2001/05/03 17:15:22
@@ -302,12 +302,16 @@
 
 :- type mlds__imports == list(mlds__import).
 
-% Currently an import just gives the name of the package to be imported.
-% This might perhaps need to be expanded to cater to different kinds of
-% imports, e.g. imports with wild-cards ("import java.lang.*").
-:- type mlds__import == mlds_module_name.
-					% Specifies the name of a package or
-					% class to import.
+% This might need to be expanded to cater to different kinds of imports,
+% e.g. imports with wild-cards ("import java.lang.*").
+:- type mlds__import
+	---> 	import(
+				% Specifies the name of a package or
+				% class to import.
+			name	:: mlds_module_name,
+				% Is this module a mercury module?
+			mercury	:: bool			
+		).
 
 % An mlds_module_name specifies the name of an mlds package or class.
 :- type mlds_module_name.
Index: mlds_to_c.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_c.m,v
retrieving revision 1.83.4.4
diff -u -r1.83.4.4 mlds_to_c.m
--- mlds_to_c.m	2001/05/03 13:04:51	1.83.4.4
+++ mlds_to_c.m	2001/05/03 17:15:25
@@ -155,11 +155,12 @@
 		% been declared.
 		[]
 	;
-		list__foldl(mlds_output_src_import(Indent), Imports)
+		list__foldl(mlds_output_src_import(Indent), 
+				list__map((func(I) = I ^ name), Imports))
 	).
 
-:- pred mlds_output_src_import(indent, mlds__import, io__state, io__state).
-:- mode mlds_output_src_import(in, in, di, uo) is det.
+:- pred mlds_output_src_import(indent::in, mlds__package_name::in,
+		io__state::di, io__state::uo) is det.
 
 mlds_output_src_import(_Indent, Import) -->
 	{ SymName = mlds_module_name_to_sym_name(Import) },
Index: mlds_to_il.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_il.m,v
retrieving revision 1.15.4.11
diff -u -r1.15.4.11 mlds_to_il.m
--- mlds_to_il.m	2001/05/03 13:04:54	1.15.4.11
+++ mlds_to_il.m	2001/05/03 17:15:29
@@ -230,7 +230,11 @@
 			% If not in the library, but we have C code,
 			% declare the foreign module as an assembly we
 			% reference
-		list__map(mangle_foreign_code_module(ModuleName),
+		list__map((pred(F::in, I::out) is det :-
+				mangle_foreign_code_module(ModuleName, F, N),
+				I = import(N, yes)
+			),
 			set__to_sorted_list(ForeignLangs),
 			ForeignCodeAssemblerRefs),
 		AssemblerRefs = list__append(ForeignCodeAssemblerRefs, Imports)
@@ -1752,8 +1759,12 @@
 		MethodDecls) },
 	test_rtti_initialization_field(DoneFieldRef, TestInstrs),
 	set_rtti_initialization_field(DoneFieldRef, SetInstrs),
-	{ CCtorCalls = list__map((func(X) = call_class_constructor(
-		mlds_module_name_to_class_name(X))), Imports) },
+	{ CCtorCalls = list__filter_map(
+		(func(X::in) = (C::out) is semidet :-
+			X ^ mercury = yes,
+			C = call_class_constructor(
+				mlds_module_name_to_class_name(X ^ name))
+		), Imports) },
 	{ AllInstrs = list__condense([TestInstrs, AllocInstrs, SetInstrs,
 		CCtorCalls, InitInstrs, [ret]]) },
 	{ MethodDecls = [instrs(AllInstrs)] }.
@@ -2596,7 +2607,7 @@
 
 mlds_to_il__generate_extern_assembly(Imports, AllDecls) :-
 	Gen = (pred(Import::in, Decl::out) is semidet :-
-		ClassName = mlds_module_name_to_class_name(Import),
+		ClassName = mlds_module_name_to_class_name(Import ^ name),
 		ClassName = structured_name(Assembly, _),
 		not (Assembly = "mercury"),
 		Decl = extern_assembly(Assembly, [])
Index: mlds_to_java.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_java.m,v
retrieving revision 1.2.4.3
diff -u -r1.2.4.3 mlds_to_java.m
--- mlds_to_java.m	2001/05/03 13:04:56	1.2.4.3
+++ mlds_to_java.m	2001/05/03 17:15:32
@@ -260,7 +260,7 @@
 :- mode output_import(in, di, uo) is det.
 
 output_import(Import) -->
-	{ SymName = mlds_module_name_to_sym_name(Import) },
+	{ SymName = mlds_module_name_to_sym_name(Import ^ name) },
 	{ prog_out__sym_name_to_string(SymName, ".", File) }, 
 	( { qualified_name_is_stdlib(SymName) } ->
 		{ enforce_java_names(File, ClassFile) }

--------------------------------------------------------------------------
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