XtoplevelThis module implements the core Read-Eval-Print Loop (REPL) functionality for the `xeus-ocaml` kernel. It is responsible for initializing the OCaml toplevel environment and for executing user-provided code.
The module relies on the `js_of_ocaml-toplevel` library for the underlying evaluation mechanism. It enhances this by capturing all forms of output (stdout, stderr, toplevel values, and rich display data from the Xlib module) and handling special toplevel directives like `#require`.
CRITICAL: The setup function in this module must only be called *after* the Xlibloader.setup function has successfully completed to ensure the necessary standard library files are present in the virtual filesystem.
Initializes the OCaml toplevel environment.
This function performs the final steps of the kernel's OCaml-side setup. It must be called after the virtual filesystem has been populated by Xlibloader.setup.
Its main tasks are:
Xlib module to make rich display functions globally available to the user.val eval : string -> Protocol.output list Lwt.tParses and evaluates a string of OCaml code.
This is the main execution function for the kernel. It takes a block of code, splits it into individual toplevel phrases (ending in `;;`), and executes them sequentially.
It captures all outputs generated during execution, including standard streams, the printed value of the last expression, and any rich outputs created via the Xlib module. It also provides special handling for the `#require "lib_name"` directive by delegating to the Xlibloader.load_on_demand function.