Jonas Maebe wrote:
On 1 aug 2006, at 23:53, Waldek Hebisch wrote:
[snip]
In principle we can change set representation. In fact, there is one change that I intend to do in the future: currently even the smalles set use a MedCard sized word, I plan to allocate smaller space for them (smallest unit which can represent them).
There have been plans for a long time to do that in FPC as well. If you do this as meticulously as Delphi does (its set size grows by 1 byte at a time), then you more or less need by definition a little- endian representation of sets in all cases though (because of the left-over bytes at the end).
For this reason, a number of FPC developers are in favour of using "little endian" sets on all platforms. I'm a bit wary of breaking backwards binary compatibility though, and possibly also compatibility with other big endian Pascal compilers (does anyone know how CodeWarrior/PPC and/or Think Pascal store their sets?)
68K and PPC CodeWarrior Pascal, YHINK Pascal, and MPW Pascal all use the same data format for sets. The format is an array of bytes and (from the CodeWarrior Pascal documentation) the formula for determining a specific set element bit in the array is:
bit : BAND(SET[|SET| - 1 - EL div 8],(BSL(1,EL mod 8))
where BAND and BSL are 68K intrinsics for 68K instructions for respectively bitwise AND and bitwise shift left. EL is the element number which corresponds to the ord of the element in the base type the set is derived from. |SET| is the number of bytes in the set, so the byte array has an index subrange of 0..(|SET| - 1).
The byte array is always sized/allocated with an element number zero base even in the cases of a subrange base type set (e.g., set of [5..15] will be allocated the same as set of [0..15] and the bits for 0..4 won't be used). The array can be as small as one byte (for sets in the subrange 0..7) and as large as 256 bytes for the maximum support set size (i.e., subrange 0..2047). For one byte sized sets, there are no alignment restrictions for storage. Larger sets are even byte aligned.
Thus, array[|array| - 1] is where bits for set elements 7..0 (in that order; i.e., set element 7 is the most significant bit in the byte) are found.
As an aside, I'll note CodeWarrior and YHINK Pascal always use RTL calls for set expression operations; whereas, MPW Pascal will use the appropriate inline bitwise and, or, and not 68K instructions for set expressions involving one, two, and four byte sized sets. Compatability with MPW Pascal and 68K inline instructions is the origin for the set data format in all the traditional MacPascal compilers.
Gale Paeper gpaeper@empirenet.com