ppx_nanocaml

Framework for writing nanopass-style compilers
IN THIS PACKAGE
Module Nanocaml . Pass
type 'a loc = 'a Ast.Asttypes.loc
type np_pass = {
npp_name : string;
npp_loc : Ast.Location.t;
npp_input : Lang.np_language;
npp_output : Lang.np_language;
npp_pre : Ast.expression -> Ast.expression;
npp_post : Ast.expression;
npp_procs : np_processor list;
}

represents a nanopass definition *

and np_processor = {
npc_name : string;
npc_loc : Ast.Location.t;
npc_dom : Lang.np_nonterm;
npc_cod : Lang.np_nonterm option;
npc_args : fun_arg list;
npc_clauses : clause list;
npc_clauses_loc : Ast.Location.t;
}

represents a processor definition (a transformation between nonterminals in a nanopass) *

and clause = np_pat * Ast.expression
and np_pat =
| NPpat_any of Ast.Location.t
| NPpat_var of string loc
| NPpat_alias of np_pat * string loc
| NPpat_tuple of np_pat list * Ast.Location.t
| NPpat_variant of string * np_pat option * Ast.Location.t
| NPpat_map of np_pat
| NPpat_cata of np_pat * Ast.expression option

represents a pattern in a production. the pattern must be parsed by nanocaml so that we can correctly map over lists and apply catamorphims, e.g. for expressions like (x, e [@r]) [@l]. *

val loc_of_pat : np_pat -> Ast.Location.t

returns the Location.t of the given pattern. *

val processor_of_rhs : name:string -> dom:Lang.np_nonterm -> cod:Lang.np_nonterm option -> loc:Ast.Location.t -> Ast.expression -> np_processor

convert the RHS of a let into a np_processor. *

val pat_of_pattern : Ast.pattern -> np_pat

convert a pattern into a np_pat. *

val signature_arrow : string
val extract_pass_sig : Ast.expression -> (string * Location.t) * (string * Location.t)

extract L0 and L1 out of expression of form L0 --> L1. returns ("L0", loc_L0), ("L1", loc_L1) (for this particular example). *

val extract_dom_cod : loc:Ast.Location.t -> Lang.np_language -> Lang.np_language -> string -> Lang.np_nonterm * Lang.np_nonterm option

extract domain and co-domain from the name of a production. the rules are: y_of_x => dom="x", cod="y" x_to_y => dom="x", cod="y" x => dom=cod="x" x_f => dom="x", cof=None

if the co-domain is not a valid nonterm of the output language, then the co-domain is None.

given the string name, returns dom, opt_cod. *

val pass_of_value_binding : Ast.value_binding -> np_pass

convert a value_binding into a np_pass