Skip to main content

Module v2_struct

Module v2_struct 

Source
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.