[m-rev.] for review: implement solutions on the IL backend
Peter Ross
peter.ross at miscrit.be
Sun Jul 15 00:15:59 AEST 2001
Hi,
For Fergus to review.
I haven't tested this change very much yet, but thought I would get some
review comments on it so that I can finish it off at work on Monday.
===================================================================
Estimated hours taken: 4
Branches: main
Get solutions working on the IL backend.
compiler/ml_code_gen.m:
Avoid generating casts and assignments from MR_Box to MR_Word as
these operations aren't type-safe on the IL backend.
compiler/mlds_to_il.m:
Workaround a bug where private classes aren't accessible from
classes in the same assembly when that assembly is created by
al.exe. The workaround is to make the class public. The only
assembly which is created by al.exe currently is the mercury std
library.
library/std_util.m:
Implement the MC++ code required for builtin__aggregate to work.
Index: compiler/ml_code_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_code_gen.m,v
retrieving revision 1.94
diff -u -r1.94 ml_code_gen.m
--- compiler/ml_code_gen.m 13 Jul 2001 12:02:17 -0000 1.94
+++ compiler/ml_code_gen.m 14 Jul 2001 14:01:27 -0000
@@ -2117,7 +2117,7 @@
%
% Generate <declaration of one local variable for each arg>
%
- { ml_gen_pragma_c_decls(ArgList, ArgDeclsList) },
+ ml_gen_pragma_c_decls(ArgList, ArgDeclsList),
%
% Generate definitions of the FAIL, SUCCEED, SUCCEED_LAST,
@@ -2375,7 +2375,7 @@
%
% Generate <declaration of one local variable for each arg>
%
- { ml_gen_pragma_c_decls(ArgList, ArgDeclsList) },
+ ml_gen_pragma_c_decls(ArgList, ArgDeclsList),
%
% Generate code to set the values of the input variables.
@@ -2547,32 +2547,45 @@
% for a `pragma c_code' declaration.
%
:- pred ml_gen_pragma_c_decls(list(ml_c_arg)::in,
- list(target_code_component)::out) is det.
+ list(target_code_component)::out,
+ ml_gen_info::in, ml_gen_info::out) is det.
-ml_gen_pragma_c_decls([], []).
-ml_gen_pragma_c_decls([Arg|Args], [Decl|Decls]) :-
+ml_gen_pragma_c_decls([], []) --> [].
+ml_gen_pragma_c_decls([Arg|Args], [Decl|Decls]) -->
ml_gen_pragma_c_decl(Arg, Decl),
ml_gen_pragma_c_decls(Args, Decls).
% ml_gen_pragma_c_decl generates C code to declare an argument
% of a `pragma c_code' declaration.
%
-:- pred ml_gen_pragma_c_decl(ml_c_arg::in, target_code_component::out) is det.
+:- pred ml_gen_pragma_c_decl(ml_c_arg::in, target_code_component::out,
+ ml_gen_info::in, ml_gen_info::out) is det.
-ml_gen_pragma_c_decl(ml_c_arg(_Var, MaybeNameAndMode, Type), Decl) :-
- (
+ml_gen_pragma_c_decl(ml_c_arg(_Var, MaybeNameAndMode, Type), Decl) -->
+ =(MLDSGenInfo),
+ { ml_gen_info_get_module_info(MLDSGenInfo, ModuleInfo) },
+ { module_info_globals(ModuleInfo, Globals) },
+ { globals__get_target(Globals, Target) },
+ {
MaybeNameAndMode = yes(ArgName - _Mode),
\+ var_is_singleton(ArgName)
->
- export__type_to_type_string(Type, TypeString),
+ (
+ type_util__var(Type, _),
+ Target = il
+ ->
+ TypeString = "MR_Box"
+ ;
+ export__type_to_type_string(Type, TypeString)
+ ),
string__format("\t%s %s;\n", [s(TypeString), s(ArgName)],
DeclString)
;
% if the variable doesn't occur in the ArgNames list,
% it can't be used, so we just ignore it
DeclString = ""
- ),
- Decl = raw_target_code(DeclString).
+ },
+ { Decl = raw_target_code(DeclString) }.
%-----------------------------------------------------------------------------%
@@ -2634,6 +2647,7 @@
{ module_info_globals(ModuleInfo, Globals) },
{ globals__lookup_bool_option(Globals, highlevel_data,
HighLevelData) },
+ { globals__get_target(Globals, Target) },
{ HighLevelData = yes ->
% In general, the types used for the C interface
% are not the same as the types used by
@@ -2647,7 +2661,12 @@
% a cast is for polymorphic types, which are
% `Word' in the C interface but `MR_Box' in the
% MLDS back-end.
- ( type_util__var(OrigType, _) ->
+ % Except for --grade ilc, where polymorphic types
+ % are MR_Box.
+ (
+ type_util__var(OrigType, _),
+ Target \= il
+ ->
Cast = "(MR_Word) "
;
Cast = ""
Index: compiler/mlds_to_il.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_il.m,v
retrieving revision 1.50
diff -u -r1.50 mlds_to_il.m
--- compiler/mlds_to_il.m 13 Jul 2001 14:21:21 -0000 1.50
+++ compiler/mlds_to_il.m 14 Jul 2001 14:01:29 -0000
@@ -454,7 +454,7 @@
function(_MaybePredProcId, _Params, _MaybeStmts)),
_Decl, Info, Info) :-
sorry(this_file, "top level function definition!").
-mlds_defn_to_ilasm_decl(defn(Name, _Context, Flags, class(ClassDefn)),
+mlds_defn_to_ilasm_decl(defn(Name, _Context, Flags0, class(ClassDefn)),
Decl, Info0, Info) :-
il_info_new_class(ClassDefn, Info0, Info1),
@@ -485,6 +485,16 @@
;
MethodDecls = MethodsAndFieldsAndCtors,
Info = Info2
+ ),
+ % XXX Needed to work around a bug where private classes
+ % aren't accessible from classes in the same assembly
+ % when that assembly is created by al.exe.
+ % This occurs for nondet environment classes in the
+ % mercury std library.
+ ( ClassName = structured_name("mercury", _) ->
+ Flags = set_access(Flags0, public)
+ ;
+ Flags = Flags0
),
Decl = class(decl_flags_to_classattrs(Flags), EntityName, Extends,
Interfaces, MethodDecls).
Index: library/std_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/std_util.m,v
retrieving revision 1.235
diff -u -r1.235 std_util.m
--- library/std_util.m 3 Jul 2001 08:16:25 -0000 1.235
+++ library/std_util.m 14 Jul 2001 14:01:31 -0000
@@ -955,8 +955,6 @@
** than defining our own heaps. So we don't need to
** worry about swapping them. Hence do nothing here.
*/
-
- mercury::runtime::Errors::SORRY(""foreign code for this function"");
").
%
@@ -1124,28 +1122,30 @@
").
:- pragma foreign_proc("MC++",
- new_mutvar(_X::in, _Ref::out), will_not_call_mercury,
+ new_mutvar(X::in, Ref::out), will_not_call_mercury,
"
- mercury::runtime::Errors::SORRY(""foreign code for this function"");
+ MR_untagged_newobj(Ref, 1);
+ Ref[0] = X;
").
:- pragma foreign_proc("MC++",
- new_mutvar(_X::di, _Ref::uo), will_not_call_mercury,
+ new_mutvar(X::di, Ref::uo), will_not_call_mercury,
"
- mercury::runtime::Errors::SORRY(""foreign code for this function"");
+ MR_untagged_newobj(Ref, 1);
+ Ref[0] = X;
").
:- pragma inline(get_mutvar/2).
:- pragma foreign_proc("MC++",
- get_mutvar(_Ref::in, _X::uo), will_not_call_mercury,
+ get_mutvar(Ref::in, X::uo), will_not_call_mercury,
"
- mercury::runtime::Errors::SORRY(""foreign code for this function"");
+ X = Ref[0];
").
:- pragma inline(set_mutvar/2).
:- pragma foreign_proc("MC++",
- set_mutvar(_Ref::in, _X::in), will_not_call_mercury,
+ set_mutvar(Ref::in, X::in), will_not_call_mercury,
"
- mercury::runtime::Errors::SORRY(""foreign code for this function"");
+ Ref[0] = X;
").
--------------------------------------------------------------------------
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