Module Sarek_ppx

val registered_types : Sarek_ppx_lib.Sarek_ast.type_decl list Stdlib.ref
val registered_mods : Sarek_ppx_lib.Sarek_ast.module_item list Stdlib.ref
val tdecl_key : Sarek_ppx_lib.Sarek_ast.type_decl -> string
val flatten_longident : Ppxlib.longident -> string list
val core_type_to_sarek_type_expr : loc:Ppxlib.Location.t -> Ppxlib.core_type -> Sarek_ppx_lib.Sarek_ast.type_expr
val module_name_of_loc : Ppxlib.location -> string
val type_size_registry : (string, int) Stdlib.Hashtbl.t
val get_type_size_from_core_type : Ppxlib.core_type -> int
val calc_type_size_early : Ppxlib.label_declaration list -> int
val variant_payload_byte_size : Ppxlib.constructor_declaration -> int
val register_type_size : Ppxlib.type_declaration -> unit
val register_sarek_type_decl : loc:Ppxlib.Location.t -> Ppxlib.type_declaration -> unit
val register_sarek_module_item : loc:'a -> Sarek_ppx_lib.Sarek_ast.module_item -> unit
val scan_file_for_sarek_types : string -> unit

Scan a single .ml file for @@sarek.type and @sarek.module declarations

val scan_dir_for_sarek_types : ?single_file:string -> string -> unit

Scan a directory for .ml files with Sarek declarations, or scan a single file

val sarek_type_attr : (Ppxlib__.Import.type_declaration, unit) Ppxlib.Attribute.t
val sarek_type_private_attr : (Ppxlib__.Import.type_declaration, unit) Ppxlib.Attribute.t
val generate_field_accessors : loc:Ppxlib.location -> Ppxlib.type_declaration -> Ppxlib.structure_item list

Generate field accessor functions for a record type. Example: for type point with fields x and y, generates: let sarek_get_point_x (p : point) : float32 = p.x let sarek_get_point_y (p : point) : float32 = p.y

val type_name_of_core_type : Ppxlib.core_type -> string

Extract type name from a core_type for registry registration

val calc_type_size : Ppxlib.label_declaration list -> int

Calculate the size in bytes of a sarek type based on its fields. Uses 4 bytes for int32/float32, 8 bytes for int64/float64.

val get_accessor_for_type : loc:Ppxlib.location -> Ppxlib.core_type -> Ppxlib.expression

Get the accessor function for a field type (legacy SPOC path removed)

val set_accessor_for_type : loc:Ppxlib.location -> Ppxlib.core_type -> Ppxlib.expression

Get the setter function for a field type (legacy SPOC path removed)

val field_element_count : Ppxlib.core_type -> int

Get the field count (number of primitive fields, counting nested as 1 for now)

val field_byte_size : Ppxlib.core_type -> int

Get field size in bytes for V2 custom types

val gen_field_read : loc:Ppxlib.location -> Ppxlib.core_type -> Ppxlib.expression -> Ppxlib.expression

Helper to generate a V2 field read expression based on field type. Dispatches to the correct Custom_helpers function. For nested custom types, generates a call using the nested type's _custom accessor.

val gen_field_write : loc:Ppxlib.location -> Ppxlib.core_type -> Ppxlib.expression -> Ppxlib.expression -> Ppxlib.expression

Helper to generate a V2 field write expression based on field type.

val generate_custom_value : loc:Ppxlib__.Location.t -> Ppxlib.type_declaration -> Ppxlib.structure_item list

Generate a <name>_custom value for Spoc_core.Vector.custom_type. For a record type (e.g., point with float32 fields), generates get/set functions using Ctypes pointer arithmetic. Supports nested custom types via their _custom accessor.

val generate_interp_helpers : loc:Ppxlib.location -> Ppxlib.type_declaration -> Ppxlib.structure_item list

Generate interpreter helper module for type-safe value conversion. Provides typed constructors for custom type handling.

val generate_type_registration : loc:Ppxlib.location -> Ppxlib.type_declaration -> Ppxlib.structure_item list

Generate runtime registration code for a type. The PPX emits calls to Sarek_registry at module initialization time so type info is available to codegen (record fields, variants, sizes).

val sarek_type_rule : Ppxlib.Context_free.Rule.t
val sarek_type_private_rule : Ppxlib.Context_free.Rule.t
val expand_kernel : ctxt:Ppxlib.Expansion_context.Extension.t -> Ppxlib.expression -> Ppxlib.expression

The main kernel expansion function

val kernel_extension : Ppxlib.Extension.V3.t

The %kernel ... extension for expressions

val expand_sarek_type : ctxt:Ppxlib.Expansion_context.Extension.t -> Ppxlib.payload -> Ppxlib.structure_item list
val sarek_type_extension : unit
val process_structure_for_module_items : Ppxlib.structure -> Ppxlib.structure

Register sarek.module bindings on any structure we process, so libraries can publish module items for use in kernels.

This generates registration code that runs at module initialization time, registering the items in Sarek_ppx_registry. This allows cross-module references: a library can define @sarek.module items and link with the PPX so they become available to kernels in other compilation units.

val expand_sarek_include : ctxt:Ppxlib.Expansion_context.Extension.t -> Ppxlib.payload -> Ppxlib_ast.Ast.structure_item

%sarek_include "path/to/file.ml" - Include types and module items from another file.

This scans the specified file for @@sarek.type and @sarek.module declarations and registers them for use in kernels in the current file. The path is relative to the current file's directory.

Usage: %sarek_include "registered_defs.ml"

let kernel = %kernel fun ... -> let open Registered_defs in ... use types and functions from registered_defs.ml ...

val sarek_include_extension : Ppxlib.Extension.V3.t