[m-dev.] sourcing foreign code

Peter Wang novalazy at gmail.com
Wed Feb 26 12:43:00 AEDT 2014


Hi,

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?

Peter



More information about the developers mailing list