Implementing NaN Boxing in a Stack-Based VM

2作者: tracyspacy大约 1 个月前原帖
## My Implementation<p>I&#x27;m using a 64-bit layout:<p>- Bits 63-51: Quiet NaN signature (0x7FFC...)<p>- Bits 50-18: 32-bit payload (integers, string pool indices, etc.)<p>- Bits 17-3: Unused&#x2F; (15 bits)<p>- Bits 2-0: 3-bit type tag<p>So it allows me to have 5 tagged types: `TRUE_VAL`, `FALSE_VAL`, `STRING_VAL`, `CALLDATA_VAL`, `U32_VAL`<p>This is for a domain-specific VM I&#x27;m building for programmable task management (think &quot;Vim for todo apps&quot; - small core with scriptable behaviors). The VM is stack-based with:<p>- String pooling &amp; instructions pooling (indices stored as NaN-boxed values) - Call stack for task instructions execution.<p>code is here : https:&#x2F;&#x2F;github.com&#x2F;tracyspacy&#x2F;spacydo&#x2F;blob&#x2F;main&#x2F;src&#x2F;values.rs
查看原文
## My Implementation<p>I&#x27;m using a 64-bit layout:<p>- Bits 63-51: Quiet NaN signature (0x7FFC...)<p>- Bits 50-18: 32-bit payload (integers, string pool indices, etc.)<p>- Bits 17-3: Unused&#x2F; (15 bits)<p>- Bits 2-0: 3-bit type tag<p>So it allows me to have 5 tagged types: `TRUE_VAL`, `FALSE_VAL`, `STRING_VAL`, `CALLDATA_VAL`, `U32_VAL`<p>This is for a domain-specific VM I&#x27;m building for programmable task management (think &quot;Vim for todo apps&quot; - small core with scriptable behaviors). The VM is stack-based with:<p>- String pooling &amp; instructions pooling (indices stored as NaN-boxed values) - Call stack for task instructions execution.<p>code is here : https:&#x2F;&#x2F;github.com&#x2F;tracyspacy&#x2F;spacydo&#x2F;blob&#x2F;main&#x2F;src&#x2F;values.rs