compiler/shared/runtime/l0_runtime.h
Overview Symbols grouped by source file: compiler/shared/runtime/l0_runtime.h
Source: compiler/shared/runtime/l0_runtime.h Language: C
L0 Runtime Library (K0 - Kernel Layer)
Header-only C99 runtime providing:
- Memory allocation and deallocation
- Whole-file I/O operations
- Basic printing to stdout/stderr
- Panic mechanism for defined runtime aborts
- UB-free integer operations
- String type and operations
- Optional type support
- Random number generation
- Wall/monotonic time snapshots and local-time metadata
- Support for L0 new and drop semantics
- Environment variable access
- Reading from stdin
- Errno access
Design principles:
- All UB and platform quirks are confined to this file
- L0 programs use l0_int (int32_t); this layer handles size_t conversion
- Portable C99 code, no compiler-specific extensions
Imports / Includes
stdio.hstdlib.hstdint.hstddef.hstring.hstdarg.herrno.htime.hsys/types.hsys/stat.hunistd.hsys/wait.hdea_siphash.h
Symbols
- DEA_RUNTIME_FCLOSE
- DEA_RUNTIME_FILE_INFO_STAT
- DEA_RUNTIME_REMOVE
- _RT_ALIGNOF
- L0_UNREACHABLE
- _RT_TRACE_ARC
- _RT_TRACE_ARC_LOC
- _RT_TRACE_MEM
- _RT_TRACE_MEM_LOC
- L0_STRING_K_STATIC
- L0_STRING_K_HEAP
- L0_STRING_CONST
- L0_OPT_BOOL_DEFINED
- L0_OPT_BYTE_DEFINED
- L0_OPT_INT_DEFINED
- L0_OPT_STRING_DEFINED
- L0_DEFINED_l0_sys_rt_RtTimeParts
- L0_DEFINED_l0_sys_rt_RtFileInfo
- _RT_ALLOC_INIT_CAP
- _RT_ALLOC_LIVE
- _RT_ALLOC_QUARANTINED
- _RT_ALLOC_POOLED
- _RT_MEM_RAW
- _RT_MEM_NEW
- _RT_MEM_ARC
- _RT_MEM_STATIC
- _RT_MEM_FOREIGN
- _RT_ACCESS_READ
- _RT_ACCESS_WRITE
- _RT_ACCESS_UNTRACKED_OK
- _RT_QUARANTINE_MAX_BYTES
- _RT_QUARANTINE_MAX_COUNT
- _RT_REC_POOL_CHUNK
- _RT_ALLOC_TOMBSTONE
- _rt_rec_cold
- _L0_TAG_OPT
- _L0_TAG_PTR
- _L0_TAG_ENUM
- _L0_TAG_STRUCT
- l0_bool
- l0_tiny
- l0_short
- l0_int
- l0_long
- l0_byte
- l0_ushort
- l0_uint
- l0_ulong
- l0_float
- l0_double
- _rt_alloc_record
- _rt_alloc_record_cold
- _rt_ptr_site
- _rt_alloc_record_size_check
- _rt_siphash_key_t
- _rt_siphash_tag8_t
- _RT_MEM_SENTINEL
- L0_STRING_EMPTY
- L0_OPT_STRING_NULL
- L0_OPT_STRING_EMPTY
- _rt_argc
- _rt_argv
- _rt_alloc_table
- _rt_alloc_table_cap
- _rt_alloc_table_cnt
- _rt_alloc_table_tombstones
- _rt_alloc_next_generation
- _rt_alloc_tree_root
- _rt_rec_free_list
- _rt_cold_chunks
- _rt_rec_pool_chunks
- _rt_quarantine_head
- _rt_quarantine_tail
- _rt_quarantine_bytes
- _rt_quarantine_count
- _l0_sh_tag_bool
- _l0_sh_tag_byte
- _l0_sh_tag_int
- _l0_sh_tag_string
- _l0_sh_tag_data
- _rt_sh_key
- _rt_init_args
- _rt_panic
- _rt_panic_fmt
- _rt_idiv
- _rt_imod
- _rt_iadd
- _rt_isub
- _rt_imul
- _rt_narrow_l0_byte
- _unwrap_ptr
- _unwrap_opt
- _rt_track_alloc_record
- _rt_promote_new_alloc
- _rt_release_tracked_alloc
- _rt_realloc_tracked_alloc
- _rt_check_ptr_site_slow
- _rt_check_index_ptr_site_slow
- _rt_drop_begin_impl
- _rt_drop_finish_impl
- _rt_validate_derived_ptr
- _rt_track_arc_bytes
- _rt_untrack_arc_alloc
- _rt_track_static_bytes
- _rt_check_ptr_site
- _rt_check_index_ptr_site
- _rt_l0_string_from_const_literal
- _rt_init_heap_string
- _rt_alloc_string
- _rt_free_string
- _rt_realloc_string
- _rt_new_l0_string
- _rt_string_bytes
- rt_strlen
- rt_string_get
- rt_string_bytes_ptr
- rt_string_equals
- rt_string_compare
- rt_string_concat
- rt_string_slice
- rt_string_from_byte
- rt_string_from_byte_array
- rt_string_retain
- rt_string_release
- rt_system
- rt_get_env_var
- rt_get_argc
- _rt_pid_to_l0_int
- rt_get_pid
- rt_get_argv
- _rt_time_to_l0_int_sec
- _rt_time_to_l0_int_nsec
- _rt_time_write_parts
- rt_time_unix
- rt_time_monotonic
- rt_time_monotonic_supported
- rt_time_local_offset_sec
- rt_time_local_is_dst
- rt_read_file_all
- rt_write_file_all
- rt_file_info
- rt_delete_file
- _rt_stream_write_some
- rt_stdin_read
- rt_stdout_write
- rt_stderr_write
- rt_flush_stdout
- rt_flush_stderr
- _rt_print
- rt_print
- rt_print_stderr
- rt_println
- rt_println_stderr
- rt_print_int
- rt_print_int_stderr
- rt_print_bool
- rt_print_bool_stderr
- rt_read_line
- rt_read_char
- rt_abort
- rt_exit
- rt_srand
- rt_rand
- rt_errno
- rt_alloc
- rt_realloc
- rt_free
- rt_calloc
- rt_memset
- rt_memcpy
- rt_memcmp
- rt_array_element
- _rt_rec_new
- _rt_rec_recycle
- _rt_alloc_hash
- _rt_alloc_table_rehash
- _rt_alloc_table_lookup
- _rt_alloc_table_insert
- _rt_alloc_table_remove
- _rt_panic_invalid_access
- _rt_panic_invalid_drop
- _rt_panic_invalid_release
- _rt_trace_invalid_drop
- _rt_ptr_is_aligned
- _rt_range_contains
- _rt_tree_prio_for
- _rt_tree_insert_at
- _rt_tree_merge
- _rt_tree_remove_at
- _rt_alloc_tree_insert
- _rt_alloc_tree_remove
- _rt_alloc_tree_glb
- _rt_alloc_tree_lub
- _rt_alloc_tree_find_containing
- _rt_ptr_site_store
- _rt_required_size
- _rt_required_align
- _rt_index_element_size
- _rt_index_offset
- _rt_required_access_mode
- _rt_index_access_mode
- _rt_index_allows_untracked
- _rt_check_ptr_align
- _rt_check_record_writeable
- _rt_track_alloc_record_kind
- rt_register_foreign
- rt_unregister_foreign
- _rt_evict_quarantine
- _rt_quarantine_alloc_record
- _rt_alloc_obj
- _rt_fmix32
- _rt_fold_u64_to_u32_fmix
- _rt_hash_tag8
- _rt_hash_bool
- _rt_hash_byte
- _rt_hash_int
- _rt_hash_string
- _rt_hash_data
- rt_hash_bool
- rt_hash_byte
- rt_hash_int
- rt_hash_string
- rt_hash_data
- rt_hash_opt_bool
- rt_hash_opt_byte
- rt_hash_opt_int
- rt_hash_opt_string
- rt_hash_ptr
- rt_hash_opt_ptr
- _l0_h_string
- l0_string
- l0_opt_bool
- l0_opt_byte
- l0_opt_int
- l0_opt_string
- _l0_base_opt
- l0_sys_rt_RtTimeParts
- l0_sys_rt_RtFileInfo
- _rt_alloc_record
- _rt_alloc_record_cold
- _rt_ptr_site
Macro DEA_RUNTIME_FCLOSE
DEA_RUNTIME_FCLOSE
Macro DEA_RUNTIME_FILE_INFO_STAT
DEA_RUNTIME_FILE_INFO_STAT
Macro DEA_RUNTIME_REMOVE
DEA_RUNTIME_REMOVE
Macro _RT_ALIGNOF
_RT_ALIGNOF
Macro L0_UNREACHABLE
L0_UNREACHABLE
Macro _RT_TRACE_ARC
_RT_TRACE_ARC
Macro _RT_TRACE_ARC_LOC
_RT_TRACE_ARC_LOC
Macro _RT_TRACE_MEM
_RT_TRACE_MEM
Macro _RT_TRACE_MEM_LOC
_RT_TRACE_MEM_LOC
Macro L0_STRING_K_STATIC
L0_STRING_K_STATIC
Macro L0_STRING_K_HEAP
L0_STRING_K_HEAP
Macro L0_STRING_CONST
L0_STRING_CONST
String literal construction macro.
Macro L0_OPT_BOOL_DEFINED
L0_OPT_BOOL_DEFINED
Macro L0_OPT_BYTE_DEFINED
L0_OPT_BYTE_DEFINED
Macro L0_OPT_INT_DEFINED
L0_OPT_INT_DEFINED
Macro L0_OPT_STRING_DEFINED
L0_OPT_STRING_DEFINED
Macro L0_DEFINED_l0_sys_rt_RtTimeParts
L0_DEFINED_l0_sys_rt_RtTimeParts
Macro L0_DEFINED_l0_sys_rt_RtFileInfo
L0_DEFINED_l0_sys_rt_RtFileInfo
Macro _RT_ALLOC_INIT_CAP
_RT_ALLOC_INIT_CAP
Macro _RT_ALLOC_LIVE
_RT_ALLOC_LIVE
Macro _RT_ALLOC_QUARANTINED
_RT_ALLOC_QUARANTINED
Macro _RT_ALLOC_POOLED
_RT_ALLOC_POOLED
Macro _RT_MEM_RAW
_RT_MEM_RAW
Macro _RT_MEM_NEW
_RT_MEM_NEW
Macro _RT_MEM_ARC
_RT_MEM_ARC
Macro _RT_MEM_STATIC
_RT_MEM_STATIC
Macro _RT_MEM_FOREIGN
_RT_MEM_FOREIGN
Macro _RT_ACCESS_READ
_RT_ACCESS_READ
Macro _RT_ACCESS_WRITE
_RT_ACCESS_WRITE
Macro _RT_ACCESS_UNTRACKED_OK
_RT_ACCESS_UNTRACKED_OK
Macro _RT_QUARANTINE_MAX_BYTES
_RT_QUARANTINE_MAX_BYTES
Macro _RT_QUARANTINE_MAX_COUNT
_RT_QUARANTINE_MAX_COUNT
Macro _RT_REC_POOL_CHUNK
_RT_REC_POOL_CHUNK
Macro _RT_ALLOC_TOMBSTONE
_RT_ALLOC_TOMBSTONE
Macro _rt_rec_cold
_rt_rec_cold
Macro _L0_TAG_OPT
_L0_TAG_OPT
Macro _L0_TAG_PTR
_L0_TAG_PTR
Macro _L0_TAG_ENUM
_L0_TAG_ENUM
Macro _L0_TAG_STRUCT
_L0_TAG_STRUCT
Type Alias l0_bool
typedef uint8_t l0_bool
Type Alias l0_tiny
typedef int8_t l0_tiny
future use
Type Alias l0_short
typedef int16_t l0_short
Type Alias l0_int
typedef int32_t l0_int
Type Alias l0_long
typedef int64_t l0_long
Type Alias l0_byte
typedef uint8_t l0_byte
Type Alias l0_ushort
typedef uint16_t l0_ushort
Type Alias l0_uint
typedef uint32_t l0_uint
Type Alias l0_ulong
typedef uint64_t l0_ulong
Type Alias l0_float
typedef float l0_float
Type Alias l0_double
typedef double l0_double
Type Alias _rt_alloc_record
typedef struct _rt_alloc_record _rt_alloc_record
Type Alias _rt_alloc_record_cold
typedef struct _rt_alloc_record_cold _rt_alloc_record_cold
Type Alias _rt_ptr_site
typedef struct _rt_ptr_site _rt_ptr_site
Type Alias :-1]
typedef char _rt_alloc_record_size_check[(sizeof(_rt_alloc_record)==64) ? 1 :-1][(sizeof(_rt_alloc_record)==64) ? 1 :-1]
Type Alias _rt_siphash_key_t[16]
typedef uint8_t _rt_siphash_key_t[16][16]
Type Alias _rt_siphash_tag8_t[8]
typedef uint8_t _rt_siphash_tag8_t[8][8]
Variable _RT_MEM_SENTINEL
const l0_int _RT_MEM_SENTINEL
Sentinel value for memory checks.
Variable L0_STRING_EMPTY
l0_string L0_STRING_EMPTY
Static empty string instance.
Variable L0_OPT_STRING_NULL
l0_opt_string L0_OPT_STRING_NULL
Static instance for null optional string.
Variable L0_OPT_STRING_EMPTY
l0_opt_string L0_OPT_STRING_EMPTY
Static instance for empty optional string.
Variable _rt_argc
int _rt_argc
Variable _rt_argv
char** _rt_argv
Variable _rt_alloc_table
_rt_alloc_record** _rt_alloc_table
Variable _rt_alloc_table_cap
size_t _rt_alloc_table_cap
Variable _rt_alloc_table_cnt
size_t _rt_alloc_table_cnt
Variable _rt_alloc_table_tombstones
size_t _rt_alloc_table_tombstones
Variable _rt_alloc_next_generation
uint64_t _rt_alloc_next_generation
Variable _rt_alloc_tree_root
_rt_alloc_record* _rt_alloc_tree_root
Variable _rt_rec_free_list
_rt_alloc_record* _rt_rec_free_list
Variable _rt_cold_chunks
_rt_alloc_record_cold** _rt_cold_chunks
Variable _rt_rec_pool_chunks
size_t _rt_rec_pool_chunks
Variable _rt_quarantine_head
_rt_alloc_record* _rt_quarantine_head
Variable _rt_quarantine_tail
_rt_alloc_record* _rt_quarantine_tail
Variable _rt_quarantine_bytes
size_t _rt_quarantine_bytes
Variable _rt_quarantine_count
size_t _rt_quarantine_count
Variable _l0_sh_tag_bool
const _rt_siphash_tag8_t _l0_sh_tag_bool
Variable _l0_sh_tag_byte
const _rt_siphash_tag8_t _l0_sh_tag_byte
Variable _l0_sh_tag_int
const _rt_siphash_tag8_t _l0_sh_tag_int
Variable _l0_sh_tag_string
const _rt_siphash_tag8_t _l0_sh_tag_string
Variable _l0_sh_tag_data
const _rt_siphash_tag8_t _l0_sh_tag_data
Variable _rt_sh_key
_rt_siphash_key_t _rt_sh_key
Default (debug) SipHash key for L0 runtime.
In production, it will be randomized at runtime to prevent hash-flooding attacks.
Function _rt_init_args
void _rt_init_args(int argc, char **argv)
Initialize command-line arguments.
Parameters:
argc: Number of arguments.argv: Argument vector.
Function _rt_panic
static void _rt_panic(const char *message)
Abort the program with a message.
Parameters:
message: The panic message.
Function _rt_panic_fmt
static void _rt_panic_fmt(const char *fmt,...)
Abort the program with a formatted message.
Parameters:
fmt: Format string.
Function _rt_idiv
static l0_int _rt_idiv(l0_int a, l0_int b)
Safe integer division.
Parameters:
a: Dividend.b: Divisor.
Returns: Quotient.
Function _rt_imod
static l0_int _rt_imod(l0_int a, l0_int b)
Safe integer modulo.
Parameters:
a: Dividend.b: Divisor.
Returns: Remainder.
Function _rt_iadd
static l0_int _rt_iadd(l0_int a, l0_int b)
Safe integer addition with overflow check.
Parameters:
a: First operand.b: Second operand.
Returns: Sum.
Function _rt_isub
static l0_int _rt_isub(l0_int a, l0_int b)
Safe integer subtraction with overflow check.
Parameters:
a: First operand.b: Second operand.
Returns: Difference.
Function _rt_imul
static l0_int _rt_imul(l0_int a, l0_int b)
Safe integer multiplication with overflow check.
Parameters:
a: First operand.b: Second operand.
Returns: Product.
Function _rt_narrow_l0_byte
l0_byte _rt_narrow_l0_byte(l0_int value)
Narrow l0_int to l0_byte with range check.
Parameters:
value: Integer value.
Returns: Byte value.
Function _unwrap_ptr
static void * _unwrap_ptr(void *opt, const char *type_name)
Unwrap a pointer, panicking if NULL.
Parameters:
opt: Pointer to unwrap.type_name: Name of the type for error reporting.
Returns: Unwrapped pointer.
Function _unwrap_opt
static void * _unwrap_opt(void *opt_ptr, const char *type_name)
Unwrap an optional type structure, panicking if it has no value.
Parameters:
opt_ptr: Pointer to the optional structure.type_name: Name of the type for error reporting.
Returns: Pointer to the optional structure.
Function _rt_track_alloc_record
static void _rt_track_alloc_record(void *ptr, size_t size, size_t align, uint32_t type_id, const char *loc_file, int loc_line)
Function _rt_promote_new_alloc
static void _rt_promote_new_alloc(void *ptr)
Function _rt_release_tracked_alloc
static void _rt_release_tracked_alloc(void *ptr, const char *loc_file, int loc_line, const char *op_name)
Function _rt_realloc_tracked_alloc
static void * _rt_realloc_tracked_alloc(void *ptr, size_t new_size, const char *loc_file, int loc_line)
Function _rt_check_ptr_site_slow
static void * _rt_check_ptr_site_slow(_rt_ptr_site *site, void *ptr, l0_int required_size, l0_int required_align, int access_mode, const char *loc_file, int loc_line)
Function _rt_check_index_ptr_site_slow
static void * _rt_check_index_ptr_site_slow(_rt_ptr_site *site, void *base_ptr, l0_int index, l0_int element_size, l0_int required_align, int access_mode, const char *loc_file, int loc_line)
Function _rt_drop_begin_impl
static void * _rt_drop_begin_impl(void *ptr, l0_int required_size, l0_int required_align, const char *loc_file, int loc_line)
Function _rt_drop_finish_impl
static void _rt_drop_finish_impl(void *ptr, const char *loc_file, int loc_line)
Function _rt_validate_derived_ptr
static void * _rt_validate_derived_ptr(void *derived, void *parent_base, l0_int size, l0_int align, const char *loc_file, int loc_line)
Function _rt_track_arc_bytes
static void _rt_track_arc_bytes(void *ptr, size_t size)
Lazily register ARC-managed string storage as a read-only tracked record.
Idempotent: repeated exposure of the same live block is a no-op, so rt_string_bytes_ptr may call this on every invocation.
Function _rt_untrack_arc_alloc
static void _rt_untrack_arc_alloc(void *ptr)
Function _rt_track_static_bytes
static void _rt_track_static_bytes(const void *ptr, size_t size)
Function _rt_check_ptr_site
static void * _rt_check_ptr_site(_rt_ptr_site *site, void *ptr, l0_int required_size, l0_int required_align, int access_mode, const char *loc_file, int loc_line)
Validate one pointer access through a call-site cache.
Parameters:
site: Per-call-site cache slot owned by the generated access site.ptr: Pointer about to be dereferenced.required_size: Size in bytes of the access.required_align: Required alignment, or 0 for no alignment check.access_mode:_RT_ACCESS_READor_RT_ACCESS_WRITE.loc_file: Source file of the access site.loc_line: Source line of the access site.
Returns: ptr when the access is valid; panics otherwise.
Function _rt_check_index_ptr_site
static void * _rt_check_index_ptr_site(_rt_ptr_site *site, void *base_ptr, l0_int index, l0_int element_size, l0_int required_align, int access_mode, const char *loc_file, int loc_line)
Validate and derive one indexed pointer access through a call-site cache.
The checked path validates the base pointer and target byte range before forming the target pointer value, avoiding out-of-object C pointer arithmetic in generated code.
Parameters:
site: Per-call-site cache slot owned by the generated access site.base_ptr: Base pointer expression before indexing.index: Element index.element_size: Size in bytes of one indexed element.required_align: Required target alignment, or 0 for no alignment check.access_mode:_RT_ACCESS_READor_RT_ACCESS_WRITE.loc_file: Source file of the access site.loc_line: Source line of the access site.
Returns: Target pointer when the access is valid; panics otherwise.
Function _rt_l0_string_from_const_literal
static l0_string _rt_l0_string_from_const_literal(const char *c_str)
Create an L0 string from a constant C string.
Returns a string with len=0 if c_str is NULL.
Note: Does NOT allocate or copy - just wraps the existing C string. Use only for string literals or static const data.
Parameters:
c_str: Constant C string.
Returns: L0 string.
Function _rt_init_heap_string
static l0_string _rt_init_heap_string(void *mem, l0_int s_len)
Initialize a heap-allocated L0_string in the given memory.
Character data (bytes[]) is uninitialized; caller must fill it in. Length is assumed to be already validated by the caller. Size of mem MUST be at least sizeof(_l0_h_string) + s_len + 1.
The returned string is of kind L0_STRING_K_HEAP and its data is null-terminated in advance.
Parameters:
mem: Allocated memory block.s_len: Length of the string.
Returns: Initialized L0 string.
Function _rt_alloc_string
static l0_string _rt_alloc_string(l0_int len)
Allocate a new reference counted L0_string of the given length.
Character data (bytes[]) is uninitialized; caller must fill it in. Panics on allocation failure or negative length. Size of allocated memory is: string header + len + 1 for null terminator.
The returned string is of kind L0_STRING_K_HEAP and its data is null-terminated in advance.
Parameters:
len: Length of the string.
Returns: Allocated L0 string.
Function _rt_free_string
static void _rt_free_string(l0_string str)
Free a string's allocated data, if applicable.
If reference counted, decrements reference count and frees when it reaches zero.
Parameters:
str: L0 string to free.
Function _rt_realloc_string
static l0_string _rt_realloc_string(l0_string s, l0_int new_len)
Reallocate a heap string to a new length.
Parameters:
s: Current L0 string.new_len: New length.
Returns: Updated L0 string.
Function _rt_new_l0_string
static l0_string _rt_new_l0_string(const char *c_str)
Create a new reference counted L0_string from a null-terminated C string.
Allocates new memory and copies data.
Parameters:
c_str: Null-terminated C string.
Returns: L0 string.
Function _rt_string_bytes
static char * _rt_string_bytes(l0_string s)
Gets the null-terminated C string underlying an L0 string.
or NULL if not available, e.g. for static empty strings. Useful when interfacing with C APIs that require null-terminated strings.
Note: This is an internal helper, not exposed to L0 code.
Parameters:
s: L0 string.
Returns: Pointer to character data.
Function rt_strlen
static l0_int rt_strlen(l0_string str)
Get the length of a string.
L0 signature: extern func rt_strlen(str: string) -> int;
Parameters:
str: L0 string.
Returns: Length in bytes.
Function rt_string_get
static l0_byte rt_string_get(l0_string a, l0_int index)
Bounds-checked character access.
Returns the character at the given index, or panics if out of bounds.
L0 signature: extern func rt_string_get(s: string, index: int) -> byte;
Parameters:
a: L0 string.index: Index.
Returns: Byte value.
Function rt_string_bytes_ptr
static l0_byte * rt_string_bytes_ptr(l0_string s)
Return a pointer to the raw byte data of a string.
L0 signature: extern func rt_string_bytes_ptr(s: string) -> byte*;
Heap and static string storage is registered with the pointer access tracker lazily here, at first raw-byte exposure, so the returned pointer stays dereferenceable by checked generated code while strings that never hand out raw bytes stay out of the tracker. Both are runtime-managed: passing the returned pointer to drop or rt_free is a runtime error.
Parameters:
s: L0 string.
Returns: Pointer to the first byte.
Function rt_string_equals
static l0_bool rt_string_equals(l0_string a, l0_string b)
Check if two strings are equal.
L0 signature: extern func rt_string_equals(a: string, b: string) -> bool;
Parameters:
a: First string.b: Second string.
Returns: 1 if equal, 0 otherwise.
Function rt_string_compare
static l0_int rt_string_compare(l0_string a, l0_string b)
Compare two strings lexicographically.
Returns 0 if equal, <0 if a < b, >0 if a > b.
L0 signature: extern func rt_string_compare(a: string, b: string) -> int;
Parameters:
a: First string.b: Second string.
Returns: Comparison result.
Function rt_string_concat
static l0_string rt_string_concat(l0_string a, l0_string b)
Concatenate two strings (allocates new memory).
Returns a heap-allocated string containing a + b.
L0 signature: extern func rt_string_concat(a: string, b: string) -> string;
Parameters:
a: First string.b: Second string.
Returns: Concatenated string.
Function rt_string_slice
static l0_string rt_string_slice(l0_string s, l0_int start, l0_int end)
Create a substring (allocates new memory).
Panics if start/end are out of bounds or start > end.
L0 signature: extern func rt_string_slice(s: string, start: int, end: int) -> string;
Parameters:
s: Source string.start: Start index.end: End index.
Returns: Slice string.
Function rt_string_from_byte
static l0_string rt_string_from_byte(l0_byte b)
Create an L0 string from a single character (byte).
Allocates a new heap string of length 1. Note: Caller must free the returned string using _rt_free_string.
L0 signature: extern func rt_string_from_byte(b: byte) -> string;
Parameters:
b: Character.
Returns: L0 string.
Function rt_string_from_byte_array
static l0_string rt_string_from_byte_array(l0_byte *bytes, l0_int len)
Create an L0 string from a byte array and a length.
Allocates a new heap string of the given length and copies data. The array does not need to be a null-terminated C string: all bytes are copied and a null terminator is added for C interoperability. Panics if len is negative.
L0 signature: extern func rt_string_from_byte_array(bytes: byte*, len: int) -> string;
Parameters:
bytes: Pointer to bytes.len: Length.
Returns: L0 string.
Function rt_string_retain
static void rt_string_retain(l0_string s)
Increment reference count for heap strings (no-op for static).
Panics if the string is heap-allocated but has an invalid refcount state (e.g. double free detected).
L0 signature: extern func rt_string_retain(s: string) -> void;
Parameters:
s: L0 string.
Function rt_string_release
static void rt_string_release(l0_string s)
Decrement reference count, freeing if zero.
L0 signature: extern func rt_string_release(s: string) -> void;
Parameters:
s: L0 string.
Function rt_system
static l0_int rt_system(l0_string cmd)
Execute a system command and return its normalized status.
Returns the command exit code, 128 + signal when terminated by a signal, or a negative value on error launching the shell.
L0 signature: extern func rt_system(cmd: string) -> int;
Parameters:
cmd: Command string.
Returns: Normalized status.
Function rt_get_env_var
static l0_opt_string rt_get_env_var(l0_string name)
Get an environment variable as an L0 optional string.
Returns null (empty optional) if the variable is not set.
L0 signature: extern func rt_get_env_var(name: string) -> string?;
Parameters:
name: Variable name.
Returns: Optional string value.
Function rt_get_argc
static l0_int rt_get_argc(void)
Get the number of command-line arguments.
L0 signature: extern func rt_get_argc() -> int;
Returns: Argument count.
Function _rt_pid_to_l0_int
static l0_bool _rt_pid_to_l0_int(intmax_t value, l0_int *out)
Convert a native process identifier into l0_int .
Parameters:
value: Native process identifier.out: Output location.
Returns: 1 when value fits in l0_int, otherwise 0.
Function rt_get_pid
static l0_int rt_get_pid(void)
Get the current process identifier.
L0 signature: extern func rt_get_pid() -> int;
Returns: Process identifier.
Function rt_get_argv
static l0_string rt_get_argv(l0_int i)
Get the command-line argument at the given index.
Panics if index is out of bounds.
L0 signature: extern func rt_get_argv(i: int) -> string;
Parameters:
i: Index.
Returns: Argument string.
Function _rt_time_to_l0_int_sec
static l0_bool _rt_time_to_l0_int_sec(time_t value, l0_int *out)
Internal helper to convert time_t to l0_int seconds.
Function _rt_time_to_l0_int_nsec
static l0_bool _rt_time_to_l0_int_nsec(long value, l0_int *out)
Internal helper to convert long to l0_int nanoseconds.
Function _rt_time_write_parts
static l0_bool _rt_time_write_parts(struct l0_sys_rt_RtTimeParts *out, l0_int sec, l0_int nsec)
Internal helper to write time parts to struct.
Function rt_time_unix
static l0_bool rt_time_unix(struct l0_sys_rt_RtTimeParts *out)
Capture current unix wall clock into out .
L0 signature: extern func rt_time_unix(out: RtTimeParts*) -> bool;
Parameters:
out: Pointer to RtTimeParts.
Returns: 1 on success, 0 on failure.
Function rt_time_monotonic
static l0_bool rt_time_monotonic(struct l0_sys_rt_RtTimeParts *out)
Capture current monotonic clock into out .
L0 signature: extern func rt_time_monotonic(out: RtTimeParts*) -> bool;
Parameters:
out: Pointer to RtTimeParts.
Returns: 1 on success, 0 on failure.
Function rt_time_monotonic_supported
static l0_bool rt_time_monotonic_supported(void)
Returns whether a monotonic clock source is available.
L0 signature: extern func rt_time_monotonic_supported() -> bool;
Returns: 1 if supported, 0 otherwise.
Function rt_time_local_offset_sec
static l0_opt_int rt_time_local_offset_sec(l0_int unix_sec)
Returns local UTC offset in seconds for unix_sec .
Computes the offset by comparing gmtime and localtime breakdowns directly, avoiding mktime which rejects pre-epoch values on some platforms.
L0 signature: extern func rt_time_local_offset_sec(unix_sec: int) -> int?;
Parameters:
unix_sec: Unix timestamp.
Returns: Optional integer offset.
Function rt_time_local_is_dst
static l0_opt_bool rt_time_local_is_dst(l0_int unix_sec)
Returns whether local time is daylight-saving time for unix_sec .
L0 signature: extern func rt_time_local_is_dst(unix_sec: int) -> bool?;
Parameters:
unix_sec: Unix timestamp.
Returns: Optional boolean.
Function rt_read_file_all
static l0_opt_string rt_read_file_all(l0_string path)
Read entire file contents into a string.
Returns empty string on error (file not found, read error, allocation failure).
L0 signature: extern func rt_read_file_all(path: string) -> string?;
Parameters:
path: File path.
Returns: Optional string containing file contents.
Function rt_write_file_all
static l0_bool rt_write_file_all(l0_string path, l0_string data)
Write string data to a file.
Returns 1 (true) on success, 0 (false) on error.
L0 signature: extern func rt_write_file_all(path: string, data: string) -> bool;
Parameters:
path: File path.data: Data string.
Returns: 1 on success, 0 on failure.
Function rt_file_info
static struct l0_sys_rt_RtFileInfo rt_file_info(l0_string path)
Return basic metadata for a path.
L0 signature: extern func rt_file_info(path: string) -> RtFileInfo;
Parameters:
path: File path.
Returns: Metadata record with nullable size and mtime fields.
Function rt_delete_file
static l0_bool rt_delete_file(l0_string path)
Delete the file at the given path.
Returns 1 (true) on success, 0 (false) on error.
L0 signature: extern func rt_delete_file(path: string) -> bool;
Parameters:
path: File path.
Returns: 1 on success, 0 on failure.
Function _rt_stream_write_some
static l0_int _rt_stream_write_some(FILE *stream, const l0_byte *buf, l0_int len)
Write raw bytes to one standard stream.
Parameters:
stream: Target stream.buf: Source bytes.len: Maximum number of bytes to write.
Returns: Bytes written, or -1 on error.
Function rt_stdin_read
static l0_int rt_stdin_read(l0_byte *buf, l0_int capacity)
Read raw bytes from standard input.
L0 signature: extern func rt_stdin_read(buf: byte*?, capacity: int) -> int;
Parameters:
buf: Destination bytes. A NULL buffer is reported as-1.capacity: Maximum number of bytes to read.
Returns: Bytes read, 0 on EOF, or -1 on error (including a NULL buf when capacity > 0).
Function rt_stdout_write
static l0_int rt_stdout_write(l0_byte *buf, l0_int len)
Write raw bytes to standard output.
L0 signature: extern func rt_stdout_write(buf: byte*?, len: int) -> int;
Parameters:
buf: Source bytes. A NULL buffer is reported as-1.len: Maximum number of bytes to write.
Returns: Bytes written, or -1 on error (including a NULL buf when len > 0).
Function rt_stderr_write
static l0_int rt_stderr_write(l0_byte *buf, l0_int len)
Write raw bytes to standard error.
L0 signature: extern func rt_stderr_write(buf: byte*?, len: int) -> int;
Parameters:
buf: Source bytes. A NULL buffer is reported as-1.len: Maximum number of bytes to write.
Returns: Bytes written, or -1 on error (including a NULL buf when len > 0).
Function rt_flush_stdout
static void rt_flush_stdout(void)
Flush stdout.
Function rt_flush_stderr
static void rt_flush_stderr(void)
Flush stderr.
L0 signature: extern func rt_flush_stdout() -> void;
L0 signature: extern func rt_flush_stderr() -> void;
Function _rt_print
void _rt_print(l0_string s, FILE *stream)
Internal helper to print an l0_string to a given stream.
Parameters:
s: String to print.stream: Target stream.
Function rt_print
static void rt_print(l0_string s)
Print a string to stdout.
L0 signature: extern func rt_print(s: string) -> void;
Parameters:
s: String to print.
Function rt_print_stderr
static void rt_print_stderr(l0_string s)
Print a string to stderr.
L0 signature: extern func rt_print_stderr(s: string) -> void;
Parameters:
s: String to print.
Function rt_println
static void rt_println(void)
Print a newline to stdout.
Function rt_println_stderr
static void rt_println_stderr(void)
Print a newline to stderr.
L0 signature: extern func rt_println() -> void;
L0 signature: extern func rt_println_stderr() -> void;
Function rt_print_int
static void rt_print_int(l0_int x)
Print an integer to stdout.
L0 signature: extern func rt_print_int(x: int) -> void;
Parameters:
x: Integer value.
Function rt_print_int_stderr
static void rt_print_int_stderr(l0_int x)
Print an integer to stderr.
L0 signature: extern func rt_print_int_stderr(x: int) -> void;
Parameters:
x: Integer value.
Function rt_print_bool
static void rt_print_bool(l0_bool x)
Print a bool to stdout.
L0 signature: extern func rt_print_bool(x: bool) -> void;
Parameters:
x: Boolean value.
Function rt_print_bool_stderr
static void rt_print_bool_stderr(l0_bool x)
Print a bool to stderr.
L0 signature: extern func rt_print_bool_stderr(x: bool) -> void;
Parameters:
x: Boolean value.
Function rt_read_line
static l0_opt_string rt_read_line(void)
Read a line from stdin into a dynamically allocated buffer.
Returns None on EOF (no characters read).
- Ownership: on Some(s), s.data is heap-allocated and must be freed by calling rt_string_release(s) (directly or indirectly via stdlib).
L0 signature: extern func rt_read_line() -> string?;
Returns: Optional string containing the line.
Function rt_read_char
static l0_int rt_read_char(void)
Read one character from stdin.
Returns -1 on EOF or error.
L0 signature: extern func rt_read_char() -> int;
Returns: Character value or -1.
Function rt_abort
static void rt_abort(l0_string message)
Abort the program with a panic message.
L0 signature: extern func rt_abort(message: string) -> void;
Parameters:
message: Panic message.
Function rt_exit
static void rt_exit(l0_int code)
Exit the program with the given exit code.
L0 signature: extern func rt_exit(code: int) -> void;
Parameters:
code: Exit code.
Function rt_srand
static void rt_srand(l0_int seed)
Seed the random number generator.
Uses current time if seed is 0.
L0 signature: extern func rt_srand(seed: int) -> void;
Parameters:
seed: Seed value.
Function rt_rand
static l0_int rt_rand(l0_int max)
Generate a random integer in the range [0, max).
Returns 0 if max <= 0.
L0 signature: extern func rt_rand(max: int) -> int;
Parameters:
max: Upper bound (exclusive).
Returns: Random value.
Function rt_errno
static l0_int rt_errno(void)
Get the current errno value.
L0 signature: extern func rt_errno() -> int;
Returns: errno value.
Function rt_alloc
static void * rt_alloc(l0_int bytes)
Allocate memory of the given size in bytes.
Returns NULL on allocation failure or if bytes is zero. Panics if bytes is negative, or too large to fit in size_t (platform-dependent).
L0 signature: extern func rt_alloc(bytes: int) -> void*?;
Parameters:
bytes: Size in bytes.
Returns: Pointer to allocated memory or NULL.
Function rt_realloc
static void * rt_realloc(void *ptr, l0_int new_bytes)
Reallocate a raw runtime allocation to a new size.
Returns NULL on failure. Panics if new_bytes is negative or too large to fit in size_t (platform-dependent). If ptr is NULL, behaves like rt_alloc.
L0 signature: extern func rt_realloc(ptr: void?, new_bytes: int) -> void?;
Parameters:
ptr: Pointer to memory, or NULL to allocate fresh.new_bytes: New size.
Returns: Pointer to reallocated memory or NULL.
Function rt_free
static void rt_free(void *ptr)
Free a raw runtime allocation.
L0 signature: extern func rt_free(ptr: void*?) -> void;
Parameters:
ptr: Pointer to free.
Function rt_calloc
static void * rt_calloc(l0_int count, l0_int elem_size)
Allocate zeroed memory for an array of elements.
Returns NULL on allocation failure or if count/elem_size is negative.
L0 signature: extern func rt_calloc(count: int, elem_size: int) -> void*?;
Parameters:
count: Number of elements.elem_size: Element size.
Returns: Pointer to zeroed memory or NULL.
Function rt_memset
static void * rt_memset(void *dest, l0_int value, l0_int bytes)
Set memory to a specific byte value.
Returns destination pointer.
L0 signature: extern func rt_memset(dest: void, value: int, bytes: int) -> void;
Parameters:
dest: Destination pointer.value: Byte value.bytes: Number of bytes.
Returns: dest.
Function rt_memcpy
static void * rt_memcpy(void *dest, void *src, l0_int bytes)
Copy memory from source to destination.
Returns destination pointer.
L0 signature: extern func rt_memcpy(dest: void, src: void, bytes: int) -> void*;
Parameters:
dest: Destination.src: Source.bytes: Number of bytes.
Returns: dest.
Function rt_memcmp
static l0_int rt_memcmp(void *a, void *b, l0_int bytes)
Compare two memory regions.
Returns 0 if equal, <0 if a < b, >0 if a > b.
L0 signature: extern func rt_memcmp(a: void, b: void, bytes: int) -> int;
Parameters:
a: First region.b: Second region.bytes: Number of bytes.
Returns: Comparison result.
Function rt_array_element
static void * rt_array_element(void *array_data, l0_int element_size, l0_int index)
Get a pointer to an element in an array.
Panics if array_data is NULL, element_size is non-positive, or index is negative.
L0 signature: extern func rt_array_element(array_data: void, element_size: int, index: int) -> void;
Parameters:
array_data: Pointer to array data.element_size: Size of one element.index: Element index.
Returns: Pointer to the element.
Function _rt_rec_new
static _rt_alloc_record * _rt_rec_new(_rt_alloc_record_cold **cold_out)
Take one record from the pool, refilling it chunk-wise.
Pool memory is never returned to the C allocator, so stale record pointers held by call-site caches remain safe to dereference.
Function _rt_rec_recycle
static void _rt_rec_recycle(_rt_alloc_record *rec)
Function _rt_alloc_hash
static size_t _rt_alloc_hash(void *ptr, size_t cap)
Function _rt_alloc_table_rehash
static void _rt_alloc_table_rehash(void)
Rebuild the hash table sized from the live record count.
Sizing from the live count (not the old capacity) keeps sustained alloc/free churn from ratcheting the table up: a tombstone-triggered rebuild purges tombstones at a stable or smaller capacity instead of doubling it, and a shrunken live set lets the table contract.
Function _rt_alloc_table_lookup
static _rt_alloc_record * _rt_alloc_table_lookup(void *ptr)
Function _rt_alloc_table_insert
static void _rt_alloc_table_insert(_rt_alloc_record *rec)
Function _rt_alloc_table_remove
static void _rt_alloc_table_remove(_rt_alloc_record *target)
Function _rt_panic_invalid_access
static void _rt_panic_invalid_access(const char *reason, void *ptr, const char *loc_file, int loc_line)
Function _rt_panic_invalid_drop
static void _rt_panic_invalid_drop(const char *reason, void *ptr, const char *loc_file, int loc_line)
Function _rt_panic_invalid_release
static void _rt_panic_invalid_release(const char *op_name, const char *reason, void *ptr, const char *loc_file, int loc_line)
Function _rt_trace_invalid_drop
static void _rt_trace_invalid_drop(void *ptr, const char *loc_file, int loc_line)
Function _rt_ptr_is_aligned
static int _rt_ptr_is_aligned(void *ptr, size_t align)
Function _rt_range_contains
static int _rt_range_contains(void *base, size_t total_size, void *ptr, size_t need_size, size_t *offset_out)
Function _rt_tree_prio_for
static uint32_t _rt_tree_prio_for(void *base)
Function _rt_tree_insert_at
static _rt_alloc_record * _rt_tree_insert_at(_rt_alloc_record *node, _rt_alloc_record *rec)
Function _rt_tree_merge
static _rt_alloc_record * _rt_tree_merge(_rt_alloc_record *a, _rt_alloc_record *b)
Merge two treaps where every base in a is below every base in b .
Function _rt_tree_remove_at
static _rt_alloc_record * _rt_tree_remove_at(_rt_alloc_record *node, void *base)
Function _rt_alloc_tree_insert
static void _rt_alloc_tree_insert(_rt_alloc_record *rec)
Function _rt_alloc_tree_remove
static void _rt_alloc_tree_remove(_rt_alloc_record *rec)
Function _rt_alloc_tree_glb
static _rt_alloc_record * _rt_alloc_tree_glb(void *ptr)
Return the tracked record with the greatest base at or below ptr .
Function _rt_alloc_tree_lub
static _rt_alloc_record * _rt_alloc_tree_lub(void *ptr)
Return the tracked record with the lowest base at or above ptr .
Function _rt_alloc_tree_find_containing
static _rt_alloc_record * _rt_alloc_tree_find_containing(void *ptr, size_t need_size)
Function _rt_ptr_site_store
static void _rt_ptr_site_store(_rt_ptr_site *site, _rt_alloc_record *owner)
Function _rt_required_size
static size_t _rt_required_size(l0_int required_size)
Function _rt_required_align
static size_t _rt_required_align(l0_int required_align)
Function _rt_index_element_size
static size_t _rt_index_element_size(l0_int element_size)
Function _rt_index_offset
static size_t _rt_index_offset(l0_int index, size_t element_size)
Function _rt_required_access_mode
static int _rt_required_access_mode(int access_mode)
Function _rt_index_access_mode
static int _rt_index_access_mode(int access_mode)
Function _rt_index_allows_untracked
static int _rt_index_allows_untracked(int access_mode)
Function _rt_check_ptr_align
static void _rt_check_ptr_align(void *ptr, size_t need_align, const char *loc_file, int loc_line)
Panic when a validated access target misses its required alignment.
Parameters:
ptr: Access target to check.need_align: Required alignment; values below 2 always pass.loc_file: Source file of the access site.loc_line: Source line of the access site.
Function _rt_check_record_writeable
static void _rt_check_record_writeable(_rt_alloc_record *rec, void *ptr, int access_mode, const char *loc_file, int loc_line)
Function _rt_track_alloc_record_kind
static void _rt_track_alloc_record_kind(void *ptr, size_t size, size_t align, uint32_t type_id, int mem_kind, int read_only, const char *loc_file, int loc_line)
Function rt_register_foreign
static void rt_register_foreign(void *ptr, l0_int bytes, l0_bool read_only)
Register externally owned storage for checked generated pointer accesses.
Function rt_unregister_foreign
static void rt_unregister_foreign(void *ptr)
Unregister externally owned storage without releasing its payload.
Function _rt_evict_quarantine
static void _rt_evict_quarantine(void)
Function _rt_quarantine_alloc_record
static void _rt_quarantine_alloc_record(_rt_alloc_record *rec, _rt_alloc_record_cold *cold, const char *loc_file, int loc_line)
Function _rt_alloc_obj
static void * _rt_alloc_obj(l0_int bytes)
Function _rt_fmix32
static uint32_t _rt_fmix32(uint32_t x)
Final mixing function for 32-bit hashes (MurmurHash3 fmix32).
Parameters:
x: Current hash.
Returns: Mixed hash.
Function _rt_fold_u64_to_u32_fmix
static uint32_t _rt_fold_u64_to_u32_fmix(uint64_t h)
Fold a 64-bit hash into a 32-bit hash with final mixing.
Parameters:
h: 64-bit hash.
Returns: 32-bit hash.
Function _rt_hash_tag8
static l0_int _rt_hash_tag8(const _rt_siphash_tag8_t tag8, const uint8_t flags, const void *data, size_t len, const _rt_siphash_key_t key)
Internal helper to hash data with a given 8-byte tag and flags.
Parameters:
tag8: 8-byte tag.flags: Flags.data: Pointer to data.len: Data length.key: SipHash key.
Returns: 32-bit hash.
Function _rt_hash_bool
static l0_int _rt_hash_bool(l0_bool value, const uint8_t flags)
Hash a boolean value with the runtime bool tag.
Parameters:
value: Boolean value to hash.flags: Type-shaping flags mixed into the hash domain.
Returns: 32-bit hash.
Function _rt_hash_byte
static l0_int _rt_hash_byte(l0_byte value, const uint8_t flags)
Hash a byte value with the runtime byte tag.
Parameters:
value: Byte value to hash.flags: Type-shaping flags mixed into the hash domain.
Returns: 32-bit hash.
Function _rt_hash_int
static l0_int _rt_hash_int(l0_int value, const uint8_t flags)
Hash an integer value with the runtime int tag.
Parameters:
value: Integer value to hash.flags: Type-shaping flags mixed into the hash domain.
Returns: 32-bit hash.
Function _rt_hash_string
static l0_int _rt_hash_string(l0_string str, const uint8_t flags)
Hash a string's byte contents with the runtime string tag.
Parameters:
str: String value to hash.flags: Type-shaping flags mixed into the hash domain.
Returns: 32-bit hash.
Function _rt_hash_data
static l0_int _rt_hash_data(void *data, l0_int size, const uint8_t flags)
Hash an arbitrary byte sequence with the runtime data tag.
Parameters:
data: Pointer to the byte sequence.size: Size ofdatain bytes.flags: Type-shaping flags mixed into the hash domain.
Returns: 32-bit hash.
Function rt_hash_bool
static l0_int rt_hash_bool(l0_bool value)
Hash a boolean value.
L0 signature: extern func rt_hash_bool(value: bool) -> int;
Parameters:
value: Boolean value.
Returns: 32-bit hash.
Function rt_hash_byte
static l0_int rt_hash_byte(l0_byte value)
Hash a byte value.
L0 signature: extern func rt_hash_byte(value: byte) -> int;
Parameters:
value: Byte value.
Returns: 32-bit hash.
Function rt_hash_int
static l0_int rt_hash_int(l0_int value)
Hash an integer value.
L0 signature: extern func rt_hash_int(value: int) -> int;
Parameters:
value: Integer value.
Returns: 32-bit hash.
Function rt_hash_string
static l0_int rt_hash_string(l0_string value)
Hash a string value.
L0 signature: extern func rt_hash_string(value: string) -> int;
Parameters:
value: L0 string.
Returns: 32-bit hash.
Function rt_hash_data
static l0_int rt_hash_data(void *data, l0_int size)
Hash raw data.
Panics if data is null or size is negative.
L0 signature: extern func rt_hash_data(data: void*, size: int) -> int;
Parameters:
data: Pointer to data.size: Data size.
Returns: 32-bit hash.
Function rt_hash_opt_bool
static l0_int rt_hash_opt_bool(l0_opt_bool opt)
Hash an optional boolean value.
L0 signature: extern func rt_hash_opt_bool(opt: bool?) -> int;
Parameters:
opt: Optional bool.
Returns: 32-bit hash.
Function rt_hash_opt_byte
static l0_int rt_hash_opt_byte(l0_opt_byte opt)
Hash an optional byte value.
L0 signature: extern func rt_hash_opt_byte(opt: byte?) -> int;
Parameters:
opt: Optional byte.
Returns: 32-bit hash.
Function rt_hash_opt_int
static l0_int rt_hash_opt_int(l0_opt_int opt)
Hash an optional integer value.
L0 signature: extern func rt_hash_opt_int(opt: int?) -> int;
Parameters:
opt: Optional int.
Returns: 32-bit hash.
Function rt_hash_opt_string
static l0_int rt_hash_opt_string(l0_opt_string opt)
Hash an optional string value.
If opt is empty, hashes as an empty string with the optional flag.
L0 signature: extern func rt_hash_opt_string(opt: string?) -> int;
Parameters:
opt: Optional string.
Returns: 32-bit hash.
Function rt_hash_ptr
static l0_int rt_hash_ptr(void *ptr)
Hash a pointer value.
Note: this hashes the pointer value (address), not the data it points to. Panics if ptr is null.
L0 signature: extern func rt_hash_ptr(ptr: void*) -> int;
Parameters:
ptr: Pointer.
Returns: 32-bit hash.
Function rt_hash_opt_ptr
static l0_int rt_hash_opt_ptr(void *opt)
Hash an optional pointer value.
Note: this hashes the pointer value (address), not the data it points to. Panics if opt is empty (null pointer).
L0 signature: extern func rt_hash_opt_ptr(opt: void*?) -> int;
Parameters:
opt: Pointer.
Returns: 32-bit hash.
Struct _l0_h_string
Heap-allocated L0 string header.
L0 string: length-tracked, reference counted, immutable character sequence. Strings are always length-tracked to prevent out-of-bounds access. An l0_string with len=0 represents an empty string. Data should be NULL for empty strings to maintain consistency, but non-NULL is tolerated. refcount is used for memory management; if refcount == INT32_MAX, the string is not reference counted (e.g. allocated strings). Strings with refcount > 0 are reference counted and should be freed when refcount reaches zero. Strings with refcount == INT32_MAX are not ref-counted, but heap-allocated or empty, and should be freed manually. Strings with refcount == _RT_MEM_SENTINEL have already been freed (double-free detected). Data is null-terminated for C interoperability, but length is authoritative.
Member Data _l0_h_string::refcount
l0_int refcount
Reference count for memory management, or INT32_MAX if not reference counted.
Member Data _l0_h_string::len
l0_int len
Length in bytes (must be >= 0)
Member Data _l0_h_string::bytes
char bytes
Mutable character data, 0-terminated for C interoperability.
Struct l0_string
Unified L0 string type (static or heap-allocated).
Member Data l0_string::kind
unsigned int kind: 1
Kind of string: either L0_STRING_K_STATIC (0) or L0_STRING_K_HEAP (1)
Member Data l0_string::int
unsigned int: 0
Align to next unsigned int boundary.
Member Data l0_string::len
l0_int len
Length in bytes (for constant inline strings)
Member Data l0_string::bytes
const char* bytes
Pointer to character data (may be NULL for empty string)
Member Data l0_string::s_str
struct l0_string s_str
Static string structure for constant inline strings.
Member Data l0_string::h_str
_l0_h_string* h_str
Heap-allocated string structure for dynamic strings.
Member Data l0_string::data
union l0_string data
Struct l0_opt_bool
Optional boolean wrapper.
Member Data l0_opt_bool::has_value
l0_bool has_value
Member Data l0_opt_bool::value
l0_bool value
Struct l0_opt_byte
Optional byte wrapper.
Member Data l0_opt_byte::has_value
l0_bool has_value
Member Data l0_opt_byte::value
l0_byte value
Struct l0_opt_int
Optional integer wrapper.
Member Data l0_opt_int::has_value
l0_bool has_value
Member Data l0_opt_int::value
l0_int value
Struct l0_opt_string
Optional string wrapper.
Member Data l0_opt_string::has_value
l0_bool has_value
Member Data l0_opt_string::value
l0_string value
Struct _l0_base_opt
Base structure for optional types to access has_value .
Member Data _l0_base_opt::has_value
l0_bool has_value
Struct l0_sys_rt_RtTimeParts
Definition for sys.rt::RtTimeParts .
Member Data l0_sys_rt_RtTimeParts::sec
l0_int sec
Member Data l0_sys_rt_RtTimeParts::nsec
l0_int nsec
Struct l0_sys_rt_RtFileInfo
Definition for sys.rt::RtFileInfo .
Member Data l0_sys_rt_RtFileInfo::exists
l0_bool exists
Member Data l0_sys_rt_RtFileInfo::is_file
l0_bool is_file
Member Data l0_sys_rt_RtFileInfo::is_dir
l0_bool is_dir
Member Data l0_sys_rt_RtFileInfo::size
l0_opt_int size
Member Data l0_sys_rt_RtFileInfo::mtime_sec
l0_opt_int mtime_sec
Member Data l0_sys_rt_RtFileInfo::mtime_nsec
l0_opt_int mtime_nsec
Struct _rt_alloc_record
Hot allocation fields read by checked pointer cache hits and allocation tracker mutation paths.
Records are pool-allocated and never freed, so a stale record pointer held by a call-site cache stays dereferenceable; the generation counter rejects reuse.
Member Data _rt_alloc_record::base
void* base
Member Data _rt_alloc_record::size
size_t size
Member Data _rt_alloc_record::generation
uint64_t generation
Member Data _rt_alloc_record::tree_left
_rt_alloc_record* tree_left
Member Data _rt_alloc_record::tree_right
_rt_alloc_record* tree_right
Member Data _rt_alloc_record::q_next
_rt_alloc_record* q_next
Member Data _rt_alloc_record::tree_prio
uint32_t tree_prio
Member Data _rt_alloc_record::cold_index
uint32_t cold_index
Member Data _rt_alloc_record::state
uint8_t state
Member Data _rt_alloc_record::read_only
uint8_t read_only
Member Data _rt_alloc_record::mem_kind
uint8_t mem_kind
Member Data _rt_alloc_record::hot_pad
uint8_t hot_pad
Struct _rt_alloc_record_cold
Cold allocation fields used by diagnostics and rare metadata reads.
Member Data _rt_alloc_record_cold::align
size_t align
Member Data _rt_alloc_record_cold::type_id
uint32_t type_id
Member Data _rt_alloc_record_cold::alloc_line
int alloc_line
Member Data _rt_alloc_record_cold::drop_line
int drop_line
Member Data _rt_alloc_record_cold::reserved
uint32_t reserved
Member Data _rt_alloc_record_cold::alloc_file
const char* alloc_file
Member Data _rt_alloc_record_cold::drop_file
const char* drop_file
Struct _rt_ptr_site
Per-call-site pointer check cache.
Generated code declares one static instance per checked access site; a hit validates with one generation compare and one range check, without hashing.
Member Data _rt_ptr_site::owner
_rt_alloc_record* owner
Member Data _rt_ptr_site::generation
uint64_t generation