[m-dev.] for review: add MR_ to Word, Integer, String, etc...

Tyson Dowd trd at cs.mu.OZ.AU
Tue Aug 1 00:32:36 AEST 2000


Hi,

This is a pretty simple change, but might affect a few people.
If you have changes to the runtime or trace directories checked out,
please be aware that this will cause conflicts, although the conflicts
should be pretty easy to resolve as you just have to update your type
names.

As soon as this change is installed, the compiler will start generating
MR_* types in the .c files.  You might need to at least use the #defines
in mercury_bootstrap.h to keep backwards compatibility (so updating the
runtime might be a good idea).

I haven't included the entire diffas it is huge and very boring (and
majordomo on mulga will reject it unless I break it up into small boring
pieces).  See ~trd/namespace.diff for the rest if you are really
interested.

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


Estimated hours taken: 4

Add MR_ prefixes to the types used when generating C code.
This means types such as Word, String, Bool, Float become MR_Word,
MR_String, MR_Bool, MR_Float.

This is very important in environments where String or Bool have already
been used as system types (for example, managed C++).  And besides, we
should do it anyway as part of the grand namespace cleanup.

I have fixed all of the uses of the non-prefixed types in the runtime
and trace directories.  I haven't done it for the library and compiler
directories yet (no promises that I will do it in future either).  But
if you see a non-prefixed type in code from now on, please consider it a
bug and fix it.

mercury_bootstrap.h contains #defines to map the non-prefixed types into
the prefixed ones.  Like many of the other namespace cleaning backwards
compatibility macros, this can be turned off with
MR_NO_BACKWARDS_COMPAT.

This shouldn't break any code, but this kind of change affects so many
things that of course there could be problems lurking in there somewhere.  

If you start getting errors from the C compiler after this change is
installed, you will want to make sure you at least have the runtime
system updated so that you are getting the backwards compatibility
definitions in mercury_bootstrap.h.  Then if you continue to have
problems you can bug me about it.

compiler/export.m:
compiler/llds_out.m:
compiler/mlds_to_c.m:
	Use MR_Word, MR_Float, MR_Bool, etc when generating C.

runtime/mercury_bootstrap.h:
	Add bootstrapping #defines

