Richard Sharman wrote:
The example below shows that sets have the wrong value from the initialization, but are ok if calcuated or if set in the code.
var vowels : letter_set := [ 'a', 'e', 'i', 'o', 'u' ] ;
is inconrrect,
vowels := [ 'a', 'e', 'i', 'o', 'u' ] ;
works fine.
I suspect it would work on a low-endian machine, but does not work on a big-endian. [...]
Your observation is correct. We recently discovered that there is a disagreement about the representation of sets (as fields consisting of bytes or words) betweem the frontend and backend. On little-endian machines, this doesn't matter, but on big-endian ones, it's a problem.
Since I experienced the problem on a Sun as well, and currently no-one has the time to make a real solution, I made a quick patch (aka kludge)-: for 32-bit big-endian machines. It doesn't change anything on little-endian machines, but it still does not work on 64-bit big-endian machines.
The following is for GCC-2.8.1, but might work with EGCS as well (to be applied in the gcc source directory, not the p subdirectory). This is an "unofficial" patch, but your test program works with this patch under sparc-sun-solaris2.
--- tree.c.orig Fri Apr 30 04:08:09 1999 +++ tree.c Fri Apr 30 04:13:13 1999 @@ -4801,8 +4801,7 @@ tree vals = TREE_OPERAND (init, 1); int set_word_size = BITS_PER_UNIT; int bit_size = wd_size * set_word_size; - int bit_pos = 0; - unsigned char *bytep = buffer; + int bit_pos = 0, byte_index = 0; char *bit_buffer = (char *) alloca(bit_size); tree non_const_bits = get_set_constructor_bits (init, bit_buffer, bit_size);
@@ -4813,14 +4812,18 @@ { if (bit_buffer[i]) { +/* @@@@@@@@@@@ THIS IS A KLUDGE FOR GPC SETS!!! + IT WORKS ONLY FOR 32 BIT BIG-ENDIAN SYSTEMS. + (On little-endian systems, it works correctly.) */ +#define BYTES_PER_WORD 4 if (BYTES_BIG_ENDIAN) - *bytep |= (1 << (set_word_size - 1 - bit_pos)); + buffer [byte_index + BYTES_PER_WORD - 1 - 2 * (byte_index % BYTES_PER_WORD)] |= 1 << bit_pos; else - *bytep |= 1 << bit_pos; + buffer [byte_index] |= 1 << bit_pos; } bit_pos++; if (bit_pos >= set_word_size) - bit_pos = 0, bytep++; + bit_pos = 0, byte_index++; } return non_const_bits; }
Frank
-- Frank Heckenbach, frank@fjf.gnu.de, http://fjf.gnu.de/ GPC To-Do list, latest features, fixed bugs: http://agnes.dida.physik.uni-essen.de/~gnu-pascal/todo.html