Struct passerine::vm::tag::Tagged [−][src]
pub struct Tagged(_);
Expand description
Tagged
implements Nan-tagging around the Data
enum.
In essence, it’s possible to exploit the representation of f64
NaNs
to store pointers to other datatypes.
When laid out, this is what the bit-level representation of a double-precision floating-point number looks like:
SExponent---QIMantissa------------------------------------------
PNaN--------11D-Payload-------------------------------------...T
Where S
is sign, Q
is quiet flag, I
is Intel’s “QNan Floating-Point Indefinite”;
P
is pointer flag, D
is Data Tag (should always be 1), T
is Tag.
By exploiting this fact, assuming a 64-bit system,
each item on the stack only takes up a machine word.
This differs from having a stack of Box
’d Data
,
because small items, like booleans, stack frames, etc.
can be encoded directly into the tag
rather than having to follow a pointer.
It also keeps math fast for f64s, as a simple check and transmutation
is all that’s needed to reinterpret the bits as a valid number.
NOTE: implementation modeled after:
- rpjohnst/dejavu,
- and the Optimization chapter from Crafting Interpreters.
Thank you!
Implementations
Unwraps a tagged number into the appropriate datatype, consuming the tagged number.