mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-18 07:15:19 +00:00
Estimated hours taken: 30
Branches: main
Add a new pragma, foreign_export_enum, that allows the names of constructors
of Mercury enumeration types to be exported across the foreign language
interface and referred to by code in the foreign language.
The new pragma is intended to be used to avoid a situation that frequently
occurs when creating Mercury bindings to foreign language libraries, namely
arguments and return values being passed across the foreign language boundary
as small integers. Exporting the names of enumeration values to foreign
languages should make this task less error prone and more portable.
Using the new construct programmers can either specify a foreign language name
for each enumeration constructor, or since this is tedious, there is also a
default mapping defined for each foreign language that should work in most
cases for that language. (In the cases where it does not work the compiler
requires the programmer to provide a valid name.)
Currently, pragma foreign_export_enum is only supported by the C backends.
compiler/prog_data.m:
compiler/prog_item.m:
Add a new item to the parse tree for representing
foreign_export_enum pragmas.
compiler/prog_io_pragma.m:
Parse the new pragma.
compiler/module_qual.m:
Handle foreign_export_enum pragmas.
Add a predicate to for module qualifying type_ctors, i.e. a
type identified by its sym_name and arity, for use by the
above.
compiler/mercury_to_mercury.m:
Write out foreign_export_enum pragmas.
compiler/hlds_module.m:
Add a type to represent exported enumerations.
Add a field to the module_info to hold information about
exported enumerations. Add access procedures for this.
compiler/make_hlds_passes.m:
compiler/add_pragma.m:
Handle foreign_export_enum pragmas: generate the set of foreign names
for each of the constructors of an enumeration type and check that
their validity in the foreign language. Attach this information to
the HLDS.
compiler/export.m:
Output #defined constants for C foreign_export_enum pragmas in
.mh files.
compiler/mlds.m:
Add an MLDS specific representation of exported enumerations.
compiler/ml_type_gen.m:
Convert the HLDS representation of exported enumerations into
an MLDS specific one.
compiler/mlds_to_c.m:
Output #defined constants for C foreign_export_enum pragmas in
.mih files.
compiler/ml_code_gen.m:
compiler/ml_elim_nested.m:
compiler/ml_tailcall.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_ilasm.m:
compiler/mlds_to_java.m:
compiler/mlds_to_managed.m:
Conform to the above changes to the MLDS.
compiler/mercury_compile.m:
Pass the list of export enumerations to the code that writes
out .mh files.
compiler/c_util.m:
Add a predicate that tests if a string is a valid C identifier.
compiler/modules.m:
compiler/recompilation.version.m:
Conform to the above changes.
doc/reference_manual.texi:
Document the new pragma.
tests/hard_coded/Mmakefile:
tests/hard_coded/ee_dummy.{m,exp}:
tests/hard_coded/ee_valid.{m,exp}:
Test valid uses of foreign_export_enum pragmas.
tests/invalid/Mmakefile:
tests/invalid/Mercury.options:
tests/invalid/ee_invalid.{m,err_exp}:
Check we generate error messages for invalid
foreign_export_enum pragmas.
NEWS:
Announce the new pragma.
vim/syntax/mercury.vim:
Highlight the new syntax.
Mercury Syntax Highlighting Under Vim 6.0 1. Create a diretory `~/.vim': $ mkdir ~/.vim 2. Copy everything recursively from this directory into `~/.vim': $ cp -r . ~/.vim IMPORTANT: If you already have a file `~/.vim/after/filetype.vim' then you should copy the files from this directory one by one, except for `after/filetype.vim' which you should append to your own `~/.vim/after/filetype.vim'. 3. Ensure you have the following lines in your `~/.vimrc' file: filetype on filetype plugin on syntax enable 4. If you wish to change the colour scheme used by Vim's syntax highlighting, we suggest you put the necessary commands in `~/.vim/colors/mycolours.vim' and append the following to the above list of commands in your `~/.vimrc': colors mycolours 4. Vim will load `~/.vim/syntax/mercury.vim' and `~/.vim/ftplugin/mercury.vim' automatically when opening a .m or .moo file. The syntax file describes two options you may wish to alter from your `~/.vimrc' file. The ftplugin file defines a number of useful keyboard mappings you may wish to consider.