text
stringlengths
12
786k
let list = { space_after_opening = true ; space_after_separator = true ; space_before_separator = false ; separators_stick_left = true ; space_before_closing = true ; stick_to_label = true ; align_closing = true ; wrap_body = ` Wrap_atoms ; indent_body = 2 ; list_style = None ; openi...
type label_param = { label_break : label_break ; space_after_label : bool ; indent_after_label : int ; label_style : style_name option ; }
let label = { label_break = ` Auto ; space_after_label = true ; indent_after_label = 2 ; label_style = None ; }
type t = Atom of string * atom_param | List of ( string * string * string * list_param ) * t list | Label of ( t * label_param ) * t | Custom of ( formatter -> unit )
type escape = [ ` None | ` Escape of ( ( string -> int -> int -> unit ) -> string -> int -> int -> unit ) | ` Escape_string of ( string -> string ) ]
type styles = ( style_name * style ) list
let propagate_from_leaf_to_root ~ init_acc ~ merge_acc ~ map_node x = let rec aux x = match x with | Atom _ -> let acc = init_acc x in map_node x acc | List ( param , children ) -> let new_children , accs = List . rev_split ( List . rev_map aux children ) in let acc = List . fold_left mer...
let propagate_forced_breaks x = let init_acc = function | List ( ( _ , _ , _ , { wrap_body = ` Force_breaks_rec } ) , _ ) | Label ( ( _ , { label_break = ` Always_rec } ) , _ ) -> true | Atom _ | Label _ | Custom _ | List _ -> false in let merge_acc force_br...
module Pretty = struct let rewrite x = propagate_forced_breaks x let set_escape fmt escape = let print0 , flush0 = pp_get_formatter_output_functions fmt ( ) in let tagf0 = ( pp_get_formatter_tag_functions [ @ warning " - 3 " ] ) fmt ( ) in let is_tag = ref false in let mot tag = is_tag ...
module Compact = struct open Printf let rec fprint_t buf = function Atom ( s , _ ) -> Buffer . add_string buf s | List ( param , l ) -> fprint_list buf param l | Label ( label , x ) -> fprint_pair buf label x | Custom f -> let fmt = formatter_of_buffer buf in f fmt ; pp_print_flush fmt ...
module Param = struct let list_true = { space_after_opening = true ; space_after_separator = true ; space_before_separator = true ; separators_stick_left = true ; space_before_closing = true ; stick_to_label = true ; align_closing = true ; wrap_body = ` Wrap_atoms ; indent_body = 2 ; l...
module Prop = struct module Boolean = Boolean include Option include Set end
let f t = [ 1 ] @ t
let f t = 1 :: [ ] @ t
let f ( t : int * int ) = fst t + snd t
let dounit ( ) = ( )
let f ( ) = if x then ( if x then x else y ) else y
let f ( ) = if x then ( if x then x else let z = 3 in dounit ( ) ; ( if z = 2 then x else y ) ) else y
let f ( ) = let l = [ ] in begin match l with | [ ] -> begin match l with | [ ] -> let z = [ ] in begin match z with | _ -> true end | _ -> false end | _ -> true end
let z = if x then 1 else if y then 2 else if x & y then 3 else 4
let z = if x then 1 else if y then 2 else if x & y then 3 else if z = 4 then 3 else 9
let z = ( x = TConstr 3 || x = TConstr 4 )
let z = ( x = [ 12 ] || x = [ 50 ] )
let z = ( x = 5 || x = 6 )
let z = ( x = TConstr 3 && x = TConstr 4 )
let z = ( x = [ 12 ] && x = [ 50 ] )
let z = ( x = 5 && x = 6 )
let z = ( x = TConstr 3 || not ( x = TConstr 3 ) )
let z = ( x = [ ] || x = [ ] )
let z = ( x = None || x = None )
let z = ( x = 5 || x = 5 )
let z = ( x = TConstr 3 || x = TConstr 3 )
let z = ( x = TConstr 3 || x = TConstr 3 || x = TConstr 4 )
let z = ( x = TConstr 3 || x = TConstr 4 || x = TConstr 3 )
let z = ( x = [ ] && x = [ ] )
let z = ( x = None && x = None )
let z = ( x = 5 && x = 5 )
let z = ( x = TConstr 3 && x = TConstr 3 )
let z = ( x = TConstr 3 && x = TConstr 3 && x = TConstr 4 )
let z = ( x = TConstr 3 && x = TConstr 4 && x = TConstr 3 )
let ( ) = Alcotest . run ~ verbose : true __FILE__ [ ( " alpha " , [ Alcotest . test_case " 0 newlines " ` Quick ( fun ( ) -> Format . printf " Print inside alpha " ) ; ] ) ; ( " beta " , [ Alcotest . test_case " 1 newline " ` Quick ( fun ( ) ...
val mutable x : int = x method x = x val mutable y : int = y method y = y val mutable width = w method width = width method draw = fill_rect x y width width method private contains x ' y ' = x <= x ' && x ' <= x + width && y <= y ' && y ' <= y + width method on_click ? start ? stop f =...
module Verifier_index_json = struct module Lookup = struct type lookups_used = Kimchi_types . VerifierIndex . Lookup . lookups_used = | Single | Joint [ @@ deriving yojson ] yojson type ' polyComm t = ' polyComm Kimchi_types . VerifierIndex . Lookup . t = { lookup_used : lookups_used ; lookup_tabl...
module Data = struct [ %% versioned module Stable = struct module V1 = struct type t = { constraints : int } [ @@ deriving yojson ] yojson let to_latest = Fn . id end end ] end end
module Repr = struct [ %% versioned module Stable = struct module V2 = struct type t = { commitments : Backend . Tock . Curve . Affine . Stable . V1 . t Plonk_verification_key_evals . Stable . V2 . t ; step_domains : Domains . Stable . V2 . t array ; data : Data . Stable . V1 . t } [ @@ derivin...
module Stable = struct module V2 = struct type t = { commitments : Backend . Tock . Curve . Affine . t Plonk_verification_key_evals . t ; step_domains : Domains . t array ; index : ( Impls . Wrap . Verification_key . t [ @ to_yojson Verifier_index_json . to_yojson Backend . Tock . Field . to_...
let dummy_commitments g = let open Plonk_types in { Plonk_verification_key_evals . sigma_comm = Vector . init Permuts . n ~ f ( : fun _ -> g ) g ; coefficients_comm = Vector . init Columns . n ~ f ( : fun _ -> g ) g ; generic_comm = g ; psm_comm = g ; complete_add_comm = g ; mul_c...
let dummy = lazy ( let rows = Domain . size ( Common . wrap_domains ~ proofs_verified : 2 ) 2 . h in let g = Backend . Tock . Curve ( . to_affine_exn one ) one in { Repr . commitments = dummy_commitments g ; step_domains = [ ] || ; data = { constraints = rows } } |> St...
module Base = struct module type S = sig type t type ledger_proof type invalid = [ ` Invalid_keys of Signature_lib . Public_key . Compressed . t list | ` Invalid_signature of Signature_lib . Public_key . Compressed . t list | ` Invalid_proof | ` Missing_verification_key of Signature_lib . Public_key ....
module type S = sig include Base . S val create : logger : Logger . t -> proof_level : Genesis_constants . Proof_level . t -> constraint_constants : Genesis_constants . Constraint_constants . t -> pids : Child_processes . Termination . t -> conf_dir : string option -> t Deferred . t end
let extract_sources sources = let erl = List . hd sources in let ml = List . hd ( List . tl sources ) in ( erl , ml )
let compare_parsetree a b = if a = b then Ok ( ) else Error ` not_equal
let remove_locations parsetree = let open Ast_mapper in let open Parsetree in let map_structure_item sub { pstr_loc = loc ; pstr_desc = desc } = let open Ast_helper . Str in let loc = sub . location sub loc in match desc with | Pstr_value ( _r , vbs ) -> value ~ loc Recursive ( List . map (...
let verify sources = let erl , ml = extract_sources sources in let ml_parsetree = Ocaml . parse_implementation ~ dump_ast : false ~ source_file : ml |> remove_locations in Printast . structure 0 Format . std_formatter ml_parsetree ; Format . fprintf Format . std_formatter " \ n \ n " ; %...
let ( . <> ) f g x = f ( g x )
module Scheduler = Carton . Make ( Fiber )
module SHA1 = struct include Digestif . SHA1 let feed ctx ? off ? len bs = feed_bigstring ctx ? off ? len bs let null = digest_string " " let length = digest_size let compare a b = String . compare ( to_raw_string a ) ( to_raw_string b ) end
module Verify = Carton . Dec . Verify ( SHA1 ) ( Scheduler ) ( Fiber )
module First_pass = Carton . Dec . Fp ( SHA1 )
let sched = let open Scheduler in { Carton . bind = ( fun x f -> inj ( bind ( prj x ) ( fun x -> prj ( f x ) ) ) ) ; return = ( fun x -> inj ( return x ) ) ; }
let z = De . bigstring_create De . io_buffer_size
let allocate bits = De . make_window ~ bits
let replace hashtbl k v = try let v ' = Hashtbl . find hashtbl k in if v < v ' then Hashtbl . replace hashtbl k v ' with _ -> Hashtbl . add hashtbl k v
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_s...
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 ( ` Ch...
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 le...
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 [ | le...
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 ) ...
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 . " ; ...
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 | _ -> ( ) ...
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 " ...
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 bpr...
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 " % ...
let write chan circ = let b = Verilog . write circ in output_string chan ( Buffer . contents b )