[m-rev.] for review: pragma foreign_import_module

Simon Taylor stayl at cs.mu.OZ.AU
Wed Oct 31 02:12:33 AEDT 2001


On 25-Oct-2001, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> Estimated hours taken: 10
> 
> Implement `:- pragma foreign_import_module(Lang, Module)', which tells
> the compiler that the foreign code in the module containing the
> declaration uses `:- pragma export'ed procedures from module `Module'.
> This information is needed for mmake to build things in the right order.
> Currently programmers can hand code the required mmake rules, but
> `mmc --make' will have no mechanism for doing this.

> Index: compiler/intermod.m
> ===================================================================
> +			/*
> +			% XXX We should do this, but mmake can't
> +			% handle the extra dependencies properly yet,
> +			% so building the standard library fails.
> +		
> +			% The `:- pragma export'ed procedures may be
> +			% referred to by the C code we are writing to
> +			% the `.opt' file.
> +			% XXX Currently we only handle procedures
> +			% exported to C.
> +			module_info_name(ModuleInfo, ModuleName),
> +			ForeignImportThisModule = foreign_import_module(c,
> +				ModuleName, term__context_init),
> +			ForeignImports =
> +				[ForeignImportThisModule | ForeignImports0]
> +			*/

Fergus wanted some clarification on this.

Simon.

--- intermod.m	2001/10/29 07:19:56	1.3
+++ intermod.m	2001/10/30 15:10:37
@@ -1122,18 +1122,20 @@
 			PragmaExportedProcs) },
 		{ ForeignDecls = list__reverse(RevForeignDecls) },
 		{ ForeignImports0 = list__reverse(RevForeignImports) },
-		{ PragmaExportedProcs = [] ->
-			ForeignImports = ForeignImports0
-		;
-			ForeignImports = ForeignImports0
-			/*
-			% XXX We should do this, but mmake can't
-			% handle the extra dependencies properly yet,
-			% so building the standard library fails.
-		
-			% The `:- pragma export'ed procedures may be
-			% referred to by the C code we are writing to
-			% the `.opt' file.
+
+		%
+		% If this module contains `:- pragma export' declarations,
+		% they may be referred to by the C code we are writing
+		% to the `.opt' file, so write the implicit
+		% `:- pragma foreign_import_module("C", ModuleName).' 
+		% to the `.opt' file.
+		%
+		% XXX We should do this, but mmake can't handle
+		% the extra dependencies properly yet, so building
+		% the standard library fails (mmake attempts to build
+		% tree234.o before std_util.h is built).
+		%
+		{ semidet_fail, PragmaExportedProcs \= [] ->
 			% XXX Currently we only handle procedures
 			% exported to C.
 			module_info_name(ModuleInfo, ModuleName),
@@ -1141,7 +1143,8 @@
 				ModuleName, term__context_init),
 			ForeignImports =
 				[ForeignImportThisModule | ForeignImports0]
-			*/
+		;
+			ForeignImports = ForeignImports0
 		},
 		list__foldl(
 		    (pred(ForeignImport::in, di, uo) is det -->
@@ -1150,6 +1153,7 @@
 		    	mercury_output_pragma_foreign_import_module(Lang,
 				Import)
 		    ), ForeignImports),
+
 		list__foldl(
 		    (pred(ForeignDecl::in, di, uo) is det -->
 		    	{ ForeignDecl = foreign_decl_code(Lang, Header, _) },
--------------------------------------------------------------------------
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