jon.recoil.org

Module Flambda2_to_jsir.To_jsir_env

type t

Translation environment for Flambda to Js_of_ocaml IR translation.

val create : module_symbol:Flambda2_identifiers.Symbol.t -> return_continuation:Flambda2_identifiers.Continuation.t -> exn_continuation:Flambda2_identifiers.Continuation.t -> t

Create a new environment.

return_continuation and exn_continuation refer to the top-level return/exception continuations, and does not change once the environment is created.

val return_continuation : t -> Flambda2_identifiers.Continuation.t
val exn_continuation : t -> Flambda2_identifiers.Continuation.t
val enter_function_body : t -> return_continuation:Flambda2_identifiers.Continuation.t -> exn_continuation:Flambda2_identifiers.Continuation.t -> t

Enter a function body, with the corresponding return and exception continuations.

val module_symbol : t -> Flambda2_identifiers.Symbol.t

Symbol corresponding to the module currently compiling.

val add_continuation : t -> Flambda2_identifiers.Continuation.t -> Jsoo_imports.Import.Jsir.Addr.t -> t

Map a Flambda2 continuation to the address of the corresponding block. Not to be used for continuations used as exception handlers (use add_exn_handler).

type exn_handler = {
  1. addr : Jsoo_imports.Import.Jsir.Addr.t;
  2. exn_param : Jsoo_imports.Import.Jsir.Var.t;
  3. extra_args : Jsoo_imports.Import.Jsir.Var.t list;
}
val add_exn_handler : t -> Flambda2_identifiers.Continuation.t -> addr:Jsoo_imports.Import.Jsir.Addr.t -> exn_param:Jsoo_imports.Import.Jsir.Var.t -> extra_args:Jsoo_imports.Import.Jsir.Var.t list -> t

Add continuations used as exception handlers, along with its exception parameter and any variables used to pass in extra_args.

val add_var : t -> Flambda2_identifiers.Variable.t -> Jsoo_imports.Import.Jsir.Var.t -> t

Map a Flambda2 variable to a JSIR variable.

val add_var_alias_of_var_exn : t -> var:Flambda2_identifiers.Variable.t -> alias_of:Flambda2_identifiers.Variable.t -> t

Set var to be an alias of alias_of. Raises if alias_of is not found in the environment.

val add_symbol : t -> res:To_jsir_result.t -> Flambda2_identifiers.Symbol.t -> Jsoo_imports.Import.Jsir.Var.t -> t * To_jsir_result.t

Map a Flambda2 symbol to a JSIR variable, and register it to the global symbol table.

val add_symbol_without_registering : t -> Flambda2_identifiers.Symbol.t -> Jsoo_imports.Import.Jsir.Var.t -> t

Symbols added through this function must be registered to the global symbol table after the definitions for them are added to the result, using register_symbol_exn. Otherwise, they will not be available to other compilation units.

val register_symbol_exn : t -> res:To_jsir_result.t -> Flambda2_identifiers.Symbol.t -> To_jsir_result.t

Register the given symbol to the global symbol table. Raises if the symbol is not in the environment.

Note that calling this function is usually a mistake, as most functions that add symbols will automatically call this function. However, it is necessary for add_symbol_without_registering.

val add_var_alias_of_symbol_exn : t -> res:To_jsir_result.t -> var:Flambda2_identifiers.Variable.t -> alias_of:Flambda2_identifiers.Symbol.t -> t * To_jsir_result.t

Set var/symbol to be an alias of alias_of. Raises if alias_of is from the current compilation unit and is not found in the environment.

val add_symbol_alias_of_var_exn : t -> res:To_jsir_result.t -> symbol:Flambda2_identifiers.Symbol.t -> alias_of:Flambda2_identifiers.Variable.t -> t * To_jsir_result.t
type code_id = {
  1. addr : Jsoo_imports.Import.Jsir.Addr.t;
  2. params : Jsoo_imports.Import.Jsir.Var.t list;
  3. closure : Jsoo_imports.Import.Jsir.Var.t;
}
val add_code_id : t -> Flambda2_identifiers.Code_id.t -> addr:Jsoo_imports.Import.Jsir.Addr.t -> params:Jsoo_imports.Import.Jsir.Var.t list -> closure:Jsoo_imports.Import.Jsir.Var.t -> t

Map a Flambda2 code ID to the address of the corresponding JSIR block, its parameters, and the JSIR varible corresponding to its closure.

val add_function_slot : t -> Flambda2_identifiers.Function_slot.t -> Jsoo_imports.Import.Jsir.Var.t -> t

Map a Flambda2 function slot to the corresponding JSIR closure variable.

val add_value_slot : t -> Flambda2_identifiers.Value_slot.t -> Jsoo_imports.Import.Jsir.Var.t -> t

Map a Flambda2 value slot to the corresponding JSIR closure variable.

val get_continuation_exn : t -> Flambda2_identifiers.Continuation.t -> Jsoo_imports.Import.Jsir.Addr.t

Return the block address for the given continuation. Raises if given an unbound continuation.

val get_exn_handler_exn : t -> Flambda2_identifiers.Continuation.t -> exn_handler

Return the block address and parameters for exception-handling continuations. Raises if given an unbound exception handler.

val get_var_exn : t -> Flambda2_identifiers.Variable.t -> Jsoo_imports.Import.Jsir.Var.t

Return the JSIR variable for the given Flambda variable. Raises if given an unbound variable.

val get_symbol : t -> res:To_jsir_result.t -> Flambda2_identifiers.Symbol.t -> (Jsoo_imports.Import.Jsir.Var.t * To_jsir_result.t) option

Return the JSIR variable for the given Flambda symbol.

If the symbol is from the current compilation unit, we look it up in the environment; otherwise, we fetch from the global symbol table.

val get_symbol_exn : t -> res:To_jsir_result.t -> Flambda2_identifiers.Symbol.t -> Jsoo_imports.Import.Jsir.Var.t * To_jsir_result.t
val get_code_id_exn : t -> Flambda2_identifiers.Code_id.t -> code_id

Return the block address, parameter variables and closure variable corresponding to the given Code_id.t.

val get_function_slot : t -> Flambda2_identifiers.Function_slot.t -> Jsoo_imports.Import.Jsir.Var.t option

Return the variable corresponding to a function slot.

val get_function_slot_exn : t -> Flambda2_identifiers.Function_slot.t -> Jsoo_imports.Import.Jsir.Var.t
val get_value_slot : t -> Flambda2_identifiers.Value_slot.t -> Jsoo_imports.Import.Jsir.Var.t option

Return the variable corresponding to a value slot.

val get_value_slot_exn : t -> Flambda2_identifiers.Value_slot.t -> Jsoo_imports.Import.Jsir.Var.t

These functions first check whether the given item exists in the environment. If it exists, the environment is unchanged. Otherwise, we create a fresh variable, and add the mapping to the environment.

val add_function_slot_if_not_found : t -> Flambda2_identifiers.Function_slot.t -> t
val add_value_slot_if_not_found : t -> Flambda2_identifiers.Value_slot.t -> t
val set_my_closure : t -> Flambda2_identifiers.Variable.t -> Jsoo_imports.Import.Jsir.Var.t -> t

Keep track of the my_closure of the current code block being translated, and maintain a mapping to its JSIR equivalent.

val is_my_closure : t -> Flambda2_identifiers.Variable.t -> bool