[m-rev.] [dotnet-foreign] diff: use System.Array for mercury arrays
Peter Ross
peter.ross at miscrit.be
Wed Aug 1 20:12:56 AEST 2001
Hi,
===================================================================
Estimated hours taken: 2
Branches: dotnet-foreign
A change to allow the IL backend represent the mercury type array(T) by
System.Array.
mlds.m:
Add a new field to mercury_type which records whether or not the
type is an array type. If it is an array type we calculate what the
element type is as an mlds type.
mlds_to_il.m:
Use System.Array to represent mercury arrays.
ml_code_util.m:
ml_simplify_switch.m:
ml_switch_gen.m:
ml_unify_gen.m:
mlds_to_c.m:
mlds_to_gcc.m:
mlds_to_java.m:
rtti_to_mlds.m:
Code to handle the extra field.
Index: ml_code_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_code_util.m,v
retrieving revision 1.33.4.8
diff -u -r1.33.4.8 ml_code_util.m
--- ml_code_util.m 16 Jul 2001 13:52:40 -0000 1.33.4.8
+++ ml_code_util.m 1 Aug 2001 09:54:35 -0000
@@ -956,7 +956,7 @@
ml_gen_array_elem_type(elem_type_int) = mlds__native_int_type.
ml_gen_array_elem_type(elem_type_generic) = mlds__generic_type.
-ml_string_type = mercury_type(string_type, str_type, "MR_String").
+ml_string_type = mercury_type(string_type, str_type, "MR_String", no).
%-----------------------------------------------------------------------------%
%
Index: ml_simplify_switch.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_simplify_switch.m,v
retrieving revision 1.2.14.1
diff -u -r1.2.14.1 ml_simplify_switch.m
--- ml_simplify_switch.m 9 Apr 2001 14:08:19 -0000 1.2.14.1
+++ ml_simplify_switch.m 1 Aug 2001 09:54:35 -0000
@@ -100,9 +100,9 @@
:- pred is_integral_type(mlds__type::in) is semidet.
is_integral_type(mlds__native_int_type).
is_integral_type(mlds__native_char_type).
-is_integral_type(mlds__mercury_type(_, int_type, _)).
-is_integral_type(mlds__mercury_type(_, char_type, _)).
-is_integral_type(mlds__mercury_type(_, enum_type, _)).
+is_integral_type(mlds__mercury_type(_, int_type, _, _)).
+is_integral_type(mlds__mercury_type(_, char_type, _, _)).
+is_integral_type(mlds__mercury_type(_, enum_type, _, _)).
:- pred is_dense_switch(list(mlds__switch_case)::in, int::in) is semidet.
is_dense_switch(Cases, ReqDensity) :-
Index: ml_switch_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_switch_gen.m,v
retrieving revision 1.7.12.1
diff -u -r1.7.12.1 ml_switch_gen.m
--- ml_switch_gen.m 9 Apr 2001 14:08:20 -0000 1.7.12.1
+++ ml_switch_gen.m 1 Aug 2001 09:54:36 -0000
@@ -397,7 +397,7 @@
{
ml_gen_info_get_module_info(MLGenInfo, ModuleInfo),
export__type_to_type_string(ModuleInfo, Type, TypeString),
- MLDS_Type = mercury_type(Type, TypeCategory, TypeString),
+ MLDS_Type = mercury_type(Type, TypeCategory, TypeString, _),
switch_util__type_range(TypeCategory, Type, ModuleInfo,
MinRange, MaxRange)
->
Index: ml_unify_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_unify_gen.m,v
retrieving revision 1.32.4.8
diff -u -r1.32.4.8 ml_unify_gen.m
--- ml_unify_gen.m 16 Jul 2001 13:52:42 -0000 1.32.4.8
+++ ml_unify_gen.m 1 Aug 2001 09:54:36 -0000
@@ -1144,7 +1144,7 @@
ml_gen_box_const_rval(Type, Rval, Context, ConstDefns, BoxedRval) -->
(
- { Type = mercury_type(term__variable(_), _, _)
+ { Type = mercury_type(term__variable(_), _, _, _)
; Type = mlds__generic_type
}
->
@@ -1159,7 +1159,7 @@
% but calls to malloc() are not).
%
{ Type = mercury_type(term__functor(term__atom("float"),
- [], _), _, _)
+ [], _), _, _, _)
; Type = mlds__native_float_type
}
->
Index: mlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds.m,v
retrieving revision 1.49.4.15
diff -u -r1.49.4.15 mlds.m
--- mlds.m 24 Jul 2001 18:57:13 -0000 1.49.4.15
+++ mlds.m 1 Aug 2001 09:54:37 -0000
@@ -533,6 +533,11 @@
members :: mlds__defns % contains these members
).
+ % Record the number of array wrappers around some mlds__type.
+:- type array
+ ---> array(array)
+ ; type(mlds__type).
+
% Note: the definition of the `mlds__type' type is subject to change.
% In particular, we might add new alternatives here, so try to avoid
% switching on this type.
@@ -542,9 +547,11 @@
prog_data__type, % the exact Mercury type
builtin_type, % what kind of type it is:
% enum, float, etc.
- string % the result of
+ string, % the result of
% export__type_to_type_string
-
+ maybe(array) % If the current type is an array,
+ % record the amount of nesting
+ % and the element type.
)
% The type for the continuation functions used
@@ -1520,6 +1527,21 @@
% MLDS type and instead fully convert all Mercury types to MLDS types.
mercury_type_to_mlds_type(ModuleInfo, Type) = MLDS_Type :-
+ ArrayType = mercury_type_to_array_type(ModuleInfo, Type),
+ MLDS_Type0 = mercury_type_to_mlds_type_2(ModuleInfo, Type),
+ ( ArrayType = type(_),
+ MLDS_Type = MLDS_Type0
+ ; ArrayType = array(_),
+ ( MLDS_Type0 = mercury_type(T, B, E, _) ->
+ MLDS_Type = mercury_type(T, B, E, yes(ArrayType))
+ ;
+ error("mercury_type_to_mlds_type: non mercury type")
+ )
+ ).
+
+:- func mercury_type_to_mlds_type_2(module_info, mercury_type) = mlds__type.
+
+mercury_type_to_mlds_type_2(ModuleInfo, Type) = MLDS_Type :-
module_info_types(ModuleInfo, Types),
classify_type(Type, ModuleInfo, Category),
export__type_to_type_string(ModuleInfo, Type, TypeString),
@@ -1531,12 +1553,25 @@
( Body = foreign_type(ForeignType, ForeignLoc) ->
MLDS_Type = mlds__foreign_type(ForeignType, ForeignLoc)
;
- MLDS_Type = mercury_type(Type, Category, TypeString)
+ MLDS_Type = mercury_type(Type, Category, TypeString, no)
)
;
- MLDS_Type = mercury_type(Type, Category, TypeString)
+ MLDS_Type = mercury_type(Type, Category, TypeString, no)
).
+:- func mercury_type_to_array_type(module_info, prog_data__type) = array.
+
+mercury_type_to_array_type(ModuleInfo, Type) =
+ (
+ type_to_type_id(Type, TypeId, [ElementType]),
+ type_id_is_array(TypeId)
+ ->
+ array(mercury_type_to_array_type(ModuleInfo, ElementType))
+ ;
+ type(mercury_type_to_mlds_type_2(ModuleInfo, Type))
+ ).
+
+
%-----------------------------------------------------------------------------%
Index: mlds_to_c.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_c.m,v
retrieving revision 1.83.4.14
diff -u -r1.83.4.14 mlds_to_c.m
--- mlds_to_c.m 24 Jul 2001 18:57:14 -0000 1.83.4.14
+++ mlds_to_c.m 1 Aug 2001 09:54:38 -0000
@@ -602,7 +602,7 @@
:- mode mlds_output_pragma_export_type(in, in, di, uo) is det.
mlds_output_pragma_export_type(suffix, _Type) --> [].
-mlds_output_pragma_export_type(prefix, mercury_type(_, _, TypeString)) -->
+mlds_output_pragma_export_type(prefix, mercury_type(_, _, TypeString, _)) -->
io__write_string(TypeString).
mlds_output_pragma_export_type(prefix, mlds__cont_type(_)) -->
io__write_string("MR_Word").
@@ -860,7 +860,7 @@
Kind \= mlds__enum,
ClassType = Type
;
- Type = mercury_type(MercuryType, user_type, _),
+ Type = mercury_type(MercuryType, user_type, _, _),
type_to_type_id(MercuryType, TypeId, _ArgsTypes),
ml_gen_type_name(TypeId, ClassName, ClassArity),
ClassType = mlds__class_type(ClassName, ClassArity,
@@ -1522,7 +1522,7 @@
:- pred mlds_output_type_prefix(mlds__type, io__state, io__state).
:- mode mlds_output_type_prefix(in, di, uo) is det.
-mlds_output_type_prefix(mercury_type(Type, TypeCategory, _)) -->
+mlds_output_type_prefix(mercury_type(Type, TypeCategory, _, _)) -->
mlds_output_mercury_type_prefix(Type, TypeCategory).
mlds_output_type_prefix(mlds__native_int_type) --> io__write_string("int").
mlds_output_type_prefix(mlds__native_float_type) --> io__write_string("float").
@@ -1682,7 +1682,7 @@
io__state, io__state).
:- mode mlds_output_type_suffix(in, in, di, uo) is det.
-mlds_output_type_suffix(mercury_type(_, _, _), _) --> [].
+mlds_output_type_suffix(mercury_type(_, _, _, _), _) --> [].
mlds_output_type_suffix(mlds__native_int_type, _) --> [].
mlds_output_type_suffix(mlds__native_float_type, _) --> [].
mlds_output_type_suffix(mlds__native_bool_type, _) --> [].
@@ -2574,7 +2574,7 @@
FieldType, _ClassType)) -->
(
{ FieldType = mlds__generic_type
- ; FieldType = mlds__mercury_type(term__variable(_), _, _)
+ ; FieldType = mlds__mercury_type(term__variable(_), _, _, _)
}
->
io__write_string("(")
@@ -2772,7 +2772,7 @@
mlds_output_boxed_rval(Type, InnerExprn)
;
{ Type = mlds__mercury_type(term__functor(term__atom("float"),
- [], _), _, _)
+ [], _), _, _, _)
; Type = mlds__native_float_type
}
->
@@ -2780,8 +2780,8 @@
mlds_output_rval(Exprn),
io__write_string(")")
;
- { Type = mlds__mercury_type(term__functor(term__atom("character"),
- [], _), _, _)
+ { Type = mlds__mercury_type(term__functor(
+ term__atom("character"), [], _), _, _, _)
; Type = mlds__native_char_type
; Type = mlds__native_bool_type
; Type = mlds__native_int_type
@@ -2805,7 +2805,7 @@
mlds_output_unboxed_rval(Type, Exprn) -->
(
{ Type = mlds__mercury_type(term__functor(term__atom("float"),
- [], _), _, _)
+ [], _), _, _, _)
; Type = mlds__native_float_type
}
->
@@ -2813,8 +2813,8 @@
mlds_output_rval(Exprn),
io__write_string(")")
;
- { Type = mlds__mercury_type(term__functor(term__atom("character"),
- [], _), _, _)
+ { Type = mlds__mercury_type(term__functor(
+ term__atom("character"), [], _), _, _, _)
; Type = mlds__native_char_type
; Type = mlds__native_bool_type
; Type = mlds__native_int_type
Index: mlds_to_gcc.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_gcc.m,v
retrieving revision 1.36.4.8
diff -u -r1.36.4.8 mlds_to_gcc.m
--- mlds_to_gcc.m 24 Jul 2001 18:57:16 -0000 1.36.4.8
+++ mlds_to_gcc.m 1 Aug 2001 09:54:39 -0000
@@ -1670,7 +1670,7 @@
gcc__type, io__state, io__state).
:- mode build_type(in, in, in, out, di, uo) is det.
-build_type(mercury_type(Type, TypeCategory, _ExportType), _, _, GCC_Type) -->
+build_type(mercury_type(Type, TypeCategory, _ExportType, _), _, _, GCC_Type) -->
build_mercury_type(Type, TypeCategory, GCC_Type).
build_type(mlds__foreign_type(_, _), _, _, _) -->
{ sorry(this_file, "foreign_type not implemented") }.
@@ -2807,7 +2807,7 @@
% sanity check (copied from mlds_to_c.m)
(
{ FieldType = mlds__generic_type
- ; FieldType = mlds__mercury_type(term__variable(_), _, _)
+ ; FieldType = mlds__mercury_type(term__variable(_), _, _, _)
}
->
[]
@@ -3009,7 +3009,7 @@
:- pred type_is_float(mlds__type::in) is semidet.
type_is_float(Type) :-
( Type = mlds__mercury_type(term__functor(term__atom("float"),
- [], _), _, _)
+ [], _), _, _, _)
; Type = mlds__native_float_type
).
Index: mlds_to_il.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_il.m,v
retrieving revision 1.15.4.31
diff -u -r1.15.4.31 mlds_to_il.m
--- mlds_to_il.m 31 Jul 2001 13:15:18 -0000 1.15.4.31
+++ mlds_to_il.m 1 Aug 2001 09:54:40 -0000
@@ -1707,7 +1707,7 @@
Type = mlds__class_type(_, _, mlds__class)
;
DataRep ^ highlevel_data = yes,
- Type = mlds__mercury_type(_, user_type, _)
+ Type = mlds__mercury_type(_, user_type, _, _)
}
->
% If this is a class, we should call the
@@ -2108,7 +2108,7 @@
)
;
( already_boxed(RvalILType) ->
- ( RvalType = mercury_type(_, user_type, _) ->
+ ( RvalType = mercury_type(_, user_type, _, _) ->
% XXX we should look into a nicer way to
% generate MLDS so we don't need to do this
Instrs = tree__list([
@@ -2619,25 +2619,41 @@
mlds_type_to_ilds_type(ILDataRep, mlds__ptr_type(MLDSType)) =
ilds__type([], '&'(mlds_type_to_ilds_type(ILDataRep, MLDSType))).
-mlds_type_to_ilds_type(_, mercury_type(_, int_type, _)) = ilds__type([], int32).
-mlds_type_to_ilds_type(_, mercury_type(_, char_type, _)) = ilds__type([], char).
-mlds_type_to_ilds_type(_, mercury_type(_, float_type, _)) =
+mlds_type_to_ilds_type(_, mercury_type(_, int_type, _, _)) =
+ ilds__type([], int32).
+mlds_type_to_ilds_type(_, mercury_type(_, char_type, _, _)) =
+ ilds__type([], char).
+mlds_type_to_ilds_type(_, mercury_type(_, float_type, _, _)) =
ilds__type([], float64).
-mlds_type_to_ilds_type(_, mercury_type(_, str_type, _)) = il_string_type.
-mlds_type_to_ilds_type(_, mercury_type(_, pred_type, _)) = il_array_type.
-mlds_type_to_ilds_type(_, mercury_type(_, tuple_type, _)) = il_array_type.
-mlds_type_to_ilds_type(_, mercury_type(_, enum_type, _)) = il_array_type.
-mlds_type_to_ilds_type(_, mercury_type(_, polymorphic_type, _))
+mlds_type_to_ilds_type(_, mercury_type(_, str_type, _, _)) = il_string_type.
+mlds_type_to_ilds_type(_, mercury_type(_, pred_type, _, _)) = il_array_type.
+mlds_type_to_ilds_type(_, mercury_type(_, tuple_type, _, _)) = il_array_type.
+mlds_type_to_ilds_type(_, mercury_type(_, enum_type, _, _)) = il_array_type.
+mlds_type_to_ilds_type(_, mercury_type(_, polymorphic_type, _, _))
= il_generic_type.
-mlds_type_to_ilds_type(DataRep, mercury_type(MercuryType, user_type, _)) =
- ( DataRep ^ highlevel_data = yes ->
- mercury_type_to_highlevel_class_type(MercuryType)
- ;
- il_array_type
+mlds_type_to_ilds_type(DataRep,
+ mercury_type(MercuryType, user_type, _, MaybeArray))
+ = ILDS_Type :-
+ ( MaybeArray = yes(Array),
+ ILDS_Type = array_type_to_ilds_type(DataRep, Array)
+ ; MaybeArray = no,
+ ( DataRep ^ highlevel_data = yes ->
+ ILDS_Type = mercury_type_to_highlevel_class_type(
+ MercuryType)
+ ;
+ ILDS_Type = il_array_type
+ )
).
mlds_type_to_ilds_type(_, mlds__unknown_type) = _ :-
unexpected(this_file, "mlds_type_to_ilds_type: unknown_type").
+:- func array_type_to_ilds_type(il_data_rep, array) = ilds__type.
+
+array_type_to_ilds_type(DataRep, type(MLDS_Type)) =
+ mlds_type_to_ilds_type(DataRep, MLDS_Type).
+array_type_to_ilds_type(DataRep, array(ArrayType))
+ = ilds__type([], '[]'(array_type_to_ilds_type(DataRep, ArrayType), [])).
+
:- func mlds_class_to_ilds_simple_type(mlds__class_kind, ilds__class_name) =
ilds__simple_type.
mlds_class_to_ilds_simple_type(Kind, ClassName) = SimpleType :-
@@ -3117,20 +3133,20 @@
mlds__func_params([], [])).
rval_const_to_type(int_const(_))
= mercury_type(term__functor(term__atom("int"), [], context("", 0)),
- int_type, "MR_Integer").
+ int_type, "MR_Integer", no).
rval_const_to_type(float_const(_))
= mercury_type(term__functor(term__atom("float"), [], context("", 0)),
- float_type, "MR_Float").
+ float_type, "MR_Float", no).
rval_const_to_type(false) = mlds__native_bool_type.
rval_const_to_type(true) = mlds__native_bool_type.
rval_const_to_type(string_const(_))
= mercury_type(
term__functor(term__atom("string"), [], context("", 0)),
- str_type, "MR_String").
+ str_type, "MR_String", no).
rval_const_to_type(multi_string_const(_, _))
= mercury_type(term__functor(term__atom("string"), [], context("", 0)),
% XXX Should this be MR_Word instead?
- str_type, "MR_String").
+ str_type, "MR_String", no).
rval_const_to_type(null(MldsType)) = MldsType.
%-----------------------------------------------------------------------------%
Index: mlds_to_java.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_java.m,v
retrieving revision 1.2.4.11
diff -u -r1.2.4.11 mlds_to_java.m
--- mlds_to_java.m 16 Jul 2001 13:52:47 -0000 1.2.4.11
+++ mlds_to_java.m 1 Aug 2001 09:54:41 -0000
@@ -129,7 +129,7 @@
:- mode type_is_enum(in) is semidet.
type_is_enum(Type) :-
- Type = mercury_type(_, Builtin, _),
+ Type = mercury_type(_, Builtin, _, _),
Builtin = enum_type.
% Succeeds iff this type is something that
@@ -140,7 +140,7 @@
:- mode type_is_object(in) is semidet.
type_is_object(Type) :-
- Type = mercury_type(_, Builtin, _),
+ Type = mercury_type(_, Builtin, _, _),
( Builtin = enum_type
; Builtin = polymorphic_type
; Builtin = user_type
@@ -848,15 +848,15 @@
:- func get_java_type_initializer(mlds__type) = string.
:- mode get_java_type_initializer(in) = out is det.
-get_java_type_initializer(mercury_type(_, int_type, _)) = "0".
-get_java_type_initializer(mercury_type(_, char_type, _)) = "0".
-get_java_type_initializer(mercury_type(_, float_type, _)) = "0".
-get_java_type_initializer(mercury_type(_, str_type, _)) = "null".
-get_java_type_initializer(mercury_type(_, pred_type, _)) = "null".
-get_java_type_initializer(mercury_type(_, tuple_type, _)) = "null".
-get_java_type_initializer(mercury_type(_, enum_type, _)) = "null".
-get_java_type_initializer(mercury_type(_, polymorphic_type, _)) = "null".
-get_java_type_initializer(mercury_type(_, user_type, _)) = "null".
+get_java_type_initializer(mercury_type(_, int_type, _, _)) = "0".
+get_java_type_initializer(mercury_type(_, char_type, _, _)) = "0".
+get_java_type_initializer(mercury_type(_, float_type, _, _)) = "0".
+get_java_type_initializer(mercury_type(_, str_type, _, _)) = "null".
+get_java_type_initializer(mercury_type(_, pred_type, _, _)) = "null".
+get_java_type_initializer(mercury_type(_, tuple_type, _, _)) = "null".
+get_java_type_initializer(mercury_type(_, enum_type, _, _)) = "null".
+get_java_type_initializer(mercury_type(_, polymorphic_type, _, _)) = "null".
+get_java_type_initializer(mercury_type(_, user_type, _, _)) = "null".
get_java_type_initializer(mlds__cont_type(_)) = "null".
get_java_type_initializer(mlds__commit_type) = "null".
get_java_type_initializer(mlds__native_bool_type) = "false".
@@ -1208,7 +1208,7 @@
:- pred output_type(mlds__type, io__state, io__state).
:- mode output_type(in, di, uo) is det.
-output_type(mercury_type(Type, TypeCategory, _)) -->
+output_type(mercury_type(Type, TypeCategory, _, _)) -->
output_mercury_type(Type, TypeCategory).
output_type(mlds__native_int_type) --> io__write_string("int").
output_type(mlds__native_float_type) --> io__write_string("double").
@@ -1889,9 +1889,9 @@
{ TargetType = ArgType }
;
{ TargetType = mercury_type(
- _, TargetBuiltinType, _),
+ _, TargetBuiltinType, _, _),
ArgType = mercury_type(
- _, ArgBuiltinType, _),
+ _, ArgBuiltinType, _, _),
TargetBuiltinType = ArgBuiltinType }
)
@@ -2104,17 +2104,17 @@
Type = mlds__native_int_type.
java_builtin_type(Type, "int", "java.lang.Integer", "intValue") :-
Type = mlds__mercury_type(term__functor(term__atom("int"),
- [], _), _, _).
+ [], _), _, _, _).
java_builtin_type(Type, "double", "java.lang.Double", "doubleValue") :-
Type = mlds__native_float_type.
java_builtin_type(Type, "double", "java.lang.Double", "doubleValue") :-
Type = mlds__mercury_type(term__functor(term__atom("float"),
- [], _), _, _).
+ [], _), _, _, _).
java_builtin_type(Type, "char", "java.lang.Character", "charValue") :-
Type = mlds__native_char_type.
java_builtin_type(Type, "char", "java.lang.Character", "charValue") :-
Type = mlds__mercury_type(term__functor(term__atom("character"),
- [], _), _, _).
+ [], _), _, _, _).
java_builtin_type(Type, "boolean", "java.lang.Boolean", "booleanValue") :-
Type = mlds__native_bool_type.
Index: rtti_to_mlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/rtti_to_mlds.m,v
retrieving revision 1.12.4.6
diff -u -r1.12.4.6 rtti_to_mlds.m
--- rtti_to_mlds.m 11 Jul 2001 08:37:20 -0000 1.12.4.6
+++ rtti_to_mlds.m 1 Aug 2001 09:54:41 -0000
@@ -135,7 +135,7 @@
Init, []) :-
Init = gen_init_array(gen_init_maybe(
mercury_type(functor(atom("string"), [],
- context("", 0)), str_type, "MR_String"),
+ context("", 0)), str_type, "MR_String", no),
gen_init_string), MaybeNames).
gen_init_rtti_data_defn(field_types(_RttiTypeId, _Ordinal, Types),
ModuleName, _, Init, []) :-
--------------------------------------------------------------------------
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