diff --git a/compiler/ilasm.m b/compiler/ilasm.m index bfdfeb15f..ca4a58c19 100644 --- a/compiler/ilasm.m +++ b/compiler/ilasm.m @@ -714,7 +714,7 @@ output_simple_type(class(Name), Info0, Info) --> 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(object) --> io__write_string("ref"). 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"). diff --git a/compiler/ilds.m b/compiler/ilds.m index b598b5c7c..1108fb3e9 100644 --- a/compiler/ilds.m +++ b/compiler/ilds.m @@ -1,5 +1,5 @@ %-----------------------------------------------------------------------------% -% Copyright (C) 1999-2001 The University of Melbourne. +% Copyright (C) 1999-2002 The University of Melbourne. % This file may only be copied under the terms of the GNU General % Public License - see the file COPYING in the Mercury distribution. %-----------------------------------------------------------------------------% @@ -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 diff --git a/compiler/mlds_to_csharp.m b/compiler/mlds_to_csharp.m index c14ea4d87..257749998 100644 --- a/compiler/mlds_to_csharp.m +++ b/compiler/mlds_to_csharp.m @@ -1,5 +1,5 @@ %-----------------------------------------------------------------------------% -% Copyright (C) 2001 The University of Melbourne. +% Copyright (C) 2001-2002 The University of Melbourne. % This file may only be copied under the terms of the GNU General % Public License - see the file COPYING in the Mercury distribution. %-----------------------------------------------------------------------------% @@ -490,7 +490,7 @@ write_il_simple_type_as_csharp_type(refany) --> 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") }. diff --git a/compiler/mlds_to_il.m b/compiler/mlds_to_il.m index 094d8a714..f5300dbbe 100644 --- a/compiler/mlds_to_il.m +++ b/compiler/mlds_to_il.m @@ -2929,7 +2929,7 @@ mlds_type_to_ilds_type(_, mlds__foreign_type(IsBoxed, ForeignType, Assembly)) 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 @@ mlds_class_to_ilds_simple_type(Kind, ClassName) = SimpleType :- ( 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 @@ mlds_type_to_ilds_class_name(DataRep, MldsType) = 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 @@ defn_to_local(ModuleName, 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"). %-----------------------------------------------------------------------------% diff --git a/compiler/mlds_to_mcpp.m b/compiler/mlds_to_mcpp.m index 33332c441..8d6e2dbb1 100644 --- a/compiler/mlds_to_mcpp.m +++ b/compiler/mlds_to_mcpp.m @@ -1,5 +1,5 @@ %-----------------------------------------------------------------------------% -% Copyright (C) 2001 The University of Melbourne. +% Copyright (C) 2001-2002 The University of Melbourne. % This file may only be copied under the terms of the GNU General % Public License - see the file COPYING in the Mercury distribution. %-----------------------------------------------------------------------------% @@ -599,7 +599,7 @@ write_il_simple_type_as_managed_cpp_type(class(ClassName)) --> 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(" *"). diff --git a/compiler/prog_data.m b/compiler/prog_data.m index f63cfb35b..65b106fa4 100644 --- a/compiler/prog_data.m +++ b/compiler/prog_data.m @@ -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 diff --git a/doc/reference_manual.texi b/doc/reference_manual.texi index c25e88f2f..537fa3d9f 100644 --- a/doc/reference_manual.texi +++ b/doc/reference_manual.texi @@ -5464,14 +5464,11 @@ The CIL assembler syntax is used to specify type names for all the .NET CLR 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 -@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. -@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 +@samp{"class [AssemblyName]ReferenceTypeName"} for reference types and +@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