Skip to main content

Module v2_string_ffi

Module v2_string_ffi 

Source
Expand description

v2 String FFI functions for JIT-compiled code.

These functions operate on the v2 StringObj layout — a compact, C-compatible representation that the JIT can manipulate with native pointer types instead of NaN-boxed u64 values.

§StringObj memory layout (24 bytes)

Offset  Size  Field
------  ----  -----
  0       4   refcount (u32)
  4       2   kind (u16, = HK_STRING = 0)
  6       2   (padding)
  8       8   data (*const u8, UTF-8 bytes)
 16       4   len (u32, byte length)
 20       4   (padding)

The 8-byte header at offset 0 packs refcount + kind + padding so that the data pointer is naturally 8-byte aligned.

Functions§

jit_v2_string_alloc
Allocate a new StringObj from raw UTF-8 bytes. Returns a raw pointer to the StringObj (which the JIT treats as *mut u8 / I64).
jit_v2_string_concat
Concatenate two v2 strings. Returns a freshly allocated StringObj with refcount 1. Neither input is consumed (their refcounts are unchanged).
jit_v2_string_data
Return a pointer to the raw UTF-8 data bytes.
jit_v2_string_eq
Compare two v2 strings for byte-equality. Returns 1 if equal, 0 otherwise.
jit_v2_string_len
Return the byte length of the string.
jit_v2_string_print
Print a v2 string to stdout (with trailing newline), used by the print builtin in JIT-compiled code.
jit_v2_string_release
Decrement the reference count (release). Deallocates the object when the count reaches zero. No-op on null.
jit_v2_string_retain
Increment the reference count (retain). No-op on null.