Implementing NaN Boxing in a Stack-Based VM
## My Implementation I'm using a 64-bit layout: - Bits 63-51: Quiet NaN signature (0x7FFC...) - Bits 50-18: 32-bit payload (integers, string pool indices, etc.) - Bits 17-3: Unused/ (15 bits) - Bits 2-0: 3-bit type tag So it allows me to have 5 tagged types: `TRUE_VAL`, `FALSE_VAL`, `STRING_VAL`, `CALLDATA_VAL`, `U32_VAL` This is for a domain-specific VM I'm building for programmable task management (think "Vim for todo apps" - small core with scriptable behaviors). The VM is stack-based with: - String pooling & instructions pooling (indices stored as NaN-boxed values) - Call stack for task instructions execution. code is here : https://ift.tt/DyFs0IB 0 comments on Hacker News.
## My Implementation I'm using a 64-bit layout: - Bits 63-51: Quiet NaN signature (0x7FFC...) - Bits 50-18: 32-bit payload (integers, string pool indices, etc.) - Bits 17-3: Unused/ (15 bits) - Bits 2-0: 3-bit type tag So it allows me to have 5 tagged types: `TRUE_VAL`, `FALSE_VAL`, `STRING_VAL`, `CALLDATA_VAL`, `U32_VAL` This is for a domain-specific VM I'm building for programmable task management (think "Vim for todo apps" - small core with scriptable behaviors). The VM is stack-based with: - String pooling & instructions pooling (indices stored as NaN-boxed values) - Call stack for task instructions execution. code is here : https://ift.tt/DyFs0IB
## My Implementation I'm using a 64-bit layout: - Bits 63-51: Quiet NaN signature (0x7FFC...) - Bits 50-18: 32-bit payload (integers, string pool indices, etc.) - Bits 17-3: Unused/ (15 bits) - Bits 2-0: 3-bit type tag So it allows me to have 5 tagged types: `TRUE_VAL`, `FALSE_VAL`, `STRING_VAL`, `CALLDATA_VAL`, `U32_VAL` This is for a domain-specific VM I'm building for programmable task management (think "Vim for todo apps" - small core with scriptable behaviors). The VM is stack-based with: - String pooling & instructions pooling (indices stored as NaN-boxed values) - Call stack for task instructions execution. code is here : https://ift.tt/DyFs0IB 0 comments on Hacker News.
## My Implementation I'm using a 64-bit layout: - Bits 63-51: Quiet NaN signature (0x7FFC...) - Bits 50-18: 32-bit payload (integers, string pool indices, etc.) - Bits 17-3: Unused/ (15 bits) - Bits 2-0: 3-bit type tag So it allows me to have 5 tagged types: `TRUE_VAL`, `FALSE_VAL`, `STRING_VAL`, `CALLDATA_VAL`, `U32_VAL` This is for a domain-specific VM I'm building for programmable task management (think "Vim for todo apps" - small core with scriptable behaviors). The VM is stack-based with: - String pooling & instructions pooling (indices stored as NaN-boxed values) - Call stack for task instructions execution. code is here : https://ift.tt/DyFs0IB
Hacker News story: Implementing NaN Boxing in a Stack-Based VM
Reviewed by Tha Kur
on
January 07, 2026
Rating:
No comments: