[m-rev.] for review: pragma foreign_import_module on the IL backend

Simon Taylor stayl at cs.mu.OZ.AU
Fri Dec 13 17:48:38 AEDT 2002


On 10-Dec-2002, Peter Ross <pro at missioncriticalit.com> wrote:
> Estimated hours taken: 8
> Branches: main
> 
> Get pragma foreign_import_module working on the IL backend.
> 
> compiler/foreign.m:
> 	Add two utility predicates which are used to get the module
> 	name a foreign_module_import refers to.
> 
> compiler/ml_code_gen.m:
> 	The wanted foreign imports are the imports for every backend
> 	language.  This is because, for example, managed C++ can refer
> 	to something defined in IL.
> 
> compiler/mlds_to_managed.m:
> 	For managed C++ output a #using for every module implied by the
> 	pragma foreign_import_module.
> 	
> compiler/modules.m:
> 	Factor the code for outputting the dependencies implied by the
> 	pragma foreign_import_modules so that they work for both the
> 	IL and C backend.
> 	For C# add a reference to every module implied by the pragma
> 	foreign_import_module.

You haven't fixed `mmc --make' (see my other mail).

One other thing I just noticed -- `mmc --target il foo' won't
compile any foreign code contained in module `foo'.

compile_target_code__compile_csharp_file will need to be modified
to take a list of referenced assemblies.


> Index: compiler/foreign.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/compiler/foreign.m,v
> retrieving revision 1.22
> diff -u -r1.22 foreign.m
> --- compiler/foreign.m	5 Aug 2002 21:46:09 -0000	1.22
> +++ compiler/foreign.m	10 Dec 2002 13:54:01 -0000
> @@ -89,6 +89,26 @@
>  :- func foreign__to_type_string(foreign_language, exported_type) = string.
>  :- func foreign__to_type_string(foreign_language, module_info, (type)) = string.
>  
> +	%
> +	% foreign__module_name(ForeignImport)
> +	%
> +	% returns the module name which represents the ForeignImport.
> +	%
> +	% For instance for the foreign_import_module representing
> +	% 	:- foreign_import_module("MC++", module)
> +	% would return the module_name
> +	% 	unqualified("module__cpp_code")
> +	%
> +:- func foreign__module_name(foreign_import_module) = module_name.

> +	% foreign__module_name(ForeignImport, CurrentModule)
> +	%
> +	% returns the module name needed to refer to ForeignImport from the
> +	% CurrentModule.
> +	%
> +:- func foreign__module_name(foreign_import_module, module_name) =
> +		module_name.
> +

s/foreign__module_name/foreign__foreign_import_module_name/

> @@ -685,6 +706,53 @@
> +foreign__module_name(foreign_import_module(Lang, ForeignImportModule, _)) =
> +		ModuleName :-
> +	( Lang = c,
> +		ModuleName = ForeignImportModule
> +	; Lang = il,
> +		ModuleName = ForeignImportModule
> +	; Lang = managed_cplusplus,
> +		ModuleName = foreign_language_module_name(ForeignImportModule,
> +				Lang)
> +	; Lang = csharp,
> +		ModuleName = foreign_language_module_name(ForeignImportModule,
> +				Lang)
> +	).
> +
> +foreign__module_name(ForeignImportModule, CurrentModule) =
> +		ModuleName :-
> +	ForeignImportModule = foreign_import_module(Lang, _, _),
> +	ModuleName1 = ForeignImportModule ^ foreign__module_name,
> +	( Lang = c,
> +		ModuleName = ModuleName1
> +	; Lang = il,
> +		ModuleName = handle_std_library(CurrentModule, ModuleName1)
> +	; Lang = managed_cplusplus,
> +		ModuleName = handle_std_library(CurrentModule, ModuleName1)
> +	; Lang = csharp,
> +		ModuleName = handle_std_library(CurrentModule, ModuleName1)
> +	).

I'd suggest s/ForeignImportModule/ModuleForeignImported/
and s/ModuleName/ImportedForeignCodeModuleName/

> Index: compiler/modules.m
> ===================================================================
> @@ -2599,19 +2598,31 @@
>  		% Handle dependencies introduced by
>  		% `:- pragma foreign_import_module' declarations.
>  		%
> -		{ ForeignImportedModules =
> -		    list__map(
> -			(func(foreign_import_module(_, ForeignImportModule, _))
> -				= ForeignImportModule),
> -			ForeignImports) },
> -		( { ForeignImports = [] } ->
> +		{ list__filter_map(
> +			(pred(ForeignImportMod::in, Import::out) is semidet :-
> +				Import = foreign__module_name(
> +						ForeignImportMod,
> +						SourceFileModuleName),
> +
> +				% We can't include mercury.dll as mmake
> +				% can't find it, but we know that it exists.
> +				Import \= unqualified("mercury")
> +			), ForeignImports, ForeignImportedModules) },

Shouldn't this comment have an XXX?

> @@ -2833,10 +2844,10 @@
>  	% scripts/Mmake.rules).
>  	% 
>  :- pred write_foreign_dependency_for_il(io__output_stream::in,sym_name::in,
> -		list(module_name)::in, foreign_language::in,
> -		io__state::di, io__state::uo) is det.
> -write_foreign_dependency_for_il(DepStream, ModuleName, AllDeps, ForeignLang)
> -		-->
> +		list(module_name)::in, foreign_import_module_info::in,
> +		foreign_language::in, io__state::di, io__state::uo) is det.
> +write_foreign_dependency_for_il(DepStream, ModuleName, AllDeps,
> +		ForeignImports, ForeignLang) -->
>  	( 
>  		{ ForeignModuleName = foreign_language_module_name(
>  			ModuleName, ForeignLang) },
> @@ -2880,8 +2891,13 @@
>  			;
>  				Prefix = "/r:"
>  			},
> +			{ ForeignDeps = list__map(
> +				(func(M) =
> +					foreign__module_name(M, ModuleName)
> +				), ForeignImports) },
> +			{ Deps = AllDeps ++ ForeignDeps },
>  			write_dll_dependencies_list(
> -				referenced_dlls(ModuleName, AllDeps),
> +				referenced_dlls(ModuleName, Deps),
>  				Prefix, DepStream),
>  			io__nl(DepStream)

I'm not sure why Deps can't just be ForeignDeps.
At least it deserves a comment.

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