[m-rev.] for review: multiple foreign language support
Tyson Dowd
trd at cs.mu.OZ.AU
Mon Jul 23 21:10:28 AEST 2001
On 23-Jul-2001, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> On 19-Jul-2001, Tyson Dowd <trd at cs.mu.OZ.AU> wrote:
> > + % Generate the following dependency. This dependency is
> > + % needed because module__cpp_code.dll might refer to
> > + % high level data in any of the mercury modules it
> > + % imports plus itself.
> > + %
> > + % For example, for MC++ we generate:
> > + %
> > + % <module>__cpp_code.dll : <module>.dll <imports>.dll
> > + %
> > + %
> > + % Generate the following sequence of rules which state
> > + % how to generate the module__cpp_code.dll.
> > + %
> > + % For example, for MC++ we generate:
> > + %
> > + % <module>__cpp_code.dll : <module>__cpp_code.cpp
>
> Why is that rule needed?
> Doesn't that follow automatically from the pattern rule in
> scripts/Mmake.rules?
I was just generalizing this code, but it isn't necessary.
So I've removed it.
>
> > + % <module>__cpp_code.cpp : <module>.il
>
> It would be helpful to have a comment explaining that rule.
Done.
I've also made the other changes you suggested.
===================================================================
Estimated hours taken: 0.3
Branches: main
compiler/foreign.m:
Add some comments.
Put code for Target = asm in explicitly instead of re-using
C code (the re-use might be confusing or hard to see and
therefore lead to complications some day).
compiler/globals.m:
Fix some spacing.
compiler/make_hlds.m:
Fix an off-by-one error -- list__replace_nth_det expects
indexing to start at 1 but clauses were being counted from zero.
compiler/modules.m:
Improve some comments.
doc/user_guide.texi:
Remove --use-foreign-language from the documentation (as it is
no longer a valid option).
Index: compiler/foreign.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/foreign.m,v
retrieving revision 1.6
diff -u -r1.6 foreign.m
--- compiler/foreign.m 2001/07/20 14:13:22 1.6
+++ compiler/foreign.m 2001/07/23 11:06:48
@@ -117,7 +117,7 @@
% interfaces, but if we added appropriate options we might want
% to do this later.
- % C is always preferred over any other language.
+ % When compiling to C, C is always preferred over any other language.
prefer_foreign_language(_Globals, c, Lang1, Lang2) =
( Lang2 = c, not Lang1 = c ->
yes
@@ -125,12 +125,16 @@
no
).
- % Same as for C
-prefer_foreign_language(Globals, asm, Lang1, Lang2) =
- prefer_foreign_language(Globals, c, Lang1, Lang2).
+ % When compiling to asm, C is always preferred over any other language.
+prefer_foreign_language(_Globals, asm, Lang1, Lang2) =
+ ( Lang2 = c, not Lang1 = c ->
+ yes
+ ;
+ no
+ ).
- % First prefer il, then csharp, then prefer managed_cplusplus, after
- % that we don't care.
+ % Whe compiling to il, first we prefer il, then csharp, then
+ % managed_cplusplus, after that we don't care.
prefer_foreign_language(_Globals, il, Lang1, Lang2) = Comp :-
PreferredList = [il, csharp, managed_cplusplus],
Index: compiler/globals.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/globals.m,v
retrieving revision 1.45
diff -u -r1.45 globals.m
--- compiler/globals.m 2001/07/20 14:13:22 1.45
+++ compiler/globals.m 2001/07/23 11:06:48
@@ -246,7 +246,7 @@
globals__lookup_accumulating_option(Globals, backend_foreign_languages,
LangStrs),
ForeignLangs = list__map(func(String) = ForeignLang :-
- (convert_foreign_language(String, ForeignLang0) ->
+ ( convert_foreign_language(String, ForeignLang0) ->
ForeignLang = ForeignLang0
;
error("globals__io_get_backend_foreign_languages: invalid foreign_language string")
Index: compiler/make_hlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make_hlds.m,v
retrieving revision 1.376
diff -u -r1.376 make_hlds.m
--- compiler/make_hlds.m 2001/07/20 14:13:38 1.376
+++ compiler/make_hlds.m 2001/07/23 11:06:55
@@ -5258,7 +5258,7 @@
Res = Res0,
N = N0 + 1
)
- ), ClauseList, [], LangClauses, 0, _) },
+ ), ClauseList, [], LangClauses, 1, _) },
globals__io_get_globals(Globals),
globals__io_get_target(Target),
@@ -5296,12 +5296,12 @@
LangClauses = [ForeignLang - ClauseNumber | Rest],
ForeignLang = foreign_language(OldLang),
( Rest = [] ->
- Compare = foreign__prefer_foreign_language(Globals,
- Target, OldLang, NewLang),
+ PreferNewLang = foreign__prefer_foreign_language(
+ Globals, Target, OldLang, NewLang),
(
% This language is preferred to the old
% language, so we should replace it
- Compare = yes ->
+ PreferNewLang = yes ->
UpdateClauses =
(pred(NewCl::in, Cs::out) is det :-
list__replace_nth_det(ClauseList,
Index: compiler/modules.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modules.m,v
retrieving revision 1.179
diff -u -r1.179 modules.m
--- compiler/modules.m 2001/07/20 14:14:10 1.179
+++ compiler/modules.m 2001/07/23 11:06:59
@@ -2203,20 +2203,18 @@
% needed because module__cpp_code.dll might refer to
% high level data in any of the mercury modules it
% imports plus itself.
+ % We also generate a dependency on the .il file, so that mmake
+ % knows we need to generate the .il file to get the foreign language
+ % source file (e.g. .cpp file).
%
% For example, for MC++ we generate:
%
% <module>__cpp_code.dll : <module>.dll <imports>.dll
- %
- %
- % Generate the following sequence of rules which state
- % how to generate the module__cpp_code.dll.
- %
- % For example, for MC++ we generate:
- %
- % <module>__cpp_code.dll : <module>__cpp_code.cpp
% <module>__cpp_code.cpp : <module>.il
%
+ % (the rule to generate .dll from .cpp is a pattern rule in
+ % scripts/Mmake.rules).
+ %
:- pred write_foreign_dependency_for_il(io__output_stream::in, sym_name::in,
foreign_language::in, io__state::di, io__state::uo) is det.
write_foreign_dependency_for_il(DepStream, ModuleName, ForeignLang) -->
@@ -2243,7 +2241,6 @@
io__nl(DepStream),
io__write_strings(DepStream, [
- ForeignDllFileName, " : ", ForeignFileName,"\n",
ForeignFileName, " : ", IlFileName, "\n\n"])
;
% This foreign language doesn't generate an external file
Index: doc/user_guide.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/user_guide.texi,v
retrieving revision 1.262
diff -u -r1.262 user_guide.texi
--- doc/user_guide.texi 2001/07/18 10:21:03 1.262
+++ doc/user_guide.texi 2001/07/23 11:07:07
@@ -4383,19 +4383,6 @@
is determined by the auto-configuration script.
@sp 1
- at item @code{--use-foreign-language @var{foreign language}}
- at findex --use-foreign-language
- at cindex Foreign language interfacing
- at cindex Interfacing with other languages
-Use the given foreign language to implement predicates
-written in foreign languages. Any name that can be used
-to specify foreign languages in @samp{pragma foreign} declarations
-is valid, but not all foreign languages are implemented
-in all backends.
-Default value is `C' for the LLDS and MLDS->C backends,
-or `ManagedC++' for the .NET backend.
-
- at sp 1
@item @code{--no-type-layout}
@findex --no-type-layout
@findex --type-layout
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list