mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-15 13:55:07 +00:00
Add MR_ prefixes to the types used when generating C code.
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. Also define MR_Box for both the LLDS and MLDS backends so we can use it uniformly. 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. doc/reference_manual.texi: Update the reference manual to talk about MR_Word, MR_String, MR_Char, etc. runtime/mercury_bootstrap.h: Add bootstrapping typedefs. runtime/*: trace/*: Change Word, Float, Bool, Code, String, etc to MR_Word, MR_Float, MR_Bool, MR_Code, MR_String.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** Copyright (C) 1997 The University of Melbourne.
|
||||
** Copyright (C) 1997, 2000 The University of Melbourne.
|
||||
** This file may only be copied under the terms of the GNU Library General
|
||||
** Public License - see the file COPYING.LIB in the Mercury distribution.
|
||||
*/
|
||||
@@ -9,37 +9,37 @@
|
||||
/*
|
||||
** The function `hash_float()' is used by the library predicate `float__hash'
|
||||
** and also for hashing floats for `pragma fact_table' indexing.
|
||||
** It computes a non-negative Integer hash value for a Float.
|
||||
** The exact hash function used depend on the relative sizes of Float and
|
||||
** Integer.
|
||||
** It computes a non-negative MR_Integer hash value for a MR_Float.
|
||||
** The exact hash function used depend on the relative sizes of MR_Float and
|
||||
** MR_Integer.
|
||||
*/
|
||||
|
||||
union FloatInteger {
|
||||
Float f;
|
||||
Integer i;
|
||||
Integer j[(sizeof(Float)/sizeof(Integer) > 0
|
||||
? sizeof(Float)/sizeof(Integer) : 1)];
|
||||
char c[sizeof(Float)/sizeof(char)];
|
||||
union MR_Float_Integer {
|
||||
MR_Float f;
|
||||
MR_Integer i;
|
||||
MR_Integer j[(sizeof(MR_Float)/sizeof(MR_Integer) > 0
|
||||
? sizeof(MR_Float)/sizeof(MR_Integer) : 1)];
|
||||
char c[sizeof(MR_Float)/sizeof(char)];
|
||||
};
|
||||
|
||||
Integer
|
||||
hash_float(Float f)
|
||||
MR_Integer
|
||||
hash_float(MR_Float f)
|
||||
{
|
||||
union FloatInteger fi;
|
||||
union MR_Float_Integer fi;
|
||||
size_t i;
|
||||
Integer h = 0;
|
||||
MR_Integer h = 0;
|
||||
|
||||
fi.i = 0;
|
||||
fi.f = f;
|
||||
|
||||
if (sizeof(Float) <= sizeof(Integer)) {
|
||||
if (sizeof(MR_Float) <= sizeof(MR_Integer)) {
|
||||
h = fi.i;
|
||||
} else if (sizeof(Float) % sizeof(Integer) == 0) {
|
||||
for (i = 0; i < sizeof(Float)/sizeof(Integer); i++) {
|
||||
} else if (sizeof(MR_Float) % sizeof(MR_Integer) == 0) {
|
||||
for (i = 0; i < sizeof(MR_Float)/sizeof(MR_Integer); i++) {
|
||||
h ^= fi.j[i];
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < sizeof(Float)/sizeof(char); i++) {
|
||||
for (i = 0; i < sizeof(MR_Float)/sizeof(char); i++) {
|
||||
h ^= (h << 5);
|
||||
h ^= fi.c[i];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user