text
stringlengths
0
601k
let never _ = assert false
let digest ~ kind ( ? off = 0 ) ? len buf = let len = match len with Some len -> len | None -> Bigstringaf . length buf - off in let ctx = SHA1 . empty in let ctx = match kind with | ` A -> SHA1 . feed_string ctx ( Fmt . str " commit % d \ 000 " len ) | ` B -> SHA1 . feed_string ctx ( Fmt . str " tree % d \ 000 " len )...
let ( >>= ) = sched . bind
let read fd buf ~ off ~ len = let len = input fd buf off len in return len
let first_pass fpath = let ic = open_in ( Fpath . to_string fpath ) in let zw = De . make_window ~ bits : 15 in let allocate _ = zw in First_pass . check_header sched read ic >>= fun ( max , _ , _ ) -> seek_in ic 0 ; let decoder = First_pass . decoder ~ o : z ~ allocate ( ` Channel ic ) in let children = Hashtbl . crea...
let map ~ max fd ~ pos len = let len = Stdlib . min len ( Int64 . to_int ( Int64 . sub max pos ) ) in let res = Unix . map_file fd ~ pos Bigarray . char Bigarray . c_layout false [ | len ] | in Bigarray . array1_of_genarray res
let second_pass fpath ( hash , oracle , matrix ) = let open Fiber in let fd = Unix . openfile ( Fpath . to_string fpath ) Unix . [ O_RDONLY ] 0o644 in let max = ( Unix . LargeFile . fstat fd ) . Unix . LargeFile . st_size in let map fd ~ pos len = map ~ max fd ~ pos len in let pack = Carton . Dec . make fd ~ allocate ~...
let pp_kind ppf = function | ` A -> Fmt . string ppf " commit " | ` B -> Fmt . string ppf " tree " | ` C -> Fmt . string ppf " blob " | ` D -> Fmt . string ppf " tag "
let pp_delta ppf status = match Verify . source_of_status status with | Some uid -> Fmt . pf ppf " % d % a " ( Verify . depth_of_status status ) SHA1 . pp uid | None -> ( )
let verify_hash ~ memory hash = let max = Bigstringaf . length memory in let hash ' = SHA1 . of_raw_string ( Bigstringaf . substring memory ~ off ( : max - ( 2 * SHA1 . length ) ) ~ len : SHA1 . length ) in SHA1 . equal hash hash '
let verify ~ verbose fpath hash length carbon matrix = let fd = Unix . openfile ( Fpath . to_string fpath ) Unix . [ O_RDONLY ] 0o644 in let len = ( Unix . fstat fd ) . Unix . st_size in let memory = Unix . map_file fd ~ pos : 0L Bigarray . char Bigarray . c_layout false [ | len ] | in let memory = Bigarray . array1_of...
let ( >>? ) x f = let open Fiber in x >>= function Ok x -> f x | Error err -> return ( Error err )
let run ~ verbose fpath = let pack = Fpath . set_ext " pack " fpath in Bos . OS . File . must_exist pack |> Fiber . return >>? fun pack -> first_pass pack |> Scheduler . prj >>? fun ( hash , oracle , matrix , length , carbon ) -> second_pass pack ( hash , oracle , matrix ) >>? fun ( hash , matrix ) -> verify ~ verbose ...
let run verbose fpath = match Fiber . run ( run ~ verbose fpath ) with | Ok ( ) -> Ok ( ) | Error ( ` Msg err ) -> Error ( Fmt . str " % s . " err )
let verbose = let doc = " After verifying the pack , show list of objects contained in the pack and \ histogram of delta chain length . " in Arg . ( value & flag & info [ " v " ; " verbose " ] ~ doc )
let fpath = let parser x = match Fpath . of_string x with | Ok v when Sys . file_exists x -> Ok v | Ok v -> R . error_msgf " % a not found " Fpath . pp v | Error _ as err -> err in Arg . conv ( parser , Fpath . pp )
let fpath = let doc = " The idx files to verify . " in Arg . ( required & pos ~ rev : true 0 ( some fpath ) None & info [ ] ~ doc )
let cmd = let doc = " Validate packed Git archive files " in let man = [ ` S Manpage . s_description ; ` P " Reads given idx file for packed Git archive created with the ( $ i , git ) \ ( $ i , pack - objets ) command and verifies idx file and the corresponding \ pack file . " ; ] in let info = Cmd . info " verify - pa...
let ( ) = exit @@ Cmd . eval_result cmd
let parse s = Pb_parsing_parser . proto_ Pb_parsing_lexer . lexer ( Lexing . from_string s ) s
let ( ) = let proto = parse " message M { string no_label = 1 ; } " in match Pb_parsing_util . finalize_proto_value proto with | _ -> assert ( assertfalse ) assertfalse | exception E . Compilation_error _ -> ( )
let ( ) = let proto = parse " \ syntax = " \ proto2 " ; \ \ message M { \ string no_label = 1 ; \ } " in match Pb_parsing_util . finalize_proto_value proto with | _ -> assert ( assertfalse ) assertfalse | exception E . Compilation_error _ -> ( )
let ( ) = let proto = parse " \ syntax = " \ proto3 " ; \ \ message M { \ string no_label = 1 ; \ repeated string r = 2 ; \ message S { \ string s_no_label = 3 ; \ repeated string s_r = 4 ; \ } \ } " in match Pb_parsing_util . finalize_proto_value proto with | _ -> ( ) | exception E . Compilation_error _ -> assert ( as...
let ( ) = let proto = parse " \ syntax = " \ proto3 " ; \ \ message M { \ required string no_label = 1 ; \ } " in match Pb_parsing_util . finalize_proto_value proto with | _ -> assert ( assertfalse ) assertfalse | exception E . Compilation_error _ -> ( )
let ( ) = let proto = parse " \ syntax = " \ proto3 " ; \ \ message M { message S { \ required string no_label = 1 ; \ } } " in match Pb_parsing_util . finalize_proto_value proto with | _ -> assert ( assertfalse ) assertfalse | exception E . Compilation_error _ -> ( )
let ( ) = let proto = parse " \ syntax = " \ proto3 " ; \ \ enum E { EN1 = 1 ; EN2 = 2 ; } \ message M { } \ " in match Pb_parsing_util . finalize_proto_value proto with | _ -> assert ( assertfalse ) assertfalse | exception E . Compilation_error _ -> ( )
let ( ) = let proto = parse " \ syntax = " \ proto3 " ; \ \ message M { \ enum E { EN1 = 1 ; EN2 = 2 ; } \ } " in match Pb_parsing_util . finalize_proto_value proto with | _ -> assert ( assertfalse ) assertfalse | exception E . Compilation_error _ -> ( )
let ( ) = let proto = parse " \ syntax = " \ proto3 " ; \ \ message M { \ enum E { EN0 = 0 ; EN2 = 2 ; } \ } " in match Pb_parsing_util . finalize_proto_value proto with | _ -> ( ) | exception E . Compilation_error _ -> assert ( assertfalse ) assertfalse
let ( ) = print_endline " Verify syntax invariants . . . Ok "
let failwith str = raise ( Failure str )
let ( ) @ a b = let a = List . rev a in let rec f a b = match b with | [ ] -> a | h :: t -> f ( h :: a ) t in List . rev ( f a b )
let reserved = [ " and " ; " always " ; " assign " ; " attribute " ; " begin " ; " buf " ; " bufif0 " ; " bufif1 " ; " case " ; " cmos " ; " deassign " ; " default " ; " defparam " ; " disable " ; " else " ; " endattribute " ; " end " ; " endcase " ; " endfunction " ; " endprimitive " ; " endmodule " ; " endtable " ; "...
let iteri f l = let rec iteri n l = match l with | [ ] -> ( ) | h :: t -> f n h ; iteri ( n + 1 ) t in iteri 0 l
let folds c s = List . fold_left ( fun s n -> if s = " " then n else n ^ c ^ s ) " " s
let write circuit = let inputs = Circuit . inputs circuit in let outputs = Circuit . outputs circuit in let buf = Buffer . create ( 10 * 1024 ) in let name = Circuit . mangle_names reserved prefix circuit in let write_signal_decl typ signal = let write typ name ass = if width signal = 1 then bprintf buf " % s % s % s ;...
module Testbench = struct let write clocks resets circuit = let buf = Buffer . create ( 10 * 1024 ) in let inputs = Circuit . inputs circuit in let outputs = Circuit . outputs circuit in let name s = List . hd ( names s ) in let write_signal_decl t s = if width s = 1 then bprintf buf " % s % s ; \ n " t ( name s ) else...
let write chan circ = let b = Verilog . write circ in output_string chan ( Buffer . contents b )
module Testbench = struct let write chan a b c = let b = Verilog . Testbench . write a b c in output_string chan ( Buffer . contents b ) end
module Hierarchy = struct open Signal . Types let vwrite = write let inst_name = function | Signal_inst ( _ , _ , i ) -> i . inst_name | _ -> failwith " expecting instantiation " let rec write ( ? transforms [ ] ) = database path circ = let name = Circuit . name circ in let f = open_out ( path ^ name ^ " . v " ) in let...
let qualified_name m name = Conflict . qualified_name m . mod_namespace name
let pp_lwt_return fmt = function | Some lwt_module -> fprintf fmt " % s . return " lwt_module | _ -> assert false
type from_require_import = { import_from : string ; import_module : string }
let pp_from_require_import fmt fri = fprintf fmt " From % s Require Import % s . " fri . import_from fri . import_module
type from_require_export = { export_from : string ; export_module : string }
let pp_from_require_export fmt fre = fprintf fmt " From % s Require Export % s . " fre . export_from fre . export_module
type require = { require_module : string }
let pp_require fmt req = fprintf fmt " Require % s . " req . require_module
type constructor = { constructor_name : coq_name ; constructor_prototype : Repr . prototype_repr ; }
let pp_constructor fmt c = fprintf fmt " | [ @< hov 2 [ >@< hov 2 >% a % a % a % a % a ] @@ : % a ] " @ pp_coq_name c . constructor_name ( pp_if_not_empty pp_print_space ) c . constructor_prototype . prototype_type_args pp_type_args_list c . constructor_prototype . prototype_type_args ( pp_if_not_empty pp_print_space )...
type inductive = { inductive_name : coq_name ; inductive_type_args : string list ; inductive_type : Repr . type_repr ; inductive_constructors : constructor list ; }
let pp_inductive fmt = function | [ ] -> ( ) | lind -> let pp_inductive_aux fmt ind = fprintf fmt " % a % a % a @ : % a ] :=@@ % a " pp_coq_name ind . inductive_name ( pp_if_not_empty pp_print_space ) ind . inductive_type_args pp_type_args_list ind . inductive_type_args pp_type_repr ind . inductive_type ( pp_print_list...
type field = { field_name : coq_name ; field_type : mono_type_repr }
type record = { record_name : coq_name ; record_type_args : string list ; record_fields : field list ; }
let pp_record fmt r = let pp_field fmt f = fprintf fmt " % a : % a " pp_coq_name f . field_name pp_mono_type_repr f . field_type in fprintf fmt " [ @< hov 2 > Record % a % a % a :=@ [ @< hov { >@ % a @ } . ] ] " @@ pp_coq_name r . record_name ( pp_if_not_empty ( fun fmt _ -> pp_print_text fmt " " ) ) r . record_type_ar...
type definition = { def_name : coq_name ; def_typeclass_args : string list ; def_prototype : Repr . prototype_repr ; def_body : Format . formatter -> unit -> unit ; }
let pp_definition fmt def = fprintf fmt " [ @< hov 2 [ >@< hov 2 > Definition % a % a % a % a % a % a ] @ :@ % a :=@ % a . ] " @ pp_coq_name def . def_name ( pp_list ~ pp_prefix ( : fun fmt _ -> pp_print_string fmt " ` { " ) ~ pp_suffix ( : fun fmt _ -> pp_print_string fmt " } " ) ~ pp_sep : pp_print_space pp_print_str...
type typeclass = { class_name : coq_name ; class_typeclass_args : string list ; class_args : ( string * Repr . type_repr ) list ; class_type : Repr . type_repr ; class_members : ( coq_name * Repr . type_repr ) list ; }
let pp_typeclass fmt cls = fprintf fmt " [ @< hov 2 [ >@< hov 2 > Class % a % a % a % a % a ] @ :@ % a :=@ [ @< v { > % a @ ] } . ] " @@ pp_coq_name cls . class_name ( pp_if_not_empty pp_print_space ) cls . class_typeclass_args ( pp_print_list ~ pp_sep : pp_print_space pp_print_string ) cls . class_typeclass_args ( pp_...
type instance = { instance_name : coq_name ; instance_typeclass_args : string list ; instance_type : Repr . type_repr ; instance_members : ( coq_name * string ) list ; }
let pp_instance fmt inst = fprintf fmt " [ @< hov 2 > Instance % a % a @ : % a :=@ [ @< v { > % a @ } . ] ] " @@ pp_coq_name inst . instance_name ( pp_list ~ pp_prefix ( : fun fmt _ -> pp_print_string fmt " ` { " ) ~ pp_suffix ( : fun fmt _ -> pp_print_string fmt " } " ) ~ pp_sep ( : fun fmt _ -> pp_print_string fmt " ...
type axiom = { axiom_name : coq_name ; axiom_typeclass_args : string list ; axiom_type : Repr . type_repr ; }
let pp_axiom fmt ax = fprintf fmt " [ @< hov 2 > Axiom % a @ : % a % a . ] " @ pp_coq_name ax . axiom_name ( pp_list ~ pp_prefix ( : fun fmt _ -> pp_print_text fmt " forall ` { " ) ~ pp_suffix ( : fun fmt _ -> pp_print_text fmt " } , " ) ~ pp_sep ( : fun fmt _ -> pp_print_text fmt " , @ " ) pp_print_text ) ax . axiom_t...
type extract_constant = { constant_qualid : coq_name ; constant_type_vars : string list ; constant_target : string ; }
let pp_extract_constant fmt extr = let print_args_prod fmt = function | [ ] -> ( ) | [ x ] -> fprintf fmt " ' % s " x | args -> fprintf fmt " ( % a ) " ( pp_print_list ~ pp_sep ( : fun fmt _ -> pp_print_text fmt " , " ) ( fun fmt -> fprintf fmt " ' % s " ) ) args in fprintf fmt " [ @< hov 2 > Extract Constant % a % a @...
type extract_inductive = { inductive_qualid : coq_name ; inductive_target : string ; inductive_variants_target : string list ; }
let pp_extract_inductive fmt ind = fprintf fmt " [ @< hov 2 > Extract Inductive % a =>@ " \% s " \@ [ [ @< hov 2 >% a ] ] . ] " @@ pp_coq_name ind . inductive_qualid ind . inductive_target ( pp_list ~ pp_sep : pp_print_space ~ pp_prefix : pp_print_space ~ pp_suffix : pp_print_space ( fun fmt t -> fprintf fmt " " \% s "...
type coq_module = { coqmod_name : coq_name ; coqmod_content : t } | Section of string | Subsection of string | Comment of string | Block of t Lazylist . t | CompactedBlock of t Lazylist . t | CoqModule of coq_module | ConfigPrologue | FromRequireImport of from_require_import | FromRequireExport of from_require_export |...
let exn_t = TParam ( CName " exn " , [ ] )
let monadic_may_raise_t may_raise t = if may_raise then map_codomain ( function | TParam ( m , [ t ] ) -> TParam ( m , [ TParam ( CName " sum " , [ t ; exn_t ] ) ] ) | _ -> assert false ) t else t
let may_raise_t may_raise t = if may_raise then map_codomain ( fun t -> TParam ( CName " sum " , [ t ; exn_t ] ) ) t else t
let rec pp_vernac fmt = function | Block l -> fprintf fmt " [ @< v >% a ] " @ ( pp_print_lazylist ~ pp_sep ( : fun fmt _ -> fprintf fmt " @ @ " ) pp_vernac ) l | CompactedBlock l -> fprintf fmt " [ @< v >% a ] " @ ( pp_print_lazylist ~ pp_sep : pp_print_space pp_vernac ) l | Comment str -> fprintf fmt " " str | Section...
let block_of_list l = Block ( of_list l )
let compacted_block_of_list l = CompactedBlock ( of_list l )
let empty = function [ ] -> true | _ -> false
let ( @? ) cond f = if cond then f else fun x -> x
let proto_vars proto = List . map ( fun ( l , _ ) -> asprintf " % a " pp_arg_name l ) proto . prototype_args
let call_vars proto = List . map ( fun ( l , _ ) -> asprintf " % a " pp_arg_call l ) proto . prototype_args
let instance_member_body proto name = let tvars = proto . prototype_type_args in let vars = proto_vars proto in if 0 < List . length tvars then asprintf " [ @< h 2 > fun % a % a @ => % a % a ] " @ ( pp_list ~ pp_prefix ( : fun fmt _ -> pp_print_text fmt " " ) ~ pp_sep ( : fun fmt _ -> pp_print_text fmt " " ) ( fun fmt ...
let requires_vernac features models = let requires_freespec = Lazylist . push ( FromRequireImport { import_from = " FreeSpec . Core " ; import_module = " Core " } ) in let requires_io = Lazylist . push ( FromRequireImport { import_from = " SimpleIO " ; import_module = " IO_Monad " } ) in let requires_interface = Lazyli...
let functions_vernac ~ rev_namespace conflicts m = let to_def f = let func_type = may_raise_t f . func_may_raise f . func_type in let func_name = Conflict . get_coq_value rev_namespace conflicts ~ value : f . func_name in match f . func_model with | Some model -> Definition { def_name = func_name ; def_typeclass_args =...
let variant_entry_to_constructor ~ rev_namespace conflicts owner v = { constructor_name = Conflict . get_coq_constructor rev_namespace conflicts ~ owner ~ cstr : v . variant_name ; constructor_prototype = v . variant_prototype ; }
let field_entry_to_field ~ rev_namespace owner conflicts ( r : field_entry ) = let field_name = Conflict . get_coq_field rev_namespace conflicts ~ owner ~ field : r . field_name in { field_name ; field_type = r . field_type }
let ind_type = let rec aux pos arity = if arity == 0 then type_sort_mono else TLambda { argtype = { position = pos ; kind = PositionedArg } ; domain = type_sort_mono ; codomain = aux ( pos + 1 ) ( arity - 1 ) ; } in aux 0
let type_entry_to_vernac ~ rev_namespace conflicts features t = let transparent = is_enabled features TransparentTypes in let type_name = Conflict . get_coq_type rev_namespace conflicts ~ ty : t . type_name in match ( t . type_value , t . type_model , transparent ) with | Variant l , None , true -> Inductive [ { induct...
let io_primitives_vernac ~ rev_namespace conflicts m = let io_axiom_name name = Conflict . get_coq_helper rev_namespace conflicts name Name . io_helper in let to_axiom prim = let axiom_type = type_lift " IO " ( may_raise_t prim . prim_may_raise prim . prim_type ) in let axiom_name = io_axiom_name prim . prim_name in Ax...
let interface_constructor_name rev_namespace conflicts name = Conflict . get_coq_helper rev_namespace conflicts ~ owner ( : List . hd rev_namespace ) name Name . interface_cstr
let interface_vernac ~ rev_namespace conflicts mod_name interface_name class_name instance_name all_prims vernacs = let interface_name = Conflict . get_coq_helper rev_namespace conflicts ~ owner : mod_name mod_name interface_name in let hof ( i , p ) = Repr . higher_order_monadic ( CPlaceholder i ) p . prim_type in let...
let lwt_primitives_vernac ~ rev_namespace conflicts lwt_module m vernacs = let to_lwt t = TParam ( CName " Lwt . t " , [ t ] ) in let axiom_name prim = let owner = prim . prim_name in Conflict . get_coq_helper rev_namespace conflicts owner Name . lwt_sync_helper in let to_axiom prim = Axiom { axiom_typeclass_args = [ ]...
let semantics_vernac ~ rev_namespace conflicts m vernacs = let axiom_name owner = Conflict . get_coq_helper rev_namespace conflicts owner Name . semantics_helper in let target_name value = Conflict . get_ocaml_value rev_namespace conflicts ~ value in let mod_name = String . uppercase_ascii m . mod_name in let mod_type ...
let exceptions_vernac ~ rev_namespace conflicts m vernacs = let exception_vernac v e = let exn_name = e . exception_name in let exn_type = TParam ( CName " exn " , [ ] ) in let proxy_name = Conflict . get_coq_helper rev_namespace conflicts exn_name Name . exn_proxy_type in let proxy_constructor_name = Conflict . get_co...
let monad_vernac ~ rev_namespace conflicts mod_name prims = let prim_to_members prim = let prim_type = may_raise_t prim . prim_may_raise prim . prim_type in let prim_name = Conflict . get_coq_value rev_namespace conflicts ~ value : prim . prim_name in ( prim_name , type_lift " m " prim_type ) in let class_name = Confli...
let primitives_vernac ~ rev_namespace conflicts lwt_module features m vernacs = let prims = List . map ( fun p -> let t = p . prim_type in let i = Repr . fresh_placeholder t in let p = { p with prim_type = Repr . map_codomain ( fun x -> TParam ( CPlaceholder i , [ x ] ) ) t ; } in ( i , p ) ) m . mod_primitives in vern...
let lwt_vernac ~ rev_namespace conflicts features m vernacs = let lwt_t = " Lwt . t " in let to_prim lwt = ( lwt . lwt_placeholder , { prim_name = lwt . lwt_name ; prim_type = lwt . lwt_type ; prim_may_raise = false ; prim_loc = lwt . lwt_loc ; } ) in let prims = List . map to_prim m . mod_lwt in let axiom_name lwt = l...
let rec module_vernac ~ rev_namespace conflicts lwt_module features models m vernac = let rev_namespace = m . mod_name :: rev_namespace in vernac |> ( not ( empty m . mod_intro ) ) @? intros_vernac ~ rev_namespace conflicts lwt_module features models m |> ( not ( empty m . mod_exceptions ) ) @? exceptions_vernac ~ rev_...
let of_mod lwt_module features models conflicts m = Block ( of_list [ Comment " This file has been generated by coqffi . " ; ConfigPrologue ] |> requires_vernac features models |> module_vernac ~ rev_namespace [ ] : conflicts lwt_module features models m |+ Comment " The generated file ends here . " )
type choice ' a ' b = [ Left of ' a | Right of ' b ] ; match x with | Some x -> Some ( f x ) | None -> None end ; Some x -> x ] ; Left x -> x ] ; Left _ -> failwith ( " choice : " ^ symbol ) ] ; Sys . ocaml_version ; ( loc ) with Location . loc_ghost = True } ; let loc_at n lnum bolp = { Lexing . pos_fname = if lnum = ...
let params = List . map ( fun ( os , va ) -> match os with [ None -> ( ocaml_mktyp loc Ptyp_any , convert_camlp5_variance va ) | Some s -> ( ocaml_mktyp loc ( Ptyp_var s ) , convert_camlp5_variance va ) ] ) params in { ptyext_path = mkloc loc pathlid ; ptyext_params = params ; ptyext_constructors = ecstrs ; ptyext_priv...
type additional_info = Dev | RC of int | Release
let string_of_additional_info = function | Dev -> " + dev " | RC n -> " ~ rc " ^ string_of_int n | Release -> " "
type t = { major : int ; minor : int ; additional_info : additional_info }