[m-rev.] for review: minor changes for valuetype foreign_types
Tyson Dowd
trd at cs.mu.OZ.AU
Sun Jan 20 17:28:11 AEDT 2002
Hi,
Pete, can you check over these changes before I commit?
===================================================================
Estimated hours taken: 0.5
Branches: main
A few minor fixes promped by petdr's addition of support for value types
for foreign_type.
compiler/ilasm.m:
compiler/ilds.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_il.m:
compiler/mlds_to_mcpp.m:
Mirror the IL syntax more closely, use valuetype instead of
value_class.
compiler/prog_data.m:
Add some comments and improve formatting of type declarations for
pragma foreign_type.
doc/reference_manual.texi:
Improve the documentation wording for pragma foreign_type, and
remove the XXX saying that we should accept value types, because
we now accept value types.
Index: compiler/ilasm.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ilasm.m,v
retrieving revision 1.29
diff -u -r1.29 ilasm.m
--- compiler/ilasm.m 16 Jan 2002 01:13:22 -0000 1.29
+++ compiler/ilasm.m 20 Jan 2002 05:14:50 -0000
@@ -714,7 +714,7 @@
io__write_string("class "),
output_structured_name(Name, Info0, Info)
).
-output_simple_type(value_class(Name), Info0, Info) -->
+output_simple_type(valuetype(Name), Info0, Info) -->
( { name_to_simple_type(Name, Type) } ->
( { Type = value(SimpleType) } ->
output_simple_type(SimpleType, Info0, Info)
@@ -820,7 +820,7 @@
output_simple_type_opcode(string) --> io__write_string("ref").
output_simple_type_opcode(refany) --> io__write_string("ref").
output_simple_type_opcode(class(_Name)) --> io__write_string("ref").
-output_simple_type_opcode(value_class(_Name)) --> io__write_string("ref").
+output_simple_type_opcode(valuetype(_Name)) --> io__write_string("ref").
output_simple_type_opcode(interface(_Name)) --> io__write_string("ref").
output_simple_type_opcode('[]'(_Type, _Bounds)) --> io__write_string("ref").
output_simple_type_opcode('*'(_Type)) --> io__write_string("ref").
Index: compiler/ilds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ilds.m,v
retrieving revision 1.12
diff -u -r1.12 ilds.m
--- compiler/ilds.m 24 Oct 2001 13:34:14 -0000 1.12
+++ compiler/ilds.m 20 Jan 2002 05:15:05 -0000
@@ -174,7 +174,7 @@
; refany % a reference to value with an attached
% type
; class(class_name)
- ; value_class(class_name)
+ ; valuetype(class_name)
; interface(class_name)
; '[]'(ilds__type, bounds) % An array
; '&'(ilds__type) % A managed pointer
Index: compiler/mlds_to_csharp.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_csharp.m,v
retrieving revision 1.20
diff -u -r1.20 mlds_to_csharp.m
--- compiler/mlds_to_csharp.m 11 Jan 2002 07:41:29 -0000 1.20
+++ compiler/mlds_to_csharp.m 20 Jan 2002 05:15:58 -0000
@@ -490,7 +490,7 @@
io__write_string("mercury.MR_RefAny").
write_il_simple_type_as_csharp_type(class(ClassName)) -->
write_csharp_class_name(ClassName).
-write_il_simple_type_as_csharp_type(value_class(_ClassName)) -->
+write_il_simple_type_as_csharp_type(valuetype(_ClassName)) -->
{ sorry(this_file, "value classes") }.
write_il_simple_type_as_csharp_type(interface(_ClassName)) -->
{ sorry(this_file, "interfaces") }.
Index: compiler/mlds_to_il.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_il.m,v
retrieving revision 1.96
diff -u -r1.96 mlds_to_il.m
--- compiler/mlds_to_il.m 16 Jan 2002 01:23:54 -0000 1.96
+++ compiler/mlds_to_il.m 20 Jan 2002 05:15:44 -0000
@@ -2929,7 +2929,7 @@
Class = class(structured_name(assembly(Assembly),
ForeignClassName, []))
; IsBoxed = no,
- Class = value_class(structured_name(assembly(Assembly),
+ Class = valuetype(structured_name(assembly(Assembly),
ForeignClassName, []))
).
@@ -2964,8 +2964,8 @@
( Kind = mlds__package, SimpleType = class(ClassName)
; Kind = mlds__class, SimpleType = class(ClassName)
; Kind = mlds__interface, SimpleType = class(ClassName)
- ; Kind = mlds__struct, SimpleType = value_class(ClassName)
- ; Kind = mlds__enum, SimpleType = value_class(ClassName)
+ ; Kind = mlds__struct, SimpleType = valuetype(ClassName)
+ ; Kind = mlds__enum, SimpleType = valuetype(ClassName)
).
:- func mercury_type_to_highlevel_class_type(mercury_type) = ilds__type.
@@ -2995,7 +2995,7 @@
get_ilds_type_class_name(ILType) = ClassName :-
(
( ILType = ilds__type(_, class(ClassName0))
- ; ILType = ilds__type(_, value_class(ClassName0))
+ ; ILType = ilds__type(_, valuetype(ClassName0))
)
->
ClassName = ClassName0
@@ -3641,62 +3641,62 @@
convert_to_object(Type) = instr_node(box(ValueType)) :-
Type = ilds__type(_, SimpleType),
- ValueType = simple_type_to_value_class(SimpleType).
+ ValueType = simple_type_to_valuetype(SimpleType).
:- func convert_from_object(ilds__type) = instr_tree.
convert_from_object(Type) = node([unbox(Type), ldobj(Type)]).
-:- func simple_type_to_value_class(simple_type) = ilds__type.
-simple_type_to_value_class(int8) =
- ilds__type([], value_class(il_system_name(["SByte"]))).
-simple_type_to_value_class(int16) =
- ilds__type([], value_class(il_system_name(["Int16"]))).
-simple_type_to_value_class(int32) =
- ilds__type([], value_class(il_system_name(["Int32"]))).
-simple_type_to_value_class(int64) =
- ilds__type([], value_class(il_system_name(["Int64"]))).
-simple_type_to_value_class(uint8) =
- ilds__type([], value_class(il_system_name(["Byte"]))).
-simple_type_to_value_class(uint16) =
- ilds__type([], value_class(il_system_name(["UInt16"]))).
-simple_type_to_value_class(uint32) =
- ilds__type([], value_class(il_system_name(["UInt32"]))).
-simple_type_to_value_class(uint64) =
- ilds__type([], value_class(il_system_name(["UInt64"]))).
-simple_type_to_value_class(float32) =
- ilds__type([], value_class(il_system_name(["Single"]))).
-simple_type_to_value_class(float64) =
- ilds__type([], value_class(il_system_name(["Double"]))).
-simple_type_to_value_class(bool) =
- ilds__type([], value_class(il_system_name(["Boolean"]))).
-simple_type_to_value_class(char) =
- ilds__type([], value_class(il_system_name(["Char"]))).
-simple_type_to_value_class(object) = _ :-
- % ilds__type([], value_class(il_system_name(["Object"]))).
+:- func simple_type_to_valuetype(simple_type) = ilds__type.
+simple_type_to_valuetype(int8) =
+ ilds__type([], valuetype(il_system_name(["SByte"]))).
+simple_type_to_valuetype(int16) =
+ ilds__type([], valuetype(il_system_name(["Int16"]))).
+simple_type_to_valuetype(int32) =
+ ilds__type([], valuetype(il_system_name(["Int32"]))).
+simple_type_to_valuetype(int64) =
+ ilds__type([], valuetype(il_system_name(["Int64"]))).
+simple_type_to_valuetype(uint8) =
+ ilds__type([], valuetype(il_system_name(["Byte"]))).
+simple_type_to_valuetype(uint16) =
+ ilds__type([], valuetype(il_system_name(["UInt16"]))).
+simple_type_to_valuetype(uint32) =
+ ilds__type([], valuetype(il_system_name(["UInt32"]))).
+simple_type_to_valuetype(uint64) =
+ ilds__type([], valuetype(il_system_name(["UInt64"]))).
+simple_type_to_valuetype(float32) =
+ ilds__type([], valuetype(il_system_name(["Single"]))).
+simple_type_to_valuetype(float64) =
+ ilds__type([], valuetype(il_system_name(["Double"]))).
+simple_type_to_valuetype(bool) =
+ ilds__type([], valuetype(il_system_name(["Boolean"]))).
+simple_type_to_valuetype(char) =
+ ilds__type([], valuetype(il_system_name(["Char"]))).
+simple_type_to_valuetype(object) = _ :-
+ % ilds__type([], valuetype(il_system_name(["Object"]))).
error("no value class for System.Object").
-simple_type_to_value_class(string) = _ :-
- % ilds__type([], value_class(il_system_name(["String"]))).
+simple_type_to_valuetype(string) = _ :-
+ % ilds__type([], valuetype(il_system_name(["String"]))).
error("no value class for System.String").
-simple_type_to_value_class(refany) = _ :-
+simple_type_to_valuetype(refany) = _ :-
error("no value class for refany").
-simple_type_to_value_class(class(_)) = _ :-
+simple_type_to_valuetype(class(_)) = _ :-
error("no value class for class").
-simple_type_to_value_class(value_class(Name)) =
- ilds__type([], value_class(Name)).
-simple_type_to_value_class(interface(_)) = _ :-
+simple_type_to_valuetype(valuetype(Name)) =
+ ilds__type([], valuetype(Name)).
+simple_type_to_valuetype(interface(_)) = _ :-
error("no value class for interface").
-simple_type_to_value_class('[]'(_, _)) = _ :-
+simple_type_to_valuetype('[]'(_, _)) = _ :-
error("no value class for array").
-simple_type_to_value_class('&'( _)) = _ :-
+simple_type_to_valuetype('&'( _)) = _ :-
error("no value class for '&'").
-simple_type_to_value_class('*'(_)) = _ :-
+simple_type_to_valuetype('*'(_)) = _ :-
error("no value class for '*'").
-simple_type_to_value_class(native_float) = _ :-
+simple_type_to_valuetype(native_float) = _ :-
error("no value class for native float").
-simple_type_to_value_class(native_int) = _ :-
+simple_type_to_valuetype(native_int) = _ :-
error("no value class for native int").
-simple_type_to_value_class(native_uint) = _ :-
+simple_type_to_valuetype(native_uint) = _ :-
error("no value class for native uint").
%-----------------------------------------------------------------------------%
Index: compiler/mlds_to_mcpp.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_mcpp.m,v
retrieving revision 1.24
diff -u -r1.24 mlds_to_mcpp.m
--- compiler/mlds_to_mcpp.m 11 Jan 2002 07:41:31 -0000 1.24
+++ compiler/mlds_to_mcpp.m 20 Jan 2002 05:20:00 -0000
@@ -599,7 +599,7 @@
io__write_string(" *")
).
% XXX this is not the right syntax
-write_il_simple_type_as_managed_cpp_type(value_class(ClassName)) -->
+write_il_simple_type_as_managed_cpp_type(valuetype(ClassName)) -->
io__write_string("value class "),
write_managed_cpp_class_name(ClassName),
io__write_string(" *").
Index: compiler/prog_data.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_data.m,v
retrieving revision 1.74
diff -u -r1.74 prog_data.m
--- compiler/prog_data.m 16 Jan 2002 01:13:39 -0000 1.74
+++ compiler/prog_data.m 20 Jan 2002 05:14:19 -0000
@@ -294,16 +294,25 @@
% Currently we only support foreign_language_types for IL.
%
+
+ %
+ % It is important to distinguish between IL value types and
+ % reference types, the compiler may need to generate different code
+ % for each of these cases.
+ %
+
:- type ref_or_val
---> reference
; value.
:- type foreign_language_type
- % An indicator of whether the type is a
- % reference of value type.
- % The location of the .NET name (the assembly),
- % and the .NET type name (represented as a sym_name)
- ---> il(ref_or_val, string, sym_name).
+ ---> il(
+ ref_or_val, % An indicator of whether the type is a
+ % reference of value type.
+ string, % The location of the .NET name (the
+ % assembly)
+ sym_name % The .NET type name
+ ).
%
% Stuff for tabling pragmas
Index: doc/reference_manual.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/reference_manual.texi,v
retrieving revision 1.236
diff -u -r1.236 reference_manual.texi
--- doc/reference_manual.texi 16 Jan 2002 01:13:47 -0000 1.236
+++ doc/reference_manual.texi 20 Jan 2002 05:26:01 -0000
@@ -5464,14 +5464,11 @@
languages (IL, C# and Managed C++) supported by Mercury's
@samp{foreign_proc} mechanism.
This syntax is documented in the ECMA specifications for .NET).
-Currently on the .NET CLR backend reference and value types are
-supported using
- at samp{pragma foreign_type}, and hence the supported syntax is
-DotNetForeignType is @samp{"class [AssemblyName]ReferenceTypeName"} for
-reference types and
-DotNetForeignType is @samp{"valuetype [AssemblyName]ValueTypeName"} for
-value types.
- at c XXX this restriction should be lifted
+The .NET CLR backend supports reference and value types
+using @samp{pragma foreign_type}, where DotNetForeignType is
+specified using the syntax
+ at samp{"class [AssemblyName]ReferenceTypeName"} for reference types and
+ at samp{"valuetype [AssemblyName]ValueTypeName"} for value types.
Note that extra whitespace is not handled --- there should only be a single
space between the class keyword and the assembly specifier.
@c XXX we should handle whitespace better
--
Tyson Dowd #
# Surreal humour isn't everyone's cup of fur.
trd at cs.mu.oz.au #
http://www.cs.mu.oz.au/~trd #
--------------------------------------------------------------------------
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