[m-rev.] for review: implement pragma foreign_export

Ian MacLarty maclarty at csse.unimelb.edu.au
Wed Jul 19 12:59:55 AEST 2006


On Wed, Jul 12, 2006 at 06:34:57PM +1000, Julien Fischer wrote:
> 
> Estimated hours taken: 12
> Branches: main
> 
> Implement `:- pragma foreign_export'.  This is intended to be a replacement
> for `:- pragma export'.  The principle difference is that `:- pragma
> foreign_export' allows you to restrict exports to a particular foreign
> language.  This language will usually be the target language but in the case
> of backends that support multiple foreign languages, e.g. the IL backend, it
> also allows us to restrict the exports to a subset of the available foreign
> languages.
> 
> Add some support for exporting procedures in the Java backend.  This is
> currently undocumented because I cannot test it properly while the Java
> backend is not working.  (The reason for adding the support was to make sure
> that all of the MLDS backends were handling foreign_export declarations
> correctly.)
> 
> Make the compiler emit warnings about exports for Java, IL, C# and MC++ not
> yet being implemented.  For the latter two this is true.  As mentioned above
> this change adds some support for exports in the Java backend and there was
> some pre-existing (but undocumented) support for exports to IL.  (The 
> warnings
> can be deleted once exports for these languages are properly documented 
> and/or
> implemented.)
> 

[...]

> 
> compiler/hlds_module.m:
> 	Add an extra field the pragma_exported_proc structure to hold the 

Add an extra field *to* the prag...

> 	name
> 	of the foreign language that the corresponding foreign_export
> 	declaration is for.
> 
> compiler/mercury_to_mercury.m:
> 	Add code to output foreign_export pragmas.
> 
> compiler/ml_code_gen.m:
> 	Don't filter out exports for Java, C# and MC++.  The Java exports
> 	can now be passed down to mlds_to_java.m and other two ought to

...and *the* other two...

> 	be caught by the frontend of the compiler.
> 
> compiler/mlds_to_java.m
> 	Add a tentative implementation of pragma foreign_export for Java.
> 	This is currently not documented in the reference manual because
> 	it is (largely) untested.
> 
> compiler/mlds_to_c.m:
> 	Change an if-then-else to a switch.
> 
> 	Add a sanity check.  Exports for languages other than C should not
> 	reach here.
> 
> compiler/mlds_to_il.m:
> 	Update the TODO list at the head of this file.
> 
> 	Add a sanity check.  Exports for languages other than IL should not
> 	reach here.
> 
> compiler/dead_proc_elim.m:
> compiler/det_analysis.m:
> compiler/foreign.m:
> compiler/handle_options.m:
> compiler/make_hlds_passes.m:
> compiler/mlds.m:
> compiler/mlds_to_managed.m:
> compiler/module_qual.m:
> compiler/modules.m:
> compiler/recompilation.version.m:
> 	Conform to the above changes.
> 
> 	Minor formatting changes.
> 
> doc/reference_manual.texi:
> 	Add a new section to the foreign language interface chapter
> 	documenting the new pragma.
> 
> 	Update the descriptions of the language specific bindings to include
> 	the new pragma.
> 
> tests/hard_coded/Mmakefile:
> tests/hard_coded/pragma_foreign_export.{m,exp}:
> 	Make sure that we can parse the new syntax and run a simple program
> 	that uses exported procedures.
> 

Are you planning to replace all uses of ":- pragma export" in the
compiler (such as in browser/declarative_debugger.m) with the new pragma
in a subsequent diff?

> tests/invalid/invalid_export_detism.{m,err_exp}:
> 	Update this test case to conform to the new pragma name.
> 
> Julien.
> 

[...]

> Index: compiler/modules.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/compiler/modules.m,v
> retrieving revision 1.395
> diff -u -r1.395 modules.m
> --- compiler/modules.m	28 Jun 2006 04:46:16 -0000	1.395
> +++ compiler/modules.m	10 Jul 2006 07:05:56 -0000
> @@ -2111,7 +2111,7 @@
>  pragma_allowed_in_interface(inline(_, _), no).
>  pragma_allowed_in_interface(no_inline(_, _), no).
>  pragma_allowed_in_interface(obsolete(_, _), yes).
> -pragma_allowed_in_interface(export(_, _, _, _), no).
> +pragma_allowed_in_interface(foreign_export(_, _, _, _, _), no).
>  pragma_allowed_in_interface(import(_, _, _, _, _), no).
>  pragma_allowed_in_interface(source_file(_), yes).
>      % yes, but the parser will strip out `source_file' pragmas anyway...
> @@ -5857,11 +5857,11 @@
>          % code for it, rather than assembler code.  So
>          % we need to treat `pragma export' like the
>          % other pragmas for foreign code.
> -        Pragma = export(_, _, _, _),
> -        list.member(lang_c, BackendLangs)
> +        % XXX How is this going to be affected now we have moved
> +        % to pragma foreign_export? - juliensf

I don't understand this comment.  Could you elaborate?

[...]

> Index: doc/reference_manual.texi
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/doc/reference_manual.texi,v
> retrieving revision 1.357
> diff -u -r1.357 reference_manual.texi
> --- doc/reference_manual.texi	5 Jul 2006 08:45:37 -0000	1.357
> +++ doc/reference_manual.texi	12 Jul 2006 08:05:27 -0000
> @@ -6071,6 +6071,9 @@
>  				       or function as a call to code
>  				       written in a different
>  				       programming language.
> +* Calling Mercury from foreign code::  How to call a Mercury predicate
> +                                       or funciton from a different
> +                                       programming language.
>  * Using foreign types from Mercury::   How to use a type defined in
>  				       a different programming language
>  				       in Mercury code. 
> @@ -6388,6 +6391,41 @@
> 
>  @c -----------------------------------------------------------------------
> 
> + at node Calling Mercury from foreign code
> + at section Calling Mercury from foreign code
> +
> +Mercury procedures may be exported so that they can be called by code 
> written
> +in a foreign language.
> +

I think you need to clarify that the foreign code that calls the Mercury
code must in turn have been called from Mercury code, or alternatively
the user needs to take steps to initialize the Mercury runtime before
calling the exported procedure.

[...]

> Index: tests/invalid/invalid_export_detism.err_exp
> ===================================================================
> RCS file: 
> /home/mercury1/repository/tests/invalid/invalid_export_detism.err_exp,v
> retrieving revision 1.2
> diff -u -r1.2 invalid_export_detism.err_exp
> --- tests/invalid/invalid_export_detism.err_exp	14 Sep 2005 05:26:47 
> -0000	1.2
> +++ tests/invalid/invalid_export_detism.err_exp	11 Jul 2006 12:26:35 
> -0000
> @@ -1,3 +1,3 @@
> -invalid_export_detism.m:009: Error: `:- pragma export' declaration for a
> -invalid_export_detism.m:009:   procedure that has a declared determinism of
> +invalid_export_detism.m:009: Error: `:- pragma foreign_export' declaration 
> for
> +invalid_export_detism.m:009:   a procedure that has a declared determinism 
> of
>  invalid_export_detism.m:009:   nondet.

You might want to also test the warnings for non-c pragma
foreign_exports.

[...]

Otherwise that looks fine.

Ian.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at csse.unimelb.edu.au
administrative address: owner-mercury-reviews at csse.unimelb.edu.au
unsubscribe: Address: mercury-reviews-request at csse.unimelb.edu.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at csse.unimelb.edu.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list