[m-dev.] sourcing foreign code
paul at bone.id.au
Wed Feb 26 13:54:15 AEDT 2014
On Wed, Feb 26, 2014 at 12:43:00PM +1100, Peter Wang wrote:
> Writing foreign code inside foreign_code is a bit painful (no syntax
> highlighting, need to escape quotes and backslashes). When the amount
> of foreign code is significant, I would like to keep it in a separate
> file and reference it from the Mercury file. This is possible using the
> C preprocessor but not ideal:
> * mmc --make does not know about the dependency so you must manually
> touch the relevant .m file. Imagine if you switch branches in a
> workspace and the .c file is touched but not the .m file.
> * you must tell the C compiler where to find the .c file,
> e.g. with --c-include-dir in Mercury.options
> * only works for C backends
> A solution might be to extend pragma foreign_decl/foreign_code like so:
> :- pragma foreign_code("C", source_file("<path>")).
> where <path> is _relative to the .m file_, or else an absolute path.
> I have not looked into how much work it would be to modify mmc --make,
> but what do you think?
Does this embed the contents of the file in the current compilation unit
(like #include in C)? Or does this tell mmc --make to compile the external
file separately using the C compiler and then link it with the other object
I can see reasons for wanting both behaviours; it may be a good idea to
implement both behaviours.
I have no objections.
More information about the developers