Sarek_native_genval gen_expr_impl :
loc:Ppxlib__.Location.t ->
ctx:Sarek_native_gen_base.gen_context ->
Sarek_typed_ast.texpr ->
Ppxlib_ast.Ast.expressionGenerate OCaml expression from typed Sarek expression.
val gen_pattern_impl :
loc:Ppxlib.location ->
ctx:Sarek_native_gen_base.gen_context ->
Sarek_typed_ast.tpattern ->
Ppxlib.patternGenerate pattern from typed pattern. Takes context to detect same-module types that shouldn't be qualified.
val gen_binop :
loc:Ppxlib.location ->
Sarek_ast.binop ->
Ppxlib.expression ->
Ppxlib.expression ->
Sarek_types.typ ->
Ppxlib.expressionGenerate binary operation
val gen_unop :
loc:Ppxlib.location ->
Sarek_ast.unop ->
Ppxlib.expression ->
Sarek_types.typ ->
Ppxlib.expressionGenerate unary operation
val module_name_of_sarek_loc : Sarek_ast.loc -> stringExtract module name from a Sarek location (file path). For "/path/to/test_registered_variant.ml", returns "Test_registered_variant".
val gen_expr :
loc:Ppxlib__.Location.t ->
Sarek_typed_ast.texpr ->
Ppxlib.expressionTop-level entry point for generating expressions. Starts with empty context.
val gen_expr_with_inline_types :
loc:Ppxlib__.Location.t ->
inline_type_names:Sarek_native_gen_base.StringSet.t ->
current_module:string option ->
Sarek_typed_ast.texpr ->
Ppxlib.expressionGenerate expression with inline types context for first-class modules.
val gen_module_fun :
loc:Ppxlib__.Location.t ->
string ->
Sarek_typed_ast.tparam list ->
Sarek_typed_ast.texpr ->
Ppxlib.pattern * Ppxlib.expressionGenerate a module-level function (TMFun) as a let binding.
val gen_module_const :
loc:Ppxlib__.Location.t ->
string ->
int ->
Sarek_types.typ ->
Sarek_typed_ast.texpr ->
Ppxlib.pattern * Ppxlib.expressionGenerate a module-level constant (TMConst) as a let binding.
val gen_type_decl_record :
loc:Ppxlib.location ->
string ->
(string * Sarek_types.typ * bool) list ->
Ppxlib.structure_itemGenerate a type declaration for a record type
val gen_type_decl_variant :
loc:Ppxlib.location ->
string ->
(string * Sarek_types.typ option) list ->
Ppxlib.structure_itemGenerate a type declaration for a variant type
val gen_type_decl_item :
loc:Ppxlib.location ->
Sarek_typed_ast.ttype_decl ->
Ppxlib.structure_itemGenerate a structure item from a typed type declaration
val wrap_module_items :
loc:Ppxlib__.Location.t ->
Sarek_typed_ast.tmodule_item list ->
Ppxlib.expression ->
Ppxlib.expressionWrap expression with module item bindings.
To avoid "type escapes its scope" errors, we use first-class modules to encapsulate inline types. The approach:
1. Generate a module signature KERNEL_TYPES with abstract types and accessors 2. Generate a concrete module implementation with the actual types 3. Transform the kernel body to use T.get_field and T.make_type accessors 4. Pass (module T : KERNEL_TYPES) as a parameter to the kernel
This keeps the concrete types hidden behind an existential type.
val gen_module_impl :
loc:Ppxlib.location ->
Sarek_typed_ast.ttype_decl list ->
Ppxlib.module_exprGenerate a concrete module implementation for inline types (types only). Example for record type point with fields x and y: struct type point = record with fields x: float and y: float end
Note: We only generate type declarations here, not accessor functions. The accessor functions are generated as object methods by gen_types_object.
val inline_type_decls :
Sarek_typed_ast.ttype_decl list ->
Sarek_typed_ast.ttype_decl listGet only inline type declarations (those without module prefix). External/registered types have qualified names like "Module.type".
val has_inline_types : Sarek_typed_ast.tkernel -> boolCheck if a kernel has inline types that need first-class module handling