123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199(************************************************************************)(* * The Coq Proof Assistant / The Coq Development Team *)(* v * Copyright INRIA, CNRS and contributors *)(* <O___,, * (see version control and CREDITS file for authors & dates) *)(* \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) *)(************************************************************************)openPpopenCoqargs(** This file provides generic support for Coq executables + specific
support for the coqtop executable *)let()=at_exitflush_allletget_version~boot=ifbootthenCoq_config.versionelsetryletenv=Boot.Env.init()inletrevision=Boot.Env.revisionenv|>Boot.Path.to_stringinletch=open_inrevisioninletver=input_linechinletrev=input_linechinlet()=close_inchinPrintf.sprintf"%s (%s)"verrevwith_->Coq_config.versionletprint_header~boot()=Feedback.msg_info(str"Welcome to Coq "++str(get_version~boot));flush_all()(******************************************************************************)(* Fatal Errors *)(******************************************************************************)(** Prints info which is either an error or an anomaly and then exits
with the appropriate error code *)letfatal_error_exnexn=Topfmt.(in_phase~phase:Initializationprint_err_exnexn);flush_all();letexit_code=if(CErrors.is_anomalyexn)then129else1inexitexit_codetype('a,'b)custom_toplevel={parse_extra:stringlist->'a*stringlist;usage:Boot.Usage.specific_usage;init_extra:'a->Coqargs.injection_commandlist->opts:Coqargs.t->'b;initial_args:Coqargs.t;run:'a->opts:Coqargs.t->'b->unit}(** Main init routine *)letinit_toplevel{parse_extra;init_extra;usage;initial_args}=Coqinit.init_ocaml();letopts,customopts=Coqinit.parse_arguments~parse_extra~usage~initial_args()inStm.init_process(sndcustomopts);letinjections=Coqinit.init_runtimeoptsin(* This state will be shared by all the documents *)Stm.init_core();letcustomstate=init_extra~optscustomoptsinjectionsinopts,customopts,customstateletstart_coqcustom=letinit_feeder=Feedback.add_feederCoqloop.coqloop_feedin(* Init phase *)letopts,custom_opts,state=tryinit_toplevelcustomwithany->flush_all();fatal_error_exnanyinFeedback.del_feederinit_feeder;(* Run phase *)custom.run~optscustom_optsstate(** ****************************************)(** Specific support for coqtop executable *)letltac_debug_answer=letopenDebugHook.Answerinfunction|Promptprompt->(* No newline *)Format.fprintf!Topfmt.err_ft"@[%a@]%!"Pp.pp_withprompt|Goalg->Format.fprintf!Topfmt.err_ft"@[%a@]@\n%!"Pp.pp_withg|Outputo->Format.fprintf!Topfmt.err_ft"@[%a@]@\n%!"Pp.pp_witho|Init->Format.fprintf!Topfmt.err_ft"@[%a@]@\n%!"Pp.pp_with(str"Init")|Stack_|Vars_->CErrors.anomaly(str"ltac_debug_answer: unsupported Answer type")letltac_debug_parse()=letopenDebugHookinletact=tryAction.parse(read_line())withEnd_of_file->OkAction.Interruptinmatchactwith|Okact->act|Errorerror->ltac_debug_answer(Answer.Output(strerror));Action.Failedtypequery=PrintTags|PrintModUidofstringlisttyperun_mode=Interactive|Batch|Queryofquerytypetoplevel_options={run_mode:run_mode;color_mode:Colors.color;}letinit_documentoptsstm_optionsinjections=(* Coq init process, phase 3: Stm initialization, backtracking state.
It is essential that the module system is in a consistent
state before we take the first snapshot. This was not
guaranteed in the past, but now is thanks to the STM API.
*)(* Next line allows loading .vos files when in interactive mode *)Flags.load_vos_libraries:=true;letopenVernac.Stateinletdoc,sid=Stm.(new_doc{doc_type=Interactiveopts.config.logic.toplevel_name;injections;})in{doc;sid;proof=None;time=Option.mapVernac.make_time_outputopts.config.time}letinit_toploopoptsstm_optsinjections=letstate=init_documentoptsstm_optsinjectionsinletstate=Load.load_init_vernacularsopts~stateinstateletcoqtop_init({run_mode;color_mode},async_opts)injections~opts=ifrun_mode!=InteractivethenFlags.quiet:=true;Colors.init_color(ifopts.config.print_emacsthen`EMACSelsecolor_mode);Flags.if_verbose(print_header~boot:opts.pre.boot)();DebugHook.Intf.(set{read_cmd=ltac_debug_parse;submit_answer=ltac_debug_answer;isTerminal=true});init_toploopoptsasync_optsinjectionsletcoqtop_parse_extraextras=letrecparse_extrarun_mode=function|"-batch"::rest->parse_extraBatchrest|"-print-mod-uid"::rest->Query(PrintModUidrest),[]|x::rest->letrun_mode,rest=parse_extrarun_moderestinrun_mode,x::rest|[]->run_mode,[]inletrun_mode,extras=parse_extraInteractiveextrasinletcolor_mode,extras=Colors.parse_extra_colorsextrasinletasync_opts,extras=Stmargs.parse_args~init:Stm.AsyncOpts.default_optsextrasin({run_mode;color_mode},async_opts),extrasletfix_windows_dirseps=ifSys.win32thenStr.(global_replace(regexp"\\(.\\)\\")"\\1/"s)elsesletget_native_names=(* We ignore even critical errors because this mode has to be super silent *)tryfix_windows_dirsep@@Filename.(List.fold_leftconcat(dirnames)[!Nativelib.output_dir;Library.native_name_from_filenames])with_->""letcoqtop_run({run_mode;color_mode},_)~optsstate=matchrun_modewith|Interactive->Coqloop.run~opts~state;|QueryPrintTags->Colors.print_style_tagscolor_mode;exit0|Query(PrintModUidsl)->lets=String.concat" "(List.mapget_native_namesl)inprint_endlines;exit0|Batch->exit0letcoqtop_specific_usage=Boot.Usage.{executable_name="coqtop";extra_args="";extra_options="\n\
coqtop specific options:\n\
\n -batch batch mode (exits after interpretation of command line)\
\n"}letcoqtop_toplevel={parse_extra=coqtop_parse_extra;usage=coqtop_specific_usage;init_extra=coqtop_init;run=coqtop_run;initial_args=Coqargs.default}