Open mthom opened 3 years ago
I'm not sure I entirely understand, but would an API like this work for you?
pub enum HeapCellValueTag {
Cons(Cons) = 0b00,
F64(F64) = 0b01,
Atom(Atom) = 0b1010,
/* ... */
}
struct Atom {
spec_bit_3: B1, //or with your newer verion: `is_functor: bool,`
m: bool,
}
Ah, it is just tagged union with bitfields
I'm writing a dynamic language interpreter that uses pointer tagging to identify records in memory. It uses staged tagging, so that the number of tag bits can vary depending on the type of record. These records are primarily defined as values of:
where tag is a bitfield specifier enum:
I highlight
Cons
,F64
andAtom
because their tag sizes are 2 bits, 2 bits, and 4 bits respectively. All other tags use the full 6 bits ofHeapCellValueTag
. For the smaller tags, the remaining tag bits ofHeapCellValue
are used for other data. In particular,Atom
-tagged cells are actually formatted like this:My problem is that I can't extract the smaller tags from
HeapCellValue
values using the generated bitfield functions without adjacent bits ofAtomCell
being included in the resultingHeapCellValue
'stag
field upon conversion. Is it possible to access the bits of the bitfield without making assumptions about the endianness of the machine?