text
stringlengths
12
786k
let empty_code = { mem = State . empty ; init = Osequence [ ] ;
let seq { mem = m1 ; init = i1 ; instances = j1 ; reset = r1 ; step = s1 } { mem = State . seq m1 m2 ; init = sequence i1 i2 ; instances = State . par j1 j2 ; reset = sequence r1 r2 ; step = sequence s1 s2 }
let entry_of n env = try Env . find n env with Not_found -> Zmisc . internal_error " Unbound variable " Printer . name n
let immediate = function | Deftypes . Eint ( i ) -> Oint ( i ) | Deftypes . Efloat ( f ) -> Ofloat ( f ) | Deftypes . Ebool ( b ) -> Obool ( b ) | Deftypes . Echar ( c ) -> Ochar ( c ) | Deftypes . Estring ( s ) -> Ostring ( s ) | Deftypes . Evoid -> Ovoi...
let constant = function | Deftypes . Cimmediate ( i ) -> Oconst ( immediate i ) | Deftypes . Cglobal ( ln ) -> Oglobal ( ln )
let state is_read n k = match k with | None -> Oleft_state_name ( n ) | Some ( k ) -> match k with | Deftypes . Cont -> | Deftypes . Zero -> Oleft_state_primitive_access | Deftypes . Horizon | Deftypes . Period | Deftypes . Encore | Deftypes . Major -> Oleft_state_name ( n )
let rec index e = function [ ] -> e | ei :: ei_list -> Oaccess ( index e ei_list , Olocal ( ei ) )
let rec left_value_index lv = function | [ ] -> lv | ei :: ei_list -> Oleft_index ( left_value_index lv ei_list , Olocal ( ei ) )
let rec left_state_value_index lv = function | [ ] -> lv | ei :: ei_list -> Oleft_state_index ( left_state_value_index lv ei_list , Olocal ( ei ) )
let var { e_sort = sort ; e_typ = ty ; e_size = ei_list } = match sort with | In ( e ) -> index e ei_list | Out ( n , sort ) -> match sort with | Sstatic | Sval -> index ( Olocal ( n ) ) ei_list | Svar _ -> index ( Ovar ( is_mutable ty , n ) ) ei_list | Smem { m_kind...
let assign { e_sort = sort ; e_size = ei_list } e = match sort with | In _ -> assert false | Out ( n , sort ) -> match sort with | Sstatic | Sval -> assert false | Svar _ -> Oassign ( left_value_index ( Oleft_name n ) ei_list , e ) | Smem { m_kind = k } ->
let def { e_typ = ty ; e_sort = sort ; e_size = ei_list } e ( { step = s } as code ) = match sort with | In _ -> assert false | Out ( n , sort ) -> match sort with | Sstatic | Sval -> { code with step = Olet ( Ovarpat ( n , type_expression_of_typ ty ) , e , s ) } |...
let der { e_sort = sort ; e_size = ei_list } e ( { step = s } as code ) = match sort with | In _ -> assert false | Out ( n , sort ) -> { code with step = e ) )
let ifthen r_e i_code s = sequence ( Oif ( r_e , i_code , None ) ) s
let for_loop direction ix e1 e2 i_body = match i_body with | Osequence [ ] -> Osequence [ ] | _ -> Ofor ( direction , ix , e1 , e2 , i_body )
let letpat p e ( { step = s } as code ) = { code with step = Olet ( p , e , s ) }
let rec letvar l s = match l with | [ ] -> s | ( n , is_mutable , ty , v_opt ) :: l -> Oletvar ( n , is_mutable , ty , v_opt , letvar l s )
let pluseq ( { e_sort = sort ; e_size = ei_list } as entry ) let ln = match sort with | In _ -> assert false | Out ( n , sort ) -> match sort with | Svar { v_combine = Some ( ln ) } | Smem { m_combine = Some ( ln ) } -> ln | _ -> Zmisc . internal_error " Unbound varia...
let out_of n env = let { e_typ = ty ; e_sort = sort ; e_size = ix_list } = entry_of n env in match sort with | In _ -> assert false | Out ( x , sort ) -> x , ty , sort , ix_list
let rec size_of_type = function | Tconst ( i ) -> Sconst ( i ) | Tglobal ( q ) -> Sglobal ( Lident . Modname ( q ) ) | Tname ( n ) -> Sname ( n ) | Top ( op , s1 , s2 ) -> let e1 = size_of_type s1 in let e2 = size_of_type s2 in match op with | Tplus -> Sop ( Splus , ...
let rec size { Zelus . desc = desc } = match desc with | Zelus . Sconst ( i ) -> Sconst ( i ) | Zelus . Sglobal ( ln ) -> Sglobal ( ln ) | Zelus . Sname n -> Sname ( n ) | Zelus . Sop ( op , s1 , s2 ) -> let s1 = size s1 in let s2 = size s2 in match op with | Zelus...
let choose env ty = let tuple l = Otuple ( l ) in let efalse = Oconst ( Obool ( false ) ) in let echar0 = Oconst ( Ochar ( ' a ' ) ) in let ezero = Oconst ( Oint ( 42 ) ) in let efzero = Oconst ( Ofloat ( 42 . 0 ) ) in let estring0 = Oconst ( Ostring ( " aaaaaaa...
let default env ty v_opt = match v_opt with | None -> choose env ty | Some ( v ) -> Some ( constant v )
let append loop_path l_env env = let addrec n { t_sort = k ; t_typ = ty } ( env_acc , mem_acc , var_acc ) = match k with | Sstatic | Sval -> | Svar { v_default = v_opt } -> | Smem { m_kind = k_opt } -> Env . fold addrec l_env ( env , State . empty , [ ] )
let apply k env loop_path e e_list match k with | Deftypes . Tstatic _ | Deftypes . Tany | Deftypes . Tdiscrete ( false ) -> Oapp ( e , e_list ) , code | Deftypes . Tdiscrete ( true ) | Deftypes . Tcont | Deftypes . Tproba -> let se_list , arg = Zmisc . firsts e_list in let f_o...
let rec exp env loop_path code { Zelus . e_desc = desc } = match desc with | Zelus . Econst ( i ) -> Oconst ( immediate i ) , code | Zelus . Elocal ( n ) | Zelus . Elast ( n ) -> var ( entry_of n env ) , code | Zelus . Eglobal { lname = ln } -> Oglobal ( ln ) , ...
let rec equation env loop_path { Zelus . eq_desc = desc } code = match desc with | Zelus . EQeq ( { Zelus . p_desc = Zelus . Evarpat ( n ) } , e ) -> let e , code = exp env loop_path code e in def ( entry_of n env ) e code | Zelus . EQeq ( p , e ) -> let e , code = exp...
let machine n k pat_list { mem = m ; instances = j ; reset = r ; step = s } let k = Interface . kindtype k in match k with | Deftypes . Tstatic _ | Deftypes . Tany | Deftypes . Tdiscrete ( false ) -> Oletfun ( n , pat_list , s ) | Deftypes . Tdiscrete ( true ) | Deftypes ...
let expression env ( { Zelus . e_desc = desc } as e ) = match desc with | Zelus . Elet ( l , e_let ) -> local env empty_path l e_let | _ -> let e , code = exp env empty_path empty_code e in
let implementation { Zelus . desc = desc } = match desc with | Zelus . Eopen ( n ) -> Oopen ( n ) | Zelus . Etypedecl ( n , params , ty_decl ) -> Otypedecl ( [ n , params , type_of_type_decl ty_decl ] ) | Zelus . Econstdecl ( n , _ , e ) -> let { step = s } ...
let implementation_list impl_list = Zmisc . iter implementation impl_list
type concrete_regexp = | Epsilon | Eof | Characters of Fcset . t | Sequence of concrete_regexp * concrete_regexp | Alternative of concrete_regexp * concrete_regexp | Repetition of concrete_regexp | Bind of concrete_regexp * ( Locf . t * string )
type ' a entry = { shortest : bool ; clauses : ( concrete_regexp * ' a ) list }
let regexp_for_string s = let rec re_string n = let len = String . length s in if n >= len then Epsilon else if n + 1 = len then Characters ( Fcset . singleton ( Char . code s . [ n ] ) ) else Sequence ( Characters ( Fcset . singleton ( Char . code s . [ n ] ) ) , re_str...
let rec remove_as x = match x with | Bind ( e , _ ) -> remove_as e | Epsilon | Eof | Characters _ as e -> e | Sequence ( e1 , e2 ) -> Sequence ( remove_as e1 , remove_as e2 ) | Alternative ( e1 , e2 ) -> Alternative ( remove_as e1 , remove_as e2 ) | Repetition e -> Repetitio...
let as_cset = function | Characters s -> s | _ -> raise Bad
let remove_nested_as e : concrete_regexp = let rec do_remove_nested ( to_remove : Id_set . t ) x : concrete_regexp = match x with | Bind ( e , x ) -> if Id_set . mem x to_remove then do_remove_nested to_remove e else Bind ( do_remove_nested ( Id_set . add x to_remove ) e , x ) | Epsilo...
let rec find_all_vars ( x : concrete_regexp ) : Id_set . t = let open Id_set in match x with | Characters _ | Epsilon | Eof -> empty | Bind ( e , x ) -> add x ( find_all_vars e ) | Sequence ( e1 , e2 ) | Alternative ( e1 , e2 ) -> union ( find_all_vars e1 ) ( find_all_vars...
let find_optional e = let rec do_find_opt x : Id_set . t * Id_set . t = let open Id_set in match x with | Characters _ | Epsilon | Eof -> ( empty , empty ) | Bind ( e , x ) -> let ( opt , all ) = do_find_opt e in ( opt , add x all ) | Sequence ( e1 , e2 ) -> let ( opt1 ...
let rec do_find_double x : Id_set . t * Id_set . t = let open Id_set in match x with | Characters _ | Epsilon | Eof -> ( empty , empty ) | Bind ( e , x ) -> let ( dbl , all ) = do_find_double e in ( ( if mem x all then add x dbl else dbl ) , add x all ) | Sequence ( e1 , ...
let find_double e = do_find_double e
let add_some x = function | Some i -> Some ( x + i ) | None -> None
let add_some_some x y = match x , y with | ( Some i , Some j ) -> Some ( i + j ) | ( _ , _ ) -> None
let find_chars e = let open Id_set in let rec do_find_chars ( sz : int option ) x = match x with | Epsilon | Eof -> ( empty , empty , sz ) | Characters _ -> ( empty , empty , add_some 1 sz ) | Bind ( e , x ) -> let ( c , s , e_sz ) = do_find_chars ( Some 0 ) e in begi...
let chars = ref ( [ ] : Fcset . t list )
let chars_count = ref 0
let rec encode_regexp ( char_vars : Id_set . t ) ( act : int ) x : regexp = match x with | Epsilon -> Empty | Characters cl -> let n = ! chars_count in begin chars := cl :: ! chars ; incr chars_count ; Chars ( n , false ) end | Eof -> let n = ! chars_count in begin chars := Fcset ....
let mk_seq ( r1 : regexp ) ( r2 : regexp ) : regexp = match r1 , r2 with | Empty , _ -> r2 | _ , Empty -> r1 | _ -> Seq ( r1 , r2 )
let add_pos p i = match ( p : Automata_def . tag_addr option ) with | Some ( a , n ) -> Some ( a , n + i ) | None -> None
let mem_name name ( id_set : Id_set . t ) : bool = Id_set . exists ( function ( _ , id_name ) -> name = id_name ) id_set
let rec size_forward pos ( x : regexp ) : int option = match x with | Empty | Chars ( _ , true ) | Tag _ -> Some pos | Chars ( _ , false ) -> Some ( pos + 1 ) | Seq ( r1 , r2 ) -> begin match size_forward pos r1 with | None -> None | Some pos -> size_forward pos r2 end | A...
let rec size_backward pos ( x : regexp ) = match x with | Empty | Chars ( _ , true ) | Tag _ -> Some pos | Chars ( _ , false ) -> Some ( pos - 1 ) | Seq ( r1 , r2 ) -> begin match size_backward pos r2 with | None -> None | Some pos -> size_backward pos r1 end | Alt ( r1 ,...
let opt_regexp all_vars char_vars optional_vars double_vars ( r : regexp ) : ( Id_set . elt * ident_info ) list * regexp * int = let env = Hashtbl . create 17 in let rec simple_forward pos r double_vars = match r with | Tag n -> if mem_name n . id double_vars then ( r , Some pos ) else be...
let encode_casedef ( regexps ( : concrete_regexp * ' a ) list ) = List . fold_left ( fun ( reg , actions , count , ntags ) ( expr , act ) -> let expr = remove_nested_as expr in let char_vars = find_chars expr in let opt_vars = find_optional expr in let ( double_vars , all_vars )...
let reset ( ) = chars := [ ] ; chars_count := 0
type ' a lexer_entry = { lex_regexp : regexp ; lex_mem_tags : int ; lex_actions : ( int * t_env * ' a ) list }
let encode_lexdef ( def ' : a entry list ) : Fcset . t array * ( ' a lexer_entry * bool ) list = reset ( ) ; let entry_list = List . map ( fun { shortest ; clauses } -> let ( lex_regexp , actions , _ , lex_mem_tags ) = encode_casedef clauses in ( { lex_regexp ; lex...
let encode_single_lexdef ( def ' : a entry ) : Fcset . t array * ( ' a lexer_entry * bool ) = reset ( ) ; let result = match def with { shortest ; clauses } -> let ( lex_regexp , actions , _ , lex_mem_tags ) = encode_casedef clauses in ( { lex_regexp ; lex_mem_tags ; ...
module Table = Map . Make ( String )
module Namespace = struct type t = string Table . t let empty : t = Table . empty let translate ~ ocaml ~ coq = Table . add ocaml coq let preserve ocaml = translate ~ ocaml ~ coq : ocaml let find ~ ocaml : from = Table . find_opt from end
type t = Namespace . t Table . t
let qualname prefix suffix = prefix ^ " . " ^ suffix
let rec translate ( ? rev_namespace = [ ] ) ~ ocaml ~ coq t = let prefix = String . concat " . " rev_namespace in let t = Table . update prefix ( fun ns -> Option . value ~ default : Namespace . empty ns |> Namespace . translate ~ ocaml ~ coq |> Option . some ) t in match rev...
let preserve ( ? rev_namespace = [ ] ) ocaml = translate ~ rev_namespace ~ ocaml ~ coq : ocaml
let rec find ( ? rev_namespace = [ ] ) ~ ocaml t = let prefix = String . concat " . " rev_namespace in match Option . bind ( Table . find_opt prefix t ) ( Namespace . find ~ ocaml ) with | Some coq -> Some coq | None -> ( match rev_namespace with | _ :: rev_namespace -> fin...
let types_table = let rec ( -- ) x y = if x < y then x :: ( x + 1 -- y ) else [ y ] in let translate_tuples l ns = List . fold_left ( fun ns x -> Namespace . translate ~ ocaml ( : Format . sprintf " Coq_coqffi . Shim . tupl % d " x ) ~ coq ( : Format . sprintf " tupl...
type token = | Range of Ckappa_sig . c_site_name * Ckappa_sig . c_state list | Equiv of ( Ckappa_sig . c_site_name * Ckappa_sig . c_state ) * ( Ckappa_sig . c_site_name * Ckappa_sig . c_state ) | Imply of ( Ckappa_sig . c_site_name * Ckappa_sig . c_state ) * ( Ckappa_sig . c_si...
type rename_sites = ( Remanent_parameters_sig . parameters -> Exception . method_handler -> Ckappa_sig . Site_map_and_set . Map . elt -> Exception . method_handler * Ckappa_sig . Site_map_and_set . Map . elt )
let non_relational parameters handler error mvbdu = let error , handler , list = Ckappa_sig . Views_bdu . mvbdu_cartesian_abstraction parameters handler error mvbdu in let error , handler , mvbdu_true = Ckappa_sig . Views_bdu . mvbdu_true parameters handler error in let error , handler , recompos...
let try_partitioning parameters handler error ( rename_site_inverse : rename_sites ) mvbdu = let error , handler , mvbdu_true = Ckappa_sig . Views_bdu . mvbdu_true parameters handler error in let error , handler , var_hconsed_list = Ckappa_sig . Views_bdu . variables_list_of_mvbdu parameters han...
let translate parameters handler error ( rename_site_inverse : rename_sites ) mvbdu = let error , handler , list = Ckappa_sig . Views_bdu . extensional_of_mvbdu parameters handler error mvbdu in let error , list = List . fold_left ( fun ( error , list ) elt1 -> let error , elt1 = List . ...
let rec print ? beginning_of_sentence ( : beggining = true ) ? prompt_agent_type ( : prompt_agent_type = true ) ? html_mode ( : html_mode = false ) ~ show_dep_with_dimmension_higher_than : dim_min parameters handler_kappa error agent_string agent_type agent_id translation t = let tab = if html_...
let rec convert_views_internal_constraints_list_aux ~ show_dep_with_dimmension_higher_than : dim_min parameters handler_kappa error agent_string agent_type agent_id translation t current_list = let error , current_list = match translation with | Range ( site_type , state_list ) -> begin if dim_min <= 1 ...
let convert_views_internal_constraints_list ~ show_dep_with_dimmension_higher_than : dim_min parameters handler_kappa error agent_string agent_type translation current_list = let t = Site_graphs . KaSa_site_graph . empty in let error ' , agent_id , t = Site_graphs . KaSa_site_graph . add_agent parame...
let print ? beginning_of_sentence ( : beggining = true ) ? prompt_agent_type ( : prompt_agent_type = true ) ? html_mode ( : html_mode = false ) ~ show_dep_with_dimmension_higher_than : dim_min parameters handler_kappa error agent_string agent_type translation = let t = Site_graphs . KaSa_site...
exception Internal_error of [ ` Cannot_parse of exn | ` Ast_changed | ` Doc_comment of Normalize . docstring_error list | ` Comment | ` Comment_dropped of Cmt . t list | ` Warning50 of ( Location . t * Warnings . t ) list ] * ( string * Sexp . t ) list
let internal_error msg kvs = raise ( Internal_error ( msg , kvs ) )
type error = | Invalid_source of { exn : exn } | Unstable of { iteration : int ; prev : string ; next : string } | Ocamlformat_bug of { exn : exn } | User_error of string
let ellipsis n msg = let msg = String . strip msg in if n > 0 && String . length msg > ( n * 2 ) + 10 then Format . sprintf " % s . . . % s " ( String . prefix msg n ) ( String . suffix msg n ) else msg
let ellipsis_cmt = ellipsis 50
let with_file input_name output_file suf ext f = let dir = match output_file with | Some filename -> Filename . dirname filename | None -> Filename . get_temp_dir_name ( ) in let base = Filename . remove_extension ( Filename . basename input_name ) in let tmp = Filename . concat dir ( base ...
let dump_ast ~ input_name ? output_file ~ suffix fmt = let ext = " . ast " in with_file input_name output_file suffix ext ( fun oc -> fmt ( Format . formatter_of_out_channel oc ) )
let dump_formatted ~ input_name ? output_file ~ suffix fmted = let ext = Filename . extension input_name in with_file input_name output_file suffix ext ( fun oc -> Out_channel . output_string oc fmted )
let print_error ~ fmt ~ exe ~ debug ~ quiet ~ input_name error = match error with | Invalid_source _ when quiet -> ( ) | Invalid_source { exn } -> ( let reason = match exn with | Syntaxerr . Error _ | Lexer . Error _ -> " ( syntax error ) " | Warning50 _ -> " ( misplaced do...
let check_all_locations fmt cmts_t = match Cmts . remaining_locs cmts_t with | [ ] -> ( ) | l -> let print l = Format . fprintf fmt " % a \ n " %! Location . print l in Format . fprintf fmt " Warning : Some locations have not been considered \ n " %! ; List . iter ~ f : print (...
let check_margin conf ~ filename ~ fmted = List . iteri ( String . split_lines fmted ) ~ f ( : fun i line -> if String . length line > conf . Conf . margin then Format . fprintf Format . err_formatter " Warning : % s :% i exceeds the margin \ n " %! filename i )
let with_optional_box_debug ~ box_debug k = if box_debug then Fmt . with_box_debug k else k
let with_buffer_formatter ~ buffer_size k = let buffer = Buffer . create buffer_size in let fs = Format_ . formatter_of_buffer buffer in Fmt . eval fs k ; Format_ . pp_print_flush fs ( ) ; if Buffer . length buffer > 0 then Format_ . pp_print_newline fs ( ) ; Buffer . contents buffer
let equal fragment ~ ignore_doc_comments c a b = Normalize . equal fragment ~ ignore_doc_comments c a . Parse_with_comments . ast b . Parse_with_comments . ast
let normalize fragment c { Parse_with_comments . ast ; _ } = Normalize . normalize fragment c ast
let recover ( type a ) : a Traverse . fragment -> _ = function | Traverse . Structure -> Parse_wyc . Make_parsable . structure | Traverse . Signature -> Parse_wyc . Make_parsable . signature | Traverse . Use_file -> Parse_wyc . Make_parsable . use_file
let format fragment ? output_file ~ input_name ~ prev_source ~ parsed conf opts = let open Result . Monad_infix in let dump_ast ~ suffix ast = if opts . Conf . debug then Some ( dump_ast ~ input_name ? output_file ~ suffix ( fun fmt -> Migrate_ast . Printast . fragment fragment fmt ast ) ) ...
let parse_result fragment conf ( opts : Conf . opts ) ~ source ~ input_name = match parse fragment conf ~ source with | exception exn -> if opts . format_invalid_files then ( match parse fragment conf ~ source ( : recover fragment source ) with | exception exn -> Error ( Invalid_source { ex...
let parse_and_format fragment ? output_file ~ input_name ~ source conf opts = Ocaml_common . Location . input_name := input_name ; let open Result . Monad_infix in parse_result fragment conf opts ~ source ~ input_name >>= fun parsed -> format fragment ? output_file ~ input_name ~ prev_source : sour...
module Config = struct type config = { generator_config : Michelson_generation . generator_config ; michelson_terms_file : string option ; } let default_config = { generator_config = Michelson_generation . default_generator_config ; michelson_terms_file = None ; } let config_encoding = let o...
module Default_boilerplate = struct type workload = Translator_workload . t let workload_encoding = Translator_workload . encoding let workload_to_vector = Translator_workload . workload_to_sparse_vec let tags = [ Tags . translator ] let make_models t_kind code_or_data = [ ( " gas_translator_mod...
type phase = Workload_production | In_protocol | Global
type error_kind = | Global_error of { benchmark_name : string ; workload : Tezos_base . TzPervasives . tztrace ; } | Bad_data of { benchmark_name : string ; micheline : Alpha_context . Script . expr ; expected_type : Alpha_context . Script . expr ; phase : phase ; } | Bad_code ...
let pp_phase fmtr ( phase : phase ) = match phase with | Workload_production -> Format . fprintf fmtr " workload production " | In_protocol -> Format . fprintf fmtr " in protocol " | Global -> Format . fprintf fmtr " global "
let report_michelson_errors fmtr errs = Michelson_v1_error_reporter . report_errors ~ details : true ~ show_source : true fmtr errs