Js_of_ocaml_toplevel_worker_lwt_clienttype 'a result = 'a Js_of_ocaml_toplevel_protocol.Wrapped_intf.result Lwt.tHandle for a worker-side parsing session created by open_lexbuf and stepped one phrase at a time with step.
exception Init_failed of Js_of_ocaml_toplevel_protocol.Wrapped_intf.errorRaised (as the result of the create thread) when the worker fails to initialize its toplevel environment — for instance when the worker script cannot be loaded or stdlib.cmis.js is missing under the cmis_base_url.
val create :
?cmis_base_url:string ->
?after_init:(toplevel -> unit Lwt.t) ->
pp_stdout:output ->
pp_stderr:output ->
js_file:string ->
unit ->
toplevel Lwt.tSpawn the worker and initialize its toplevel. The returned thread fails with Init_failed if initialization does not succeed.
The worker fetches <cmis_base_url>stdlib.cmis.js at startup only if the cmis are not already embedded (i.e. it was built with --no-cmis).
val import_cmis_js :
toplevel ->
string ->
unit Js_of_ocaml_toplevel_protocol.Wrapped_intf.result Lwt.tval reset : toplevel -> ?timeout:(unit -> unit Lwt.t) -> unit -> unit Lwt.tval interrupt : toplevel -> unit Lwt.tForcibly terminate the worker — use this when a computation is stuck in an infinite loop and so cannot be reached by reset's cooperative Reset message — and respawn a fresh, re-initialized one (re-importing the cmis bundles and running after_init). Any request in flight fails with Lwt.Canceled. All toplevel state is lost, since the worker process is killed.
val clear_check : toplevel -> unit Lwt.tDiscard the scratch typing environment left by check ~setenv:true on the worker, re-enabling execute and the other code-running operations. See Js_of_ocaml_toplevel.Wrapped.clear_check.
Open a worker-side parsing session over code to be stepped with step. When ppf_code is given, the source is echoed to it as it is consumed. Release it with close_lexbuf.
val step :
toplevel ->
?print_outcome:bool ->
ppf_answer:output ->
lexbuf ->
[ `Phrase of bool | `Eof ] resultEvaluate the next phrase of a session. `Phrase ok ran a phrase (ok is false if it raised at evaluation), `Eof once the buffer is exhausted, and an Error result on a parse/type error. The caller drives the loop and decides whether to continue after a failure.
Release a session opened with open_lexbuf.
include Js_of_ocaml_toplevel_protocol.Wrapped_intf.Wrapped
with type toplevel := toplevel
and type 'a result := 'a result
and type output := outputParse and typecheck a given source code
val execute :
toplevel ->
?ppf_code:output ->
?print_outcome:bool ->
ppf_answer:output ->
string ->
bool resultExecute a given source code. The evaluation stops after the first toplevel phrase (as terminated by ";;") that fails to compile or for which the evaluation raises an uncaught exception.
val use :
toplevel ->
?filename:string ->
?print_outcome:bool ->
ppf_answer:output ->
string ->
bool resultExecute a given source code. Unlike execute, the whole buffer is parsed up front (using Toploop.parse_use_file); each resulting phrase is then typechecked and evaluated in sequence. Parse errors abort before any phrase runs.