123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146(************************************************************************)(* * The Coq Proof Assistant / The Coq Development Team *)(* v * INRIA, CNRS and contributors - Copyright 1999-2018 *)(* <O___,, * (see CREDITS file for the list of authors) *)(* \VV/ **************************************************************)(* // * This file is distributed under the terms of the *)(* * GNU Lesser General Public License Version 2.1 *)(* * (see LICENSE file for the text of the license) *)(************************************************************************)(************************************************************************)(* Coq serialization API/Plugin *)(* Copyright 2016-2019 MINES ParisTech *)(************************************************************************)(* Status: Very Experimental *)(************************************************************************)(* Init options for coq *)typeasync_flags={enable_async:stringoption;deep_edits:bool;async_workers:int;error_recovery:bool}typecoq_opts={(* callback to handle async feedback *)fb_handler:Format.formatter->Feedback.feedback->unit;(* callback to load cma/cmo files *)ml_load:(string->unit)option;(* Enable Coq Debug mode *)debug:bool;(* Allow SProp *)allow_sprop:bool;indices_matter:bool;}(**************************************************************************)(* Low-level, internal Coq initialization *)(**************************************************************************)(* Reference to feedback_handler *)letfb=ref0letcoq_initoptsout_fmt=ifopts.debugthenbeginPrintexc.record_backtracetrue;Flags.debug:=true;end;letload_obj=Sertop_loader.plugin_handleropts.ml_loadin(* XXX: We may not have to set path once the issue in Coq upstream is fixed. *)letadd_dir=Sertop_loader.add_ml_pathin(* Custom toplevel is used for bytecode-to-js dynlink *)letser_mltop:Mltop.toplevel=letopenMltopin{load_obj(* We ignore all the other operations for now. *);add_dir;ml_loop=(fun_->())}inMltop.set_topser_mltop;(* Core Coq initialization *)Lib.init();(* This should be configurable somehow. *)Global.set_engagementDeclarations.PredicativeSet;Global.set_indices_matteropts.indices_matter;(* --allow-sprop in agreement with coq v8.11 *)Global.set_allow_spropopts.allow_sprop;(* XXX fixme *)Flags.set_native_compilerfalse;(**************************************************************************)(* Feedback setup *)(**************************************************************************)(* Initialize logging. *)fb:=Feedback.add_feeder(opts.fb_handlerout_fmt);(**************************************************************************)(* Start the STM!! *)(**************************************************************************)Stm.init_core();(* End of initialization *)()letupdate_fb_handler~pp_feedout_fmt=Feedback.del_feeder!fb;fb:=Feedback.add_feeder(pp_feedout_fmt)(******************************************************************************)(* Async setup *)(******************************************************************************)(* Set async flags; IMPORTANT, this has to happen before STM.init () ! *)letprocess_stm_flagsopts=letstm_opts=Stm.AsyncOpts.default_optsin(* Process error resilience *)letasync_proofs_tac_error_resilience,async_proofs_cmd_error_resilience=ifopts.error_recoverythen`All,trueelse`None,falseinletstm_opts={stm_optswithasync_proofs_tac_error_resilience;async_proofs_cmd_error_resilience}in(* Enable async mode if requested *)Option.cata(funcoqtop->(* Whether to forward Glob output to the IDE. *)letdump_opt="-no-glob"inletopenStm.AsyncOptsinletopts={stm_optswithasync_proofs_mode=APon(* Imitate CoqIDE *);async_proofs_never_reopen_branch=notopts.deep_edits;async_proofs_n_workers=opts.async_workers;async_proofs_n_tacworkers=opts.async_workers}in(* async_proofs_worker_priority); *)AsyncTaskQueue.async_proofs_flags_for_workers:=[dump_opt];CoqworkmgrApi.(initHigh);(* Uh! XXXX *)fori=0toArray.lengthSys.argv-1doArray.setSys.argvi"-m"done;Array.setSys.argv0coqtop;opts)stm_optsopts.enable_async