[m-rev.] for review: foreign type imports

Peter Ross peter.ross at miscrit.be
Thu Oct 25 01:17:02 AEST 2001


Hi,

For Tyson to review.

With this change the main branch is now able to use the intgen tool
provided you re-enable parsing of the prog_io pragma.

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


Estimated hours taken: 0.5
Branches: main

Port the change to handle foreign imports onto the main branch.

The foreign_type pragma allows one to specify where a declaration for a
foreign type is located, thus this import must be output in the correct
source module.

compiler/mlds.m:
    Change the import type so that as well as the name of the import it
    also includes whether or not this import is of a file generated by
    the mercury system.
    
compiler/ml_code_gen.m:
    For each foreign type add its location to the list of mlds imports.

compiler/mlds_to_il.m:
    Changes due to the new mlds__import definition.
    Only output calls to the class constructors for those modules which
    are mercury modules.

compiler/mlds_to_c.m:
compiler/mlds_to_java.m:
    Changes due to the new mlds__import definition.


Index: compiler/ml_code_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_code_gen.m,v
retrieving revision 1.102
diff -u -r1.102 ml_code_gen.m
--- compiler/ml_code_gen.m	24 Oct 2001 13:34:25 -0000	1.102
+++ compiler/ml_code_gen.m	24 Oct 2001 15:05:04 -0000
@@ -838,9 +838,22 @@
 :- mode ml_gen_imports(in, out) is det.
 
 ml_gen_imports(ModuleInfo, MLDS_ImportList) :-
+		% Determine all the mercury imports.
 	module_info_get_all_deps(ModuleInfo, AllImports),
-	MLDS_ImportList = list__map(mercury_module_name_to_mlds,
-		set__to_sorted_list(AllImports)).
+	P = (func(Name) = import(mercury_module_name_to_mlds(Name), yes)),
+
+		% For every foreign type determine the import needed to
+		% find the declaration for that type.
+	module_info_types(ModuleInfo, Types),
+	list__filter_map((pred(TypeDefn::in, Import::out) is semidet :-
+			hlds_data__get_type_defn_body(TypeDefn, Body),
+			Body = foreign_type(_, Location),
+			Import = import(mercury_module_name_to_mlds(
+					unqualified(Location)), no)
+		), map__values(Types), ForeignTypeImports),
+
+	MLDS_ImportList = ForeignTypeImports ++ 
+			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: compiler/mlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds.m,v
retrieving revision 1.72
diff -u -r1.72 mlds.m
--- compiler/mlds.m	24 Oct 2001 13:34:28 -0000	1.72
+++ compiler/mlds.m	24 Oct 2001 15:05:04 -0000
@@ -321,9 +321,11 @@
 % 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.
+:- type mlds__import
+	--->	import(
+			import_name		:: mlds_module_name,
+			is_mercury_import	:: bool
+		).
 
 % An mlds_module_name specifies the name of an mlds package or class.
 :- type mlds_module_name.
Index: compiler/mlds_to_c.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_c.m,v
retrieving revision 1.105
diff -u -r1.105 mlds_to_c.m
--- compiler/mlds_to_c.m	24 Oct 2001 13:34:28 -0000	1.105
+++ compiler/mlds_to_c.m	24 Oct 2001 15:05:05 -0000
@@ -179,7 +179,7 @@
 :- mode mlds_output_src_import(in, in, di, uo) is det.
 
 mlds_output_src_import(_Indent, Import) -->
-	{ SymName = mlds_module_name_to_sym_name(Import) },
+	{ SymName = mlds_module_name_to_sym_name(Import ^ import_name) },
 	module_name_to_file_name(SymName, ".h", no, HeaderFile),
 	io__write_strings(["#include """, HeaderFile, """\n"]).
 
@@ -297,7 +297,7 @@
 	io__write_string("/* :- implementation. */\n"),
 	mlds_output_src_bootstrap_defines, io__nl,
 	mlds_output_src_import(Indent,
-		mercury_module_name_to_mlds(ModuleName)),
+		import(mercury_module_name_to_mlds(ModuleName), yes)),
 	io__nl.
 
 	%
Index: compiler/mlds_to_il.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_il.m,v
retrieving revision 1.87
diff -u -r1.87 mlds_to_il.m
--- compiler/mlds_to_il.m	24 Oct 2001 13:34:30 -0000	1.87
+++ compiler/mlds_to_il.m	24 Oct 2001 15:05:07 -0000
@@ -253,7 +253,10 @@
 			% If not in the library, but we have foreign 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)
@@ -2736,8 +2739,12 @@
 		MethodDecls) },
 	test_rtti_initialization_field(DoneFieldRef, TestInstrs),
 	set_rtti_initialization_field(DoneFieldRef, SetInstrs),
-	{ CCtorCalls = list__map((func(X) = call_class_constructor(
-		class_name(X, wrapper_class_name))), Imports) },
+	{ CCtorCalls = list__filter_map(
+		(func(I::in) = (C::out) is semidet :-
+			I ^ is_mercury_import = yes,
+			C = call_class_constructor(
+				class_name(I ^ import_name, wrapper_class_name))
+		), Imports) },
 	{ AllInstrs = list__condense([TestInstrs, AllocInstrs, SetInstrs,
 		CCtorCalls, InitInstrs, [ret]]) },
 	{ MethodDecls = [instrs(AllInstrs)] }.
@@ -3875,7 +3882,8 @@
 		AsmDecls = []
 	),
 	Gen = (pred(Import::in, Decl::out) is semidet :-
-		AsmName = mlds_module_name_to_assembly_name(Import),
+		AsmName = mlds_module_name_to_assembly_name(
+				Import ^ import_name),
 		( AsmName = assembly(Assembly),
 			Assembly \= "mercury",
 			Decl = [extern_assembly(Assembly, AsmDecls)]
Index: compiler/mlds_to_java.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_java.m,v
retrieving revision 1.15
diff -u -r1.15 mlds_to_java.m
--- compiler/mlds_to_java.m	24 Oct 2001 13:34:31 -0000	1.15
+++ compiler/mlds_to_java.m	24 Oct 2001 15:05:08 -0000
@@ -261,7 +261,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 ^ 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