mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-12 04:14:06 +00:00
Implement `:- pragma foreign_import_module(Lang, Module)', which tells
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.
`:- pragma c_import_module(Module)' is a synonym for
`:- pragma foreign_import_module("C", Module)'.
compiler/prog_io_pragma.m:
Parse the new pragmas.
compiler/prog_data.m:
compiler/foreign.m:
compiler/hlds_module.m:
compiler/mlds.m:
compiler/modules.m:
Add the `:- pragma foreign_import_module' to the
compiler's datastructures.
compiler/make_hlds.m:
Insert `:- pragma foreign_import_module' declarations
into the HLDS.
compiler/modules.m:
Add the extra dependency information from
`:- pragma foreign_import_module' declarations
to the `.d' files.
compiler/llds.m:
compiler/foreign.m:
Move some non-backend-specific types describing the foreign
language interface from llds.m to foreign.m.
compiler/intermod.m:
Write `:- pragma foreign_import_module' declarations
to `.opt' files. XXX mmake doesn't support this properly yet.
compiler/mercury_compile.m:
compiler/foreign.m:
compiler/ml_code_gen.m:
compiler/ml_code_gen.m:
compiler/mlds_to_c.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_mcpp.m:
Convert `:- pragma foreign_import_module' to `#include'
statements where appropriate depending on the target
language.
compiler/*.m:
Handle `:- pragma foreign_import_module'.
Import foreign.m rather than llds.m for the foreign
interface types.
doc/reference_manual.texi:
NEWS:
Document the new pragmas.
Minor fixes for the foreign code documentation.
tests/hard_coded/Mmakefile:
tests/hard_coded/foreign_import_module.m:
tests/hard_coded/foreign_import_module_2.m:
tests/hard_coded/foreign_import_module.exp:
Test case.
This commit is contained in:
@@ -171,6 +171,41 @@ parse_pragma_type(ModuleName, "c_code", PragmaTerms,
|
||||
ErrorTerm)
|
||||
).
|
||||
|
||||
parse_pragma_type(_ModuleName, "c_import_module", PragmaTerms,
|
||||
ErrorTerm, _VarSet, Result) :-
|
||||
(
|
||||
PragmaTerms = [ImportTerm],
|
||||
sym_name_and_args(ImportTerm, Import, [])
|
||||
->
|
||||
Result = ok(pragma(foreign_import_module(c, Import)))
|
||||
;
|
||||
Result = error("wrong number of arguments or invalid module name in `:- pragma c_import_module' declaration",
|
||||
ErrorTerm)
|
||||
).
|
||||
|
||||
parse_pragma_type(_ModuleName, "foreign_import_module", PragmaTerms,
|
||||
ErrorTerm, _VarSet, Result) :-
|
||||
(
|
||||
PragmaTerms = [LangTerm, ImportTerm],
|
||||
sym_name_and_args(ImportTerm, Import, [])
|
||||
->
|
||||
( parse_foreign_language(LangTerm, Language) ->
|
||||
( Language = c ->
|
||||
Result = ok(pragma(
|
||||
foreign_import_module(Language, Import)))
|
||||
;
|
||||
Result = error("`:- pragma foreign_import_module' not yet supported for languages other than C", LangTerm)
|
||||
)
|
||||
;
|
||||
Result = error("invalid foreign language in `:- pragma foreign_import_module' declaration",
|
||||
LangTerm)
|
||||
)
|
||||
;
|
||||
Result = error("wrong number of arguments or invalid module name in `:- pragma foreign_import_module' declaration",
|
||||
ErrorTerm)
|
||||
|
||||
).
|
||||
|
||||
:- pred parse_foreign_language(term, foreign_language).
|
||||
:- mode parse_foreign_language(in, out) is semidet.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user