[m-rev.] patch: pragma import on il backend
Peter Ross
pro at missioncriticalit.com
Wed Dec 11 04:52:46 AEDT 2002
This patch almost gets foreign import/export working on the IL
backend, so I am sending it to the mailing list for prosterity.
The main problem is that is that we rather hackily use MC++ like it
could just simply be used for C. This is not true.
Index: foreign.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/foreign.m,v
retrieving revision 1.22
diff -u -r1.22 foreign.m
--- foreign.m 5 Aug 2002 21:46:09 -0000 1.22
+++ foreign.m 10 Dec 2002 17:33:07 -0000
@@ -262,14 +283,9 @@
WantedLang = Lang),
Bodys0, LangBodys, NotLangBodys).
-foreign__extrude_pragma_implementation([], _PragmaVars,
- _PredName, _PredOrFunc, _Context, _ModuleInfo0, _Attributes, _Impl0,
- _ModuleInfo, _NewAttributes, _Impl) :-
- unexpected(this_file, "no suitable target languages available").
-
% We just use the first target language for now, it might be nice
% to try a few others if the backend supports multiple ones.
-foreign__extrude_pragma_implementation([TargetLang | TargetLangs],
+foreign__extrude_pragma_implementation(TargetLangs,
_PragmaVars, _PredName, _PredOrFunc, _Context,
ModuleInfo0, Attributes, Impl0,
ModuleInfo, NewAttributes, Impl) :-
@@ -277,21 +293,57 @@
% If the foreign language is available as a target language,
% we don't need to do anything.
- ( list__member(ForeignLanguage, [TargetLang | TargetLangs]) ->
+ (
+ list__member(ForeignLanguage, TargetLangs)
+ ->
Impl = Impl0,
ModuleInfo = ModuleInfo0,
NewAttributes = Attributes
;
- set_foreign_language(Attributes, TargetLang, NewAttributes),
- extrude_pragma_implementation_2(TargetLang, ForeignLanguage,
- ModuleInfo0, Impl0, ModuleInfo, Impl)
+ extrude_pragma_implementation_2(TargetLangs, ForeignLanguage,
+ ModuleInfo0, Impl0,
+ ChosenTargetLang, ModuleInfo1, Impl1)
+ ->
+ set_foreign_language(Attributes,
+ ChosenTargetLang, NewAttributes),
+ ModuleInfo = ModuleInfo1,
+ Impl = Impl1
+ ;
+ Str = "unable to call " ++
+ foreign_language_string(ForeignLanguage) ++
+ " from any of " ++
+ string__append_list(list__map((func(L) =
+ foreign_language_string(L) ++
+ " "
+ ), TargetLangs)),
+ unexpected(this_file, Str)
).
-
:- pred extrude_pragma_implementation_2(
+ list(foreign_language)::in, foreign_language::in,
+ module_info::in, pragma_foreign_code_impl::in,
+ foreign_language::out,
+ module_info::out, pragma_foreign_code_impl::out) is semidet.
+
+extrude_pragma_implementation_2([TargetLang | TargetLangs], ForeignLanguage,
+ ModuleInfo0, Impl0, ChosenTargetLang, ModuleInfo, Impl) :-
+ (
+ extrude_pragma_implementation_3(TargetLang, ForeignLanguage,
+ ModuleInfo0, Impl0, ModuleInfo1, Impl1)
+ ->
+ ChosenTargetLang = TargetLang,
+ ModuleInfo = ModuleInfo1,
+ Impl = Impl1
+ ;
+ extrude_pragma_implementation_2(TargetLangs, ForeignLanguage,
+ ModuleInfo0, Impl0, ChosenTargetLang,
+ ModuleInfo, Impl)
+ ).
+
+:- pred extrude_pragma_implementation_3(
foreign_language::in, foreign_language::in,
module_info::in, pragma_foreign_code_impl::in,
- module_info::out, pragma_foreign_code_impl::out) is det.
+ module_info::out, pragma_foreign_code_impl::out) is semidet.
% This isn't finished yet, and we probably won't implement it for C
% calling MC++. For C calling normal C++ we would generate a proxy
@@ -313,61 +365,22 @@
Impl = import(NewName, ReturnCode, VarString, no)
*/
-extrude_pragma_implementation_2(c, managed_cplusplus, _, _, _, _) :-
- unimplemented_combination(c, managed_cplusplus).
-
-extrude_pragma_implementation_2(c, csharp, _, _, _, _) :-
- unimplemented_combination(c, csharp).
-
-extrude_pragma_implementation_2(c, il, _, _, _, _) :-
- unimplemented_combination(c, il).
-
-extrude_pragma_implementation_2(c, c, ModuleInfo, Impl, ModuleInfo, Impl).
-
+extrude_pragma_implementation_3(c, c, ModuleInfo, Impl, ModuleInfo, Impl).
% Don't do anything - C and MC++ are embedded inside MC++
% without any changes.
-extrude_pragma_implementation_2(managed_cplusplus, managed_cplusplus,
+extrude_pragma_implementation_3(managed_cplusplus, managed_cplusplus,
ModuleInfo, Impl, ModuleInfo, Impl).
-extrude_pragma_implementation_2(managed_cplusplus, c,
+extrude_pragma_implementation_3(managed_cplusplus, c,
ModuleInfo, Impl, ModuleInfo, Impl).
-extrude_pragma_implementation_2(managed_cplusplus, csharp, _, _, _, _) :-
- unimplemented_combination(managed_cplusplus, csharp).
-
-extrude_pragma_implementation_2(managed_cplusplus, il, _, _, _, _) :-
- unimplemented_combination(managed_cplusplus, il).
-
-
-
-extrude_pragma_implementation_2(csharp, csharp,
+extrude_pragma_implementation_3(csharp, csharp,
ModuleInfo, Impl, ModuleInfo, Impl).
-extrude_pragma_implementation_2(csharp, c, _, _, _, _) :-
- unimplemented_combination(csharp, c).
-
-extrude_pragma_implementation_2(csharp, managed_cplusplus, _, _, _, _) :-
- unimplemented_combination(csharp, managed_cplusplus).
-
-extrude_pragma_implementation_2(csharp, il, _, _, _, _) :-
- unimplemented_combination(csharp, il).
-
-
-extrude_pragma_implementation_2(il, il,
+extrude_pragma_implementation_3(il, il,
ModuleInfo, Impl, ModuleInfo, Impl).
-extrude_pragma_implementation_2(il, c, _, _, _, _) :-
- unimplemented_combination(il, c).
-
-extrude_pragma_implementation_2(il, managed_cplusplus, _, _, _, _) :-
- unimplemented_combination(il, managed_cplusplus).
-
-extrude_pragma_implementation_2(il, csharp, _, _, _, _) :-
- unimplemented_combination(il, csharp).
-
-
-
:- pred unimplemented_combination(foreign_language::in, foreign_language::in)
is erroneous.
Index: modules.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modules.m,v
retrieving revision 1.255
diff -u -r1.255 modules.m
--- modules.m 10 Dec 2002 07:38:09 -0000 1.255
+++ modules.m 10 Dec 2002 17:33:09 -0000
@@ -4834,6 +4850,14 @@
)
)
;
+ % XXX petdr
+ Pragma = import(_, _, _, _, _),
+ Lang = managed_cplusplus,
+ list__member(Lang, BackendLangs)
+ ->
+ Info = Info0 ^ used_foreign_languages :=
+ set__insert(Info0 ^ used_foreign_languages, Lang)
+ ;
% XXX `pragma export' should not be treated as
% foreign, but currently mlds_to_gcc.m doesn't
% handle that declaration, and instead just
--------------------------------------------------------------------------
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