[m-rev.] for review: merge foreign_type pragma on to the main branch

Peter Ross peter.ross at miscrit.be
Thu Nov 1 00:25:25 AEDT 2001


On Wed, Oct 31, 2001 at 11:32:04PM +1100, Fergus Henderson wrote:
> On 31-Oct-2001, Peter Ross <peter.ross at miscrit.be> wrote:
> > Fergus wrote:
> > >
> > > `bool' is equivalent to `value class [mscorlib]System.Boolean',
> > > not to `class [mscorlib]System.Boolean'.
> > >
> > > So shouldn't the tests for "Boolean" and other builtin
> > > value types be in the `value_class/1' clause,
> > > rather than the `class/1' clause?
> > >
> > You are correct, however I think you have found a bug in our code.  I think
> > there are times when we generate code which constructs 'class
> > [mscorlib]System.Bool'.  I will change to code so that it throws an error
> > when trying to output a class which should be a value class.
> 
> I think it should be OK to use such classes.  For every value class type,
> there is a corresponding reference class type which is the boxed version
> of the value type.  I think (but am not 100% sure) that for a value
> class `value class Foo', the corresponding reference class is just spelt
> `class Foo'.
> 
> So `class [mscorlib]System.Bool' would be the boxed version of the
> boolean type.  It should be OK to use that as a class name.
> 
> It's only `value class [mscorlib]System.Bool' that needs to be
> treated specially; that must be written as `bool'.
> 

===================================================================


Estimated hours taken: 0.25
Branches: main

compiler/ilasm.m:
    Factor out the code to turn a structured name into a simple type.
    Use this factored out code to determine the correct way to output
    valueclasses and classes in the IL.

Index: ilasm.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ilasm.m,v
retrieving revision 1.25
diff -u -r1.25 ilasm.m
--- ilasm.m	24 Oct 2001 13:34:13 -0000	1.25
+++ ilasm.m	31 Oct 2001 13:17:46 -0000
@@ -701,50 +701,13 @@
 output_simple_type(string, I, I) --> io__write_string("string").
 output_simple_type(refany, I, I) --> io__write_string("refany").
 output_simple_type(class(Name), Info0, Info) --> 
-	{ Name = structured_name(AssemblyName, QualifiedName, _) },
-		% Parition II section 'Built-in Types' (7.2 in Beta2) states
-		% that all builtin types *must* be rereferenced by their
-		% special encoding.  See Parition I 'Built-In Types' 
-		% (8.2.2 in Beta2) for the list of all builtin types.
-	( 
-		{ AssemblyName = assembly("mscorlib") },
-		{ QualifiedName = ["System", TypeName] }
-	->
-		( { TypeName = "Boolean" } ->
-			output_simple_type(bool, Info0, Info)
-		; { TypeName = "Char" } ->
-			output_simple_type(char, Info0, Info)
-		; { TypeName = "Object" } ->
-			output_simple_type(object, Info0, Info)
-		; { TypeName = "String" } ->
-			output_simple_type(string, Info0, Info)
-		; { TypeName = "Single" } ->
-			output_simple_type(float32, Info0, Info)
-		; { TypeName = "Double" } ->
-			output_simple_type(float64, Info0, Info)
-		; { TypeName = "SByte" } ->
-			output_simple_type(int8, Info0, Info)
-		; { TypeName = "Int16" } ->
-			output_simple_type(int16, Info0, Info)
-		; { TypeName = "Int32" } ->
-			output_simple_type(int32, Info0, Info)
-		; { TypeName = "Int64" } ->
-			output_simple_type(int64, Info0, Info)
-		; { TypeName = "IntPtr" } ->
-			output_simple_type(native_int, Info0, Info)
-		; { TypeName = "UIntPtr" } ->
-			output_simple_type(native_uint, Info0, Info)
-		; { TypeName = "TypedReference" } ->
-			output_simple_type(refany, Info0, Info)
-		; { TypeName = "Byte" } ->
-			output_simple_type(uint8, Info0, Info)
-		; { TypeName = "UInt16" } ->
-			output_simple_type(uint16, Info0, Info)
-		; { TypeName = "UInt32" } ->
-			output_simple_type(uint32, Info0, Info)
-		; { TypeName = "UInt64" } ->
-			output_simple_type(uint64, Info0, Info)
+	( { name_to_simple_type(Name, Type) } ->
+		( { Type = reference(SimpleType) } ->
+			output_simple_type(SimpleType, Info0, Info)
 		;
+				% If it is a value type then we are
+				% refering to the boxed version of the
+				% value type.
 			io__write_string("class "),
 			output_structured_name(Name, Info0, Info)
 		)
@@ -753,8 +716,16 @@
 		output_structured_name(Name, Info0, Info)
 	).
 output_simple_type(value_class(Name), Info0, Info) --> 
-	io__write_string("valuetype "),
-	output_structured_name(Name, Info0, Info).
+	( { name_to_simple_type(Name, Type) } ->
+		( { Type = value(SimpleType) } ->
+			output_simple_type(SimpleType, Info0, Info)
+		;
+			{ unexpected(this_file, "builtin reference type") }
+		)
+	;
+		io__write_string("valuetype "),
+		output_structured_name(Name, Info0, Info)
+	).
 output_simple_type(interface(Name), Info0, Info) --> 
 	io__write_string("interface "),
 	output_structured_name(Name, Info0, Info).
@@ -767,6 +738,56 @@
 output_simple_type('&'(Type), Info0, Info) --> 
 	output_type(Type, Info0, Info),
 	io__write_string("&").
+
+:- type ref_or_value
+	--->	reference(simple_type)
+	;	value(simple_type).
+
+:- pred name_to_simple_type(structured_name::in, ref_or_value::out) is semidet.
+
+name_to_simple_type(Name, Type) :-
+		% Parition II section 'Built-in Types' (7.2 in Beta2) states
+		% that all builtin types *must* be rereferenced by their
+		% special encoding.  See Parition I 'Built-In Types' 
+		% (8.2.2 in Beta2) for the list of all builtin types.
+	Name = structured_name(AssemblyName, QualifiedName, _),
+	AssemblyName = assembly("mscorlib"),
+	QualifiedName = ["System", TypeName],
+	( TypeName = "Boolean",
+		Type = value(bool)
+	; TypeName = "Char",
+		Type = value(char)
+	; TypeName = "Object",
+		Type = reference(object)
+	; TypeName = "String",
+		Type = reference(string)
+	; TypeName = "Single",
+		Type = value(float32)
+	; TypeName = "Double",
+		Type = value(float64)
+	; TypeName = "SByte",
+		Type = value(int8)
+	; TypeName = "Int16",
+		Type = value(int16)
+	; TypeName = "Int32",
+		Type = value(int32)
+	; TypeName = "Int64",
+		Type = value(int64)
+	; TypeName = "IntPtr",
+		Type = value(native_int)
+	; TypeName = "UIntPtr",
+		Type = value(native_uint)
+	; TypeName = "TypedReference",
+		Type = value(refany)
+	; TypeName = "Byte",
+		Type = value(uint8)
+	; TypeName = "UInt16",
+		Type = value(uint16)
+	; TypeName = "UInt32",
+		Type = value(uint32)
+	; TypeName = "UInt64",
+		Type = value(uint64)
+	).
 
 	% The names are all different if it is an opcode.
 	% There's probably a very implementation dependent reason for

--------------------------------------------------------------------------
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