runtime/*:
trace/*:
	Change Word, Float, Bool, Code, String, etc to 
	MR_Word, MR_Float, MR_Bool, MR_Code, MR_String.


Index: compiler/export.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/export.m,v
retrieving revision 1.33
diff -u -r1.33 export.m
--- compiler/export.m	2000/07/20 10:39:22	1.33
+++ compiler/export.m	2000/07/31 14:21:44
@@ -42,7 +42,7 @@
 :- mode export__produce_header_file(in, in, di, uo) is det.
 
 	% Convert the type, to a string corresponding to its C type.
-	% (Defaults to Word).
+	% (Defaults to MR_Word).
 :- pred export__type_to_type_string(type, string).
 :- mode export__type_to_type_string(in, out) is det.
 
@@ -109,11 +109,12 @@
 	% #if SEMIDET
 	%   bool
 	% #elif FUNCTION
-	%   Word
+	%   MR_Word
 	% #else
 	%   void
 	% #endif
-	% <function name>(Word Mercury__Argument1, Word *Mercury__Argument2...)
+	% <function name>(MR_Word Mercury__Argument1, 
+	%			MR_Word *Mercury__Argument2...)
 	%			/* Word for input, Word* for output */
 	% {
 	% #if NUM_REAL_REGS > 0
@@ -190,7 +191,7 @@
 				C_RetType, "\n", 
 				C_Function, "(", ArgDecls, ")\n{\n",
 				"#if NUM_REAL_REGS > 0\n",
-				"\tWord c_regs[NUM_REAL_REGS];\n",
+				"\tMR_Word c_regs[NUM_REAL_REGS];\n",
 				"#endif\n",
 				MaybeDeclareRetval,
 				"\n",
@@ -433,7 +434,7 @@
 	(
         	Type = term__functor(term__atom("string"), [], _)
 	->
-		string__append("(Word) ", Rval, ConvertedRval)
+		string__append("(MR_Word) ", Rval, ConvertedRval)
 	;
         	Type = term__functor(term__atom("float"), [], _)
 	->
@@ -454,7 +455,7 @@
 	(
         	Type = term__functor(term__atom("string"), [], _)
 	->
-		string__append("(String) ", Rval, ConvertedRval)
+		string__append("(MR_String) ", Rval, ConvertedRval)
 	;
         	Type = term__functor(term__atom("float"), [], _)
 	->
@@ -534,18 +535,20 @@
 
 	% Convert a term representation of a variable type to a string which
 	% represents the C type of the variable
-	% Apart from special cases, local variables become Words
+	% Apart from special cases, local variables become MR_Words
 export__type_to_type_string(Type, Result) :-
 	( Type = term__functor(term__atom("int"), [], _) ->
-		Result = "Integer"
+		Result = "MR_Integer"
 	; Type = term__functor(term__atom("float"), [], _) ->
-		Result = "Float"
+		Result = "MR_Float"
 	; Type = term__functor(term__atom("string"), [], _) ->
-		Result = "String"
+		Result = "MR_String"
 	; Type = term__functor(term__atom("character"), [], _) ->
-		Result = "Char"
+		Result = "MR_Char"
+	; Type = term__variable(_) ->
+		Result = "MR_Box"
 	;
-		Result = "Word"
+		Result = "MR_Word"
 	).
 
 %-----------------------------------------------------------------------------%

Index: compiler/llds_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/llds_out.m,v
retrieving revision 1.145
diff -u -r1.145 llds_out.m
--- compiler/llds_out.m	2000/06/14 14:54:05	1.145
+++ compiler/llds_out.m	2000/07/28 05:15:07
@@ -830,7 +830,7 @@
 
 output_comp_gen_c_var(tabling_pointer_var(ModuleName, ProcLabel),
 		DeclSet0, DeclSet) -->
-	io__write_string("\nWord mercury_var__tabling__"),
+	io__write_string("\nMR_Word mercury_var__tabling__"),
 	output_proc_label(ProcLabel),
 	io__write_string(" = 0;\n"),
 	{ DataAddr = data_addr(ModuleName, tabling_pointer(ProcLabel)) },
@@ -1554,14 +1554,14 @@
 output_instruction(block(TempR, TempF, Instrs), ProfInfo) -->
 	io__write_string("\t{\n"),
 	( { TempR > 0 } ->
-		io__write_string("\tWord "),
+		io__write_string("\tMR_Word "),
 		output_temp_decls(TempR, "r"),
 		io__write_string(";\n")
 	;
 		[]
 	),
 	( { TempF > 0 } ->
-		io__write_string("\tFloat "),
+		io__write_string("\tMR_Float "),
 		output_temp_decls(TempF, "f"),
 		io__write_string(";\n")
 	;
@@ -1811,7 +1811,7 @@
 output_pragma_decls([D|Decls]) -->
 	(
 		{ D = pragma_c_arg_decl(Type, VarName) },
-		% Apart from special cases, the local variables are Words
+		% Apart from special cases, the local variables are MR_Words
 		{ export__type_to_type_string(Type, VarType) },
 		io__write_string("\t"),
 		io__write_string(VarType),
@@ -1853,7 +1853,7 @@
 	(
         	{ Type = term__functor(term__atom("string"), [], _) }
 	->
-		io__write_string("(String) "),
+		output_llds_type_cast(string),
 		output_rval_as_type(Rval, word)
 	;
         	{ Type = term__functor(term__atom("float"), [], _) }
@@ -1890,7 +1890,8 @@
 	(
         	{ Type = term__functor(term__atom("string"), [], _) }
 	->
-		io__write_string("(Word) "),
+		output_llds_type_cast(word),
+		io__write_string(" "),
 		io__write_string(VarName)
 	;
         	{ Type = term__functor(term__atom("float"), [], _) }
@@ -2103,7 +2104,7 @@
 				output_indent(FirstIndent, LaterIndent, N0),
 				{ N is N0 + 1 },
 				io__write_strings([
-					"static const Float ",
+					"static const MR_Float ",
 					"mercury_float_const_", FloatName,
 					" = ", FloatString, ";\n"
 				])
@@ -2149,8 +2150,9 @@
 			{ decl_set_insert(DeclSet2, FloatLabel, DeclSet) },
 			output_indent(FirstIndent, LaterIndent, N2),
 			{ N is N2 + 1 },
-			io__write_string(
-				"static const Float mercury_float_const_"),
+			io__write_string("static const "),
+			output_llds_type(float),
+			io__write_string(" mercury_float_const_"),
 			io__write_string(FloatName),
 			io__write_string(" = "),
 				% note that we just output the expression
@@ -2275,9 +2277,9 @@
 	% We output constant terms as follows:
 	%
 	%	static const struct <foo>_struct {
-	%		Word field1;			// Def
-	%		Float field2;
-	%		Word * field3;
+	%		MR_Word field1;			// Def
+	%		MR_Float field2;
+	%		MR_Word * field3;
 	%		...
 	%	}
 	%	<foo> 					// Decl
@@ -2511,6 +2513,15 @@
 		{ ArgType = Type }
 	).
 
+	% Same as output_llds_type, but will put parentheses
+	% around the llds_type.
+:- pred output_llds_type_cast(llds_type::in, 
+			io__state::di, io__state::uo) is det.
+output_llds_type_cast(LLDSType)   --> 
+	io__write_string("("),
+	output_llds_type(LLDSType),
+	io__write_string(")").
+
 :- pred output_llds_type(llds_type::in, io__state::di, io__state::uo) is det.
 
 output_llds_type(int_least8)   --> io__write_string("MR_int_least8_t").
@@ -2519,14 +2530,14 @@
 output_llds_type(uint_least16) --> io__write_string("MR_uint_least16_t").
 output_llds_type(int_least32)  --> io__write_string("MR_int_least32_t").
 output_llds_type(uint_least32) --> io__write_string("MR_uint_least32_t").
-output_llds_type(bool)         --> io__write_string("Integer").
-output_llds_type(integer)      --> io__write_string("Integer").
-output_llds_type(unsigned)     --> io__write_string("Unsigned").
-output_llds_type(float)        --> io__write_string("Float").
-output_llds_type(word)         --> io__write_string("Word").
-output_llds_type(string)       --> io__write_string("String").
-output_llds_type(data_ptr)     --> io__write_string("Word *").
-output_llds_type(code_ptr)     --> io__write_string("Code *").
+output_llds_type(bool)         --> io__write_string("MR_Integer").
+output_llds_type(integer)      --> io__write_string("MR_Integer").
+output_llds_type(unsigned)     --> io__write_string("MR_Unsigned").
+output_llds_type(float)        --> io__write_string("MR_Float").
+output_llds_type(word)         --> io__write_string("MR_Word").
+output_llds_type(string)       --> io__write_string("MR_String").
+output_llds_type(data_ptr)     --> io__write_string("MR_Word *").
+output_llds_type(code_ptr)     --> io__write_string("MR_Code *").
 
 :- pred output_cons_arg_decls(list(maybe(rval))::in, string::in, string::in,
 	int::in, int::out, decl_set::in, decl_set::out,
@@ -3572,9 +3583,7 @@
 			)
 		;
 			% cast value to desired type
-			io__write_string("("),
-			output_llds_type(DesiredType),
-			io__write_string(") "),
+			output_llds_type_cast(DesiredType),
 			output_rval(Rval)
 		)
 	).
@@ -3595,7 +3604,7 @@
 types_match(bool, word).
 types_match(integer, bool).
 
-	% output a float rval, converted to type `Word *'
+	% output a float rval, converted to type `MR_Word *'
 	%
 :- pred output_float_rval_as_data_ptr(rval, io__state, io__state).
 :- mode output_float_rval_as_data_ptr(in, di, uo) is det.
@@ -3613,15 +3622,17 @@
 		{ UnboxFloat = no, StaticGroundTerms = yes },
 		{ llds_out__float_const_expr_name(Rval, FloatName) }
 	->
-		io__write_string("(Word *) &mercury_float_const_"),
+		output_llds_type_cast(data_ptr),
+		io__write_string(" &mercury_float_const_"),
 		io__write_string(FloatName)
 	;
-		io__write_string("(Word *) float_to_word("),
+		output_llds_type_cast(data_ptr),
+		io__write_string(" float_to_word("),
 		output_rval(Rval),
 		io__write_string(")")
 	).
 
-	% output a float rval, converted to type `Word'
+	% output a float rval, converted to type `MR_Word'
 	%
 :- pred output_float_rval_as_word(rval, io__state, io__state).
 :- mode output_float_rval_as_word(in, di, uo) is det.
@@ -3639,7 +3650,8 @@
 		{ UnboxFloat = no, StaticGroundTerms = yes },
 		{ llds_out__float_const_expr_name(Rval, FloatName) }
 	->
-		io__write_string("(Word) &mercury_float_const_"),
+		output_llds_type_cast(word),
+		io__write_string(" &mercury_float_const_"),
 		io__write_string(FloatName)
 	;
 		io__write_string("float_to_word("),
@@ -3778,17 +3790,20 @@
 output_rval(mem_addr(MemRef)) -->
 	(
 		{ MemRef = stackvar_ref(N) },
-		io__write_string("(Word *) &MR_stackvar("),
+		output_llds_type_cast(data_ptr),
+		io__write_string(" &MR_stackvar("),
 		io__write_int(N),
 		io__write_string(")")
 	;
 		{ MemRef = framevar_ref(N) },
-		io__write_string("(Word *) &MR_framevar("),
+		output_llds_type_cast(data_ptr),
+		io__write_string(" &MR_framevar("),
 		io__write_int(N),
 		io__write_string(")")
 	;
 		{ MemRef = heap_ref(Rval, Tag, FieldNum) },
-		io__write_string("(Word *) &MR_field("),
+		output_llds_type_cast(data_ptr),
+		io__write_string(" &MR_field("),
 		output_tag(Tag),
 		io__write_string(", "),
 		output_rval(Rval),
@@ -3811,13 +3826,15 @@
 	% we need to cast to (Integer) to ensure
 	% things like 1 << 32 work when `Integer' is 64 bits
 	% but `int' is 32 bits.
-	io__write_string("(Integer) "),
+	output_llds_type_cast(integer),
+	io__write_string(" "),
 	io__write_int(N).
 output_rval_const(float_const(FloatVal)) -->
 	% the cast to (Float) here lets the C compiler
 	% do arithmetic in `float' rather than `double'
 	% if `Float' is `float' not `double'.
-	io__write_string("(Float) "),
+	output_llds_type_cast(float),
+	io__write_string(" "),
 	io__write_float(FloatVal).
 output_rval_const(string_const(String)) -->
 	io__write_string("MR_string_const("""),
@@ -3839,9 +3856,10 @@
 output_rval_const(code_addr_const(CodeAddress)) -->
 	output_code_addr(CodeAddress).
 output_rval_const(data_addr_const(DataAddr)) -->
-	% data addresses are all assumed to be of type `Word *';
+	% data addresses are all assumed to be of type `MR_Word *';
 	% we need to cast them here to avoid type errors
-	io__write_string("(Word *) &"),
+	output_llds_type_cast(data_ptr),
+	io__write_string(" &"),
 	output_data_addr(DataAddr).
 output_rval_const(label_entry(Label)) -->
 	io__write_string("ENTRY("),
@@ -3851,7 +3869,7 @@
 	% Output an rval as an initializer in a static struct.
 	% Make sure it has the C type the corresponding field would have.
 	% This is the "really" natural type of the rval, free of the
-	% Mercury abstract engine's need to shoehorn things into Words.
+	% Mercury abstract engine's need to shoehorn things into MR_Words.
 
 :- pred output_static_rval(rval, io__state, io__state).
 :- mode output_static_rval(in, di, uo) is det.
@@ -3863,7 +3881,8 @@
 output_static_rval(binop(_, _, _)) -->
 	{ error("Cannot output a binop(_, _, _) in a static initializer") }.
 output_static_rval(mkword(Tag, Exprn)) -->
-	io__write_string("(Word *) MR_mkword("),
+	output_llds_type_cast(data_ptr),
+	io__write_string(" MR_mkword("),
 	output_tag(Tag),
 	io__write_string(", "),
 	output_static_rval(Exprn),
@@ -3913,7 +3932,8 @@
 output_rval_static_const(code_addr_const(CodeAddress)) -->
 	output_code_addr(CodeAddress).
 output_rval_static_const(data_addr_const(DataAddr)) -->
-	io__write_string("(Word *) &"),
+	output_llds_type_cast(data_ptr),
+	io__write_string(" &"),
 	output_data_addr(DataAddr).
 output_rval_static_const(label_entry(Label)) -->
 	io__write_string("ENTRY("),
@@ -3931,7 +3951,7 @@
 		% sanity check -- if this happens, the llds is ill-typed
 		{ error("output_lval_as_word: got float") }
 	;
-		io__write_string("LVALUE_CAST(Word,"),
+		io__write_string("LVALUE_CAST(MR_Word,"),
 		output_lval(Lval),
 		io__write_string(")")
 	).
Index: compiler/mlds_to_c.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_c.m,v
retrieving revision 1.45
diff -u -r1.45 mlds_to_c.m
--- compiler/mlds_to_c.m	2000/07/25 09:46:11	1.45
+++ compiler/mlds_to_c.m	2000/07/28 05:19:55
@@ -424,34 +424,34 @@
 	{ export__type_to_type_string(Type, String) },
 	io__write_string(String).
 mlds_output_pragma_export_type(prefix, mlds__cont_type) -->
-	io__write_string("Word").
+	io__write_string("MR_Word").
 mlds_output_pragma_export_type(prefix, mlds__commit_type) -->
-	io__write_string("Word").
+	io__write_string("MR_Word").
 mlds_output_pragma_export_type(prefix, mlds__native_bool_type) -->
-	io__write_string("Word").
+	io__write_string("MR_Word").
 mlds_output_pragma_export_type(prefix, mlds__native_int_type) -->
-	io__write_string("Integer").
+	io__write_string("MR_Integer").
 mlds_output_pragma_export_type(prefix, mlds__native_float_type) -->
-	io__write_string("Float").
+	io__write_string("MR_Float").
 mlds_output_pragma_export_type(prefix, mlds__native_char_type) -->
-	io__write_string("Char").
+	io__write_string("MR_Char").
 mlds_output_pragma_export_type(prefix, mlds__class_type(_, _, _)) -->
-	io__write_string("Word").
+	io__write_string("MR_Word").
 mlds_output_pragma_export_type(prefix, mlds__array_type(_)) -->
-	io__write_string("Word").
+	io__write_string("MR_Word").
 mlds_output_pragma_export_type(prefix, mlds__ptr_type(Type)) -->
 	mlds_output_pragma_export_type(prefix, Type),
 	io__write_string(" *").
 mlds_output_pragma_export_type(prefix, mlds__func_type(_)) -->
-	io__write_string("Word").
+	io__write_string("MR_Word").
 mlds_output_pragma_export_type(prefix, mlds__generic_type) -->
-	io__write_string("Word").
+	io__write_string("MR_Word").
 mlds_output_pragma_export_type(prefix, mlds__generic_env_ptr_type) -->
-	io__write_string("Word").
+	io__write_string("MR_Word").
 mlds_output_pragma_export_type(prefix, mlds__pseudo_type_info_type) -->
-	io__write_string("Word").
+	io__write_string("MR_Word").
 mlds_output_pragma_export_type(prefix, mlds__rtti_type(_)) -->
-	io__write_string("Word").
+	io__write_string("MR_Word").
 	
 
 	%
@@ -2532,7 +2532,8 @@
 	io__write_string(UnaryOpString),
 	io__write_string("("),
 	( { UnaryOp = tag } ->
-		% The MR_tag macro requires its argument to be of type `Word'.
+		% The MR_tag macro requires its argument to be of type 
+		% `MR_Word'.
 		% XXX should we put this cast inside the definition of MR_tag?
 		io__write_string("(MR_Word) ")
 	;
@@ -2628,16 +2629,16 @@
 mlds_output_rval_const(false) -->
 	io__write_string("FALSE").	% XXX should we use `MR_FALSE'?
 mlds_output_rval_const(int_const(N)) -->
-	% we need to cast to (Integer) to ensure
+	% we need to cast to (MR_Integer) to ensure
 	% things like 1 << 32 work when `Integer' is 64 bits
 	% but `int' is 32 bits.
-	io__write_string("(Integer) "),
+	io__write_string("(MR_Integer) "),
 	io__write_int(N).
 mlds_output_rval_const(float_const(FloatVal)) -->
-	% the cast to (Float) here lets the C compiler
+	% the cast to (MR_Float) here lets the C compiler
 	% do arithmetic in `float' rather than `double'
-	% if `Float' is `float' not `double'.
-	io__write_string("(Float) "),
+	% if `MR_Float' is `float' not `double'.
+	io__write_string("(MR_Float) "),
 	io__write_float(FloatVal).
 mlds_output_rval_const(string_const(String)) -->
 	% the cast avoids the following gcc warning


Index: runtime/mercury_bootstrap.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_bootstrap.h,v
retrieving revision 1.14
diff -u -r1.14 mercury_bootstrap.h
--- runtime/mercury_bootstrap.h	2000/05/08 13:48:44	1.14
+++ runtime/mercury_bootstrap.h	2000/07/28 01:47:59
@@ -23,8 +23,28 @@
 
 #define MR_TypeCtorInfo_struct  MR_TypeCtorInfo_Struct
 
+
 #ifndef MR_NO_BACKWARDS_COMPAT
 
+/* 
+** For a long time the Mercury C types were defined as Char, Float,
+** Integer, Word, etc.  There will doubtless be lots of C code in
+** libraries that relies upon these names.  
+*/
+
+#define Word 		MR_Word
+#define Code 		MR_Code
+#define Char 		MR_Char
+#define Float 		MR_Float
+#define Float64 	MR_Float64
+#define Integer 	MR_Integer
+#define Unsigned 	MR_Unsigned
+#define UnsignedChar 	MR_UnsignedChar
+#define String 		MR_String
+#define ConstString 	MR_ConstString
+#define Bool 		MR_Bool
+
+
 #define	COMPARE_EQUAL		MR_COMPARE_EQUAL
 #define	COMPARE_LESS		MR_COMPARE_LESS
 #define	COMPARE_GREATER		MR_COMPARE_GREATER
@@ -74,7 +94,7 @@
 #define	decr_sp(n)		MR_decr_sp(n)
 
 #define	push(w)		(					\
-				*MR_sp = (Word) (w),		\
+				*MR_sp = (MR_Word) (w),		\
 				debugpush(*MR_sp, MR_sp),	\
 				MR_sp = MR_sp + 1,		\
 				detstack_overflow_check(),	\
Index: runtime/mercury_imp.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_imp.h,v
retrieving revision 1.15
diff -u -r1.15 mercury_imp.h
--- runtime/mercury_imp.h	2000/05/05 10:14:48	1.15
+++ runtime/mercury_imp.h	2000/07/27 07:26:46
@@ -25,6 +25,7 @@
 */
 
 #include	"mercury_conf.h"
+#include	"mercury_bootstrap.h"
 
 /*
 ** The following must come before any declarations of or use of
@@ -80,6 +81,5 @@
 
 #include	"mercury_grade.h"
 
-#include	"mercury_bootstrap.h"
 
 #endif /* not MERCURY_IMP_H */


-- 
       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-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list