Codebase list coq / 9d27ae0
Imported Upstream version 8.3.pl2 Stephane Glondu 13 years ago
64 changed file(s) with 725 addition(s) and 364 deletion(s). Raw diff Collapse all Expand all
7272 coqdoc.sty
7373 ide/index_urls.txt
7474 doc/faq/html/
75 doc/refman/csdp.cache
76 doc/refman/trace
7577 doc/refman/Reference-Manual.pdf
7678 doc/refman/Reference-Manual.ps
7779 doc/refman/cover.html
0 Changes from V8.3pl1 to V8.3pl2
1 ===============================
2
3 Coqdoc and documentation bugs
4
5 - #2470 (use "membership" instead of "appartness")
6 - #2475 (documentation of the "f binders := t" notation for record fields)
7 - Documentation of module String on coq.inria.fr/stdlib
8
9 Tactics
10
11 - #2493 (dependent pairs injection failing because of Type cumulativity missing)
12 - Reduction "simpl" sometimes failing in presence of names redefined in modules
13
14 Extraction
15
16 - #2359 (Some unnecessary unsafe casts are now avoided (bug in the type checker)).
17 - #2469 (fix Extract Inlined Constant for Haskell and Scheme)
18 - #2476 (Fix indentation of default pattern in haskell case)
19 - #2477 (Avoid printing unused mutual fix components)
20 - #2478 (Add missing parenthesis around emulated pattern-match)
21 - #2482 (Extract Inductive on singleton inductives)
22 - #2484 (Avoid an assert failure with -dont-load-proofs)
23 - #2497 (malformed Haskell extraction of deeply-nested match expressions)
24 - #2515 (Allow extracting Ascii.ascii to native Char in Haskell)
25 - #2525 (Nicer error when a toplevel module has no body)
26 - Fix printing of haskell modular names
27
28 Miscellaneous bug fixes
29
30 - #2487 (compilation with camlp5 in strict mode)
31 - #2283, #2460 (new option "Set Default Timeout n / Unset Default Timeout")
32 - #2524 (In win32, the exit code of coqc should be correct now)
33 - Now, vm_compute is responsive to Ctrl-C interruption, as the rest of coqtop
34 - Fixed uncaught exception when vmcast used in Check
35 - coqdep complies with the -R visibility discipline
36 - Fixing printing of f when defined using "Notation f x := ..."
37 - Fixing Unset for options setting integer values
38 - Excluding admitted subgoals from Search/SearchAbout
39
040 Changes from V8.3 to V8.3pl1
141 ============================
242
4787 - #2434 (anomaly DuringSyntaxChecking with Local/Global prefixes)
4888 - a few improvements in efficiency
4989
90
91 Extraction
92
93 - The pretty-printer for Haskell now produces layout-independant code
5094
5195 Changes from V8.2 to V8.3
5296 =========================
+0
-8
Coq.bat less more
0 @echo off
1 set COQBIN=%~0\..\bin
2 set COQLIB=%~0\..\lib
3 echo Using COQBIN= %COQBIN%
4 echo and COQLIB= %COQLIB%
5 echo Starting Coq
6 %~0\..\bin\coqtop.opt.exe
7 pause
+0
-7
Coqide.bat less more
0 @echo off
1 set COQBIN=%~0\..\bin
2 set COQLIB=%~0\..\lib
3 echo Using COQBIN= %COQBIN%
4 echo and COQLIB= %COQLIB%
5 echo Starting Coqide
6 %~0\..\bin\coqide.opt.exe
4040
4141 Should you need or prefer to compile Coq V8.3 yourself, you need:
4242
43 - Objective Caml version 3.09.3 or later
43 - Objective Caml version 3.10.2 or later
4444 (available at http://caml.inria.fr/)
4545
4646 For Objective Caml version >= 3.10.0, you also need to install
8787 INSTALLATION PROCEDURE IN DETAILS (NORMAL USERS).
8888 =================================================
8989
90 1- Check that you have the Objective Caml compiler version 3.09.3 (or later)
90 1- Check that you have the Objective Caml compiler version 3.10.2 (or later)
9191 installed on your computer and that "ocamlmktop" and "ocamlc" (or
9292 its native code version "ocamlc.opt") lie in a directory which is present
9393 in your $PATH environment variable.
2222 Else, read the rest of this document to compile your own CoqIde.
2323
2424 REQUIREMENT:
25 - OCaml >= 3.09.3 with native threads support.
25 - OCaml >= 3.10.2 with native threads support.
2626 - make world must succeed.
2727 - The graphical toolkit GTK+ 2.x. See http://www.gtk.org.
2828 The official supported version is at least 2.10.x.
88 The Coq package for Windows comes with an auto-installer. It will
99 install Coq binaries and libraries under any directory you specify
1010 (C:\Program Files\Coq is the default path). It also creates shortcuts
11 in the Windows menus. Alternatively, you can launch Coq using Coq.bat
12 and Coqide.bat in the installation directory (C:\Program Files\Coq by
13 default).
11 in the Windows menus. Alternatively, you can launch Coq using coqide.exe
12 or coqtop.exe in the bin sub-directory of the installation
13 (C:\Program Files\Coq\bin by default).
1414
1515 COMPILATION.
1616 ============
1919 distribution. If you really need to recompile under Windows, here
2020 are some indications:
2121
22 1- Install ocaml for Windows (MinGW port), at least version 3.09.3.
22 1- Install ocaml for Windows (MinGW port), at least version 3.10.2.
2323 See: http://caml.inria.fr
2424
2525 2- Install a shell environment with at least:
5151
5252 Good luck :-)
5353
54 Alternatively, it is now possible (and even recommended ...) to build
55 Windows executables of coq from Linux thanks to a mingw cross-compiler.
56 If interested, please contact us for more details.
57
5458 The Coq Team.
99 <tools/coqdoc/main.{native,byte}> : use_str
1010 <checker/main.{native,byte}> : use_str, use_unix, use_gramlib
1111 <plugins/micromega/csdpcert.{native,byte}> : use_nums, use_unix
12 <tools/mkwinapp.{native,byte}> : use_unix
1213
1314 ## tags for ide
1415
55 #
66 ##################################
77
8 VERSION=8.3pl1
8 VERSION=8.3pl2
99 VOMAGIC=08300
1010 STATEMAGIC=58300
1111 DATE=`LANG=C date +"%B %Y"`
410410 CAMLVERSION=`"$bytecamlc" -version`
411411
412412 case $CAMLVERSION in
413 1.*|2.*|3.00|3.01|3.02|3.03|3.03alpha|3.04|3.05beta|3.05|3.06|3.07*|3.08*|3.09.[012])
413 1.*|2.*|3.00|3.01|3.02|3.03|3.03alpha|3.04|3.05beta|3.05|3.06|3.07*|3.08*|3.09*)
414414 echo "Your version of Objective-Caml is $CAMLVERSION."
415415 if [ "$force_caml_version" = "yes" ]; then
416416 echo "*Warning* You are compiling Coq with an outdated version of Objective-Caml."
417417 else
418 echo " You need Objective-Caml 3.09.3 or later."
418 echo " You need Objective-Caml 3.10.2 or later."
419419 echo " Configuration script failed!"
420420 exit 1
421421 fi;;
490490 exit 1
491491 fi
492492 camlp4oexec=`echo $camlp4oexec | sed -e 's/4/5/'`
493 if [ `$camlp4oexec -pmode 2>&1` = "strict" ]; then
494 echo "Error: Camlp5 found, but in strict mode!"
495 echo "Please compile Camlp5 in transitional mode."
496 exit 1
497 fi
498493 else
499494 case $CAMLTAG in
500495 OCAML31*)
509504 fi
510505 CAMLP4=camlp5
511506 camlp4oexec=`echo $camlp4oexec | sed -e 's/4/5/'`
512 if [ `$camlp4oexec -pmode 2>&1` = "strict" ]; then
513 echo "Error: Camlp5 found, but in strict mode!"
514 echo "Please compile Camlp5 in transitional mode."
515 exit 1
516 fi
517507 ;;
518508 *)
519509 CAMLP4=camlp4
10931083 echo "*Warning* To compile the system for a new architecture"
10941084 echo " don't forget to do a 'make archclean' before './configure'."
10951085
1096 # $Id: configure 13740 2010-12-23 12:37:18Z notin $
1086 # $Id: configure 14025 2011-04-19 07:19:00Z notin $
2323 && ~~~~\zeroone{\ident}
2424 \verb!{! \zeroone{\nelist{\field}{;}} \verb!}! \verb:.:\\
2525 & & \\
26 {\field} & ::= & {\name} : {\type} [ {\tt where} {\it notation} ] \\
27 & $|$ & {\name} {\typecstr} := {\term}
26 {\field} & ::= & {\name} \zeroone{\binders} : {\type} [ {\tt where} {\it notation} ] \\
27 & $|$ & {\name} \zeroone{\binders} {\typecstr} := {\term}
2828 \end{tabular}
2929 \end{centerframe}
3030 \caption{Syntax for the definition of {\tt Record}}
3636 \smallskip
3737 {\tt Record} {\ident} {\params} \texttt{:}
3838 {\sort} := {\ident$_0$} \verb+{+
39 {\ident$_1$} \texttt{:} {\term$_1$};
39 {\ident$_1$} \binders$_1$ \texttt{:} {\term$_1$};
4040 \dots
41 {\ident$_n$} \texttt{:} {\term$_n$} \verb+}+.
41 {\ident$_n$} \binders$_n$ \texttt{:} {\term$_n$} \verb+}+.
4242 \smallskip
4343
4444 \noindent the identifier {\ident} is the name of the defined record
4646 its constructor. If {\ident$_0$} is omitted, the default name {\tt
4747 Build\_{\ident}} is used. If {\sort} is omitted, the default sort is ``{\Type}''.
4848 The identifiers {\ident$_1$}, ..,
49 {\ident$_n$} are the names of fields and {\term$_1$}, .., {\term$_n$}
49 {\ident$_n$} are the names of fields and {\tt forall} \binders$_1${\tt ,} {\term$_1$}, ..., {\tt forall} \binders$_n${\tt ,} {\term$_n$}
5050 their respective types. Remark that the type of {\ident$_i$} may
5151 depend on the previous {\ident$_j$} (for $j<i$). Thus the order of the
5252 fields is important. Finally, {\params} are the parameters of the
928928 (time expressed in seconds), then it is interrupted and an error message
929929 is displayed.
930930
931 \subsection[\tt Set Default Timeout \textrm{\textsl{int}}.]{\tt Set
932 Default Timeout \textrm{\textsl{int}}.\comindex{Set Default Timeout}}
933
934 After using this command, all subsequent commands behave as if they
935 were passed to a {\tt Timeout} command. Commands already starting by
936 a {\tt Timeout} are unaffected.
937
938 \subsection[\tt Unset Default Timeout.]{\tt Unset Default Timeout.\comindex{Unset Default Timeout}}
939
940 This command turns off the use of a defaut timeout.
941
942 \subsection[\tt Test Default Timeout.]{\tt Test Default Timeout.\comindex{Test Default Timeout}}
943
944 This command displays whether some default timeout has be set or not.
945
931946 \section{Controlling display}
932947
933948 \subsection[\tt Set Silent.]{\tt Set Silent.\comindex{Set Silent}
11721187 \end{itemize}
11731188
11741189
1175 % $Id: RefMan-oth.tex 13454 2010-09-23 17:00:29Z aspiwack $
1190 % $Id: RefMan-oth.tex 13923 2011-03-21 16:25:20Z letouzey $
11761191
11771192 %%% Local Variables:
11781193 %%% mode: latex
451451 theories/FSets/FMapFullAVL.v
452452 </dd>
453453
454 <!-- <dt> <b>Strings</b>
454 <dt> <b>Strings</b>
455455 Implementation of string as list of ascii characters
456456 </dt>
457457 <dd>
458458 theories/Strings/Ascii.v
459459 theories/Strings/String.v
460 </dd> -->
460 </dd>
461461
462462 <dt> <b>Reals</b>:
463463 Formalization of real numbers
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (* $Id: coq.ml 13431 2010-09-18 08:15:29Z herbelin $ *)
8 (* $Id: coq.ml 13751 2010-12-24 09:56:05Z letouzey $ *)
99
1010 open Vernac
1111 open Vernacexpr
2626 open Namegen
2727 open Ideutils
2828
29 let prerr_endline s = if !debug then prerr_endline s else ()
30
31 let output = ref (Format.formatter_of_out_channel stdout)
32
3329 let msg m =
3430 let b = Buffer.create 103 in
3531 Pp.msg_with (Format.formatter_of_buffer b) m;
393389 }
394390
395391 let reset_initial () =
396 prerr_endline "Reset initial called"; flush stderr;
392 prerr_endline "Reset initial called";
397393 Vernacentries.abort_refine Lib.reset_initial ()
398394
399395 let reset_to sp =
411407 let pe = Pcoq.Gram.Entry.parse Pcoq.main_entry pa in
412408 (* Temporary hack to make coqide.byte work (WTF???) - now with less screen
413409 * pollution *)
414 Pervasives.prerr_string " \r"; Pervasives.flush stderr;
410 (try Pervasives.prerr_string " \r"; Pervasives.flush stderr with _ -> ());
415411 match pe with
416412 | None -> assert false
417413 | Some((loc,vernac) as last) ->
0 large ICON ide/coq.ico
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (* $Id: coqide.ml 13708 2010-12-13 14:49:29Z gmelquio $ *)
8 (* $Id: coqide.ml 13751 2010-12-24 09:56:05Z letouzey $ *)
99
1010 open Preferences
1111 open Vernacexpr
199199
200200 let crash_save i =
201201 (* ignore (Unix.sigprocmask Unix.SIG_BLOCK signals_to_crash);*)
202 Pervasives.prerr_endline "Trying to save all buffers in .crashcoqide files";
202 safe_prerr_endline "Trying to save all buffers in .crashcoqide files";
203203 let count = ref 0 in
204204 List.iter
205205 (function {script=view; analyzed_view = av } ->
211211 in
212212 try
213213 if try_export filename (view#buffer#get_text ()) then
214 Pervasives.prerr_endline ("Saved "^filename)
215 else Pervasives.prerr_endline ("Could not save "^filename)
216 with _ -> Pervasives.prerr_endline ("Could not save "^filename))
214 safe_prerr_endline ("Saved "^filename)
215 else safe_prerr_endline ("Could not save "^filename)
216 with _ -> safe_prerr_endline ("Could not save "^filename))
217217 )
218218 session_notebook#pages;
219 Pervasives.prerr_endline "Done. Please report.";
219 safe_prerr_endline "Done. Please report.";
220220 if i <> 127 then exit i
221221
222222 let ignore_break () =
32013201 "\nCoq is developed by the Coq Development Team\
32023202 \n(INRIA - CNRS - University Paris 11 and partners)\
32033203 \nWeb site: " ^ Coq_config.wwwcoq ^
3204 "\nFeature wish or bug report: http://logical.saclay.inria.fr/coq-bugs\
3204 "\nFeature wish or bug report: http://coq.inria.fr/bugs\
32053205 \n\
32063206 \nCredits for CoqIDE, the Integrated Development Environment for Coq:\
32073207 \n\
33313331 try
33323332 GtkThread.main ()
33333333 with
3334 | Sys.Break -> prerr_endline "Interrupted." ; flush stderr
3334 | Sys.Break -> prerr_endline "Interrupted."
33353335 | e ->
3336 Pervasives.prerr_endline ("CoqIde unexpected error:" ^ (Printexc.to_string e));
3337 flush stderr;
3336 safe_prerr_endline ("CoqIde unexpected error:" ^ (Printexc.to_string e));
3337 flush_all ();
33383338 crash_save 127
33393339 done
33403340
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (* $Id: ideutils.ml 13323 2010-07-24 15:57:30Z herbelin $ *)
8 (* $Id: ideutils.ml 13751 2010-12-24 09:56:05Z letouzey $ *)
99
1010
1111 open Preferences
3030
3131 let pbar = GRange.progress_bar ~pulse_step:0.2 ()
3232
33 (* On a Win32 application with no console, writing to stderr raise
34 a Sys_error "bad file descriptor" *)
35 let safe_prerr_endline msg = try prerr_endline msg with _ -> ()
36
3337 let debug = Flags.debug
3438
3539 let prerr_endline s =
36 if !debug then (prerr_endline s;flush stderr)
40 if !debug then try (prerr_endline s;flush stderr) with _ -> ()
3741 let prerr_string s =
38 if !debug then (prerr_string s;flush stderr)
42 if !debug then try (prerr_string s;flush stderr) with _ -> ()
3943
4044 let lib_ide_file f =
4145 let coqlib = Envars.coqlib () in
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (*i $Id: ideutils.mli 13323 2010-07-24 15:57:30Z herbelin $ i*)
8 (*i $Id: ideutils.mli 13751 2010-12-24 09:56:05Z letouzey $ i*)
99
1010 val async : ('a -> unit) -> 'a -> unit
1111 val sync : ('a -> 'b) -> 'a -> 'b
3333 val lib_ide_file : string -> string
3434 val my_stat : string -> Unix.stats option
3535
36 val safe_prerr_endline : string -> unit
3637 val prerr_endline : string -> unit
3738 val prerr_string : string -> unit
3839 val print_id : 'a -> unit
2929
3030 let html_config = "Configwin bindings configurator for html parameters"
3131
32 let home =
33 try Sys.getenv "HOME"
34 with Not_found -> ""
32 let home = System.home
3533
3634 let mCapture = "Capture";;
3735 let mType_key = "Type key" ;;
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (* $Id: constrextern.ml 13492 2010-10-04 21:20:01Z herbelin $ *)
8 (* $Id: constrextern.ml 13967 2011-04-08 14:08:43Z herbelin $ *)
99
1010 (*i*)
1111 open Pp
342342 (fun (loc,p) -> CPatPrim (loc,p))
343343 destPatPrim terms
344344
345 let mkPat loc qid l =
346 (* Normally irrelevant test with v8 syntax, but let's do it anyway *)
347 if l = [] then CPatAtom (loc,Some qid) else CPatCstr (loc,qid,l)
348
345349 (* Better to use extern_rawconstr composed with injection/retraction ?? *)
346350 let rec extern_cases_pattern_in_scope (scopes:local_scopes) vars pat =
347351 try
396400 (match keyrule with
397401 | NotationRule (sc,ntn) -> raise No_match
398402 | SynDefRule kn ->
399 let p =
400 let qid = Qualid (loc, shortest_qualid_of_syndef vars kn) in
401 if l = [] then
402 CPatAtom (loc,Some qid)
403 else
404 let l =
405 List.map (extern_cases_pattern_in_scope allscopes vars) l in
406 CPatCstr (loc,qid,l) in
407 insert_pat_alias loc p na)
403 let qid = Qualid (loc, shortest_qualid_of_syndef vars kn) in
404 let l = List.map (extern_cases_pattern_in_scope allscopes vars) l in
405 insert_pat_alias loc (mkPat loc qid l) na)
408406 | PatCstr (_,f,l,_), Some n when List.length l > n ->
409407 raise No_match
410408 | PatCstr (loc,_,_,na),_ ->
431429 insert_pat_delimiters loc
432430 (make_pat_notation loc ntn (l,ll)) key)
433431 | SynDefRule kn ->
434 let qid = shortest_qualid_of_syndef vars kn in
435 CPatAtom (loc,Some (Qualid (loc, qid))) in
432 let qid = Qualid (loc, shortest_qualid_of_syndef vars kn) in
433 let l =
434 List.map (fun (c,(scopt,scl)) ->
435 extern_cases_pattern_in_scope (scopt,scl@scopes) vars c)
436 subst in
437 assert (substlist = []);
438 mkPat loc qid l in
436439 insert_pat_alias loc p na
437440 | PatVar (loc,Anonymous),_ -> CPatAtom (loc, None)
438441 | PatVar (loc,Name id),_ -> CPatAtom (loc, Some (Ident (loc,id)))
1313 for fast computation of bounded (31bits) integers */
1414
1515 #include <stdio.h>
16 #include <signal.h>
1617 #include "coq_gc.h"
1718 #include "coq_instruct.h"
1819 #include "coq_fix_code.h"
156157 #endif
157158 #endif
158159
160 /* For signal handling, we highjack some code from the caml runtime */
161
162 extern intnat caml_signals_are_pending;
163 extern intnat caml_pending_signals[];
164 extern void caml_process_pending_signals(void);
165
159166 /* The interpreter itself */
160167
161168 value coq_interprete
413420 realloc_coq_stack(Coq_stack_threshold);
414421 sp = coq_sp;
415422 }
423 /* We also check for signals */
424 if (caml_signals_are_pending) {
425 /* If there's a Ctrl-C, we reset the vm */
426 if (caml_pending_signals[SIGINT]) { coq_sp = coq_stack_high; }
427 caml_process_pending_signals();
428 }
416429 Next;
417 /* Fall through CHECK_SIGNALS */
418430
419431 Instruct(APPTERM) {
420432 int nargs = *pc++;
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (* $Id: names.ml 13486 2010-10-03 17:01:43Z herbelin $ *)
8 (* $Id: names.ml 13804 2011-01-27 00:41:34Z letouzey $ *)
99
1010 open Pp
1111 open Util
222222
223223 let constant_of_kn kn = (kn,kn)
224224 let constant_of_kn_equiv kn1 kn2 = (kn1,kn2)
225 let make_con mp dir l = ((mp,dir,l),(mp,dir,l))
225 let make_con mp dir l = constant_of_kn (mp,dir,l)
226226 let make_con_equiv mp1 mp2 dir l = ((mp1,dir,l),(mp2,dir,l))
227227 let canonical_con con = snd con
228228 let user_con con = fst con
233233 let debug_pr_con con = str "("++ pr_kn (fst con) ++ str ","++ pr_kn (snd con)++ str ")"
234234 let eq_constant (_,kn1) (_,kn2) = kn1=kn2
235235 let debug_string_of_con con = string_of_kn (fst con)^"'"^string_of_kn (snd con)
236
237 let con_with_label ((mp1,dp1,l1),(mp2,dp2,l2) as con) lbl =
238 if lbl = l1 && lbl = l2 then con
239 else ((mp1,dp1,lbl),(mp2,dp2,lbl))
236240
237241 let con_modpath con = modpath (fst con)
238242
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (*i $Id: names.mli 13323 2010-07-24 15:57:30Z herbelin $ i*)
8 (*i $Id: names.mli 13804 2011-01-27 00:41:34Z letouzey $ i*)
99
1010 (*s Identifiers *)
1111
138138 val canonical_con : constant -> kernel_name
139139 val repr_con : constant -> module_path * dir_path * label
140140 val eq_constant : constant -> constant -> bool
141 val con_with_label : constant -> label -> constant
141142
142143 val string_of_con : constant -> string
143144 val con_label : constant -> label
1212 if !Flags.boot || Coq_config.local
1313 then Filename.concat Coq_config.coqsrc "bin"
1414 else System.canonical_path_name (Filename.dirname Sys.executable_name)
15
16 (* On win32, we add coqbin to the PATH at launch-time (this used to be
17 done in a .bat script). *)
18
19 let _ =
20 if Coq_config.arch = "win32" then
21 Unix.putenv "PATH" (coqbin() ^ ";" ^ System.getenv_else "PATH" "")
1522
1623 let guess_coqlib () =
1724 let file = "states/initial.coq" in
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (* $Id: system.ml 13323 2010-07-24 15:57:30Z herbelin $ *)
8 (* $Id: system.ml 13750 2010-12-24 09:55:54Z letouzey $ *)
99
1010 open Pp
1111 open Util
1818 Sys.getenv var
1919 with Not_found ->
2020 warning ("Environment variable "^var^" not found: using '"^def^"' .");
21 flush Pervasives.stdout;
21 flush_all ();
2222 def
2323
2424 let getenv_else s dft = try Sys.getenv s with Not_found -> dft
2525
26 let home = (safe_getenv_def "HOME" ".")
26 (* On win32, the home directory is probably not in $HOME, but in
27 some other environment variable *)
28
29 let home =
30 try Sys.getenv "HOME" with Not_found ->
31 try (Sys.getenv "HOMEDRIVE")^(Sys.getenv "HOMEPATH") with Not_found ->
32 try Sys.getenv "USERPROFILE" with Not_found ->
33 warning ("Cannot determine user home directory, using '.' .");
34 flush_all ();
35 "."
2736
2837 let safe_getenv n = safe_getenv_def n ("$"^n)
2938
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (* $Id: goptions.ml 13323 2010-07-24 15:57:30Z herbelin $ *)
8 (* $Id: goptions.ml 13922 2011-03-21 16:25:18Z letouzey $ *)
99
1010 (* This module manages customization parameters at the vernacular level *)
1111
304304
305305 let bad_type_error () = error "Bad type of value for this option."
306306
307 let set_int_option_value_gen locality = set_option_value locality
308 (fun v -> function
309 | (IntValue _) -> IntValue v
310 | _ -> bad_type_error ())
307 let check_int_value v = function
308 | IntValue _ -> IntValue v
309 | _ -> bad_type_error ()
310
311 let check_bool_value v = function
312 | BoolValue _ -> BoolValue v
313 | _ -> bad_type_error ()
314
315 let check_string_value v = function
316 | StringValue _ -> StringValue v
317 | _ -> bad_type_error ()
318
319 let check_unset_value v = function
320 | BoolValue _ -> BoolValue false
321 | IntValue _ -> IntValue None
322 | _ -> bad_type_error ()
323
324 (* Nota: For compatibility reasons, some errors are treated as
325 warning. This allows a script to refer to an option that doesn't
326 exist anymore *)
327
328 let set_int_option_value_gen locality =
329 set_option_value locality check_int_value
311330 let set_bool_option_value_gen locality key v =
312 try set_option_value locality (fun v -> function
313 | (BoolValue _) -> BoolValue v
314 | _ -> bad_type_error ()) key v
331 try set_option_value locality check_bool_value key v
315332 with UserError (_,s) -> Flags.if_verbose msg_warning s
316 let set_string_option_value_gen locality = set_option_value locality
317 (fun v -> function
318 | (StringValue _) -> StringValue v
319 | _ -> bad_type_error ())
333 let set_string_option_value_gen locality =
334 set_option_value locality check_string_value
335 let unset_option_value_gen locality key =
336 try set_option_value locality check_unset_value key ()
337 with UserError (_,s) -> Flags.if_verbose msg_warning s
320338
321339 let set_int_option_value = set_int_option_value_gen None
322340 let set_bool_option_value = set_bool_option_value_gen None
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (*i $Id: goptions.mli 13323 2010-07-24 15:57:30Z herbelin $ i*)
8 (*i $Id: goptions.mli 13922 2011-03-21 16:25:18Z letouzey $ i*)
99
1010 (* This module manages customization parameters at the vernacular level *)
1111
156156 val set_int_option_value_gen : bool option -> option_name -> int option -> unit
157157 val set_bool_option_value_gen : bool option -> option_name -> bool -> unit
158158 val set_string_option_value_gen : bool option -> option_name -> string -> unit
159 val unset_option_value_gen : bool option -> option_name -> unit
159160
160161 val set_int_option_value : option_name -> int option -> unit
161162 val set_bool_option_value : option_name -> bool -> unit
6363 let w32ocamlc = w32pref^"-ocamlc"
6464 let w32ocamlopt = w32pref^"-ocamlopt"
6565 let w32ocamlmklib = w32pref^"-ocamlmklib"
66 let w32res = w32pref^"-windres"
6667 let w32lib = "/usr/"^w32pref^"/lib/"
6768 let w32bin = "/usr/"^w32pref^"/bin/"
69 let w32ico = "ide/coq_icon.o"
6870
6971 let _ = if w32 then begin
7072 Options.ocamlopt := A w32ocamlopt;
166168 type links = Both | Best | BestInPlace | Ide
167169
168170 let all_binaries =
171 (if w32 then [ "mkwinapp", "tools/mkwinapp", Best ] else []) @
169172 [ "coqtop", coqtop, Both;
170173 "coqide", coqide, Ide;
171174 "coqmktop", coqmktop, Both;
364367 "let ide = \""^ide_mods^"\"\n"],
365368 tolink));
366369
370 (** For windows, building coff object file from a .rc (for the icon) *)
371
372 if w32 then rule ".rc.o" ~deps:["%.rc";"ide/coq.ico"] ~prod:"%.o"
373 (fun env _ ->
374 let rc = env "%.rc" and o = env "%.o" in
375 Cmd (S [P w32res;A "--input-format";A "rc";A "--input";P rc;
376 A "--output-format";A "coff";A "--output"; Px o]));
377
367378 (** Coqtop and coqide *)
368379
369380 let mktop_rule f is_ide =
370381 let fo = f^".native" and fb = f^".byte" in
371382 let ideflag = if is_ide then A"-ide" else N in
372383 let depsall = [coqmktopbest;libcoqrun] in
384 let depsall = if w32 then w32ico::depsall else depsall in
373385 let depso = "coq_config.cmx" :: core_cmxa in
374386 let depsb = "coq_config.cmo" :: core_cma in
375387 let depideo = if is_ide then [ide_cmxa] else [] in
376388 let depideb = if is_ide then [ide_cma] else [] in
377 let w32ideflag = (*if is_ide then [A"-ccopt";A"\"-link -mwindows\""] else*) [] in
378 let w32flag = if not w32 then N else S ([A"-camlbin";A w32bin]@w32ideflag) in
389 let w32ideflag =
390 (* Uncomment the following line to make coqide a console-free win32 app.
391 For the moment we don't, some issue remain to be investigated.
392 In the meantime, coqide can be made console-free a posteriori via
393 the mkwinapp tool. *)
394 (*if is_ide then [A"-ccopt";A"\"-link -Wl,-subsystem,windows\""] else*) [] in
395 let w32flag =
396 if not w32 then N
397 else S ([A"-camlbin";A w32bin;A "-ccopt";P w32ico]@w32ideflag)
398 in
379399 if opt then rule fo ~prod:fo ~deps:(depsall@depso@depideo) ~insert:`top
380400 (cmd [P coqmktopbest;w32flag;A"-boot";A"-opt";ideflag;incl fo;A"-o";Px fo]);
381401 rule fb ~prod:fb ~deps:(depsall@depsb@depideb) ~insert:`top
99 * on May-June 2006 for implementation of abstraction of pretty-printing of objects.
1010 *)
1111
12 (* $Id: prettyp.ml 13492 2010-10-04 21:20:01Z herbelin $ *)
12 (* $Id: prettyp.ml 13967 2011-04-08 14:08:43Z herbelin $ *)
1313
1414 open Pp
1515 open Util
459459 with_line_skip (print_name_infos (ConstRef sp))
460460
461461 let gallina_print_syntactic_def kn =
462 let sep = " := "
463 and qid = Nametab.shortest_qualid_of_syndef Idset.empty kn
462 let qid = Nametab.shortest_qualid_of_syndef Idset.empty kn
464463 and (vars,a) = Syntax_def.search_syntactic_definition kn in
465464 let c = Topconstr.rawconstr_of_aconstr dummy_loc a in
466 str "Notation " ++ pr_qualid qid ++
467 prlist_with_sep spc pr_id (List.map fst vars) ++ str sep ++
468 Constrextern.without_symbols pr_lrawconstr c ++ fnl ()
465 hov 2
466 (hov 4
467 (str "Notation " ++ pr_qualid qid ++
468 prlist (fun id -> spc () ++ pr_id id) (List.map fst vars) ++
469 spc () ++ str ":=") ++
470 spc () ++ Constrextern.without_symbols pr_rawconstr c) ++ fnl ()
469471
470472 let gallina_print_leaf_entry with_values ((sp,kn as oname),lobj) =
471473 let sep = if with_values then " = " else " : "
77
88 (*i camlp4use: "pa_extend.cmo q_MLast.cmo" i*)
99
10 (* $Id: tacextend.ml4 13323 2010-07-24 15:57:30Z herbelin $ *)
10 (* $Id: tacextend.ml4 13799 2011-01-25 17:38:40Z glondu $ *)
1111
1212 open Util
1313 open Genarg
5454 let add_clause s (pt,e) l =
5555 let p = make_patt pt in
5656 let w = Some (make_when (MLast.loc_of_expr e) pt) in
57 (p, w, make_let e pt)::l
57 (p, <:vala< w >>, make_let e pt)::l
5858
5959 let rec extract_signature = function
6060 | [] -> []
7171 let make_clauses s l =
7272 check_unicity s l;
7373 let default =
74 (<:patt< _ >>,None,<:expr< failwith "Tactic extension: cannot occur" >>) in
74 (<:patt< _ >>,<:vala<None>>,
75 <:expr< failwith "Tactic extension: cannot occur" >>) in
7576 List.fold_right (add_clause s) l [default]
7677
7778 let rec make_args = function
77
88 (*i camlp4use: "pa_extend.cmo q_MLast.cmo" i*)
99
10 (* $Id: vernacextend.ml4 13323 2010-07-24 15:57:30Z herbelin $ *)
10 (* $Id: vernacextend.ml4 13799 2011-01-25 17:38:40Z glondu $ *)
1111
1212 open Util
1313 open Genarg
3030 let add_clause s (_,pt,e) l =
3131 let p = make_patt pt in
3232 let w = Some (make_when (MLast.loc_of_expr e) pt) in
33 (p, w, make_let e pt)::l
33 (p, <:vala<w>>, make_let e pt)::l
3434
3535 let check_unicity s l =
3636 let l' = List.map (fun (_,l,_) -> extract_signature l) l in
4242 let make_clauses s l =
4343 check_unicity s l;
4444 let default =
45 (<:patt< _ >>,None,<:expr< failwith "Vernac extension: cannot occur" >>) in
45 (<:patt< _ >>,<:vala<None>>,
46 <:expr< failwith "Vernac extension: cannot occur" >>) in
4647 List.fold_right (add_clause s) l [default]
4748
4849 let mlexpr_of_clause =
180180 let output_file f q =
181181 let c = open_out f in
182182 let fmt = formatter_of_out_channel c in
183 fprintf fmt "include \"real.why\"@.";
184183 fprintf fmt "@[%a@]@." print_query q;
185184 close_out c
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (*i $Id: common.ml 13420 2010-09-16 15:47:08Z letouzey $ i*)
8 (*i $Id: common.ml 14010 2011-04-15 16:05:07Z letouzey $ i*)
99
1010 open Pp
1111 open Util
4141 let pr_binding = function
4242 | [] -> mt ()
4343 | l -> str " " ++ prlist_with_sep (fun () -> str " ") pr_id l
44
45 (** By default, in module Format, you can do horizontal placing of blocks
46 even if they include newlines, as long as the number of chars in the
47 blocks are less that a line length. To avoid this awkward situation,
48 we attach a big virtual size to [fnl] newlines. *)
49
50 let fnl () = stras (1000000,"") ++ fnl ()
4451
4552 let fnl2 () = fnl () ++ fnl ()
4653
508515 let pp_haskell_gen k mp rls = match rls with
509516 | [] -> assert false
510517 | s::rls' ->
511 (if base_mp mp <> top_visible_mp () then s ^ "." else "") ^
512 (if upperkind k then "" else "_") ^ pseudo_qualify rls'
518 let str = pseudo_qualify rls' in
519 let str = if is_upper str && not (upperkind k) then ("_"^str) else str in
520 let prf = if base_mp mp <> top_visible_mp () then s ^ "." else "" in
521 prf ^ str
513522
514523 (* Main name printing function for a reference *)
515524
541550 add_visible (Mod,s) l; s
542551 | _ -> pp_ocaml_gen Mod mp (List.rev ls) None
543552
544
553 (** Special hack for constants of type Ascii.ascii : if an
554 [Extract Inductive ascii => char] has been declared, then
555 the constants are directly turned into chars *)
556
557 let mk_ind path s =
558 make_mind (MPfile (dirpath_of_string path)) empty_dirpath (mk_label s)
559
560 let ind_ascii = mk_ind "Coq.Strings.Ascii" "ascii"
561
562 let check_extract_ascii () =
563 try
564 let char_type = match lang () with
565 | Ocaml -> "char"
566 | Haskell -> "Char"
567 | _ -> raise Not_found
568 in
569 find_custom (IndRef (ind_ascii,0)) = char_type
570 with Not_found -> false
571
572 let is_list_cons l =
573 List.for_all (function MLcons (_,ConstructRef(_,_),[]) -> true | _ -> false) l
574
575 let is_native_char = function
576 | MLcons(_,ConstructRef ((kn,0),1),l) ->
577 kn = ind_ascii && check_extract_ascii () && is_list_cons l
578 | _ -> false
579
580 let pp_native_char c =
581 let rec cumul = function
582 | [] -> 0
583 | MLcons(_,ConstructRef(_,j),[])::l -> (2-j) + 2 * (cumul l)
584 | _ -> assert false
585 in
586 let l = match c with MLcons(_,_,l) -> l | _ -> assert false in
587 str ("'"^Char.escaped (Char.chr (cumul l))^"'")
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (*i $Id: common.mli 13323 2010-07-24 15:57:30Z herbelin $ i*)
8 (*i $Id: common.mli 14010 2011-04-15 16:05:07Z letouzey $ i*)
99
1010 open Names
1111 open Libnames
1313 open Mlutil
1414 open Pp
1515
16 (** By default, in module Format, you can do horizontal placing of blocks
17 even if they include newlines, as long as the number of chars in the
18 blocks are less that a line length. To avoid this awkward situation,
19 we attach a big virtual size to [fnl] newlines. *)
20
21 val fnl : unit -> std_ppcmds
1622 val fnl2 : unit -> std_ppcmds
1723 val space_if : bool -> std_ppcmds
1824 val sec_space_if : bool -> std_ppcmds
5662 val reset_renaming_tables : reset_kind -> unit
5763
5864 val set_keywords : Idset.t -> unit
65
66 (** For instance: [mk_ind "Coq.Init.Datatypes" "nat"] *)
67
68 val mk_ind : string -> string -> mutual_inductive
69
70 (** Special hack for constants of type Ascii.ascii : if an
71 [Extract Inductive ascii => char] has been declared, then
72 the constants are directly turned into chars *)
73
74 val is_native_char : ml_ast -> bool
75 val pp_native_char : ml_ast -> std_ppcmds
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (*i $Id: extract_env.ml 13420 2010-09-16 15:47:08Z letouzey $ i*)
8 (*i $Id: extract_env.ml 14012 2011-04-15 16:45:27Z letouzey $ i*)
99
1010 open Term
1111 open Declarations
4848 | [] when dir_opt = None -> [current_toplevel (), toplevel_env ()]
4949 | [] -> []
5050 | d :: l ->
51 match (Global.lookup_module (MPfile d)).mod_expr with
52 | Some meb ->
53 if dir_opt = Some d then [MPfile d, meb]
54 else (MPfile d, meb) :: (parse l)
55 | _ -> assert false
51 let mb = Global.lookup_module (MPfile d) in
52 (* If -dont-load-proof has been used, mod_expr is None,
53 we try with mod_type *)
54 let meb = Option.default mb.mod_type mb.mod_expr in
55 if dir_opt = Some d then [MPfile d, meb]
56 else (MPfile d, meb) :: (parse l)
5657 in parse (Library.loaded_libraries ())
5758
5859
326327 | SEBwith (_,_) -> anomaly "Not available yet"
327328
328329 and extract_module env mp all mb =
329 (* [mb.mod_expr <> None ], since we look at modules from outside. *)
330 (* Example of module with empty [mod_expr] is X inside a Module F [X:SIG]. *)
331 { ml_mod_expr = extract_seb env mp all (Option.get mb.mod_expr);
332 ml_mod_type = extract_seb_spec env mp (my_type_of_mb mb) }
330 (* A module has an empty [mod_expr] when :
331 - it is a module variable (for instance X inside a Module F [X:SIG])
332 - it is a module assumption (Declare Module).
333 Since we look at modules from outside, we shouldn't have variables.
334 But a Declare Module at toplevel seems legal (cf #2525). For the
335 moment we don't support this situation. *)
336 match mb.mod_expr with
337 | None -> error_no_module_expr mp
338 | Some me ->
339 { ml_mod_expr = extract_seb env mp all me;
340 ml_mod_type = extract_seb_spec env mp (my_type_of_mb mb) }
333341
334342
335343 let unpack = function MEstruct (_,sel) -> sel | _ -> assert false
396404 (*s Extraction of a ml struct to a file. *)
397405
398406 let formatter dry file =
399 if dry then Format.make_formatter (fun _ _ _ -> ()) (fun _ -> ())
400 else match file with
401 | None -> !Pp_control.std_ft
402 | Some cout ->
403 let ft = Pp_control.with_output_to cout in
404 Option.iter (Format.pp_set_margin ft) (Pp_control.get_margin ());
405 ft
407 let ft =
408 if dry then Format.make_formatter (fun _ _ _ -> ()) (fun _ -> ())
409 else Pp_control.with_output_to (Option.default stdout file)
410 in
411 (* We never want to see ellipsis ... in extracted code *)
412 Format.pp_set_max_boxes ft max_int;
413 (* We reuse the width information given via "Set Printing Width" *)
414 (match Pp_control.get_margin () with
415 | None -> ()
416 | Some i ->
417 Format.pp_set_margin ft i;
418 Format.pp_set_max_indent ft (i-10));
419 (* note: max_indent should be < margin above, otherwise it's ignored *)
420 ft
406421
407422 let print_structure_to_file (fn,si,mo) dry struc =
408423 let d = descr () in
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (*i $Id: extraction.ml 13733 2010-12-21 13:08:53Z letouzey $ i*)
8 (*i $Id: extraction.ml 13795 2011-01-22 14:43:06Z glondu $ i*)
99
1010 (*i*)
1111 open Util
393393 (* Third pass: we determine special cases. *)
394394 let ind_info =
395395 try
396 let ip = (kn, 0) in
397 let r = IndRef ip in
398 if is_custom r then raise (I Standard);
396399 if not mib.mind_finite then raise (I Coinductive);
397400 if mib.mind_ntypes <> 1 then raise (I Standard);
398401 let p = packets.(0) in
404407 then raise (I Singleton);
405408 if l = [] then raise (I Standard);
406409 if not mib.mind_record then raise (I Standard);
407 let ip = (kn, 0) in
408 let r = IndRef ip in
409 if is_custom r then raise (I Standard);
410410 (* Now we're sure it's a record. *)
411411 (* First, we find its field names. *)
412412 let rec names_prod t = match kind_of_term t with
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (*i $Id: haskell.ml 13733 2010-12-21 13:08:53Z letouzey $ i*)
8 (*i $Id: haskell.ml 14010 2011-04-15 16:05:07Z letouzey $ i*)
99
1010 (*s Production of Haskell syntax. *)
1111
105105
106106 let expr_needs_par = function
107107 | MLlam _ -> true
108 | MLcase _ -> true
108 | MLcase _ -> false (* now that we use the case ... of { ... } syntax *)
109109 | _ -> false
110110
111111
128128 let pp_id = pr_id (List.hd i)
129129 and pp_a1 = pp_expr false env [] a1
130130 and pp_a2 = pp_expr (not par && expr_needs_par a2) env' [] a2 in
131 hv 0
132 (apply
133 (pp_par par'
134 (hv 0
135 (hov 5
136 (str "let" ++ spc () ++ pp_id ++ str " = " ++ pp_a1) ++
137 spc () ++ str "in") ++
138 spc () ++ hov 0 pp_a2)))
131 let pp_def =
132 str "let {" ++ cut () ++
133 hov 1 (pp_id ++ str " = " ++ pp_a1 ++ str "}")
134 in
135 apply
136 (pp_par par'
137 (hv 0 (hv 0 (hv 1 pp_def ++ spc () ++ str "in") ++
138 spc () ++ hov 0 pp_a2)))
139139 | MLglob r ->
140140 apply (pp_global Term r)
141 | MLcons _ as c when is_native_char c -> assert (args=[]); pp_native_char c
141142 | MLcons (_,r,[]) ->
142143 assert (args=[]); pp_global Cons r
143144 | MLcons (_,r,[a]) ->
152153 if ids <> [] then named_lams (List.rev ids) e
153154 else dummy_lams (ast_lift 1 e) 1
154155 in
155 hov 2 (str (find_custom_match pv) ++ fnl () ++
156 apply
157 (pp_par par'
158 (hov 2
159 (str (find_custom_match pv) ++ fnl () ++
156160 prvect (fun tr -> pp_expr true env [] (mkfun tr) ++ fnl ()) pv
157 ++ pp_expr true env [] t)
161 ++ pp_expr true env [] t)))
158162 | MLcase (info,t, pv) ->
159163 apply (pp_par par'
160 (v 0 (str "case " ++ pp_expr false env [] t ++ str " of" ++
161 fnl () ++ str " " ++ pp_pat env info pv)))
164 (v 0 (str "case " ++ pp_expr false env [] t ++ str " of {" ++
165 fnl () ++ pp_pat env info pv)))
162166 | MLfix (i,ids,defs) ->
163167 let ids',env' = push_vars (List.rev (Array.to_list ids)) env in
164168 pp_fix par env' i (Array.of_list (List.rev ids'),defs) args
175179 let pp_one_pat (name,ids,t) =
176180 let ids,env' = push_vars (List.rev_map id_of_mlid ids) env in
177181 let par = expr_needs_par t in
178 hov 2 (pp_global Cons name ++
182 hov 2 (str " " ++ pp_global Cons name ++
179183 (match ids with
180184 | [] -> mt ()
181185 | _ -> (str " " ++
182 prlist_with_sep
183 (fun () -> (spc ())) pr_id (List.rev ids))) ++
186 prlist_with_sep spc pr_id (List.rev ids))) ++
184187 str " ->" ++ spc () ++ pp_expr par env' [] t)
185188 in
186189 let factor_br, factor_set = try match info.m_same with
197200 prvecti
198201 (fun i x -> if Intset.mem i factor_set then mt () else
199202 (pp_one_pat pv.(i) ++
200 if i = last && Intset.is_empty factor_set then mt () else
201 fnl () ++ str " ")) pv
203 if i = last && Intset.is_empty factor_set then str "}" else
204 (str ";" ++ fnl ()))) pv
202205 ++
203206 if Intset.is_empty factor_set then mt () else
204207 let par = expr_needs_par factor_br in
205208 match info.m_same with
206209 | BranchFun _ ->
207210 let ids, env' = push_vars [anonymous_name] env in
208 pr_id (List.hd ids) ++ str " ->" ++ spc () ++
209 pp_expr par env' [] factor_br
211 hov 2 (str " " ++ pr_id (List.hd ids) ++ str " ->" ++ spc () ++
212 pp_expr par env' [] factor_br ++ str "}")
210213 | BranchCst _ ->
211 str "_ ->" ++ spc () ++ pp_expr par env [] factor_br
214 hov 2 (str " _ ->" ++ spc () ++ pp_expr par env [] factor_br ++ str "}")
212215 | BranchNone -> mt ()
213216
214217 (*s names of the functions ([ids]) are already pushed in [env],
217220 and pp_fix par env i (ids,bl) args =
218221 pp_par par
219222 (v 0
220 (v 2 (str "let" ++ fnl () ++
221 prvect_with_sep fnl
223 (v 1 (str "let {" ++ fnl () ++
224 prvect_with_sep (fun () -> str ";" ++ fnl ())
222225 (fun (fi,ti) -> pp_function env (pr_id fi) ti)
223 (array_map2 (fun a b -> a,b) ids bl)) ++
224 fnl () ++
225 hov 2 (str "in " ++ pp_apply (pr_id ids.(i)) false args)))
226 (array_map2 (fun a b -> a,b) ids bl) ++
227 str "}") ++
228 fnl () ++ str "in " ++ pp_apply (pr_id ids.(i)) false args))
226229
227230 and pp_function env f t =
228231 let bl,t' = collect_lams t in
261264 (fun () -> (str " ")) (pp_type true pl) l))
262265 in
263266 str (if Array.length cv = 0 then "type " else "data ") ++
264 pp_global Type (IndRef ip) ++ str " " ++
265 prlist_with_sep (fun () -> str " ") pr_lower_id pl ++
266 (if pl = [] then mt () else str " ") ++
267 if Array.length cv = 0 then str "= () -- empty inductive"
267 pp_global Type (IndRef ip) ++
268 prlist_strict (fun id -> str " " ++ pr_lower_id id) pl ++ str " =" ++
269 if Array.length cv = 0 then str " () -- empty inductive"
268270 else
269 (v 0 (str "= " ++
271 (fnl () ++ str " " ++
272 v 0 (str " " ++
270273 prvect_with_sep (fun () -> fnl () ++ str "| ") pp_constructor
271274 (Array.mapi (fun i c -> ConstructRef (ip,i+1),c) cv)))
272275
308311 in
309312 hov 2 (str "type " ++ pp_global Type r ++ spc () ++ st) ++ fnl2 ()
310313 | Dfix (rv, defs, typs) ->
311 let max = Array.length rv in
312 let rec iter i =
313 if i = max then mt ()
314 else
315 let e = pp_global Term rv.(i) in
316 e ++ str " :: " ++ pp_type false [] typs.(i) ++ fnl ()
317 ++ pp_function (empty_env ()) e defs.(i) ++ fnl2 ()
318 ++ iter (i+1)
319 in iter 0
314 let names = Array.map
315 (fun r -> if is_inline_custom r then mt () else pp_global Term r) rv
316 in
317 prvecti
318 (fun i r ->
319 let void = is_inline_custom r ||
320 (not (is_custom r) && defs.(i) = MLexn "UNUSED")
321 in
322 if void then mt ()
323 else
324 names.(i) ++ str " :: " ++ pp_type false [] typs.(i) ++ fnl () ++
325 (if is_custom r then
326 (names.(i) ++ str " = " ++ str (find_custom r))
327 else
328 (pp_function (empty_env ()) names.(i) defs.(i)))
329 ++ fnl2 ())
330 rv
320331 | Dterm (r, a, t) ->
321332 if is_inline_custom r then mt ()
322333 else
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (*i $Id: mlutil.ml 13733 2010-12-21 13:08:53Z letouzey $ i*)
8 (*i $Id: mlutil.ml 14003 2011-04-14 23:09:41Z letouzey $ i*)
99
1010 (*i*)
1111 open Pp
109109
110110 let rec mgu = function
111111 | Tmeta m, Tmeta m' when m.id = m'.id -> ()
112 | Tmeta m, t when m.contents=None ->
113 if type_occurs m.id t then raise Impossible
114 else m.contents <- Some t
115 | t, Tmeta m when m.contents=None ->
116 if type_occurs m.id t then raise Impossible
117 else m.contents <- Some t
118 | Tmeta {contents=Some u}, t -> mgu (u, t)
119 | t, Tmeta {contents=Some u} -> mgu (t, u)
112 | Tmeta m, t | t, Tmeta m ->
113 (match m.contents with
114 | Some u -> mgu (u, t)
115 | None when type_occurs m.id t -> raise Impossible
116 | None -> m.contents <- Some t)
120117 | Tarr(a, b), Tarr(a', b') ->
121118 mgu (a, a'); mgu (b, b')
122119 | Tglob (r,l), Tglob (r',l') when r = r' ->
123120 List.iter mgu (List.combine l l')
124 | Tvar i, Tvar j when i = j -> ()
125 | Tvar' i, Tvar' j when i = j -> ()
126121 | Tdummy _, Tdummy _ -> ()
127 | Tunknown, Tunknown -> ()
122 | t, u when t = u -> () (* for Tvar, Tvar', Tunknown, Taxiom *)
128123 | _ -> raise Impossible
129124
130125 let needs_magic p = try mgu p; false with Impossible -> true
827822
828823 let is_imm_apply = function MLapp (MLrel 1, _) -> true | _ -> false
829824
825 (** Program creates a let-in named "program_branch_NN" for each branch of match.
826 Unfolding them leads to more natural code (and more dummy removal) *)
827
828 let is_program_branch = function
829 | Id id ->
830 let s = string_of_id id in
831 let br = "program_branch_" in
832 let n = String.length br in
833 (try
834 ignore (int_of_string (String.sub s n (String.length s - n)));
835 String.sub s 0 n = br
836 with _ -> false)
837 | Tmp _ | Dummy -> false
838
839 let expand_linear_let o id e =
840 o.opt_lin_let || is_tmp id || is_program_branch id || is_imm_apply e
841
830842 (*S The main simplification function. *)
831843
832844 (* Some beta-iota reductions + simplifications. *)
843855 if
844856 (is_atomic c) || (is_atomic e) ||
845857 (let n = nb_occur_match e in
846 (n = 0 || (n=1 && (is_tmp id || is_imm_apply e || o.opt_lin_let))))
858 (n = 0 || (n=1 && expand_linear_let o id e)))
847859 then
848860 simpl o (ast_subst c e)
849861 else
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (*i $Id: modutil.ml 13733 2010-12-21 13:08:53Z letouzey $ i*)
8 (*i $Id: modutil.ml 14006 2011-04-14 23:09:56Z letouzey $ i*)
99
1010 open Names
1111 open Declarations
288288 (fun r -> Refset'.mem (base_r r) !needed))
289289
290290 let declared_refs = function
291 | Dind (kn,_) -> [|IndRef (mind_of_kn kn,0)|]
292 | Dtype (r,_,_) -> [|r|]
293 | Dterm (r,_,_) -> [|r|]
294 | Dfix (rv,_,_) -> rv
291 | Dind (kn,_) -> [IndRef (mind_of_kn kn,0)]
292 | Dtype (r,_,_) -> [r]
293 | Dterm (r,_,_) -> [r]
294 | Dfix (rv,_,_) -> Array.to_list rv
295295
296296 (* Computes the dependencies of a declaration, except in case
297297 of custom extraction. *)
307307 if not (is_custom r) then
308308 ast_iter_references add_needed add_needed add_needed u
309309 | Dfix _ as d ->
310 (* Todo Later : avoid dependencies when Extract Constant *)
311310 decl_iter_references add_needed add_needed add_needed d
312311
313312 let rec depcheck_se = function
314313 | [] -> []
315 | ((l,SEdecl d) as t)::se ->
316 let se' = depcheck_se se in
317 let rv = declared_refs d in
318 if not (array_exists is_needed rv) then
319 (Array.iter remove_info_axiom rv; se')
320 else
321 (Array.iter found_needed rv; compute_deps_decl d; t::se')
314 | ((l,SEdecl d) as t) :: se ->
315 let se' = depcheck_se se in
316 let refs = declared_refs d in
317 let refs' = List.filter is_needed refs in
318 if refs' = [] then
319 (List.iter remove_info_axiom refs; se')
320 else begin
321 List.iter found_needed refs';
322 (* Hack to avoid extracting unused part of a Dfix *)
323 match d with
324 | Dfix (rv,trms,tys) when (List.for_all is_custom refs') ->
325 let trms' = Array.create (Array.length rv) (MLexn "UNUSED") in
326 ((l,SEdecl (Dfix (rv,trms',tys))) :: se')
327 | _ -> (compute_deps_decl d; t::se')
328 end
322329 | _ -> raise NoDepCheck
323330
324331 let rec depcheck_struct = function
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (*i $Id: ocaml.ml 13733 2010-12-21 13:08:53Z letouzey $ i*)
8 (*i $Id: ocaml.ml 14010 2011-04-15 16:05:07Z letouzey $ i*)
99
1010 (*s Production of Ocaml syntax. *)
1111
118118
119119 (*s Pretty-printing of types. [par] is a boolean indicating whether parentheses
120120 are needed or not. *)
121
122 let mk_ind path s =
123 make_mind (MPfile (dirpath_of_string path)) empty_dirpath (mk_label s)
124121
125122 let rec pp_type par vl t =
126123 let rec pp_rec par = function
158155 | MLcase (_,_,[|_|]) -> false
159156 | MLcase (_,_,pv) -> not (is_ifthenelse pv)
160157 | _ -> false
161
162
163 (** Special hack for constants of type Ascii.ascii : if an
164 [Extract Inductive ascii => char] has been declared, then
165 the constants are directly turned into chars *)
166
167 let ind_ascii = mk_ind "Coq.Strings.Ascii" "ascii"
168
169 let check_extract_ascii () =
170 try find_custom (IndRef (ind_ascii,0)) = "char" with Not_found -> false
171
172 let is_list_cons l =
173 List.for_all (function MLcons (_,ConstructRef(_,_),[]) -> true | _ -> false) l
174
175 let pp_char l =
176 let rec cumul = function
177 | [] -> 0
178 | MLcons(_,ConstructRef(_,j),[])::l -> (2-j) + 2 * (cumul l)
179 | _ -> assert false
180 in str ("'"^Char.escaped (Char.chr (cumul l))^"'")
181158
182159 let rec pp_expr par env args =
183160 let par' = args <> [] || par
213190 let record = List.hd args in
214191 pp_apply (record ++ str "." ++ pp_global Term r) par (List.tl args)
215192 with _ -> apply (pp_global Term r))
216 | MLcons(_,ConstructRef ((kn,0),1),l)
217 when kn = ind_ascii && check_extract_ascii () & is_list_cons l ->
218 assert (args=[]);
219 pp_char l
193 | MLcons _ as c when is_native_char c -> assert (args=[]); pp_native_char c
220194 | MLcons ({c_kind = Coinductive},r,[]) ->
221195 assert (args=[]);
222196 pp_par par (str "lazy " ++ pp_global Cons r)
246220 if ids <> [] then named_lams (List.rev ids) e
247221 else dummy_lams (ast_lift 1 e) 1
248222 in
249 hov 2 (str (find_custom_match pv) ++ fnl () ++
223 apply
224 (pp_par par'
225 (hov 2
226 (str (find_custom_match pv) ++ fnl () ++
250227 prvect (fun tr -> pp_expr true env [] (mkfun tr) ++ fnl ()) pv
251 ++ pp_expr true env [] t)
228 ++ pp_expr true env [] t)))
252229 | MLcase (info, t, pv) ->
253230 let expr = if info.m_kind = Coinductive then
254231 (str "Lazy.force" ++ spc () ++ pp_expr true env [] t)
290267 (try pp_ifthenelse par' env expr pv
291268 with Not_found ->
292269 v 0 (str "match " ++ expr ++ str " with" ++ fnl () ++
293 str " | " ++ pp_pat env info pv))))
270 pp_pat env info pv))))
294271 | MLfix (i,ids,defs) ->
295272 let ids',env' = push_vars (List.rev (Array.to_list ids)) env in
296273 pp_fix par env' i (Array.of_list (List.rev ids'),defs) args
354331 prvecti
355332 (fun i x -> if Intset.mem i factor_set then mt () else
356333 let s1,s2 = pp_one_pat env info x in
357 hov 2 (s1 ++ str " ->" ++ spc () ++ s2) ++
358 if i = last && Intset.is_empty factor_set then mt () else
359 fnl () ++ str " | ") pv
334 hv 2 (hov 4 (str "| " ++ s1 ++ str " ->") ++ spc () ++ hov 2 s2) ++
335 if i = last && Intset.is_empty factor_set then mt () else fnl ())
336 pv
360337 ++
361338 if Intset.is_empty factor_set then mt () else
362339 let par = expr_needs_par factor_br in
363340 match info.m_same with
364341 | BranchFun _ ->
365342 let ids, env' = push_vars [anonymous_name] env in
366 hov 2 (pr_id (List.hd ids) ++ str " ->" ++ spc () ++
367 pp_expr par env' [] factor_br)
343 hv 2 (str "| " ++ pr_id (List.hd ids) ++ str " ->" ++ spc () ++
344 hov 2 (pp_expr par env' [] factor_br))
368345 | BranchCst _ ->
369 hov 2 (str "_ ->" ++ spc () ++ pp_expr par env [] factor_br)
346 hv 2 (str "| _ ->" ++ spc () ++ hov 2 (pp_expr par env [] factor_br))
370347 | BranchNone -> mt ()
371348
372349 and pp_function env t =
378355 if not (ast_occurs 1 (MLcase(i,MLdummy,pv))) then
379356 pr_binding (List.rev (List.tl bl)) ++
380357 str " = function" ++ fnl () ++
381 v 0 (str " | " ++ pp_pat env' i pv)
358 v 0 (pp_pat env' i pv)
382359 else
383360 pr_binding (List.rev bl) ++
384361 str " = match " ++ pr_id (List.hd bl) ++ str " with" ++ fnl () ++
385 v 0 (str " | " ++ pp_pat env' i pv)
362 v 0 (pp_pat env' i pv)
386363 | _ ->
387364 pr_binding (List.rev bl) ++
388365 str " =" ++ fnl () ++ str " " ++
411388 let names = Array.map
412389 (fun r -> if is_inline_custom r then mt () else pp_global Term r) rv
413390 in
414 let rec pp sep letand i =
415 if i >= Array.length rv then mt ()
416 else if is_inline_custom rv.(i) then pp sep letand (i+1)
391 let rec pp init i =
392 if i >= Array.length rv then
393 (if init then failwith "empty phrase" else mt ())
417394 else
418 let def =
419 if is_custom rv.(i) then str " = " ++ str (find_custom rv.(i))
420 else pp_function (empty_env ()) c.(i)
395 let void = is_inline_custom rv.(i) ||
396 (not (is_custom rv.(i)) && c.(i) = MLexn "UNUSED")
421397 in
422 sep () ++ pp_val names.(i) t.(i) ++
423 str letand ++ names.(i) ++ def ++ pp fnl2 "and " (i+1)
424 in pp mt "let rec " 0
398 if void then pp init (i+1)
399 else
400 let def =
401 if is_custom rv.(i) then str " = " ++ str (find_custom rv.(i))
402 else pp_function (empty_env ()) c.(i)
403 in
404 (if init then mt () else fnl2 ()) ++
405 pp_val names.(i) t.(i) ++
406 str (if init then "let rec " else "and ") ++ names.(i) ++ def ++
407 pp false (i+1)
408 in pp true 0
425409
426410 (*s Pretty-printing of inductive types declaration. *)
427411
438422 let pl = rename_tvars keywords pl in
439423 let pp_constructor i typs =
440424 (if i=0 then mt () else fnl ()) ++
441 hov 5 (str " | " ++ cnames.(i) ++
425 hov 3 (str "| " ++ cnames.(i) ++
442426 (if typs = [] then mt () else str " of ") ++
443427 prlist_with_sep
444428 (fun () -> spc () ++ str "* ") (pp_type true pl) typs)
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (*i $Id: scheme.ml 13733 2010-12-21 13:08:53Z letouzey $ i*)
8 (*i $Id: scheme.ml 14006 2011-04-14 23:09:56Z letouzey $ i*)
99
1010 (*s Production of Scheme syntax. *)
1111
100100 if ids <> [] then named_lams (List.rev ids) e
101101 else dummy_lams (ast_lift 1 e) 1
102102 in
103 hov 2 (str (find_custom_match pv) ++ fnl () ++
103 apply
104 (paren
105 (hov 2
106 (str (find_custom_match pv) ++ fnl () ++
104107 prvect (fun tr -> pp_expr env [] (mkfun tr) ++ fnl ()) pv
105 ++ pp_expr env [] t)
108 ++ pp_expr env [] t)))
106109 | MLcase (info,t, pv) ->
107110 let e =
108111 if info.m_kind <> Coinductive then pp_expr env [] t
162165 | Dind _ -> mt ()
163166 | Dtype _ -> mt ()
164167 | Dfix (rv, defs,_) ->
165 let ppv = Array.map (pp_global Term) rv in
166 prvect_with_sep fnl
167 (fun (pi,ti) ->
168 hov 2
169 (paren (str "define " ++ pi ++ spc () ++
170 (pp_expr (empty_env ()) [] ti))
171 ++ fnl ()))
172 (array_map2 (fun p b -> (p,b)) ppv defs) ++
173 fnl ()
168 let names = Array.map
169 (fun r -> if is_inline_custom r then mt () else pp_global Term r) rv
170 in
171 prvecti
172 (fun i r ->
173 let void = is_inline_custom r ||
174 (not (is_custom r) && defs.(i) = MLexn "UNUSED")
175 in
176 if void then mt ()
177 else
178 hov 2
179 (paren (str "define " ++ names.(i) ++ spc () ++
180 (if is_custom r then str (find_custom r)
181 else pp_expr (empty_env ()) [] defs.(i)))
182 ++ fnl ()) ++ fnl ())
183 rv
174184 | Dterm (r, a, _) ->
175185 if is_inline_custom r then mt ()
176186 else
177 if is_custom r then
178 hov 2 (paren (str "define " ++ pp_global Term r ++ spc () ++
179 str (find_custom r))) ++ fnl () ++ fnl ()
180 else
181 hov 2 (paren (str "define " ++ pp_global Term r ++ spc () ++
182 pp_expr (empty_env ()) [] a)) ++ fnl () ++ fnl ()
187 hov 2 (paren (str "define " ++ pp_global Term r ++ spc () ++
188 (if is_custom r then str (find_custom r)
189 else pp_expr (empty_env ()) [] a)))
190 ++ fnl2 ()
183191
184192 let rec pp_structure_elem = function
185193 | (l,SEdecl d) -> pp_decl d
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (*i $Id: table.ml 13733 2010-12-21 13:08:53Z letouzey $ i*)
8 (*i $Id: table.ml 14012 2011-04-15 16:45:27Z letouzey $ i*)
99
1010 open Names
1111 open Term
309309 pr_long_mp mp2 ++ str " have the same ML name.\n" ++
310310 str "This is not supported yet. Please do some renaming first.")
311311
312 let error_no_module_expr mp =
313 err (str "The module " ++ pr_long_mp mp
314 ++ str " has no body, it probably comes from\n"
315 ++ str "some Declare Module outside any Module Type.\n"
316 ++ str "This situation is currently unsupported by the extraction.")
317
312318 let error_unknown_module m =
313319 err (str "Module" ++ spc () ++ pr_qualid m ++ spc () ++ str "not found.")
314320
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (*i $Id: table.mli 13420 2010-09-16 15:47:08Z letouzey $ i*)
8 (*i $Id: table.mli 14012 2011-04-15 16:45:27Z letouzey $ i*)
99
1010 open Names
1111 open Libnames
2828 val error_inductive : global_reference -> 'a
2929 val error_nb_cons : unit -> 'a
3030 val error_module_clash : module_path -> module_path -> 'a
31 val error_no_module_expr : module_path -> 'a
3132 val error_unknown_module : qualid -> 'a
3233 val error_scheme : unit -> 'a
3334 val error_not_visible : global_reference -> 'a
66 (* * GNU Lesser General Public License Version 2.1 *)
77 (************************************************************************)
88
9 (* $Id: subtac_cases.ml 13332 2010-07-26 22:12:43Z msozeau $ *)
9 (* $Id: subtac_cases.ml 14003 2011-04-14 23:09:41Z letouzey $ *)
1010
1111 open Cases
1212 open Util
17401740 let j = typing_fun (mk_tycon tycon) rhs_env eqn.rhs.it in
17411741 let bbody = it_mkLambda_or_LetIn j.uj_val rhs_rels'
17421742 and btype = it_mkProd_or_LetIn j.uj_type rhs_rels' in
1743 let branch_name = id_of_string ("branch_" ^ (string_of_int !i)) in
1743 let branch_name = id_of_string ("program_branch_" ^ (string_of_int !i)) in
17441744 let branch_decl = (Name branch_name, Some (lift !i bbody), (lift !i btype)) in
17451745 let branch =
17461746 let bref = RVar (dummy_loc, branch_name) in
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (* $Id: cases.ml 13728 2010-12-19 11:35:20Z herbelin $ *)
8 (* $Id: cases.ml 13962 2011-04-06 17:00:45Z herbelin $ *)
99
1010 open Util
1111 open Names
12021202 let case = mkCase (ci,nf_betaiota Evd.empty pred,current,brvals) in
12031203 let inst = List.map mkRel deps in
12041204 { uj_val = applist (case, inst);
1205 uj_type = substl inst typ }
1205 uj_type = prod_applist typ inst }
12061206
12071207 and compile_branch current names deps pb arsign eqn cstr =
12081208 let sign, pb = build_branch current deps names pb arsign eqn cstr in
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (* $Id: clenv.ml 13332 2010-07-26 22:12:43Z msozeau $ *)
8 (* $Id: clenv.ml 13902 2011-03-10 15:50:24Z msozeau $ *)
99
1010 open Pp
1111 open Util
304304
305305 let connect_clenv gls clenv =
306306 { clenv with
307 evd = evars_reset_evd gls.sigma clenv.evd;
307 evd = evars_reset_evd ~with_conv_pbs:true gls.sigma clenv.evd;
308308 env = Global.env_of_context gls.it.evar_hyps }
309309
310310 (* [clenv_fchain mv clenv clenv']
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (* $Id: evd.ml 13332 2010-07-26 22:12:43Z msozeau $ *)
8 (* $Id: evd.ml 13902 2011-03-10 15:50:24Z msozeau $ *)
99
1010 open Pp
1111 open Util
506506 metas=Metamap.empty
507507 }
508508
509 let evars_reset_evd evd d = {d with evars = evd.evars}
509 let evars_reset_evd ?(with_conv_pbs=false) evd d =
510 {d with evars = evd.evars;
511 conv_pbs = if with_conv_pbs then evd.conv_pbs else d.conv_pbs}
510512 let add_conv_pb pb d = {d with conv_pbs = pb::d.conv_pbs}
511513 let evar_source evk d = (EvarMap.find d.evars evk).evar_source
512514
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (*i $Id: evd.mli 13323 2010-07-24 15:57:30Z herbelin $ i*)
8 (*i $Id: evd.mli 13902 2011-03-10 15:50:24Z msozeau $ i*)
99
1010 (*i*)
1111 open Util
176176 val subst_evar_defs_light : substitution -> evar_map -> evar_map
177177
178178 (* spiwack: this function seems to somewhat break the abstraction. *)
179 val evars_reset_evd : evar_map -> evar_map -> evar_map
179 val evars_reset_evd : ?with_conv_pbs:bool -> evar_map -> evar_map -> evar_map
180180
181181
182182 (* spiwack: [is_undefined_evar] should be considered a candidate
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (* $Id: pretyping.ml 13408 2010-09-11 19:19:04Z herbelin $ *)
8 (* $Id: pretyping.ml 13780 2011-01-07 16:37:57Z herbelin $ *)
99
1010 open Pp
1111 open Util
633633 let cty = nf_evar !evdref cj.uj_type and tval = nf_evar !evdref tj.utj_val in
634634 let cj = match k with
635635 | VMcast when not (occur_existential cty || occur_existential tval) ->
636 ignore (Reduction.vm_conv Reduction.CUMUL env cty tval); cj
636 (try ignore (Reduction.vm_conv Reduction.CUMUL env cty tval); cj
637 with Reduction.NotConvertible ->
638 error_actual_type_loc loc env !evdref cj tval)
639
637640 | _ -> inh_conv_coerce_to_tycon loc env evdref cj (mk_tycon tval)
638641 in
639642 let v = mkCast (cj.uj_val, k, tval) in
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (* $Id: tacred.ml 13323 2010-07-24 15:57:30Z herbelin $ *)
8 (* $Id: tacred.ml 13804 2011-01-27 00:41:34Z letouzey $ *)
99
1010 open Pp
1111 open Util
215215 | EvalRel _ | EvalEvar _ -> None
216216 | EvalVar id' -> Some (EvalVar id)
217217 | EvalConst kn ->
218 let (mp,dp,_) = repr_con kn in
219 Some (EvalConst (make_con mp dp (label_of_id id))) in
218 Some (EvalConst (con_with_label kn (label_of_id id))) in
220219 match refi with
221220 | None -> None
222221 | Some ref ->
480479 | CoFix (bodynum,(names,_,_) as cofix) ->
481480 let build_cofix_name =
482481 if isConst func then
483 let (mp,dp,_) = repr_con (destConst func) in
484482 let minargs = List.length mia.mcargs in
485483 fun i ->
486484 if i = bodynum then Some (minargs,func)
491489 mutual inductive, try to reuse the global name if
492490 the block was indeed initially built as a global
493491 definition *)
494 let kn = make_con mp dp (label_of_id id) in
492 let kn = con_with_label (destConst func) (label_of_id id)
493 in
495494 try match constant_opt_value env kn with
496495 | None -> None
497496 (* TODO: check kn is correct *)
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (* $Id: pfedit.ml 13323 2010-07-24 15:57:30Z herbelin $ *)
8 (* $Id: pfedit.ml 13981 2011-04-08 16:59:26Z herbelin $ *)
99
1010 open Pp
1111 open Util
343343
344344 let next = let n = ref 0 in fun () -> incr n; !n
345345
346 let build_constant_by_tactic sign typ tac =
347 let id = id_of_string ("temporary_proof"^string_of_int (next())) in
346 let build_constant_by_tactic id sign typ tac =
348347 start_proof id (Global,Proof Theorem) sign typ (fun _ _ -> ());
349348 try
350349 by tac;
356355 raise e
357356
358357 let build_by_tactic typ tac =
358 let id = id_of_string ("temporary_proof"^string_of_int (next())) in
359359 let sign = Decls.clear_proofs (Global.named_context ()) in
360 (build_constant_by_tactic sign typ tac).const_entry_body
360 (build_constant_by_tactic id sign typ tac).const_entry_body
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (*i $Id: pfedit.mli 13323 2010-07-24 15:57:30Z herbelin $ i*)
8 (*i $Id: pfedit.mli 13981 2011-04-08 16:59:26Z herbelin $ i*)
99
1010 (*i*)
1111 open Util
201201
202202 (* [build_by_tactic typ tac] returns a term of type [typ] by calling [tac] *)
203203
204 val build_constant_by_tactic : named_context_val -> types -> tactic ->
204 val build_constant_by_tactic : identifier -> named_context_val -> types -> tactic ->
205205 Entries.definition_entry
206206 val build_by_tactic : types -> tactic -> constr
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (* $Id: coqc.ml 13323 2010-07-24 15:57:30Z herbelin $ *)
8 (* $Id: coqc.ml 14015 2011-04-15 17:48:45Z letouzey $ *)
99
1010 (* Afin de rendre Coq plus portable, ce programme Caml remplace le script
1111 coqc.
8383 Unix.create_process_env command (Array.of_list args') environment
8484 Unix.stdin Unix.stdout Unix.stderr
8585 in
86 ignore (Unix.waitpid [] pid)
86 let status = snd (Unix.waitpid [] pid) in
87 let errcode =
88 match status with Unix.WEXITED c|Unix.WSTOPPED c|Unix.WSIGNALED c -> c
89 in
90 exit errcode
8791 | _ ->
8892 Unix.execvpe command (Array.of_list args') environment
8993
195199 (* List.iter (compile coqtopname args) cfiles*)
196200 Unix.handle_unix_error (compile coqtopname args) cfiles
197201
198 let _ = Printexc.print main (); exit 0
202 let _ = Printexc.print main ()
77
88 (*i camlp4deps: "parsing/grammar.cma" i*)
99
10 (* $Id: class_tactics.ml4 13332 2010-07-26 22:12:43Z msozeau $ *)
10 (* $Id: class_tactics.ml4 13902 2011-03-10 15:50:24Z msozeau $ *)
1111
1212 open Pp
1313 open Util
8484 if goals = [] then None
8585 else
8686 let goals = List.rev goals in
87 let evm' = evars_reset_evd evm' evm in
87 let evm' = evars_reset_evd ~with_conv_pbs:false evm' evm in
8888 Some (goals, evm')
8989
9090 (** Typeclasses instance search tactic / eauto *)
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (* $Id: equality.ml 13586 2010-10-27 17:42:13Z jforest $ *)
8 (* $Id: equality.ml 13874 2011-03-05 16:41:53Z herbelin $ *)
99
1010 open Pp
1111 open Util
887887 with
888888 | Some w ->
889889 let w_type = type_of env sigma w in
890 if Evarconv.e_conv env evdref w_type a then
891 applist(exist_term,[a;p_i_minus_1;w;tuple_tail])
890 if Evarconv.e_cumul env evdref w_type a then
891 applist(exist_term,[w_type;p_i_minus_1;w;tuple_tail])
892892 else
893893 error "Cannot solve a unification problem."
894894 | None -> anomaly "Not enough components to build the dependent tuple"
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (* $Id: tactics.ml 13693 2010-12-08 15:32:25Z msozeau $ *)
8 (* $Id: tactics.ml 13981 2011-04-08 16:59:26Z herbelin $ *)
99
1010 open Pp
1111 open Util
34683468 try flush_and_check_evars (project gl) concl
34693469 with Uninstantiated_evar _ ->
34703470 error "\"abstract\" cannot handle existentials." in
3471 let const = Pfedit.build_constant_by_tactic secsign concl
3471 let const = Pfedit.build_constant_by_tactic id secsign concl
34723472 (tclCOMPLETE (tclTHEN (tclDO (List.length sign) intro) tac)) in
34733473 let cd = Entries.DefinitionEntry const in
34743474 let lem = mkConst (Declare.declare_internal_constant id (cd,IsProof Lemma)) in
88 (** val wrong_id : 'a1 hole -> 'a2 hole **)
99
1010 let wrong_id = function
11 | Hole -> Hole
12 | Hole2 -> Hole2
11 | Hole -> Hole
12 | Hole2 -> Hole2
1313 (** val test3 : 'a1 option -> 'a1 option **)
1414
1515 let test3 o =
1717 (** val test4 : indu -> indu **)
1818
1919 let test4 = function
20 | A m -> A (S m)
21 | x -> x
20 | A m -> A (S m)
21 | x -> x
2222 (** val test5 : indu -> indu **)
2323
2424 let test5 = function
25 | A m -> A (S m)
26 | _ -> B
25 | A m -> A (S m)
26 | _ -> B
2727 (** val test6 : indu' -> indu' **)
2828
2929 let test6 = function
30 | A' m -> A' (S m)
31 | E' -> B'
32 | F' -> B'
33 | _ -> C'
30 | A' m -> A' (S m)
31 | E' -> B'
32 | F' -> B'
33 | _ -> C'
3434 (** val test7 : indu -> nat option **)
3535
3636 let test7 = function
37 | A m -> Some m
38 | _ -> None
37 | A m -> Some m
38 | _ -> None
3939 (** val decode_cond_mode :
4040 (word -> opcode option) -> (word -> 'a1 decoder_result) -> word -> ('a1
4141 -> opcode -> 'a2) -> 'a2 decoder_result **)
4242
4343 let decode_cond_mode condition f w g =
4444 match condition w with
45 | Some oc ->
46 (match f w with
47 | DecUndefined -> DecUndefined
48 | DecUnpredictable -> DecUnpredictable
49 | DecInst i -> DecInst (g i oc)
50 | DecError m -> DecError m)
51 | None -> DecUndefined
45 | Some oc ->
46 (match f w with
47 | DecUndefined -> DecUndefined
48 | DecUnpredictable -> DecUnpredictable
49 | DecInst i -> DecInst (g i oc)
50 | DecError m -> DecError m)
51 | None -> DecUndefined
77
88 (* Finite map library. *)
99
10 (* $Id: FMapAVL.v 13427 2010-09-17 17:37:52Z letouzey $ *)
10 (* $Id: FMapAVL.v 13768 2011-01-06 13:55:35Z glondu $ *)
1111
1212 (** * FMapAVL *)
1313
7777
7878 Definition is_empty m := match m with Leaf => true | _ => false end.
7979
80 (** * Appartness *)
81
82 (** The [mem] function is deciding appartness. It exploits the [bst] property
80 (** * Membership *)
81
82 (** The [mem] function is deciding membership. It exploits the [bst] property
8383 to achieve logarithmic complexity. *)
8484
8585 Fixpoint mem x m : bool :=
704704 destruct m; simpl; intros; try discriminate; red; intuition_in.
705705 Qed.
706706
707 (** * Appartness *)
707 (** * Membership *)
708708
709709 Lemma mem_1 : forall m x, bst m -> In x m -> mem x m = true.
710710 Proof.
8181 Definition is_empty s :=
8282 match s with Leaf => true | _ => false end.
8383
84 (** ** Appartness *)
85
86 (** The [mem] function is deciding appartness. It exploits the
84 (** ** Membership *)
85
86 (** The [mem] function is deciding membership. It exploits the
8787 binary search tree invariant to achieve logarithmic complexity. *)
8888
8989 Fixpoint mem x s :=
791791 split; auto. try discriminate. intro H; elim (H x); auto.
792792 Qed.
793793
794 (** * Appartness *)
794 (** * Membership *)
795795
796796 Lemma mem_spec : forall s x `{Ok s}, mem x s = true <-> InT x s.
797797 Proof.
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (* $Id: coqdep.ml 13323 2010-07-24 15:57:30Z herbelin $ *)
8 (* $Id: coqdep.ml 13983 2011-04-08 17:57:56Z herbelin $ *)
99
1010 open Printf
1111 open Coqdep_lexer
4040 match get_extension f [".vo"] with
4141 | (basename,".vo") ->
4242 let name = log_dir@[basename] in
43 Hashtbl.add coqlibKnown [basename] ();
44 Hashtbl.add coqlibKnown name ()
43 let paths = suffixes name in
44 List.iter (fun f -> Hashtbl.add coqlibKnown f ()) paths
4545 | _ -> ()
4646
4747 let sort () =
198198 let coqlib = Envars.coqlib () in
199199 add_rec_dir add_coqlib_known (coqlib//"theories") ["Coq"];
200200 add_rec_dir add_coqlib_known (coqlib//"plugins") ["Coq"];
201 add_dir add_coqlib_known (coqlib//"user-contrib") []
201 let user = coqlib//"user-contrib" in
202 if Sys.file_exists user then add_rec_dir add_coqlib_known user []
202203 end;
203204 List.iter (fun (f,d) -> add_mli_known f d) !mliAccu;
204205 List.iter (fun (f,d) -> add_mllib_known f d) !mllibAccu;
396396 | S_DIR when recur ->
397397 if List.mem phys_f !norecdir_list then ()
398398 else
399 let log_dir' = if log_dir = [] then ["Coq"] else log_dir@[f] in
400 add_directory recur add_file phys_f log_dir'
399 add_directory recur add_file phys_f (log_dir@[f])
401400 | S_REG -> add_file phys_dir log_dir f
402401 | _ -> ()
403402 done
0 (* OCaml-Win32
1 * mkwinapp.ml
2 * Copyright (c) 2002-2004 by Harry Chomsky
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 *)
18
19 (*********************************************************************
20 * This program alters an .exe file to make it use the "windows subsystem"
21 * instead of the "console subsystem". In other words, when Windows runs
22 * the program, it will not create a console for it.
23 *)
24
25 (* Pierre Letouzey 23/12/2010 : modification to allow selecting the
26 subsystem to use instead of just setting the windows subsystem *)
27
28 (* This tool can be run directly via :
29 ocaml unix.cma mkwinapp.ml [-set|-unset] <filename>
30 *)
31
32 exception Invalid_file_format
33
34 let input_word ic =
35 let lo = input_byte ic in
36 let hi = input_byte ic in
37 (hi lsl 8) + lo
38
39 let find_pe_header ic =
40 seek_in ic 0x3C;
41 let peheader = input_word ic in
42 seek_in ic peheader;
43 if input_char ic <> 'P' then
44 raise Invalid_file_format;
45 if input_char ic <> 'E' then
46 raise Invalid_file_format;
47 peheader
48
49 let find_optional_header ic =
50 let peheader = find_pe_header ic in
51 let coffheader = peheader + 4 in
52 seek_in ic (coffheader + 16);
53 let optsize = input_word ic in
54 if optsize < 96 then
55 raise Invalid_file_format;
56 let optheader = coffheader + 20 in
57 seek_in ic optheader;
58 let magic = input_word ic in
59 if magic <> 0x010B && magic <> 0x020B then
60 raise Invalid_file_format;
61 optheader
62
63 let change flag ic oc =
64 let optheader = find_optional_header ic in
65 seek_out oc (optheader + 64);
66 for i = 1 to 4 do
67 output_byte oc 0
68 done;
69 output_byte oc (if flag then 2 else 3)
70
71 let usage () =
72 print_endline "Alters a Win32 executable file to use the Windows subsystem or not.";
73 print_endline "Usage: mkwinapp [-set|-unset] <filename>";
74 print_endline "Giving no option is equivalent to -set";
75 exit 1
76
77 let main () =
78 let n = Array.length Sys.argv - 1 in
79 if not (n = 1 || n = 2) then usage ();
80 let flag =
81 if n = 1 then true
82 else if Sys.argv.(1) = "-set" then true
83 else if Sys.argv.(1) = "-unset" then false
84 else usage ()
85 in
86 let filename = Sys.argv.(n) in
87 let f = Unix.openfile filename [Unix.O_RDWR] 0 in
88 let ic = Unix.in_channel_of_descr f and oc = Unix.out_channel_of_descr f in
89 change flag ic oc
90
91 let _ = main ()
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (* $Id: search.ml 13323 2010-07-24 15:57:30Z herbelin $ *)
8 (* $Id: search.ml 13853 2011-02-24 07:57:31Z glondu $ *)
99
1010 open Pp
1111 open Util
196196 | l, outside -> filter_by_module l (not outside)
197197
198198 let filter_subproof gr _ _ =
199 not (string_string_contains (name_of_reference gr) "_subproof")
199 not (string_string_contains (name_of_reference gr) "_subproof") &&
200 not (string_string_contains (name_of_reference gr) "_admitted")
200201
201202 let (&&&&&) f g x y z = f x y z && g x y z
202203
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (* $Id: vernac.ml 13668 2010-12-02 17:43:59Z herbelin $ *)
8 (* $Id: vernac.ml 13923 2011-03-21 16:25:20Z letouzey $ *)
99
1010 (* Parsing of vernacular. *)
1111
5151 | Error_in_file (_, _, e) -> e
5252 | e -> e
5353
54 (** Timeout handling *)
55
56 (** A global default timeout, controled by option "Set Default Timeout n".
57 Use "Unset Default Timeout" to deactivate it (or set it to 0). *)
58
59 let default_timeout = ref None
60
61 let _ =
62 Goptions.declare_int_option
63 { Goptions.optsync = true;
64 Goptions.optname = "the default timeout";
65 Goptions.optkey = ["Default";"Timeout"];
66 Goptions.optread = (fun () -> !default_timeout);
67 Goptions.optwrite = ((:=) default_timeout) }
68
69 (** When interpreting a command, the current timeout is initially
70 the default one, but may be modified locally by a Timeout command. *)
71
72 let current_timeout = ref None
73
74 (** Installing and de-installing a timer.
75 Note: according to ocaml documentation, Unix.alarm isn't available
76 for native win32. *)
77
5478 let timeout_handler _ = raise Timeout
79
80 let set_timeout n =
81 let psh =
82 Sys.signal Sys.sigalrm (Sys.Signal_handle timeout_handler) in
83 ignore (Unix.alarm n);
84 Some psh
85
86 let default_set_timeout () =
87 match !current_timeout with
88 | Some n -> set_timeout n
89 | None -> None
90
91 let restore_timeout = function
92 | None -> ()
93 | Some psh ->
94 (* stop alarm *)
95 ignore(Unix.alarm 0);
96 (* restore handler *)
97 Sys.set_signal Sys.sigalrm psh
5598
5699 (* Opening and closing a channel. Open it twice when verbose: the first
57100 channel is used to read the commands, and the second one to print them.
184227
185228 | VernacTimeout(n,v) ->
186229 if not !just_parsing then begin
187 let psh =
188 Sys.signal Sys.sigalrm (Sys.Signal_handle timeout_handler) in
189 ignore (Unix.alarm n);
190 let stop() =
191 (* stop alarm *)
192 ignore(Unix.alarm 0);
193 (* restore handler *)
194 Sys.set_signal Sys.sigalrm psh in
195 try interp v; stop()
196 with e -> stop(); raise e
230 current_timeout := Some n;
231 interp v
197232 end
198233
199234 | v ->
200235 if not !just_parsing then
201 States.with_heavy_rollback interpfun
202 Cerrors.process_vernac_interp_error v
203
236 let psh = default_set_timeout () in
237 try
238 States.with_heavy_rollback interpfun
239 Cerrors.process_vernac_interp_error v;
240 restore_timeout psh
241 with e -> restore_timeout psh; raise e
204242 in
205243 try
244 current_timeout := !default_timeout;
206245 if do_beautify () then pr_new_syntax loc (Some com);
207246 interp com
208247 with e ->
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 (*i $Id: vernacentries.ml 13492 2010-10-04 21:20:01Z herbelin $ i*)
8 (*i $Id: vernacentries.ml 13922 2011-03-21 16:25:18Z letouzey $ i*)
99
1010 (* Concrete syntax of the mathematical vernacular MV V2.6 *)
1111
10121012 | BoolValue b -> set_bool_option_value_gen locality key b
10131013
10141014 let vernac_unset_option locality key =
1015 try set_bool_option_value_gen locality key false
1016 with _ ->
1017 set_int_option_value_gen locality key None
1015 unset_option_value_gen locality key
10181016
10191017 let vernac_add_option key lv =
10201018 let f = function