text
stringlengths 12
786k
|
---|
module List = struct include List let find_opt p xs = try Some ( find p xs ) with Not_found -> None end |
let bracket ~ init ~ fini f = let a = init ( ) in match f a with | exception exn -> fini a ; raise exn | res -> fini a ; res |
let pp_xd_gen getu8 len ( ? address = true ) ( ? ascii = false ) ( ? w = 16 ) ( ) ppf = let open Format in let rec blocks f off xs = let n = len xs - off in f off ( min n w ) xs ; if n > w then blocks f ( off + w ) xs in let line ppf off n xs = let iter f = for i = 0 to n - 1 do f i ( off + i |> getu8 xs ) done and spaces n = for _ = 1 to n do pp_print_char ppf ' ' done in if off > 0 then pp_print_cut ppf ( ) ; if address then fprintf ppf " % 04x : " off ; iter ( fun i u8 -> pp_print_string ppf ( if i > 0 then if i mod 8 = 0 then " " else " " else " " ) ; fprintf ppf " % 02x " u8 ) ; if ascii then let llen x = x * 2 + ( x - 1 |> max 0 ) + ( x - 1 ) / 8 in spaces ( 2 + llen w - llen n ) ; iter ( fun _ u8 -> fprintf ppf " % c " ( if u8 >= 0x20 && u8 < 0x7f then Char . chr u8 else ' . ' ) ) ; spaces ( w - n ) in fprintf ppf " [ @< v >% a ] " @ ( fun ppf -> blocks ( line ppf ) 0 ) |
let xd = Cstruct . ( pp_xd_gen get_uint8 len ) |
let xdb = Bytes . ( pp_xd_gen ( fun b i -> Char . code ( get b i ) ) length ) |
module Boot = struct exception Unseeded_generator end |
type action = | Insert of action_insert | Delete of action_delete | Begin_block of string | End_block of string | Func of ( ( unit -> bool ) * ( unit -> bool ) ) mutable pos : int ; mutable length : int ; } mutable text : string ; mutable where : int ; mutable bounds : int * int ; mutable prev : int ; } let undos = Stack . create ( ) in let redos = Stack . create ( ) in object ( self ) val undo = new signal ( ) val redo = new signal ( ) val can_undo_changed = new signal ( ) val can_redo_changed = new signal ( ) val text_buffer = buffer # as_buffer val mutable current_block_name = " " val mutable current_stack = undos val mutable pending_action : action option = None ; val mutable enabled = false val mutable sign_insert = buffer # connect # insert_text ~ callback ( : fun _ _ -> ( ) ) val mutable sign_delete = buffer # connect # delete_range ~ callback ( : fun ~ start : _ ~ stop : _ -> ( ) ) initializer GtkSignal . disconnect text_buffer sign_insert ; GtkSignal . disconnect text_buffer sign_delete ; ignore ( buffer # connect # begin_user_action ~ callback : begin fun ( ) -> if enabled then begin current_stack <- undos ; Stack . clear redos ; can_redo_changed # call self # can_redo ; end end ) ; sign_insert <- buffer # connect # insert_text ~ callback : begin fun start text -> let length = Glib . Utf8 . length text in try let insert_action = match [ @ warning " - 4 " ] pending_action with | Some ( ( Insert a ) as pending ) when start # equal ( buffer # get_iter ( ` OFFSET a . pos ) ) -> if length > 1 || text = " \ n " then begin self # push pending ( a . pos , a . pos ) ; let pos = start # offset + length in self # push ( Insert { pos = pos ; length = length } ) ( pos , pos ) ; pending_action <- None ; raise Exit end else a | Some ( ( Insert a ) as pending ) -> self # push pending ( a . pos , a . pos ) ; { pos = start # offset ; length = 0 } | Some ( ( Delete a ) as pending ) -> self # push pending ( a . where , a . where ) ; { pos = start # offset ; length = 0 } | None -> { pos = start # offset ; length = 0 } | _ -> assert false in insert_action . pos <- start # offset + length ; insert_action . length <- insert_action . length + length ; pending_action <- Some ( Insert insert_action ) ; if current_stack == undos then ( can_undo_changed # call self # can_undo ) else ( can_redo_changed # call self # can_redo ) ; with Exit -> ( ) end ; sign_delete <- buffer # connect # delete_range ~ callback : begin fun ~ start ~ stop -> let delete_action = match [ @ warning " - 4 " ] pending_action with | Some ( ( Insert a ) as pending ) -> self # push pending ( a . pos , a . pos ) ; { text " " ; = where = start # offset ; bounds ( = 0 , 0 ) ; prev = start # offset } | Some ( ( Delete action ) as pending ) -> let prev = buffer # get_iter ( ` OFFSET action . prev ) in if not ( start # equal prev ) && not ( stop # equal prev ) then begin self # push pending ( action . where , action . where ) ; { text " " ; = where = start # offset ; bounds ( = 0 , 0 ) ; prev = start # offset } end else begin action . prev <- start # offset ; action end | None -> { text " " ; = where = start # offset ; bounds ( = 0 , 0 ) ; prev = start # offset } | _ -> assert false in pending_action <- Some ( Delete delete_action ) ; if current_stack == undos then ( can_undo_changed # call self # can_undo ) else ( can_redo_changed # call self # can_redo ) ; let b1 , b2 = buffer # selection_bounds in if b1 # equal start && b2 # equal stop then begin let text = buffer # get_text ~ start ~ stop ( ) in let length = Glib . Utf8 . length text in delete_action . text <- text ; delete_action . bounds <- ( length , 0 ) ; self # push ( Delete delete_action ) ( start # offset , start # offset ) ; end else if ( start # equal ( buffer # get_iter ` INSERT ) ) then begin delete_action . text <- delete_action . text ^ ( buffer # get_text ~ start ~ stop ( ) ) ; delete_action . bounds <- ( let b = fst delete_action . bounds in ( b , b ) ) ; end else begin let text = buffer # get_text ~ start ~ stop ( ) in let length = Glib . Utf8 . length text in delete_action . text <- text ^ delete_action . text ; let b1 = ( fst delete_action . bounds ) + length in let b2 = if length = 1 then b1 else 0 in delete_action . bounds <- ( b1 , b2 ) ; delete_action . where <- start # offset ; end ; end ; ignore ( self # connect # undo ~ callback ( : fun ~ name : _ -> self # pop undos ) ) ; ignore ( self # connect # redo ~ callback ( : fun ~ name : _ -> self # pop redos ) ) ; self # disable ( ) ; method private push pending ( b1 , b2 ) = Stack . push ( pending , b1 , b2 ) current_stack ; pending_action <- None ; if current_stack == undos then ( can_undo_changed # call self # can_undo ) else ( can_redo_changed # call self # can_redo ) ; method private push_pending_action ( ) = match [ @ warning " - 4 " ] pending_action with | None -> ( ) | Some ( ( Insert a ) as pending ) -> self # push pending ( a . pos , a . pos ) | Some ( ( Delete a ) as pending ) -> self # push pending ( a . where , a . where ) | _ -> assert false method private pop ( ? in_block = false ) stack = let ( action , b1 , b2 ) = Stack . pop stack in current_stack <- ( if stack == undos then redos else undos ) ; begin match action with | Insert action -> let stop = buffer # get_iter ( ` OFFSET action . pos ) in buffer # delete ~ start ( : stop # backward_chars action . length ) ~ stop ; if in_block then ( self # pop ~ in_block stack ) try begin match Stack . top stack with | Insert _ , _ , _ -> self # pop stack | _ -> ( ) end ; with Stack . Empty -> ( ) end ) * | Delete action -> let iter = buffer # get_iter ( ` OFFSET b1 ) in buffer # insert ~ iter action . text ; let where = buffer # get_iter ( ` OFFSET b1 ) in if stack == undos then begin let b1 , b2 = action . bounds in buffer # select_range ( where # forward_chars b1 ) ( where # forward_chars b2 ) ; end ; if in_block then ( self # pop ~ in_block stack ) | End_block name -> self # push ( Begin_block name ) ( b1 , b2 ) ; self # pop ~ in_block : true stack ; | Begin_block name -> self # push_pending_action ( ) ; self # push ( End_block name ) ( b1 , b2 ) ; buffer # select_range ( buffer # get_iter ( ` OFFSET b1 ) ) ( buffer # get_iter ( ` OFFSET b2 ) ) ; ( assert in_block ) ; | Func ( f , g ) -> buffer # select_range ( buffer # get_iter ( ` OFFSET b1 ) ) ( buffer # get_iter ( ` OFFSET b2 ) ) ; self # disable ( ) ; let action = if stack == undos then ( ignore ( g ( ) ) ; ( Func ( g , f ) ) ) else ( ignore ( f ( ) ) ; ( Func ( f , g ) ) ) in self # push action ( ( buffer # get_iter ` INSERT ) # offset , ( buffer # get_iter ` SEL_BOUND ) # offset ) ; self # enable ( ) ; end ; self # push_pending_action ( ) ; current_stack <- stack ; can_undo_changed # call self # can_undo ; can_redo_changed # call self # can_redo ; method private revert stack = if enabled then begin self # push_pending_action ( ) ; if current_block_name <> " " then ( self # end_block ( ) ) ; if Stack . is_empty stack then begin false end else begin let ins = ( buffer # get_iter ` INSERT ) in let sel = ( buffer # get_iter ` SEL_BOUND ) in let block_name , b1 , b2 = match [ @ warning " - 4 " ] Stack . top stack with | ( Begin_block name ) , b1 , b2 -> name , b1 , b2 | ( End_block name ) , b1 , b2 -> name , b1 , b2 | _ , b1 , b2 -> " " , b1 , b2 in let b1 , b2 = ( buffer # get_iter ( ` OFFSET b1 ) ) , ( buffer # get_iter ( ` OFFSET b2 ) ) in if ins # equal b1 && sel # equal b2 then begin if stack == undos then ( undo # call block_name ) else ( redo # call block_name ) ; true end else begin buffer # select_range b1 b2 ; false end ; end ; end else false method begin_block ~ name = if enabled && current_block_name = " " then self # push_pending_action ( ) ; buffer # begin_user_action ( ) ; current_block_name <- name ; self # push ( Begin_block name ) ( ( buffer # get_iter ` INSERT ) # offset , ( buffer # get_iter ` SEL_BOUND ) # offset ) ; method end_block ( ) = if enabled && current_block_name <> " " then self # push_pending_action ( ) ; begin match [ @ warning " - 4 " ] Stack . top current_stack with | ( Begin_block name ) , _ , _ when name = current_block_name -> ignore ( Stack . pop current_stack ) | _ -> self # push ( End_block current_block_name ) ( ( buffer # get_iter ` INSERT ) # offset , ( buffer # get_iter ` SEL_BOUND ) # offset ) ; end ; current_block_name <- " " ; buffer # end_user_action ( ) ; method func f ~ inverse = if enabled then self # push_pending_action ( ) ; buffer # begin_user_action ( ) ; self # disable ( ) ; if f ( ) then begin self # push ( Func ( f , inverse ) ) ( ( buffer # get_iter ` INSERT ) # offset , ( buffer # get_iter ` SEL_BOUND ) # offset ) ; end ; self # enable ( ) ; buffer # end_user_action ( ) ; method enable ( ) = enabled <- true ; GtkSignal . handler_unblock text_buffer sign_delete ; GtkSignal . handler_unblock text_buffer sign_insert ; method disable ( ) = self # push_pending_action ( ) ; enabled <- false ; GtkSignal . handler_block text_buffer sign_delete ; GtkSignal . handler_block text_buffer sign_insert ; method is_enabled = enabled method can_undo = ( not ( Stack . is_empty undos ) ) || ( match pending_action with Some _ when current_stack == undos -> true | _ -> false ) method can_redo = ( not ( Stack . is_empty redos ) ) || ( match pending_action with Some _ when current_stack == redos -> true | _ -> false ) method redo ( ) = self # revert redos method undo ( ) = self # revert undos method length = Stack . length undos , Stack . length redos method connect = new manager_signals ~ undo ~ redo ~ can_undo_changed ~ can_redo_changed end object inherit ml_signals [ undo # disconnect ; redo # disconnect ; can_undo_changed # disconnect ; can_redo_changed # disconnect ] method can_undo_changed ~ callback = can_undo_changed # connect ~ after ~ callback method can_redo_changed ~ callback = can_redo_changed # connect ~ after ~ callback method undo ~ callback = undo # connect ~ after ~ callback ( : fun name -> callback ~ name ) method redo ~ callback = redo # connect ~ after ~ callback ( : fun name -> callback ~ name ) end |
let title = " Built - in signer using raw unencrypted keys . " |
let description = " Please DO NOT USE this signer outside of test environments . \ n \ Valid secret key URIs are of the form \ n \ \ - unencrypted :< key >\ n \ where < key > is the secret key in Base58 . \ n \ Valid public key URIs are of the form \ n \ \ - unencrypted :< public_key >\ n \ where < public_key > is the public key in Base58 . " |
let secret_key sk_uri = Lwt . return ( Signature . Secret_key . of_b58check ( Uri . path ( sk_uri : sk_uri :> Uri . t ) ) ) |
let make_sk sk = Client_keys . make_sk_uri ( Uri . make ~ scheme ~ path ( : Signature . Secret_key . to_b58check sk ) ( ) ) |
let make_sapling_key sk = let path = Base58 . simple_encode Tezos_sapling . Core . Wallet . Spending_key . b58check_encoding sk in Client_keys . make_sapling_uri ( Uri . make ~ scheme ~ path ( ) ) |
let public_key pk_uri = Lwt . return ( Signature . Public_key . of_b58check ( Uri . path ( pk_uri : pk_uri :> Uri . t ) ) ) |
let make_pk pk = Client_keys . make_pk_uri ( Uri . make ~ scheme ~ path ( : Signature . Public_key . to_b58check pk ) ( ) ) |
let neuterize sk_uri = secret_key sk_uri >>=? fun sk -> make_pk ( Signature . Secret_key . to_public_key sk ) >>?= return |
let public_key_hash pk_uri = public_key pk_uri >>=? fun pk -> return ( Signature . Public_key . hash pk , Some pk ) |
let import_secret_key ~ io : _ = public_key_hash |
let sign ? watermark sk_uri buf = secret_key sk_uri >>=? fun sk -> return ( Signature . sign ? watermark sk buf ) |
let deterministic_nonce sk_uri buf = secret_key sk_uri >>=? fun sk -> return ( Signature . deterministic_nonce sk buf ) |
let deterministic_nonce_hash sk_uri buf = secret_key sk_uri >>=? fun sk -> return ( Signature . deterministic_nonce_hash sk buf ) |
let supports_deterministic_nonces _ = return_true |
type any = Any : ' a -> any |
type any = Any : ' a -> any } ] | |
let Any x = Any ( ) ^^^^^ but this pattern introduces the existential type $ Any_ ' a . } ] | |
let ( ) = let Any x = Any ( ) and ( ) = ( ) in ( ) ^^^^^ but this pattern introduces the existential type $ Any_ ' a . } ] | |
let ( ) = let rec Any x = Any ( ) in ( ) ^^^^^ but this pattern introduces the existential type $ Any_ ' a . } ] | |
let ( ) = let [ @ attribute ] Any x = Any ( ) in ( ) ^^^^^ but this pattern introduces the existential type $ Any_ ' a . } ] | ^^^^^^^ but this pattern introduces the existential type $ Any_ ' a . } ] | ^^^^^^^ but this pattern introduces the existential type $ Any_ ' a . } ] | |
type other = Any : _ -> other |
type other = Any : ' a -> other } ] | |
let Any x = Any ( ) ^^^^^ but the constructor Any introduces existential types . } ] | ^^^^^^ but the constructor Any introduces existential types . } ] | |
let ( ) = let Any x = Any ( ) and ( ) = ( ) in ( ) ^^^^^ but the constructor Any introduces existential types . } ] | |
let ( ) = let rec Any x = Any ( ) in ( ) ^^^^^ but the constructor Any introduces existential types . } ] | |
let ( ) = let [ @ attribute ] Any x = Any ( ) in ( ) ^^^^^ but the constructor Any introduces existential types . } ] | ^^^^^^^ but the constructor Any introduces existential types . } ] | ^^^^^^^ but the constructor Any introduces existential types . } ] | ^^^^^^ but the constructor Any introduces existential types . } ] | |
module type Type = sig type text open OOChannel class nfd : UChar . t # obj_output_channel -> [ UChar . t ] t obj_output_channel class nfc : UChar . t # obj_output_channel -> [ UChar . t ] t obj_output_channel class nfkd : UChar . t # obj_output_channel -> [ UChar . t ] t obj_output_channel class nfkc : UChar . t # obj_output_channel -> [ UChar . t ] t obj_output_channel val nfd : text -> text val nfkd : text -> text val nfc : text -> text val nfkc : text -> text module NFCBuf : sig type buf val create : int -> buf val contents : buf -> text val clear : buf -> unit val reset : buf -> unit val add_char : buf -> UChar . t -> unit val add_string : buf -> text -> unit val add_buffer : buf -> buf -> unit end val nfc_append : text -> text -> text val put_nfd : XString . t -> text -> unit val put_nfkd : XString . t -> text -> unit val put_nfc : XString . t -> text -> unit val put_nfkc : XString . t -> text -> unit type index val nfd_inc : text -> index -> ( [ ` Inc of UChar . t list * index * ' a lazy_t ] as ' a ) ' a val canon_compare : text -> text -> int val nfd_decompose : UChar . t -> UChar . t list val nfkd_decompose : UChar . t -> UChar . t list end |
module Make ( Config : ConfigInt . Type ) Type ( Text : UnicodeString . Type ) Type = struct module UInfo = UCharInfo . Make ( MakeConfig ) MakeConfig let null = UChar . chr_of_uint 0 let decomposition_tbl = UInfo . load_decomposition_tbl ( ) let decomposition u = UCharTbl . get decomposition_tbl u let composition_exclusion_tbl = UInfo . load_composition_exclusion_tbl ( ) let composition_exclusion u = UCharTbl . Bool . get composition_exclusion_tbl u let composition_tbl = UInfo . load_composition_tbl ( ) let composition u = UCharTbl . get composition_tbl u let rec add_list x = function [ ] -> ( ) | u :: r -> XString . add_char x u ; add_list x r let shiftright x i j = for k = j downto i do XString . set x ( k + 1 ) 1 ( XString . get x k ) k done let rotate x i j = let u = XString . get x j in shiftright x i ( j - 1 ) 1 ; XString . set x i u let blit x i x ' i ' len = for k = 0 to len - 1 do XString . set x ' ( i ' + k ) k ( XString . get x ( i + k ) k ) k ; done let nfd u = match decomposition u with ` HangulSyllable -> Hangul . decompose u | ` Composite ( ` Canon , d ) d -> d | _ -> [ u ] u let nfd_decompose = nfd let rec nfkd u = match decomposition u with ` HangulSyllable -> Hangul . decompose u | ` Composite ( _ , d ) d -> List . fold_right ( fun u a -> ( nfkd u ) u @ a ) a d [ ] | ` Canonform -> [ u ] u let nfkd_decompose = nfkd let canon_decompose_uchar x u = match decomposition u with ` HangulSyllable -> Hangul . add_decomposition x u | ` Composite ( ` Canon , d ) d -> add_list x d | _ -> XString . add_char x u class canon_decompose ( c_out : UChar . t OOChannel . obj_output_channel ) obj_output_channel = object method put u = List . iter c_out # put ( nfd u ) u method close_out = c_out # close_out method flush ( ) = c_out # flush ( ) end let rec kompat_decompose_uchar x u = match decomposition u with ` Composite ( _ , d ) d -> List . iter ( kompat_decompose_uchar x ) x d | _ -> Hangul . add_decomposition x u class kompat_decompose c_out : [ UChar . t ] t OOChannel . obj_output_channel = object method put u = List . iter c_out # put ( nfkd u ) u method close_out = c_out # close_out method flush ( ) = c_out # flush ( ) end let canon_reorder x = let chead = ref 0 in let pos = ref 0 in for i = 0 to XString . length x - 1 do let u = XString . get x i in let c = UInfo . combined_class u in if c = 0 then chead := i else begin pos := i - 1 ; while ! pos >= ! chead && UInfo . combined_class ( XString . get x ! pos ) pos > c do decr pos done ; rotate x ( ! pos + 1 ) 1 i end done class canon_reorder c_out : [ UChar . t ] t OOChannel . obj_output_channel = object ( self ) self val mutable sq = [ ] method private out_buf = let sq ' = List . stable_sort ( fun ( c1 , _ ) _ ( c2 , _ ) _ -> c1 - c2 ) c2 sq in List . iter ( fun ( _ , u ) u -> c_out # put u ) u sq ' ; sq <- [ ] method put u = let c = UInfo . combined_class u in if c = 0 then ( if sq <> [ ] then self # out_buf ; c_out # put u ) u else sq <- ( c , u ) u :: sq method close_out ( ) = self # out_buf ; c_out # close_out ( ) method flush ( ) = if sq <> [ ] then failwith " uNF . canon_reorder # flush : \ Cannot flush the entire buffer " ; c_out # flush ( ) end let rec look_composition u1 = function [ ] -> None | ( u , u ' ) u ' :: _ when u = u1 -> if composition_exclusion u ' || UInfo . combined_class u ' <> 0 then None else Some u ' | _ :: rest -> look_composition u1 rest let rec canon_compose_loop x i j x ' k c ' = if j >= XString . length x then begin blit x i x ' ( k + 1 ) 1 ( XString . length x - i ) i ; k + max ( XString . length x - i ) i 0 end else let u = XString . get x j in let c = UInfo . combined_class u in let b = if j = i || c ' <> c then match look_composition u ( composition ( XString . get x ' k ) k ) k with None -> true | Some u ' -> XString . set x ' k u ' ; shiftright x i ( j - 1 ) 1 ; false else true in if b && c = 0 then begin blit x i x ' ( k + 1 ) 1 ( j - i + 1 ) 1 ; canon_compose_loop x ( j + 1 ) 1 ( j + 1 ) 1 x ' ( k + 1 + j - i ) i 0 end else let i ' = if b then i else i + 1 in let c ' = if b then c else c ' in canon_compose_loop x i ' ( j + 1 ) 1 x ' k c ' let canon_compose x ' x = if XString . length x = 0 then ( ) else let pos = ref 0 in while ! pos < XString . length x && UInfo . combined_class ( XString . get x ! pos ) pos <> 0 do incr pos done ; blit x 0 x ' 0 ! pos ; if ! pos < XString . length x then begin XString . set x ' ! pos ( XString . get x ! pos ) pos ; pos := canon_compose_loop x ( ! pos + 1 ) 1 ( ! pos + 1 ) 1 x ' ! pos 0 end else ( ) ; XString . shrink x ' ( ! pos + 1 ) 1 class canon_compose c_out : [ UChar . t ] t OOChannel . obj_output_channel = object ( self ) self val mutable has_strt = false val mutable strt = null val mutable cmp_cnd = [ ] val mutable lst_cc = - 1 val sq = Queue . create ( ) method private set_strt u = if has_strt then c_out # put strt ; Queue . iter c_out # put sq ; strt <- u ; has_strt <- true ; cmp_cnd <- composition u ; lst_cc <- - 1 ; Queue . clear sq method private output_buffer ( ) = if has_strt then c_out # put strt ; Queue . iter c_out # put sq ; method put u = let c = UInfo . combined_class u in if not has_strt then if c = 0 then self # set_strt u else c_out # put u else if c = lst_cc then Queue . add u sq else match look_composition u cmp_cnd with Some u ' -> strt <- u ' | None -> if c = 0 then self # set_strt u else begin Queue . add u sq ; lst_cc <- c end method close_out ( ) = self # output_buffer ( ) ; c_out # close_out ( ) method flush ( ) = self # output_buffer ( ) ; c_out # flush ( ) end class nfd c_out = let c = new canon_reorder c_out in object inherit canon_decompose c end class nfc c_out = let c = new canon_compose c_out in let c = new canon_reorder c in object inherit canon_decompose c method ! flush = c_out # flush end class nfkd c_out = let c = new canon_reorder c_out in object inherit kompat_decompose c method ! flush = c_out # flush end class nfkc c_out = let c = new canon_compose c_out in let c = new canon_reorder c in object inherit kompat_decompose c method ! flush = c_out # flush end type inc = [ ` Inc of UChar . t list * Text . index * ' a lazy_t ] lazy_t as ' a let rec inc_end i = ` Inc ( [ ] , i , lazy ( inc_end i ) i ) i let rec inc_canon_decompose t i : inc = if Text . out_of_range t i then inc_end i else let i ' = Text . next t i in ` Inc ( nfd ( Text . look t i ) i , i ' , lazy ( inc_canon_decompose t i ' ) i ' ) i ' let rec canon_insert_list ( ( _ , c ) c as x ) x a = match a with [ ] -> [ x ] x | ( _ , c ' ) c ' as y :: rest -> if c ' <= c then y :: canon_insert_list x rest else x :: a let rec split1_list = function [ ] -> [ ] | ( x , _ ) _ :: rest -> x :: split1_list rest let canon_sort_list sq = let rec loop a = function [ ] -> split1_list a | ( u , 0 ) 0 :: rest -> ( split1_list a ) a @ ( u :: ( loop [ ] rest ) rest ) rest | ( _ , _ ) _ as x :: rest -> loop ( canon_insert_list x a ) a rest in loop [ ] sq let rec read_combined_class = function [ ] -> [ ] | u :: rest -> ( u , UInfo . combined_class u ) u :: read_combined_class rest let inc_reorder f t i = let ` Inc ( us , i ' , f ) f = f t i in let rec loop ( f : inc Lazy . t ) t a i = let ` Inc ( us , i ' , f ) f = Lazy . force f in let a ' = read_combined_class us in match a ' with [ ] -> ` Inc ( canon_sort_list a , i , lazy ( inc_end i ) i ) i | ( _ , 0 ) 0 :: _ -> ` Inc ( canon_sort_list a , i , lazy ( loop f a ' i ' ) i ' ) i ' | _ -> loop f ( a @ a ' ) a ' i ' in loop f ( read_combined_class us ) us i ' let nfd_inc t i = inc_reorder inc_canon_decompose t i let canon_compare t1 t2 = let ` Inc ( Incus1 , _ , f1 ) f1 = nfd_inc t1 ( Text . nth t1 0 ) 0 in let ` Inc ( Incus2 , _ , f2 ) f2 = nfd_inc t2 ( Text . nth t2 0 ) 0 in let rec loop us1 us2 f1 f2 = match us1 , us2 with [ ] , [ ] -> 0 | [ ] , _ -> ~- 1 | _ , [ ] -> 1 | u1 :: r1 , u2 :: r2 -> let sgn = UChar . compare u1 u2 in if sgn <> 0 then sgn else let us1 , f1 = if r1 = [ ] then let ` Inc ( us1 , _ , f1 ) f1 = Lazy . force f1 in ( us1 , f1 ) f1 else ( r1 , f1 ) f1 in let us2 , f2 = if r2 = [ ] then let ` Inc ( us2 , _ , f2 ) f2 = Lazy . force f2 in ( us2 , f2 ) f2 else ( r2 , f2 ) f2 in loop us1 us2 f1 f2 in loop us1 us2 f1 f2 type text = Text . t type index = Text . index let canon_decompose x t = Text . iter ( canon_decompose_uchar x ) x t let kompat_decompose x t = Text . iter ( kompat_decompose_uchar x ) x t let text_of_xstring x = Text . init ( XString . length x ) x ( XString . get x ) x let nfd t = let x = XString . make 0 ( UChar . chr_of_uint 0 ) 0 in canon_decompose x t ; canon_reorder x ; text_of_xstring x let nfkd t = let x = XString . make 0 ( UChar . chr_of_uint 0 ) 0 in kompat_decompose x t ; canon_reorder x ; text_of_xstring x let nfc t = let x = XString . make 0 ( UChar . chr_of_uint 0 ) 0 in canon_decompose x t ; canon_reorder x ; canon_compose x x ; Hangul . compose x x ; text_of_xstring x let nfkc t = let x = XString . make 0 ( UChar . chr_of_uint 0 ) 0 in kompat_decompose x t ; canon_reorder x ; canon_compose x x ; Hangul . compose x x ; text_of_xstring x let put_nfd x t = XString . clear x ; canon_decompose x t ; canon_reorder x let put_nfkd x t = XString . clear x ; kompat_decompose x t ; canon_reorder x let put_nfc x t = XString . clear x ; canon_decompose x t ; canon_reorder x ; canon_compose x x ; Hangul . compose x x let put_nfkc x t = XString . clear x ; kompat_decompose x t ; canon_reorder x ; canon_compose x x ; Hangul . compose x x module NFCBuf = struct type buf = { mutable normalized : bool ; mutable buf : XString . t } t let create bufsize = { normalized = true ; buf = XString . make ~ bufsize 0 null } null let contents b = ( if not b . normalized then let buf = XString . make 0 null in XString . iter ( canon_decompose_uchar buf ) buf b . buf ; canon_reorder buf ; canon_compose buf buf ; b . buf <- buf ; b . normalized <- true ) true ; text_of_xstring b . buf let clear b = b . normalized <- true ; XString . clear b . buf let reset b = b . normalized <- true ; XString . reset b . buf let add_char b u = b . normalized <- false ; XString . add_char b . buf u let add_string b t = b . normalized <- false ; Text . iter ( XString . add_char b . buf ) buf t let add_buffer b1 b2 = b1 . normalized <- false ; XString . add_xstring b1 . buf b2 . buf end let nfc_append t1 t2 = let b = XString . make 0 null in canon_decompose b t1 ; canon_decompose b t2 ; canon_reorder b ; canon_compose b b ; text_of_xstring b end |
type t = ( Field . t , Field . t Scalar_challenge . t , Other_field . t Shifted_value . t , ( Field . t Scalar_challenge . t Bulletproof_challenge . t , Tock . Rounds . n ) Pickles_types . Vector . t , Field . t , Boolean . var ) Types . Step . Proof_state . Per_proof . In_circuit . t |
module Plonk_checks = struct include Plonk_checks include Plonk_checks . Make ( Shifted_value ) Shifted_value ( Plonk_checks . Scalars . Tock ) Tock end |
module Constant = struct type t = ( Challenge . Constant . t , Challenge . Constant . t Scalar_challenge . t , Tock . Field . t Shifted_value . t , ( Challenge . Constant . t Scalar_challenge . t Bulletproof_challenge . t , Tock . Rounds . n ) Vector . t , Digest . Constant . t , bool ) Types . Step . Proof_state . Per_proof . In_circuit . t let shift = Shifted_value . Shift . create ( module Tock . Field ) Field let dummy ( ) : t = let one_chal = Challenge . Constant . dummy in let open Ro in let alpha = scalar_chal ( ) in let beta = chal ( ) in let gamma = chal ( ) in let zeta = scalar_chal ( ) in let chals : _ Composition_types . Wrap . Proof_state . Deferred_values . Plonk . Minimal . t = { alpha = Common . Ipa . Wrap . endo_to_field alpha ; beta = Challenge . Constant . to_tock_field beta ; gamma = Challenge . Constant . to_tock_field gamma ; zeta = Common . Ipa . Wrap . endo_to_field zeta } in let evals = Tuple_lib . Double . map Dummy . evals_combined . evals ~ f ( : fun e -> e . evals ) evals in let env = Plonk_checks . scalars_env ( module Tock . Field ) Field ~ srs_length_log2 : Common . Max_degree . wrap_log2 ~ endo : Endo . Wrap_inner_curve . base ~ mds : Tock_field_sponge . params . mds ~ field_of_hex : ( Core_kernel . Fn . compose Tock . Field . of_bigint Kimchi_pasta . Pasta . Bigint256 . of_hex_string ) ~ domain : ( Plonk_checks . domain ( module Tock . Field ) Field ( wrap_domains ~ proofs_verified : 2 ) 2 . h ~ shifts : Common . tock_shifts ~ domain_generator : Tock . Field . domain_generator ) chals evals in { deferred_values = { plonk = { ( Plonk_checks . derive_plonk ( module Tock . Field ) Field ~ env ~ shift chals evals ) with alpha ; beta ; gamma ; zeta } ; combined_inner_product = Shifted_value ( tock ( ) ) ; xi = Scalar_challenge . create one_chal ; bulletproof_challenges = Dummy . Ipa . Wrap . challenges ; b = Shifted_value ( tock ( ) ) } ; should_finalize = false ; sponge_digest_before_evaluations = Digest . Constant . dummy } end |
let typ ~ wrap_rounds : ( t , Constant . t ) t Typ . t = Types . Step . Proof_state . Per_proof . In_circuit . spec wrap_rounds |> Spec . typ ( module Impl ) Impl ( Shifted_value . typ Other_field . typ ) typ |> Typ . transport ~ there : Types . Step . Proof_state . Per_proof . In_circuit . to_data ~ back : Types . Step . Proof_state . Per_proof . In_circuit . of_data |> Typ . transport_var ~ there : Types . Step . Proof_state . Per_proof . In_circuit . to_data ~ back : Types . Step . Proof_state . Per_proof . In_circuit . of_data |
let pp_pos ppf d = pp ppf " % d . % d ( :% d , % 06X ) " ( Uutf . decoder_line d ) ( Uutf . decoder_col d ) ( Uutf . decoder_count d ) ( Uutf . decoder_byte_count d ) |
let pp_malformed ppf bs = let l = String . length bs in pp ppf " [ @ malformed bytes [ ( " ; @ if l > 0 then pp ppf " % 02X " ( Char . code ( bs . [ 0 ] ) ) ; for i = 1 to l - 1 do pp ppf " @ % 02X " ( Char . code ( bs . [ i ] ) ) done ; pp ppf " ) ] ] " @@ |
let pp_dump_uchar ppf u = Format . fprintf ppf " U +% 04X " ( Uchar . to_int u ) |
let exec = Filename . basename Sys . executable_name |
let log f = Format . eprintf ( " % s : " ^^ f ^^ " " ) @? exec |
let input_malformed = ref false |
let log_malformed inf d bs = input_malformed := true ; log " % s :% a : % a . " @ inf pp_pos d pp_malformed bs |
let uchar_dump ppf = function |
let uchar_encoder enc = let enc = match enc with ` ISO_8859_1 | ` US_ASCII -> ` UTF_8 | # Uutf . encoding as enc -> enc in let e = Uutf . encoder enc ( ` Channel stdout ) in fun v -> ignore ( Uutf . encode e v ) |
let out_fun ascii oe = if ascii then uchar_dump Format . std_formatter else uchar_encoder oe |
let u_rep = ` Uchar Uutf . u_rep |
let id inf d first_dec out = let rec loop d = function | ` Uchar _ as v -> out v ; loop d ( Uutf . decode d ) | ` End as v -> out v | ` Malformed bs -> log_malformed inf d bs ; out u_rep ; loop d ( Uutf . decode d ) | ` Await -> assert false in if Uutf . decoder_removed_bom d then out ( ` Uchar Uutf . u_bom ) ; loop d first_dec |
let normalize nf inf d first_dec out = let n = Uunf . create nf in let rec add v = match Uunf . add n v with | ` Uchar cp as u -> out u ; add ` Await | ` Await | ` End -> ( ) in let rec loop d = function | ` Uchar _ as v -> add v ; loop d ( Uutf . decode d ) | ` End as v -> add v ; out ` End | ` Malformed bs -> log_malformed inf d bs ; add u_rep ; loop d ( Uutf . decode d ) | ` Await -> assert false in if Uutf . decoder_removed_bom d then add ( ` Uchar Uutf . u_bom ) ; loop d first_dec |
let trip nf inf enc ascii = try let ic = if inf = " " - then stdin else open_in inf in let d = Uutf . decoder ? encoding : enc ( ` Channel ic ) in let first_dec = Uutf . decode d in let out = out_fun ascii ( Uutf . decoder_encoding d ) in begin match nf with | None -> id inf d first_dec out | Some nf -> normalize nf inf d first_dec out end ; if inf <> " " - then close_in ic ; flush stdout ; with Sys_error e -> log " % s . " @ e ; exit 1 |
let unicode_version ( ) = Format . printf " % s . " @ Uunf . unicode_version |
let do_cmd cmd nf inf enc ascii = match cmd with |
let cmd = let doc = " Output supported Unicode version . " in let unicode_version = ` Unicode_version , Arg . info [ " unicode - version " ] ~ doc in Arg . ( value & vflag ` Trip [ unicode_version ] ) |
let nf = let docs = nf_doc in let doc = " Normalization Form D ( NFD ) , canonical decomposition . " in let nfd = Some ` NFD , Arg . info [ " nfd " ] ~ doc ~ docs in let doc = " Normalization Form C ( NFC ) , canonical decomposition followed by \ canonical composition . " in let nfc = Some ` NFC , Arg . info [ " nfc " ] ~ doc ~ docs in let doc = " Normalization form KD ( NFKD ) , compatibility decomposition . " in let nfkd = Some ` NFKD , Arg . info [ " nfkd " ] ~ doc ~ docs in let doc = " Normalization form KC ( NFKC ) , compatibility decomposition \ followed by canonical composition . " in let nfkc = Some ` NFKC , Arg . info [ " nfkc " ] ~ doc ~ docs in Arg . ( value & vflag None [ nfd ; nfc ; nfkd ; nfkc ] ) |
let file = let doc = " The input file . Reads from stdin if unspecified . " in Arg . ( value & pos 0 string " " - & info [ ] ~ doc ~ docv " : FILE " ) |
let enc = let enc = [ " UTF - 8 " , ` UTF_8 ; " UTF - 16 " , ` UTF_16 ; " UTF - 16LE " , ` UTF_16LE ; " UTF - 16BE " , ` UTF_16BE ; " ASCII " , ` US_ASCII ; " latin1 " , ` ISO_8859_1 ] in let doc = strf " Input encoding , must % s . If unspecified the encoding is \ guessed . The output encoding is the same as the input \ encoding except for ASCII and latin1 where UTF - 8 is output . " ( Arg . doc_alts_enum enc ) in Arg . ( value & opt ( some ( enum enc ) ) None & info [ " e " ; " encoding " ] ~ doc ) |
let ascii = let doc = " Output the input text as newline ( U + 000A ) separated Unicode scalar values written in the US - ASCII charset . " in Arg . ( value & flag & info [ " a " ; " ascii " ] ~ doc ) |
let cmd = let doc = " normalize Unicode text " in let man = [ ` S " DESCRIPTION " ; ` P " ( $ tname ) inputs Unicode text from stdin and rewrites it to stdout according to a specified Unicode normalization form ( see UAX 15 ) . " ; ` P " If no normalization form is specified the character stream is left intact . " ; ` P " Invalid byte sequences in the input are reported on stderr and replaced by the Unicode replacement character ( U + FFFD ) in the output . " ; ` S nf_doc ; ` S " OPTIONS " ; ` S " EXIT STATUS " ; ` P " ( $ tname ) exits with one of the following values " ; : ` I ( " 0 " , " no error occurred " ) ; ` I ( " 1 " , " a command line parsing error occurred " ) ; ` I ( " 2 " , " the input text was malformed " ) ; ` S " BUGS " ; ` P " This program is distributed with the Uunf OCaml library . See http :// erratique . ch / software / uunf for contact information . " ] in Term . ( pure do_cmd $ cmd $ nf $ file $ enc $ ascii ) , Term . info " unftrip " ~ version " :%% VERSION " %% ~ doc ~ man |
let ( ) = match Term . eval cmd with |
module Sessions = Hlist . Make ( LinState ) |
type ' s select = ' s ActionOut . select |
type ' s branch = ' s ActionInp . branch |
type ( ' v , ' s ) out = ( ' v , ' s ) ActionOut . out |
type ( ' v , ' s ) inp = ( ' v , ' s ) ActionInp . inp |
let close ( ) = ( ) |
type chan_table = ( string * string , DynChan . chan ) Hashtbl . t |
module UnicastEnv : EnvSpec with type entry = chan_table = struct type entry = chan_table type env_entry += E of entry let name = " unicast " let make_default ( ) = Hashtbl . create 42 let update _param _tbl = ( ) end |
module Lookup = RegisterEnvSpec ( UnicastEnv ) |
let lookup ( t : chan_table ) ( key : string * string ) = match Hashtbl . find_opt t key with | Some ch -> ch | None -> let ch = DynChan . make ( ) in Hashtbl . add t key ch ; ch |
let ( --> ) ra rb lab g env = let g = g env in let ch = lookup ( Lookup . lookup env ) ( ra . role_label . method_name , rb . role_label . method_name ) in let key = DynChan . new_name ch in let b = seq_get rb . role_index g in let g = seq_put rb . role_index g ( ActionInp . make_branch ra . role_label lab . var key b ) in let a = seq_get ra . role_index g in let g = seq_put ra . role_index g ( ActionOut . make_select rb . role_label lab . obj key a ) in g |
let ( ==> ) ra rb g env = let g = g env in let ch = lookup ( Lookup . lookup env ) ( ra . role_label . method_name , rb . role_label . method_name ) in let key = DynChan . new_name ch in let b = seq_get rb . role_index g in let g = seq_put rb . role_index g ( ActionInp . make_inp ra . role_label key b ) in let a = seq_get ra . role_index g in let g = seq_put ra . role_index g ( ActionOut . make_out rb . role_label key a ) in g |
let secondary_mask = 0xff lsl 7 let tertiary_mask = 0x7f let primary ce = ( ce land primary_mask ) primary_mask lsr 15 let secondary ce = ( ce land secondary_mask ) secondary_mask lsr 7 let tertiary ce = ce land tertiary_mask let compose_ce w1 w2 w3 = ( w1 lsl 15 ) 15 lor ( w2 lsl 7 ) 7 lor w3 let complete_ignorable = 0 type ce_tbl = ( UChar . t list * ce_type list ) list list UCharTbl . t type variable_option = [ ` Blanked | ` Non_ignorable | ` Shifted | ` Shift_Trimmed ] type col_info = { variable_top : int ; variable_option : variable_option ; french_accent : bool ; hiraganaQ : bool ; hiraganaQ_weight : int ; tbl : ce_tbl } ce_tbl let default_col_data = lazy ( read_data " allkeys " : col_info ) col_info type localedata = { col_info : col_info option } option let read_localedata c = let data : localedata = input_value c in match data . col_info with None -> raise Not_found | Some x -> x let col_tbl = Hashtbl . create 0 let get_col_info ? locale ( ) = match locale with None -> Lazy . force default_col_data | Some s -> try let b = Hashtbl . find col_tbl s in match Weak . get b 0 with None -> Hashtbl . remove col_tbl s ; raise Not_found | Some x -> x with Not_found -> try let info = Locale . read Config . localedir " mar " read_localedata s in let b = Weak . create 1 in Weak . set b 0 ( Some info ) info ; Hashtbl . add col_tbl s b ; info with Not_found -> Lazy . force default_col_data let ce tbl u = UCharTbl . get tbl u end |
module Logs = ( val Logs . ( src_log @@ Src . create __MODULE__ ) ) |
module Stack : sig type elt = | Var of Variable . t * Type . t | Expr of Type . t * Type . t type t val empty : t val pop : t -> ( elt * t ) option val push_quasi_solved : t -> Variable . t -> Type . t -> t val push_array2 : Type . t array -> Type . t array -> t -> t val [ @ warning " - 32 " ] pp : t Fmt . t [ @@ ocaml . toplevel_printer ] type elt = | Var of Variable . t * Type . t | Expr of Type . t * Type . t type t = elt list let empty : t = [ ] let [ @ inline ] pop = function | [ ] -> None | h :: t -> Some ( h , t ) let push l t1 t2 = Expr ( t1 , t2 ) :: l let push_quasi_solved l v t = Var ( v , t ) :: l let push_array2 a1 a2 stack = CCArray . fold2 push stack a1 a2 let pp_elt ppf = function | Var ( v , t ) -> Fmt . pf ppf " % a = % a " Variable . pp v Type . pp t | Expr ( t1 , t2 ) -> Fmt . pf ppf " % a = % a " Type . pp t1 Type . pp t2 let pp = Fmt . ( vbox ( list ~ sep : cut pp_elt ) ) end |
type return = | Done | FailUnif of Type . t * Type . t | FailedOccurCheck of Env . t |
let ( let ) * x1 f = match x1 with Done -> f ( ) | _ -> x1 |
let occur_check env : return = debug ( fun m -> m " [ @< v > Occur check in , @% a ] " @ Env . pp env ) ; let nb_predecessors = Variable . HMap . create 17 in let successors = Variable . HMap . create 17 in let fill_nb_predecessors x ty = let aux y = Variable . HMap . incr nb_predecessors y ; Variable . HMap . add_list successors x y ; in begin if not @@ Variable . HMap . mem nb_predecessors x then Variable . HMap . add nb_predecessors x 0 end ; Type . iter_vars ty |> Iter . iter aux in Variable . Map . iter fill_nb_predecessors ( Env . vars env ) ; let nb_representatives = Variable . HMap . length nb_predecessors in let vars_without_predecessors = Variable . HMap . fold ( fun x count_preds l -> if count_preds = 0 then x :: l else l ) nb_predecessors [ ] in debug ( fun m -> m " Predecessors : % a " ( Variable . HMap . pp Variable . pp Fmt . int ) nb_predecessors ) ; debug ( fun m -> m " Vars without predecessor : % a " ( Fmt . Dump . list Variable . pp ) vars_without_predecessors ) ; let rec loop n vars_without_predecessors = match vars_without_predecessors with | _ when n = nb_representatives -> Done | [ ] -> FailedOccurCheck env | x :: q -> let aux l v = Variable . HMap . decr nb_predecessors v ; let n = Variable . HMap . get_or ~ default : 0 nb_predecessors v in if n = 0 then v :: l else l in let succs_x = Variable . HMap . get_or ~ default [ ] : successors x in let q = List . fold_left aux q succs_x in loop ( n + 1 ) q in loop 0 vars_without_predecessors |
let rec process_stack env ( stack : Stack . t ) : return = match Stack . pop stack with | Some ( Expr ( t1 , t2 ) , stack ) -> insert_rec env stack t1 t2 | Some ( Var ( v , t ) , stack ) -> insert_var env stack v t | None -> Done match t1 , t2 with | _ when t1 == t2 -> process_stack env stack | Type . Constr ( p1 , args1 ) , Type . Constr ( p2 , args2 ) when LongIdent . compare p1 p2 = 0 -> let stack = Stack . push_array2 args1 args2 stack in process_stack env stack | Type . Arrow ( arg1 , ret1 ) , Type . Arrow ( arg2 , ret2 ) -> let stack , arg1 = variable_abstraction_all env stack arg1 in let stack , arg2 = variable_abstraction_all env stack arg2 in Env . push_arrow env ( ArrowTerm . make arg1 ret1 ) ( ArrowTerm . make arg2 ret2 ) ; process_stack env stack | Tuple s , Tuple t -> let stack , pure_s = variable_abstraction_all env stack s in let stack , pure_t = variable_abstraction_all env stack t in Env . push_tuple env pure_s pure_t ; process_stack env stack | Var v , t | t , Var v -> insert_var env stack v t | Constr _ , Constr _ | ( Constr _ | Tuple _ | Arrow _ | Other _ | FrozenVar _ ) , ( Constr _ | Tuple _ | Arrow _ | Other _ | FrozenVar _ ) -> FailUnif ( t1 , t2 ) let r = ref stack in let f x = let stack , x = variable_abstraction env ! r x in r := stack ; x in ! r , Array . map f @@ Type . NSet . as_array a match t with | Type . Tuple ts -> let stack , all_vars = variable_abstraction_all env stack ts in let var = Env . gen env in Env . push_tuple env [ | Pure . var var ] | all_vars ; stack , Pure . var var | Var i -> stack , Pure . var i | Constr ( p , [ ] ) || -> stack , Pure . constant p | Arrow _ | Constr ( _ , _ ) | Other _ | FrozenVar _ -> let var = Env . gen env in let stack = Stack . push_quasi_solved stack var t in stack , Pure . var var match s with | Type . Constr ( _ , [ ] ) || | Type . Tuple _ | Type . Constr _ | Type . Arrow _ | Type . Other _ | Type . FrozenVar _ -> quasi_solved env stack x s | Type . Var y -> non_proper env stack x y match Env . representative env x with | V x -> let * ( ) = attach env x s in process_stack env stack | E ( _ , ( Type . Tuple _ as t ) ) -> insert_rec env stack t s | E ( _ , t ) -> if Measure . make NodeCount t < Measure . make NodeCount s then insert_rec env stack t s else insert_rec env stack s t match Env . representative env x , Env . representative env y with | V x ' , V y ' when Variable . equal x ' y ' -> process_stack env stack | V x ' , ( E ( y ' , _ ) | V y ' ) | E ( y ' , _ ) , V x ' -> let * ( ) = attach env x ' ( Type . var ( Env . tyenv env ) y ' ) in process_stack env stack | E ( x ' , s ) , E ( y ' , t ) -> if Measure . make NodeCount s < Measure . make NodeCount t then begin let * ( ) = attach env y ' ( Type . var ( Env . tyenv env ) x ' ) in insert_rec env stack s t end else begin let * ( ) = attach env x ' ( Type . var ( Env . tyenv env ) y ' ) in insert_rec env stack t s end Env . add env v t ; occur_check env |
let insert env t u : return = insert_rec env Stack . empty t u |
let insert_var env x ty : return = insert_var env Stack . empty x ty |
let insert_tuple_solution env sol = let exception Bail of return in try let f ( k , v ) = match insert_var env k ( ACTerm . as_tuple ( Env . tyenv env ) v ) with | Done -> ( ) | r -> raise ( Bail r ) in sol f ; Done with | Bail r -> r |
let rec solve_tuple_problems env0 = let rec pop_all_tuples acc env = match Env . pop_tuple env with | None -> acc | Some pb -> pop_all_tuples ( pb :: acc ) env in AC . solve env0 @@ pop_all_tuples [ ] env0 |> Iter . flat_map ( try_with_solution env0 insert_tuple_solution ) let potentials = [ ( fun env ( ) -> Env . push_tuple env left . args right . args ; insert env left . ret right . ret ) ; ( fun env ( ) -> let var_arg_left = Env . gen env and var_ret_left = Env . gen env in Env . push_tuple env ( ACTerm . add left . args ( Pure . var var_arg_left ) ) right . args ; let * ( ) = insert env left . ret ( Type . arrow ( Env . tyenv env ) ( Type . var ( Env . tyenv env ) var_arg_left ) ( Type . var ( Env . tyenv env ) var_ret_left ) ) in insert_var env var_ret_left right . ret ) ; ( fun env ( ) -> let var_arg_right = Env . gen env and var_ret_right = Env . gen env in Env . push_tuple env left . args ( ACTerm . add right . args ( Pure . var var_arg_right ) ) ; let * ( ) = insert env right . ret ( Type . arrow ( Env . tyenv env ) ( Type . var ( Env . tyenv env ) var_arg_right ) ( Type . var ( Env . tyenv env ) var_ret_right ) ) in insert_var env var_ret_right left . ret ) ; ( fun env ( ) -> let var_arg_left = Env . gen env and var_ret_left = Env . gen env in let var_arg_right = Env . gen env and var_ret_right = Env . gen env in Env . push_tuple env ( ACTerm . add left . args ( Pure . var var_arg_left ) ) right . args ; Env . push_tuple env left . args ( ACTerm . add left . args ( Pure . var var_arg_right ) ) ; let * ( ) = insert env left . ret ( Type . arrow ( Env . tyenv env ) ( Type . var ( Env . tyenv env ) var_arg_left ) ( Type . var ( Env . tyenv env ) var_ret_left ) ) in let * ( ) = insert env right . ret ( Type . arrow ( Env . tyenv env ) ( Type . var ( Env . tyenv env ) var_arg_right ) ( Type . var ( Env . tyenv env ) var_ret_right ) ) in insert env ( Type . var ( Env . tyenv env ) var_ret_left ) ( Type . var ( Env . tyenv env ) var_ret_right ) ) ; ] in potentials |> Iter . of_list |> Iter . flat_map ( fun f -> try_with_solution env0 f ( ) ) : type a . _ -> ( Env . t -> a -> return ) -> a -> _ = fun env f sol k -> let env = Env . copy env in match f env sol with | Done -> solve_loop env k | FailUnif ( t1 , t2 ) -> debug ( fun m -> m " [ @< v > Conflict between ; :@< 1 2 [ >@% a ] @@ and ; @< 1 2 [ >@% a ] ] . . " @@@@ Type . pp t1 Type . pp t2 ) | FailedOccurCheck env -> debug ( fun m -> m " [ @< v > Failed occur check in env ; @% a " Env . pp env ) match Env . is_solved env with | Some map -> debug ( fun m -> m " [ @< v2 > Solved env , :@% a ] . " @@ Env . pp env ) ; k map | None -> debug ( fun m -> m " [ @< v2 > New env , :@% a ] . " @@ Env . pp env ) ; begin match Env . pop_arrow env with | Some pb -> solve_arrow_problem env pb k | None -> solve_tuple_problems env k end |
let unifiers ( tyenv : Type . Env . t ) t1 t2 : Subst . t Iter . t = let orig_vars = Variable . Set . ( union ( of_iter @@ Type . iter_vars t1 ) ( of_iter @@ Type . iter_vars t2 ) ) in let env0 = Env . make ~ tyenv ~ orig_vars in debug ( fun m -> m { [ |@< v > Unify :@ " % a " @ " % a " ] } @| Type . pp t1 Type . pp t2 ) ; match insert env0 t1 t2 with | Done -> debug ( fun m -> m " env0 : , @% a " Env . pp env0 ) ; solve_loop env0 | FailUnif _ | FailedOccurCheck _ -> Iter . empty |
let unify ( env : Type . Env . t ) t1 t2 = Iter . min ~ lt : Subst . lt @@ unifiers env t1 t2 |
let unifiable ( env : Type . Env . t ) t1 t2 = not @@ Iter . is_empty @@ unifiers env t1 t2 |
type ord = | Uncomparable | Smaller | Bigger | Equal |
let compare env t1 t2 = let b1 = unifiable env ( Type . freeze_variables env t1 ) t2 and b2 = unifiable env t1 ( Type . freeze_variables env t2 ) in match b1 , b2 with | true , true -> Equal | false , false -> Uncomparable | true , false -> Smaller | false , true -> Bigger |
module type Monad = sig type ' a m val return : ' a -> ' a m val bind : ' a m -> ( ' a -> ' b m ) -> ' b m end |
module type Extend = sig type ' a m val fmap : ( ' a -> ' b ) -> ' a m -> ' b m end |
module Extend ( M : Monad ) : Extend with type ' a m := ' a M . m = struct open M let fmap f m = bind m ( fun a -> return ( f a ) ) end |
module Option = struct type ' a t = ' a option module Monad = struct type ' a m = ' a t let return x = Some x let bind m f = match m with | None -> None | Some a -> f a end include Monad include Extend ( Monad ) end |
module type Monad2 = sig type ( ' a , ' x ) m val return : ' a -> ( ' a , ' x ) m val bind : ( ' a , ' x ) m -> ( ' a -> ( ' b , ' x ) m ) -> ( ' b , ' x ) m end |
module Extend2 ( M : Monad2 ) : sig open M val fmap : ( ' a -> ' b ) -> ( ' a , ' x ) m -> ( ' b , ' x ) m include M let fmap f m = bind m ( fun a -> return ( f a ) ) end |
module Result = struct type ( ' a , ' err ) t = Ok of ' a | Error of ' err module Monad = struct type ( ' a , ' err ) m = ( ' a , ' err ) t let return x = Ok x let bind m f = match m with | Error e -> Error e | Ok a -> f a end include Monad include Extend2 ( Monad ) end |
module Option ' = struct type ' a t = ' a option module Monad = struct type ( ' a , _ ) m = ' a t let return x = Some x let bind m f = match m with | None -> None | Some a -> f a end include Monad include ( Extend2 ( Monad ) : Extend with type ' a m := ' a t ) end |
module Make ( D : Debugger . S_base ) = struct include D module Value = struct type t = | Exists_on_target of Obj . t | Synthetic_ptr of Synthetic_ptr . t let create_exists_on_target obj = Exists_on_target obj let create_synthetic_ptr ptr = Synthetic_ptr ptr let is_block t = match t with | Exists_on_target obj -> Obj . is_block obj | Synthetic_ptr _ -> true let is_int t = not ( is_block t ) let is_null t = match t with | Exists_on_target obj -> Obj . is_null obj | Synthetic_ptr _ -> false let tag_exn t = match t with | Exists_on_target obj -> Obj . tag_exn obj | Synthetic_ptr ptr -> Synthetic_ptr . tag ptr let size_exn t = match t with | Exists_on_target obj -> Obj . size_exn obj | Synthetic_ptr ptr -> Synthetic_ptr . size ptr let field_exn t index = match t with | Exists_on_target obj -> Some ( Exists_on_target ( Obj . field_exn obj index ) ) | Synthetic_ptr ptr -> match Synthetic_ptr . field_exn ptr index with | Ok ptr -> Some ( Synthetic_ptr ptr ) | Non_synthetic obj -> Some ( Exists_on_target obj ) | Unavailable -> None let field_as_addr_exn t index = match t with | Exists_on_target obj -> Obj . field_as_addr_exn obj index | Synthetic_ptr _ptr -> D . zero_target_addr let address_of_field_exn t index = match t with | Exists_on_target obj -> Some ( Obj . address_of_field obj index ) | Synthetic_ptr _ -> None let c_string_field_exn t index = match t with | Exists_on_target obj -> Obj . c_string_field_exn obj index | Synthetic_ptr ptr -> Synthetic_ptr . c_string_field_exn ptr index let float_field_exn t index = match t with | Exists_on_target obj -> Obj . float_field_exn obj index | Synthetic_ptr ptr -> Synthetic_ptr . float_field_exn ptr index let int t = match t with | Exists_on_target obj -> Some ( Obj . int obj ) | Synthetic_ptr _ -> None let string t = match t with | Exists_on_target obj -> Obj . string obj | Synthetic_ptr ptr -> Synthetic_ptr . string ptr let raw t = match t with | Exists_on_target obj -> Some ( Obj . raw obj ) | Synthetic_ptr _ptr -> None include Identifiable . Make ( struct type nonrec t = t let print ppf t = match t with | Exists_on_target obj -> Obj . print ppf obj | Synthetic_ptr ptr -> Synthetic_ptr . print ppf ptr let output _ _ = failwith " Not yet implemented " let compare t1 t2 = match t1 , t2 with | Exists_on_target obj1 , Exists_on_target obj2 -> Obj . compare obj1 obj2 | Synthetic_ptr ptr1 , Synthetic_ptr ptr2 -> Synthetic_ptr . compare ptr1 ptr2 | Exists_on_target _ , Synthetic_ptr _ -> - 1 | Synthetic_ptr _ , Exists_on_target _ -> 1 let equal t1 t2 = ( compare t1 t2 = 0 ) let hash t = match t with | Exists_on_target obj -> Hashtbl . hash ( 0 , Obj . hash obj ) | Synthetic_ptr ptr -> Hashtbl . hash ( 1 , Synthetic_ptr . hash ptr ) end ) end end |
module type STRUCTURE = sig type ' a structure val map : ( ' a -> ' b ) -> ' a structure -> ' b structure val iter : ( ' a -> unit ) -> ' a structure -> unit exception Iter2 val iter2 : ( ' a -> ' b -> unit ) -> ' a structure -> ' b structure -> unit end |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.