Module Sarek_ppx_intrinsic

type parsed_type =
  1. | PTSimple of string
  2. | PTArray of parsed_type
  3. | PTVec of parsed_type
  4. | PTArrow of parsed_type * parsed_type

Parsed type representation for intrinsic declarations

val parsed_type_of_core_type : Ppxlib.core_type -> parsed_type

Extract parsed type from a core_type

val type_name_of_core_type : Ppxlib.core_type -> string

Extract type name from a core_type for registry registration (string representation)

val module_path_of_loc : Ppxlib.location -> string list

Get the full module path from a location. For wrapped libraries like Sarek_stdlib, modules are accessed as Sarek_stdlib.Float32, so we need Sarek_stdlib; Float32 as the path. This is derived from the directory structure.

val sarek_type_of_simple_name : loc:Ppxlib.location -> string -> Ppxlib.expression

Convert simple type name to Sarek_types representation

val flatten_arrow : parsed_type -> parsed_type list * parsed_type

Flatten a parsed arrow type into (arg_types, return_type). E.g., PTArrow(a, PTArrow(b, c)) becomes (a; b, c)

val sarek_type_of_simple_parsed : loc:Ppxlib.location -> parsed_type -> Ppxlib.expression

Convert a non-arrow parsed type to Sarek_types representation

val sarek_type_of_parsed : loc:Ppxlib__.Location.t -> parsed_type -> Ppxlib.expression

Convert parsed type to Sarek_types representation. Flattens arrow types so a -> b -> c becomes TFun(a; b, c).

val sarek_type_of_name : loc:Ppxlib.location -> string -> Ppxlib.expression

Convert type name string to Sarek_types representation (for backward compat)

val build_sarek_fun_type : loc:Ppxlib.location -> string list -> string -> Ppxlib.expression

Build a function type from argument types and return type

val size_of_type_name : loc:Ppxlib.Location.t -> string -> int

Derive the size (in bytes) of a sarek type from its name alone. This avoids the Ctypes dependency for the pure metadata path. Sizes match the Ctypes.sizeof values for the corresponding C types: float32=4, float64=8, int32=4, int64=8, bool=4, char=1, int=4 (GPU int).

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

Extension for type%%sarek_intrinsic - handles type registration. The ctype field is OPTIONAL.

  • When present: emits both Sarek_registry (JIT/FFI) and Sarek_ppx_registry registrations using Ctypes.sizeof for the authoritative byte-size.
  • When absent: emits only Sarek_ppx_registry registration using a pure size derived from the type name. No Ctypes dependency.
val extract_fun_types : Ppxlib.core_type -> string list * string

Extract argument types and return type from a function type

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

Extension for let%sarek_intrinsic - handles function registration

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

Combined extension for %sarek_intrinsic - handles both types and functions

val sarek_intrinsic_extension : Ppxlib.Extension.V3.t
val expand_sarek_extend : ctxt:Ppxlib.Expansion_context.Extension.t -> Ppxlib.payload -> Ppxlib_ast.Ast.structure_item

Extension for %sarek_extend - allows extending intrinsics for new backends.

Syntax: let%sarek_extend Module.func = fun dev -> if ... then "new_code" else Module.func_device dev

This updates the Module.func_device_ref to point to the new function, which chains to the original via Module.func_device.

val sarek_extend_extension : Ppxlib.Extension.V3.t