Expand description
v2 Typed Struct FFI Functions for JIT
Provides allocation, field access, and refcounting for v2 typed structs. These structs have a fixed layout with a HeapHeader (8 bytes) followed by fields at compile-time-known offsets:
+------------------+------------------+------------------+-----
| HeapHeader | field[0] | field[1] | ...
| (8 bytes) | (type-dependent) | (type-dependent) |
+------------------+------------------+------------------+-----
offset 0 offset 8 offset 8+sizeof(f0)HeapHeader layout (8 bytes):
- offset 0: refcount (u32) - initialized to 1
- offset 4: kind (u16) - set to HK_V2_TYPED_STRUCT
- offset 6: flags (u8) - reserved
- offset 7: padding (u8)
Field access uses raw pointer arithmetic with byte offsets known at compile time, giving O(1) access with no schema lookup.
Constants§
- HK_
V2_ TYPED_ STRUCT - Heap kind tag for v2 typed structs. Uses a JIT-private range (132+) to avoid collision with existing HK_ constants.
Functions§
- jit_
v2_ struct_ alloc - Allocate a v2 typed struct with the given total size (including header).
- jit_
v2_ struct_ get_ bool - Read a bool field (stored as u8) at the given byte offset.
- jit_
v2_ struct_ get_ f64 - Read an f64 field at the given byte offset.
- jit_
v2_ struct_ get_ i32 - Read an i32 field at the given byte offset.
- jit_
v2_ struct_ get_ i64 - Read an i64 field at the given byte offset.
- jit_
v2_ struct_ get_ ptr - Read a pointer field at the given byte offset.
- jit_
v2_ struct_ refcount - Read the current refcount of a v2 typed struct (for testing/debugging).
- jit_
v2_ struct_ release - Decrement the refcount of a v2 typed struct. Deallocates when it reaches 0.
- jit_
v2_ struct_ retain - Increment the refcount of a v2 typed struct.
- jit_
v2_ struct_ set_ bool - Write a bool field (stored as u8) at the given byte offset.
- jit_
v2_ struct_ set_ f64 - Write an f64 field at the given byte offset.
- jit_
v2_ struct_ set_ i32 - Write an i32 field at the given byte offset.
- jit_
v2_ struct_ set_ i64 - Write an i64 field at the given byte offset.
- jit_
v2_ struct_ set_ ptr - Write a pointer field at the given byte offset.