text
stringlengths
0
601k
let refresh t state = { t with image = t . refresh state ; }
let with_window ~ title i = let w = I . width i in let h = I . height i in let title = let title = I . string A . ( fg yellow ) title in I . ( ( hsnap ~ align ` : Middle w ( left <|> title <|> right ) ) </> ( top_left <|> top w 1 <|> top_right ) ) in let bottom = I . ( ( bottom_left <|> top w 1 <|> bottom_right ) ) in let left = side 1 ( h + 1 ) |> I . hpad 0 w in let right = side 1 ( h + 1 ) in let win = I . ( ( title |> vpad 0 h <-> bottom ) </> ( left <|> right ) ) in I . ( ( hpad 1 0 i |> vpad 1 2 ) </> win )
let render ~ window_h { image ; cursor ; title ; _ } = let image_h = I . height image in let crop_top = if cursor < window_h then 0 else cursor - window_h in let crop_bottom = if cursor + window_h > image_h then 0 else image_h - crop_top - window_h in let i = I . ( vcrop crop_top crop_bottom image |> vsnap window_h ) in with_window ~ title i
module T = struct include Value . Make_subtype ( struct let name = " window " let here = [ % here ] let is_in_subtype = Value . is_window end ) let equal = eq end
type window = t [ @@ deriving sexp_of ]
module Edges = struct type t = { bottom : int ; left : int ; right : int ; top : int } [ @@ deriving sexp_of ] include Valueable . Make ( struct type nonrec t = t let type_ = Value . Type . ( map ( tuple int ( tuple int ( tuple int ( tuple int unit ) ) ) ) ~ name [ :% sexp " Window . Tree . Position_and_size . t " ] ) ~ of_ ( : fun ( left , ( top , ( right , ( bottom , ( ) ) ) ) ) -> { bottom ; left ; right ; top } ) ~ to_ ( : fun { bottom ; left ; right ; top } -> left , ( top , ( right , ( bottom , ( ) ) ) ) ) ; ; end ) end
module Tree = struct module Direction = struct module T = struct type t = | Left_to_right | Top_to_bottom [ @@ deriving enumerate , sexp_of ] end include T let is_top_to_bottom = function | Left_to_right -> false | Top_to_bottom -> true ; ; include Valueable . Make ( struct type nonrec t = t let type_ = Value . Type . enum [ % sexp " Window . Tree . Direction . t " ] ( module T ) ( is_top_to_bottom >> Value . of_bool ) ; ; end ) end type t = | Combination of { children : t list ; direction : Direction . t ; edges : Edges . t } | Window of window [ @@ deriving sexp_of ] let tuple_type = Value . Type . ( tuple Direction . t ( tuple Edges . t ( list value ) ) ) let rec of_value_exn value = match T . is_in_subtype value with | true -> Window ( T . of_value_exn value ) | false -> let direction , ( edges , children ) = Value . Type . of_value_exn tuple_type value in let children = List . map children ~ f : of_value_exn in Combination { children ; direction ; edges } ; ; let rec to_value = function | Window window -> T . to_value window | Combination { children ; direction ; edges } -> Value . Type . to_value tuple_type ( direction , ( edges , List . map children ~ f : to_value ) ) ; ; let type_ = Value . Type . create [ % message " Window . Tree . t " ] [ % sexp_of : t ] of_value_exn to_value ; ; let t = type_ let parent_exn t window = let rec aux t ~ parent = match t with | Window window ' -> ( match T . equal window window ' with | true -> Some parent | false -> None ) | Combination { children ; direction = _ ; edges = _ } -> List . find_map children ~ f ( : aux ~ parent : t ) in match aux t ~ parent : t with | Some t -> t | None -> raise_s [ % message " Window not in this tree . " ( window : window ) ~ _ ( : t : t ) ] ; ; end
module type BoundedQueueWithCounter = sig type ' a t val empty : int -> ' a t val create : int -> ' a -> ' a t val is_empty : ' a t -> bool val is_full : ' a t -> bool val size : ' a t -> int val enqueue : ' a -> ' a t -> ' a t val dequeue : ' a t -> ' a option * ' a t val count : ' a t -> int val fold : ( ' b -> ' a -> ' b ) -> ' b -> ' a t -> ' b val to_list : ' a t -> ' a list end
module Window : BoundedQueueWithCounter = struct type ' a t = { data : ( ' a list ) * ( ' a list ) ; maxsize : int ; size : int ; count : int } let empty n = if n = 0 then failwith " Cannot create queue of size 0 " ! else { data = ( [ ] , [ ] ) ; maxsize = n ; size = n ; count = 0 } let create n i = let rec gen l acc i = if l = 0 then acc else gen ( l - 1 ) ( i :: acc ) i in if n = 0 then failwith " Cannot create queue of size 0 " ! else let initdata = gen n [ ] i in { data = ( initdata , [ ] ) ; maxsize = n ; size = n ; count = 0 } let is_empty q = ( q . size = 0 ) let is_full q = ( q . size = q . maxsize ) let size q = q . size let rec dequeue q = match q . data with | h :: t , b -> ( Some h , { q with data = ( t , b ) ; size = q . size - 1 } ) [ ] , [ ] | -> ( None , q ) [ ] , | h :: t -> dequeue { q with data = ( List . rev ( h :: t ) , [ ] ) } let rec enqueue item q = if is_full q then dequeue q |> snd |> enqueue item else match q . data with | f , b -> { q with data = ( f , item :: b ) ; size = q . size + 1 ; count = q . count + 1 } let count q = q . count let to_list q = ( fst q . data ) ( @ snd q . data |> List . rev ) let fold f init q = List . fold_left f init ( to_list q ) end
let winnow w h = let global_pos i w = let c = Window . count w in let s = Window . size w in c - ( s - 1 - i ) in let mincheck ( ( minval , minpos ) , count ) x = if x <= minval then ( ( x , count ) , count + 1 ) else ( ( minval , minpos ) , count + 1 ) in let rec winnowhelper hashes window acc n ( v , p ) = if n = List . length hashes then acc else begin let nexthash = List . nth hashes n in let new_window = Window . enqueue nexthash window in if nexthash <= v then let new_acc = ( nexthash , global_pos ( Window . size new_window - 1 ) new_window ) :: acc in winnowhelper hashes new_window new_acc ( n + 1 ) ( nexthash , Window . size new_window - 1 ) else begin let p = p - 1 in if p < 0 then let new_min = fst ( Window . fold mincheck ( ( max_int , 0 ) , 0 ) new_window ) in let new_acc = ( fst new_min , global_pos ( snd new_min ) new_window ) :: acc in winnowhelper hashes new_window new_acc ( n + 1 ) new_min else winnowhelper hashes new_window acc ( n + 1 ) ( v , p ) end end in let window = Window . create w max_int in let res = winnowhelper h window [ ] 0 ( max_int , 0 ) in res
let main ( ) = let top = opentk ( ) in let mbar = Frame . create top [ Relief Raised ; BorderWidth ( Pixels 2 ) ] and dummy = Frame . create top [ Width ( Centimeters 10 . ) ; Height ( Centimeters 5 . ) ] in pack [ mbar ; dummy ] [ Side Side_Top ; Fill Fill_X ] ; let file = Menubutton . create mbar [ Text " File " ; UnderlinedChar 0 ] and edit = Menubutton . create mbar [ Text " Edit " ; UnderlinedChar 0 ] and graphics = Menubutton . create mbar [ Text " Graphics " ; UnderlinedChar 0 ] and text = Menubutton . create mbar [ Text " Text " ; UnderlinedChar 0 ] and view = Menubutton . create mbar [ Text " View " ; UnderlinedChar 0 ] and help = Menubutton . create mbar [ Text " Help " ; UnderlinedChar 0 ] in pack [ file ; edit ; graphics ; text ; view ] [ Side Side_Left ] ; pack [ help ] [ Side Side_Right ] ; let m = Menu . create text [ ] in let bold = Textvariable . create ( ) and italic = Textvariable . create ( ) and underline = Textvariable . create ( ) in Menu . add_checkbutton m [ Label " Bold " ; Variable bold ] ; Menu . add_checkbutton m [ Label " Italic " ; Variable italic ] ; Menu . add_checkbutton m [ Label " Underline " ; Variable underline ] ; Menu . add_separator m ; let font = Textvariable . create ( ) in Menu . add_radiobutton m [ Label " Times " ; Variable font ; Value " times " ] ; Menu . add_radiobutton m [ Label " Helvetica " ; Variable font ; Value " helvetica " ] ; Menu . add_radiobutton m [ Label " Courier " ; Variable font ; Value " courier " ] ; Menu . add_separator m ; Menu . add_command m [ Label " Insert Bullet " ; Command ( function ( ) -> print_string " Insert Bullet \ n " ; flush stdout ) ] ; Menu . add_command m [ Label " Margins and Tags . . . " ; Command ( function ( ) -> print_string " margins \ n " ; flush stdout ) ] ; Menubutton . configure text [ Menu m ] ; mainLoop ( )
let _ = Printexc . catch main ( )
let of_int = function | 0 -> Some ( Success ) | 1 -> Some ( Invalid_function ) | 2 -> Some ( File_not_found ) | 3 -> Some ( Path_not_found ) | 4 -> Some ( Too_many_open_files ) | 5 -> Some ( Access_denied ) | 6 -> Some ( Invalid_handle ) | 7 -> Some ( Arena_trashed ) | 8 -> Some ( Not_enough_memory ) | 9 -> Some ( Invalid_block ) | 10 -> Some ( Bad_environment ) | 11 -> Some ( Bad_format ) | 12 -> Some ( Invalid_access ) | 13 -> Some ( Invalid_data ) | 14 -> Some ( Outofmemory ) | 15 -> Some ( Invalid_drive ) | 16 -> Some ( Current_directory ) | 17 -> Some ( Not_same_device ) | 18 -> Some ( No_more_files ) | 19 -> Some ( Write_protect ) | 20 -> Some ( Bad_unit ) | 21 -> Some ( Not_ready ) | 22 -> Some ( Bad_command ) | 23 -> Some ( Crc ) | 24 -> Some ( Bad_length ) | 25 -> Some ( Seek ) | 26 -> Some ( Not_dos_disk ) | 27 -> Some ( Sector_not_found ) | 28 -> Some ( Out_of_paper ) | 29 -> Some ( Write_fault ) | 30 -> Some ( Read_fault ) | 31 -> Some ( Gen_failure ) | 32 -> Some ( Sharing_violation ) | 33 -> Some ( Lock_violation ) | 34 -> Some ( Wrong_disk ) | 36 -> Some ( Sharing_buffer_exceeded ) | 38 -> Some ( Handle_eof ) | 39 -> Some ( Handle_disk_full ) | 50 -> Some ( Not_supported ) | 51 -> Some ( Rem_not_list ) | 52 -> Some ( Dup_name ) | 53 -> Some ( Bad_netpath ) | 54 -> Some ( Network_busy ) | 55 -> Some ( Dev_not_exist ) | 56 -> Some ( Too_many_cmds ) | 57 -> Some ( Adap_hdw_err ) | 58 -> Some ( Bad_net_resp ) | 59 -> Some ( Unexp_net_err ) | 60 -> Some ( Bad_rem_adap ) | 61 -> Some ( Printq_full ) | 62 -> Some ( No_spool_space ) | 63 -> Some ( Print_cancelled ) | 64 -> Some ( Netname_deleted ) | 65 -> Some ( Network_access_denied ) | 66 -> Some ( Bad_dev_type ) | 67 -> Some ( Bad_net_name ) | 68 -> Some ( Too_many_names ) | 69 -> Some ( Too_many_sess ) | 70 -> Some ( Sharing_paused ) | 71 -> Some ( Req_not_accep ) | 72 -> Some ( Redir_paused ) | 80 -> Some ( File_exists ) | 82 -> Some ( Cannot_make ) | 83 -> Some ( Fail_I24 ) | 84 -> Some ( Out_of_structures ) | 85 -> Some ( Already_assigned ) | 86 -> Some ( Invalid_password ) | 87 -> Some ( Invalid_parameter ) | 88 -> Some ( Net_write_fault ) | 89 -> Some ( No_proc_slots ) | 100 -> Some ( Too_many_semaphores ) | 101 -> Some ( Excl_sem_already_owned ) | 102 -> Some ( Sem_is_set ) | 103 -> Some ( Too_many_sem_requests ) | 104 -> Some ( Invalid_at_interrupt_time ) | 105 -> Some ( Sem_owner_died ) | 106 -> Some ( Sem_user_limit ) | 107 -> Some ( Disk_change ) | 108 -> Some ( Drive_locked ) | 109 -> Some ( Broken_pipe ) | 110 -> Some ( Open_failed ) | 111 -> Some ( Buffer_overflow ) | 112 -> Some ( Disk_full ) | 113 -> Some ( No_more_search_handles ) | 114 -> Some ( Invalid_target_handle ) | 117 -> Some ( Invalid_category ) | 118 -> Some ( Invalid_verify_switch ) | 119 -> Some ( Bad_driver_level ) | 120 -> Some ( Call_not_implemented ) | 121 -> Some ( Sem_timeout ) | 122 -> Some ( Insufficient_buffer ) | 123 -> Some ( Invalid_name ) | 124 -> Some ( Invalid_level ) | 125 -> Some ( No_volume_label ) | 126 -> Some ( Mod_not_found ) | 127 -> Some ( Proc_not_found ) | 128 -> Some ( Wait_no_children ) | 129 -> Some ( Child_not_complete ) | 130 -> Some ( Direct_access_handle ) | 131 -> Some ( Negative_seek ) | 132 -> Some ( Seek_on_device ) | 133 -> Some ( Is_join_target ) | 134 -> Some ( Is_joined ) | 135 -> Some ( Is_substed ) | 136 -> Some ( Not_joined ) | 137 -> Some ( Not_substed ) | 138 -> Some ( Join_to_join ) | 139 -> Some ( Subst_to_subst ) | 140 -> Some ( Join_to_subst ) | 141 -> Some ( Subst_to_join ) | 142 -> Some ( Busy_drive ) | 143 -> Some ( Same_drive ) | 144 -> Some ( Dir_not_root ) | 145 -> Some ( Dir_not_empty ) | 146 -> Some ( Is_subst_path ) | 147 -> Some ( Is_join_path ) | 148 -> Some ( Path_busy ) | 149 -> Some ( Is_subst_target ) | 150 -> Some ( System_trace ) | 151 -> Some ( Invalid_event_count ) | 152 -> Some ( Too_many_muxwaiters ) | 153 -> Some ( Invalid_list_format ) | 154 -> Some ( Label_too_long ) | 155 -> Some ( Too_many_tcps ) | 156 -> Some ( Signal_refused ) | 157 -> Some ( Discarded ) | 158 -> Some ( Not_locked ) | 159 -> Some ( Bad_threadid_addr ) | 160 -> Some ( Bad_arguments ) | 161 -> Some ( Bad_pathname ) | 162 -> Some ( Signal_pending ) | 164 -> Some ( Max_thrds_reached ) | 167 -> Some ( Lock_failed ) | 170 -> Some ( Busy ) | 171 -> Some ( Device_support_in_progress ) | 173 -> Some ( Cancel_violation ) | 174 -> Some ( Atomic_locks_not_supported ) | 180 -> Some ( Invalid_segment_number ) | 182 -> Some ( Invalid_ordinal ) | 183 -> Some ( Already_exists ) | 186 -> Some ( Invalid_flag_number ) | 187 -> Some ( Sem_not_found ) | 188 -> Some ( Error_invalid_starting_codeseg ) | 189 -> Some ( Invalid_stackseg ) | 190 -> Some ( Invalid_moduletype ) | 191 -> Some ( Invalid_exe_signature ) | 192 -> Some ( Exe_marked_invalid ) | 193 -> Some ( Bad_exe_format ) | 194 -> Some ( Iterated_data_exceeds_64k ) | 195 -> Some ( Invalid_minallocsize ) | 196 -> Some ( Dynlink_from_invalid_ring ) | 197 -> Some ( Iopl_not_enabled ) | 198 -> Some ( Invalid_segdpl ) | 199 -> Some ( Autodataseg_exceeds_64k ) | 200 -> Some ( Ring2seg_must_be_movable ) | 201 -> Some ( Reloc_chain_xeeds_seglim ) | 202 -> Some ( Infloop_in_reloc_chain ) | 203 -> Some ( Envvar_not_found ) | 205 -> Some ( No_signal_sent ) | 206 -> Some ( Filename_exced_range ) | 207 -> Some ( Ring2_stack_in_use ) | 208 -> Some ( Meta_expansion_too_long ) | 209 -> Some ( Invalid_signal_number ) | 210 -> Some ( Thread_1_inactive ) | 212 -> Some ( Locked ) | 214 -> Some ( Too_many_modules ) | 215 -> Some ( Nesting_not_allowed ) | 216 -> Some ( Exe_machine_type_mismatch ) | 217 -> Some ( Exe_cannot_modify_signed_binary ) | 218 -> Some ( Exe_cannot_modify_strong_signed_binary ) | 220 -> Some ( File_checked_out ) | 221 -> Some ( Checkout_required ) | 222 -> Some ( Bad_file_type ) | 223 -> Some ( File_too_large ) | 224 -> Some ( Forms_auth_required ) | 225 -> Some ( Virus_infected ) | 226 -> Some ( Virus_deleted ) | 229 -> Some ( Pipe_local ) | 230 -> Some ( Bad_pipe ) | 231 -> Some ( Pipe_busy ) | 232 -> Some ( No_data ) | 233 -> Some ( Pipe_not_connected ) | 234 -> Some ( More_data ) | 240 -> Some ( Vc_disconnected ) | 254 -> Some ( Invalid_ea_name ) | 255 -> Some ( Ea_list_inconsistent ) | 258 -> Some ( Wait_timeout ) | 259 -> Some ( No_more_items ) | 266 -> Some ( Cannot_copy ) | 267 -> Some ( Directory ) | 275 -> Some ( Eas_didnt_fit ) | 276 -> Some ( Ea_file_corrupt ) | 277 -> Some ( Ea_table_full ) | 278 -> Some ( Invalid_ea_handle ) | 282 -> Some ( Eas_not_supported ) | 288 -> Some ( Not_owner ) | 298 -> Some ( Too_many_posts ) | 299 -> Some ( Partial_copy ) | 300 -> Some ( Oplock_not_granted ) | 301 -> Some ( Invalid_oplock_protocol ) | 302 -> Some ( Disk_too_fragmented ) | 303 -> Some ( Delete_pending ) | 304 -> Some ( Incompatible_with_global_short_name_registry_setting ) | 305 -> Some ( Short_names_not_enabled_on_volume ) | 306 -> Some ( Security_stream_is_inconsistent ) | 307 -> Some ( Invalid_lock_range ) | 308 -> Some ( Image_subsystem_not_present ) | 309 -> Some ( Notification_guid_already_defined ) | 310 -> Some ( Invalid_exception_handler ) | 311 -> Some ( Duplicate_privileges ) | 312 -> Some ( No_ranges_processed ) | 313 -> Some ( Not_allowed_on_system_file ) | 314 -> Some ( Disk_resources_exhausted ) | 315 -> Some ( Invalid_token ) | 316 -> Some ( Device_feature_not_supported ) | 317 -> Some ( Mr_mid_not_found ) | 318 -> Some ( Scope_not_found ) | 319 -> Some ( Undefined_scope ) | 320 -> Some ( Invalid_cap ) | 321 -> Some ( Device_unreachable ) | 322 -> Some ( Device_no_resources ) | 323 -> Some ( Data_checksum_error ) | 324 -> Some ( Intermixed_kernel_ea_operation ) | 326 -> Some ( File_level_trim_not_supported ) | 327 -> Some ( Offset_alignment_violation ) | 328 -> Some ( Invalid_field_in_parameter_list ) | 329 -> Some ( Operation_in_progress ) | 330 -> Some ( Bad_device_path ) | 331 -> Some ( Too_many_descriptors ) | 332 -> Some ( Scrub_data_disabled ) | 333 -> Some ( Not_redundant_storage ) | 334 -> Some ( Resident_file_not_supported ) | 335 -> Some ( Compressed_file_not_supported ) | 336 -> Some ( Directory_not_supported ) | 337 -> Some ( Not_read_from_copy ) | 350 -> Some ( Fail_noaction_reboot ) | 351 -> Some ( Fail_shutdown ) | 352 -> Some ( Fail_restart ) | 353 -> Some ( Max_sessions_reached ) | 400 -> Some ( Thread_mode_already_background ) | 401 -> Some ( Thread_mode_not_background ) | 402 -> Some ( Process_mode_already_background ) | 403 -> Some ( Process_mode_not_background ) | 487 -> Some ( Invalid_address ) | _ -> None
type t = | Success | Invalid_function | File_not_found | Path_not_found | Too_many_open_files | Access_denied | Invalid_handle | Arena_trashed | Not_enough_memory | Invalid_block | Bad_environment | Bad_format | Invalid_access | Invalid_data | Outofmemory | Invalid_drive | Current_directory | Not_same_device | No_more_files | Write_protect | Bad_unit | Not_ready | Bad_command | Crc | Bad_length | Seek | Not_dos_disk | Sector_not_found | Out_of_paper | Write_fault | Read_fault | Gen_failure | Sharing_violation | Lock_violation | Wrong_disk | Sharing_buffer_exceeded | Handle_eof | Handle_disk_full | Not_supported | Rem_not_list | Dup_name | Bad_netpath | Network_busy | Dev_not_exist | Too_many_cmds | Adap_hdw_err | Bad_net_resp | Unexp_net_err | Bad_rem_adap | Printq_full | No_spool_space | Print_cancelled | Netname_deleted | Network_access_denied | Bad_dev_type | Bad_net_name | Too_many_names | Too_many_sess | Sharing_paused | Req_not_accep | Redir_paused | File_exists | Cannot_make | Fail_I24 | Out_of_structures | Already_assigned | Invalid_password | Invalid_parameter | Net_write_fault | No_proc_slots | Too_many_semaphores | Excl_sem_already_owned | Sem_is_set | Too_many_sem_requests | Invalid_at_interrupt_time | Sem_owner_died | Sem_user_limit | Disk_change | Drive_locked | Broken_pipe | Open_failed | Buffer_overflow | Disk_full | No_more_search_handles | Invalid_target_handle | Invalid_category | Invalid_verify_switch | Bad_driver_level | Call_not_implemented | Sem_timeout | Insufficient_buffer | Invalid_name | Invalid_level | No_volume_label | Mod_not_found | Proc_not_found | Wait_no_children | Child_not_complete | Direct_access_handle | Negative_seek | Seek_on_device | Is_join_target | Is_joined | Is_substed | Not_joined | Not_substed | Join_to_join | Subst_to_subst | Join_to_subst | Subst_to_join | Busy_drive | Same_drive | Dir_not_root | Dir_not_empty | Is_subst_path | Is_join_path | Path_busy | Is_subst_target | System_trace | Invalid_event_count | Too_many_muxwaiters | Invalid_list_format | Label_too_long | Too_many_tcps | Signal_refused | Discarded | Not_locked | Bad_threadid_addr | Bad_arguments | Bad_pathname | Signal_pending | Max_thrds_reached | Lock_failed | Busy | Device_support_in_progress | Cancel_violation | Atomic_locks_not_supported | Invalid_segment_number | Invalid_ordinal | Already_exists | Invalid_flag_number | Sem_not_found | Error_invalid_starting_codeseg | Invalid_stackseg | Invalid_moduletype | Invalid_exe_signature | Exe_marked_invalid | Bad_exe_format | Iterated_data_exceeds_64k | Invalid_minallocsize | Dynlink_from_invalid_ring | Iopl_not_enabled | Invalid_segdpl | Autodataseg_exceeds_64k | Ring2seg_must_be_movable | Reloc_chain_xeeds_seglim | Infloop_in_reloc_chain | Envvar_not_found | No_signal_sent | Filename_exced_range | Ring2_stack_in_use | Meta_expansion_too_long | Invalid_signal_number | Thread_1_inactive | Locked | Too_many_modules | Nesting_not_allowed | Exe_machine_type_mismatch | Exe_cannot_modify_signed_binary | Exe_cannot_modify_strong_signed_binary | File_checked_out | Checkout_required | Bad_file_type | File_too_large | Forms_auth_required | Virus_infected | Virus_deleted | Pipe_local | Bad_pipe | Pipe_busy | No_data | Pipe_not_connected | More_data | Vc_disconnected | Invalid_ea_name | Ea_list_inconsistent | Wait_timeout | No_more_items | Cannot_copy | Directory | Eas_didnt_fit | Ea_file_corrupt | Ea_table_full | Invalid_ea_handle | Eas_not_supported | Not_owner | Too_many_posts | Partial_copy | Oplock_not_granted | Invalid_oplock_protocol | Disk_too_fragmented | Delete_pending | Incompatible_with_global_short_name_registry_setting | Short_names_not_enabled_on_volume | Security_stream_is_inconsistent | Invalid_lock_range | Image_subsystem_not_present | Notification_guid_already_defined | Invalid_exception_handler | Duplicate_privileges | No_ranges_processed | Not_allowed_on_system_file | Disk_resources_exhausted | Invalid_token | Device_feature_not_supported | Mr_mid_not_found | Scope_not_found | Undefined_scope | Invalid_cap | Device_unreachable | Device_no_resources | Data_checksum_error | Intermixed_kernel_ea_operation | File_level_trim_not_supported | Offset_alignment_violation | Invalid_field_in_parameter_list | Operation_in_progress | Bad_device_path | Too_many_descriptors | Scrub_data_disabled | Not_redundant_storage | Resident_file_not_supported | Compressed_file_not_supported | Directory_not_supported | Not_read_from_copy | Fail_noaction_reboot | Fail_shutdown | Fail_restart | Max_sessions_reached | Thread_mode_already_background | Thread_mode_not_background | Process_mode_already_background | Process_mode_not_background | Invalid_address
type telnet_command = | SUBNEG_END [ @ id 240 ] | NOP [ @ id 241 ] | DATA_MARK [ @ id 242 ] | BREAK [ @ id 243 ] | INTERRUPT_PROCESS [ @ id 244 ] | ABORT_OUTPUT [ @ id 245 ] | ARE_YOU_THERE [ @ id 246 ] | ERASE_CHARACTER [ @ id 247 ] | ERASE_LINE [ @ id 248 ] | GO_AHEAD [ @ id 249 ] | SUBNEG [ @ id 250 ] | WILL [ @ id 251 ] | WILL_NOT [ @ id 252 ] | DO [ @ id 253 ] | DO_NOT [ @ id 254 ] | IAC [ @ id 255 ] [ @@ uint8_t ] [ @@ sexp ] ] [ %% cenum
type telnet_option = | Binary_Transmission | Echo | Reconnection | Suppress_Go_Ahead | Approx_Message_Size_Negotiation | Status | Timing_Mark | Remote_Controlled_Trans_and_Echo | Output_Line_Width | Output_Page_Size | Output_Carriage_Return_Disposition | Output_Horizontal_Tab_Stops | Output_Horizontal_Tab_Disposition | Output_Formfeed_Disposition | Output_Vertical_Tabstops | Output_Vertical_Tab_Disposition | Output_Linefeed_Disposition | Extended_ASCII | Logout | Byte_Macro | Data_Entry_Terminal | SUPDUP | SUPDUP_Output | Send_Location | Terminal_Type | End_of_Record | TACACS_User_Identification | Output_Marking | Terminal_Location_Number | Telnet_3270_Regime | X_3_PAD | Negotiate_About_Window_Size | Terminal_Speed | Remote_Flow_Control | Linemode | X_Display_Location | Environment_Option | Authentication_Option | Encryption_Option | New_Environment_Option | TN3270E | XAUTH | CHARSET | Telnet_Remote_Serial_Port | Com_Port_Control_Option | Telnet_Suppress_Local_Echo | Telnet_Start_TLS | KERMIT | SEND_URL | FORWARD_X | TELOPT_PRAGMA_LOGON [ @ id 138 ] | TELOPT_SSPI_LOGON | TELOPT_PRAGMA_HEARTBEAT | Extended_Options_List [ @ id 255 ] [ @@ uint8_t ] [ @@ sexp ] ]
type pc = int * int
let _read_pc conn = let % lwt frag_num = Lwt_io . BE . read_int conn . io . in_ in let % lwt pos = Lwt_io . BE . read_int conn . io . in_ in Lwt . return ( frag_num , pos ) pos
let _write_pc conn ( frag_num , pos ) pos = Lwt_io . BE . write_int conn . io . out frag_num ; % lwt Lwt_io . BE . write_int conn . io . out pos
let set_fork_mode conn mode = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' K ' ; % lwt Lwt_io . BE . write_int conn . io . out ( match mode with ` Fork_child -> 0 | ` Fork_parent -> 1 ) 1 ) 1
let set_event conn pc = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' e ' ; % lwt _write_pc conn pc ) pc
let set_breakpoint conn pc = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' B ' ; % lwt _write_pc conn pc ) pc
let reset_instr conn pc = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' i ' ; % lwt _write_pc conn pc ) pc
let set_trap_barrier conn pos = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' b ' ; % lwt Lwt_io . BE . write_int conn . io . out pos ) pos
let checkpoint conn = Lwt_conn . atomic conn ( fun conn -> if Sys . win32 then raise Operation_system_unsupported else Lwt_io . write_char conn . io . out ' c ' ; % lwt let % lwt pid = Lwt_io . BE . read_int conn . io . in_ in if pid = - 1 then assert false else Lwt . return pid ) pid
type execution_summary = [ ` Event | ` Breakpoint | ` Exited | ` Trap_barrier | ` Uncaught_exc | ` Debug_info of int Ident . Map . t * ( Instruct . debug_event list * string list ) list list | ` Code_loaded of int | ` Code_unloaded of int ]
let go conn steps = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' g ' ; % lwt Lwt_io . BE . write_int conn . io . out steps ; % lwt let % lwt summary = match % lwt Lwt_io . read_char conn . io . in_ with | ' e ' -> Lwt . return ` Event | ' b ' -> Lwt . return ` Breakpoint | ' x ' -> Lwt . return ` Exited | ' s ' -> Lwt . return ` Trap_barrier | ' u ' -> Lwt . return ` Uncaught_exc | ' D ' -> let % lwt ( evls : Instruct . debug_event list array ) array = Lwt_io . read_value conn . io . in_ in let evls = evls |> Array . to_seq |> Seq . map ( fun evl -> ( evl , [ ] ) ) |> List . of_seq in Lwt . return ( ` Debug_info ( Ident . Map . empty , evls ) evls ) evls | ' L ' -> let % lwt frag_num = Lwt_io . BE . read_int conn . io . in_ in Lwt . return ( ` Code_loaded frag_num ) frag_num | ' U ' -> let % lwt frag_num = Lwt_io . BE . read_int conn . io . in_ in Lwt . return ( ` Code_unloaded frag_num ) frag_num | _ -> assert false in let % lwt executed_steps = Lwt_io . BE . read_int conn . io . in_ in let % lwt sp = Lwt_io . BE . read_int conn . io . in_ in let % lwt pc = _read_pc conn in Lwt . return ( executed_steps , summary , match ( sp , pc ) pc with 0 , ( - 1 , 0 ) 0 -> None | _ -> Some ( sp , pc ) pc ) )
let wait conn = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' w ' ) ' w '
let stop conn = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' s ' ) ' s '
let initial_frame conn = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' 0 ' ; % lwt let % lwt stack_pos = Lwt_io . BE . read_int conn . io . in_ in let % lwt pc = _read_pc conn in Lwt . return ( stack_pos , pc ) pc ) pc
let get_frame conn = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' f ' ; % lwt let % lwt stack_pos = Lwt_io . BE . read_int conn . io . in_ in let % lwt pc = _read_pc conn in Lwt . return ( stack_pos , pc ) pc ) pc
let set_frame conn stack_pos = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' S ' ; % lwt Lwt_io . BE . write_int conn . io . out stack_pos ) stack_pos
let up_frame conn stacksize = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' U ' ; % lwt Lwt_io . BE . write_int conn . io . out stacksize ; % lwt let % lwt stack_pos = Lwt_io . BE . read_int conn . io . in_ in let % lwt res = if stack_pos = - 1 then Lwt . return None else let % lwt pc = _read_pc conn in Lwt . return ( Some ( stack_pos , pc ) pc ) pc in Lwt . return res ) res
let _read_remote_value conn = Lwt_io . read_string_exactly conn . io . in_ ( Sys . word_size / 8 ) 8
let _write_remote_value conn rv = Lwt_io . write conn . io . out rv
let get_local conn index = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' L ' ; % lwt Lwt_io . BE . write_int conn . io . out index ; % lwt let % lwt rv = _read_remote_value conn in Lwt . return rv ) rv
let get_environment conn index = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' E ' ; % lwt Lwt_io . BE . write_int conn . io . out index ; % lwt let % lwt rv = _read_remote_value conn in Lwt . return rv ) rv
let get_global conn index = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' G ' ; % lwt Lwt_io . BE . write_int conn . io . out index ; % lwt let % lwt rv = _read_remote_value conn in Lwt . return rv ) rv
let get_accu conn = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' A ' ; % lwt let % lwt rv = _read_remote_value conn in Lwt . return rv ) rv
let get_header conn rv = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' H ' ; % lwt _write_remote_value conn rv ; % lwt let % lwt hdr = Lwt_io . BE . read_int conn . io . in_ in Lwt . return hdr ) hdr
let get_field conn rv index = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' F ' ; % lwt _write_remote_value conn rv ; % lwt Lwt_io . BE . write_int conn . io . out index ; % lwt let % lwt res = match % lwt Lwt_io . read_char conn . io . in_ with | ' \ 000 ' -> let % lwt rv = _read_remote_value conn in Lwt . return rv | ' \ 001 ' -> let % lwt v = Lwt_io . read_float64 conn . io . in_ in Lwt . fail ( Float_field v ) v | _ -> assert false in Lwt . return res ) res
let marshal_obj conn rv = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' M ' ; % lwt _write_remote_value conn rv ; % lwt let % lwt v = Lwt_io . read_value conn . io . in_ in Lwt . return v ) v
let get_closure_code conn rv = Lwt_conn . atomic conn ( fun conn -> Lwt_io . write_char conn . io . out ' C ' ; % lwt _write_remote_value conn rv ; % lwt let % lwt pc = _read_pc conn in Lwt . return pc ) pc
type t = | Varint | Sixty_four | Length_delimited | Start_group | End_group | Thirty_two
let of_int = function | 0 -> Varint | 1 -> Sixty_four | 2 -> Length_delimited | 3 -> Start_group | 4 -> End_group | 5 -> Thirty_two | n -> Printf . kprintf invalid_arg " Wire_type . of_int ( % d ) " n
let to_int = function | Varint -> 0 | Sixty_four -> 1 | Length_delimited -> 2 | Start_group -> 3 | End_group -> 4 | Thirty_two -> 5
let to_string = function | Varint -> " Varint " | Sixty_four -> " Sixty_four " | Length_delimited -> " Length_delimited " | Start_group -> " Start_group " | End_group -> " End_group " | Thirty_two -> " Thirty_two "
let pp fmt v = Format . pp_print_string fmt ( to_string v )
let to_http service region req = let uri = Uri . add_query_params ( Uri . of_string ( Aws . Util . of_option_exn ( Endpoints . url_of service region ) ) ) ( List . append [ ( " Version " , [ " 2016 - 11 - 15 " ] ) ; ( " Action " , [ " WithdrawByoipCidr " ] ) ] ( Util . drop_empty ( Uri . query_of_encoded ( Query . render ( WithdrawByoipCidrRequest . to_query req ) ) ) ) ) in ( ` POST , uri , [ ] )
let of_http body = try let xml = Ezxmlm . from_string body in let resp = Xml . member " WithdrawByoipCidrResponse " ( snd xml ) in try Util . or_error ( Util . option_bind resp WithdrawByoipCidrResult . parse ) ( let open Error in BadResponse { body ; message = " Could not find well formed WithdrawByoipCidrResult . " } ) with | Xml . RequiredFieldMissing msg -> let open Error in ` Error ( BadResponse { body ; message = ( " Error parsing WithdrawByoipCidrResult - missing field in body or children : " ^ msg ) } ) with | Failure msg -> ` Error ( let open Error in BadResponse { body ; message = ( " Error parsing xml : " ^ msg ) } )
let parse_error code err = let errors = [ ] @ Errors_internal . common in match Errors_internal . of_string err with | Some var -> if ( List . mem var errors ) && ( ( match Errors_internal . to_http_code var with | Some var -> var = code | None -> true ) ) then Some var else None | None -> None
let invalid name loc = Invalid_argument ( Printf . sprintf " % s called from % s " name loc )
module Option = struct let get ~ loc = function | Some v -> v | None -> raise ( invalid " Lwtreslib . WithExceptions . Option . get " loc ) let to_exn ~ none = function Some v -> v | None -> raise none let to_exn_f ~ none = function Some v -> v | None -> raise ( none ( ) ) end
module Result = struct let get_ok ~ loc = function | Ok v -> v | Error _ -> raise ( invalid " Lwtreslib . WithExceptions . Result . get_ok " loc ) let get_error ~ loc = function | Error e -> e | Ok _ -> raise ( invalid " Lwtreslib . WithExceptions . Result . get_error " loc ) let to_exn = function Ok v -> v | Error exc -> raise exc let to_exn_f ~ error = function Ok v -> v | Error b -> raise ( error b ) end
module List = struct let rev_combine ~ loc xs ys = let rec aux acc xs ys = match ( xs , ys ) with | ( [ ] , [ ] ) -> acc | ( x :: xs , y :: ys ) -> aux ( ( x , y ) :: acc ) xs ys | ( [ ] , _ :: _ ) | ( _ :: _ , [ ] ) -> raise ( invalid " Lwtreslib . WithExceptions . List . rev_combine " loc ) in aux [ ] xs ys let combine ~ loc xs ys = let rec aux acc xs ys = match ( xs , ys ) with | ( [ ] , [ ] ) -> acc | ( x :: xs , y :: ys ) -> aux ( ( x , y ) :: acc ) xs ys | ( [ ] , _ :: _ ) | ( _ :: _ , [ ] ) -> raise ( invalid " Lwtreslib . WithExceptions . List . combine " loc ) in Stdlib . List . rev ( aux [ ] xs ys ) end
module type S_bigarray = sig open Bigarray type ' a t val bigstring : ( char , int8_unsigned_elt , c_layout ) Array1 . t t val float32_vec : ( float , float32_elt , fortran_layout ) Array1 . t t val float64_vec : ( float , float64_elt , fortran_layout ) Array1 . t t val float32_mat : ( float , float32_elt , fortran_layout ) Array2 . t t val float64_mat : ( float , float64_elt , fortran_layout ) Array2 . t t end
module type S = sig type ' a t val unit : unit t val bool : bool t val char : char t val string : string t val int : int t val int32 : int32 t val int63 : Int63 . t t val int64 : int64 t val nativeint : nativeint t val float : float t val sexp : Sexp . t t val option : ' a t -> ' a option t val list : ' a t -> ' a list t val both : ' a t -> ' b t -> ( ' a * ' b ) t val either : ' a t -> ' b t -> ( ' a , ' b ) Either . t t val result : ' a t -> ' b t -> ( ' a , ' b ) Result . t t include S_bigarray with type ' a t := ' a t end
let ( ) = Css . install_css ( )
module Legend_model = struct type t = { visibility : bool list } [ @@ deriving equal , fields ] end
let id = Type_equal . Id . create ~ name " : dygraph " [ % sexp_of : opaque ]
let widget ? with_graph ? on_zoom data options = let resize_when_inserted_into_the_dom graph _time = Graph . resize graph in let override_zoom_callback ~ graph options = match on_zoom with | None -> options | Some on_zoom -> let zoomCallback = let caller ' s_zoom_callback = Options . zoomCallback options in fun ~ xmin ~ xmax ~ yRanges -> Option . iter caller ' s_zoom_callback ~ f ( : fun f -> f ~ xmin ~ xmax ~ yRanges ) ; let is_zoomed = Graph . isZoomed graph in Vdom . Effect . Expert . handle_non_dom_event_exn ( on_zoom ~ is_zoomed ) in let our_options = Options . create ~ zoomCallback ( ) in Options . merge options ~ prefer : our_options in Vdom . Node . widget ( ) ~ id ~ destroy ( : fun ( _ , _ , _ , graph , animation_id ) _el -> Graph . destroy graph ; Dom_html . window ## cancelAnimationFrame animation_id ) ~ init ( : fun ( ) -> let el = Dom_html . createDiv Dom_html . document in let graph = Graph . create el data options in let ( ) = let options = override_zoom_callback ~ graph options in let updateOptions = Update_options . create ~ options ? data : None ( ) in Graph . updateOptions graph updateOptions in Option . iter with_graph ~ f ( : fun with_graph -> with_graph graph ) ; let animation_id = Dom_html . window ## requestAnimationFrame ( Js . wrap_callback ( resize_when_inserted_into_the_dom graph ) ) in ( data , options , on_zoom , graph , animation_id ) , el ) ~ update ( : fun ( old_data , old_options , old_on_zoom , graph , animation_id ) el -> let ( ) = let data = Option . some_if ( not ( phys_equal old_data data ) ) data in let options = match phys_equal old_options options , phys_equal old_on_zoom on_zoom with | true , true -> None | _ -> Some ( override_zoom_callback ~ graph options ) in match data , options with | None , None -> ( ) | _ -> let updateOptions = Update_options . create ? options ? data ( ) in Graph . updateOptions graph updateOptions in ( data , options , on_zoom , graph , animation_id ) , el ) ; ;
let create_graph ? with_graph ? on_zoom data options = let on_zoom = match on_zoom with | None -> Bonsai . Value . return None | Some on_zoom -> Bonsai . Value . map on_zoom ~ f : Option . some in return ( let % map . Bonsai data = data and options = options and on_zoom = on_zoom in widget ? with_graph ? on_zoom data options ) ; ;
let create_options ~ x_label ~ y_labels ~ visibility ~ legendFormatter = let labels = x_label :: y_labels in let hidden_legend = Dom_html . createDiv Dom_html . document in Options . create ( ) ~ xlabel : x_label ~ labels ~ visibility ~ legend ` : always ~ labelsDiv_el : hidden_legend ~ legendFormatter ; ;
let create_default_legend ~ x_label ~ per_series_info = let % sub model , view , inject = Default_legend . create ~ x_label ~ per_series_info in let model = let % map model = model in { Legend_model . visibility = List . map model . series ~ f : Default_legend . Model . Series . is_visible } in let inject = let % map inject = inject in fun data -> inject Default_legend . Action . ( From_graph data ) in return ( Bonsai . Value . map3 model view inject ~ f : Tuple3 . create ) ; ;
let format_legend inject_legend_data options data = let caller ' s_legend_formatter = Option . bind options ~ f : Options . legendFormatter in Option . iter caller ' s_legend_formatter ~ f ( : fun f -> ignore ( f data : string ) ) ; Vdom . Effect . Expert . handle_non_dom_event_exn ( inject_legend_data data ) ; " this should not be visible " ; ;
let build_options options visibility legendFormatter x_label y_labels = let our_options = create_options ~ x_label ~ y_labels ~ visibility ~ legendFormatter in match options with | None -> our_options | Some options -> Options . merge options ~ prefer : our_options ; ;
let visibility ~ legend_model ~ num_series = let visibility = let % map . Bonsai visibility_from_legend = legend_model >>| Legend_model . visibility and num_series = num_series in let visibility_len = List . length visibility_from_legend in if visibility_len < num_series then ( let padding = List . init ( num_series - visibility_len ) ~ f ( : Fn . const true ) in visibility_from_legend @ padding ) else visibility_from_legend in visibility |> Bonsai . Value . cutoff ~ equal [ :% equal : bool list ] ; ;
let create ~ key ~ x_label ~ per_series_info ? custom_legend ? options ? with_graph ? on_zoom ~ data ( ) = let options = Option . value_map options ~ default ( : Bonsai . Value . return None ) ~ f ( : Bonsai . Value . map ~ f : Option . some ) in let % sub legend = match custom_legend with | Some legend -> Bonsai . read legend | None -> create_default_legend ~ x_label ~ per_series_info in let % pattern_bind legend_model , legend_view , inject_legend_data = legend in let inject_legend_data = Bonsai . Value . cutoff inject_legend_data ~ equal : phys_equal in let y_labels = Bonsai . Value . map per_series_info ~ f ( : List . map ~ f : Per_series_info . label ) in let visibility = let num_series = Bonsai . Value . map per_series_info ~ f : List . length in visibility ~ legend_model ~ num_series in let legendFormatter = Bonsai . Value . map2 inject_legend_data options ~ f : format_legend in let options = Bonsai . Value . map5 options visibility legendFormatter x_label y_labels ~ f : build_options in let % sub graph = create_graph ? with_graph ? on_zoom data options in return @@ let % map graph = graph and legend_view = legend_view and key = key in Vdom . Node . div ~ key ~ attr : ( Vdom . Attr . many_without_merge [ Vdom . Attr . class_ " dygraph " ; Vdom . Attr . style ( Css_gen . flex_container ( ) ) ] ) [ graph ; legend_view ] ; ;
module type s = sig class type c = object method m : int end } ] |
module type s = sig class type ct = object method m : int end } ] |
module type s = sig type top and t = private < . . > and mid and u = private < . . > and v with type u = private < . . >
module type s = sig type top and t = private < . . > and mid and u = private < . . > and v end } ] |
let f x = match x with
let f = fun x -> match x with
let f = let g x = match x with | ` A -> " A " | ` B -> " B " in g
let f = let g = function | ` A -> " A " | ` B -> " B " in g
let f = let g = fun x -> match x with | ` A -> " A " | ` B -> " B " in g
let z = begin match x with | X -> x end
let config_converter = ( fun str -> try ignore ( IndentConfig . update_from_string IndentConfig . default str ) ; ` Ok str with Invalid_argument s -> ` Error s ) , ignore ( IndentConfig . update_from_string IndentConfig . default str ) ; ` Ok str
let f = try match a with B -> x with C -> y
let g = try match X with | X -> X with | X -> Y
type ' a return = { return : ' b . ' a -> ' b } [ @@ unboxed ]
let with_return ( type a ) f = let module M = struct exception Return of a end in let is_alive = ref true in let return a = if not ! is_alive then failwith " use of [ return ] from a [ with_return ] that already returned " ; Exn . raise_without_backtrace ( M . Return a ) in try let a = f { return } in is_alive := false ; a with | exn -> is_alive := false ; ( match exn with | M . Return a -> a | _ -> raise exn ) ; ;
let with_return_option f = with_return ( fun return -> f { return = ( fun a -> return . return ( Some a ) ) } ; None ) ; ;
let prepend { return } ~ f = { return = ( fun x -> return ( f x ) ) }
let str s = Sexp . Atom s
let list l = Sexp . List l
let ns_to_string = function | [ base ] -> [ base ] | base :: rst -> let seps = [ " . " ; " __ " ] in List . map ( fun sep -> base ^ sep ^ String . concat " . " rst ) seps | _ -> assert false
let ns_expend ns m = let m = of_coq_name m in match ns with " " -> m | ns -> ns ^ " . " ^ m
let type_to_sexp ~ libname ~ rev_namespace ~ coqns conflicts typ = let coqt = ns_expend coqns ( Conflict . get_coq_type rev_namespace conflicts ~ ty : typ . type_name ) in List . map ( fun sep -> list [ str ( libname ^ sep ^ String . concat " . " ( List . rev ( typ . type_name :: rev_namespace ) ) ) ; str " . " ; str coqt ; ] ) [ " . " ; " __ " ]
let mutually_recursive_type_to_sexp ~ libname ~ rev_namespace ~ coqns conflicts mt = Compat . concat_map ( type_to_sexp ~ libname ~ rev_namespace ~ coqns conflicts ) mt
let rec intro_to_sexp ~ libname ~ rev_namespace ~ coqns conflicts = function | Right mt -> mutually_recursive_type_to_sexp ~ libname ~ rev_namespace ~ coqns conflicts mt | Left m -> let rev_namespace = m . mod_name :: rev_namespace in let coqmod = Conflict . get_coq_module conflicts ~ m : m . mod_name in let coqns = ns_expend coqns coqmod in mod_to_sexp ~ libname ~ rev_namespace ~ coqns conflicts m Compat . concat_map ( intro_to_sexp ~ libname ~ rev_namespace ~ coqns conflicts ) m . mod_intro
let of_mod ~ coqns conflicts m = mod_to_sexp ~ libname ( : List . hd m . mod_namespace ) ~ rev_namespace [ : m . mod_name ] ~ coqns conflicts m
let pp fmt witness = let open Format in fprintf fmt " [ @< v 2 ( > translations % a ) ] " @ ( Pp . pp_list ~ pp_prefix : pp_print_space ~ pp_sep : pp_print_space Sexp . pp ) witness
module Node : Printable . S with type t = MyCFG . node = struct include Var let to_yojson = Node . to_yojson let show = Node . show_cfg let pretty = Node . pretty_trace let printXml f x = BatPrintf . fprintf f " < value >\ n < data >\ n % s \ n </ data >\ n </ value >\ n " ( XmlUtil . escape ( show x ) ) let name ( ) = " var " let invariant _ _ = Invariant . none let tag _ = failwith " PrintableVar : no tag " let arbitrary ( ) = failwith " PrintableVar : no arbitrary " end
module Edge : Printable . S with type t = MyARG . inline_edge = struct type t = MyARG . inline_edge [ @@ deriving to_yojson ] let equal = Util . equals let compare = Stdlib . compare let hash = Hashtbl . hash let name ( ) = " edge " let pretty = MyARG . pretty_inline_edge include Printable . SimplePretty ( struct type nonrec t = t let pretty = pretty end ) let invariant _ _ = Invariant . none let tag _ = failwith " Edge : no tag " let arbitrary ( ) = failwith " Edge : no arbitrary " let relift x = x end
module PathSensitive3 ( Spec : Spec ) : Spec = struct module I = struct include Spec . D let to_int = tag let name ( ) = " D " let printXml f d = BatPrintf . fprintf f " < value >% a </ value " > printXml d end module CC = struct include Spec . C let name ( ) = " C " let printXml f c = BatPrintf . fprintf f " < value >% a </ value " > printXml c end module VI = Printable . Prod3 ( Node ) ( CC ) ( I ) module VIE = struct include Printable . Prod ( VI ) ( Edge ) let leq ( ( v , c , x ' ) , e ) ( ( w , d , y ' ) , f ) = Node . equal v w && Spec . C . equal c d && I . leq x ' y ' && Edge . equal e f let join _ _ = failwith " VIE join " let meet _ _ = failwith " VIE meet " let widen x y = y let narrow x y = x let top ( ) = failwith " VIE top " let is_top _ = failwith " VIE is_top " let bot ( ) = failwith " VIE bot " let is_bot _ = failwith " VIE is_bot " let pretty_diff ( ) ( ( ( v , c , x ' ) , e ) , ( ( w , d , y ' ) , f ) ) = if not ( Node . equal v w ) then Pretty . dprintf " % a not equal % a " Node . pretty v Node . pretty w else if not ( Spec . C . equal c d ) then Pretty . dprintf " % a not equal % a " Spec . C . pretty c Spec . C . pretty d else if not ( Edge . equal e f ) then Pretty . dprintf " % a not equal % a " Edge . pretty e Edge . pretty f else I . pretty_diff ( ) ( x ' , y ' ) end module VIEB = Lattice . LiftBot ( VIE ) module VIES = HoareDomain . Set ( VIEB ) module R = VIES module Dom = struct include HoareDomain . MapBot ( Spec . D ) ( R ) let name ( ) = " PathSensitive ( " ^ name ( ) ^ " ) " let printXml f x = let print_one x r = BatPrintf . fprintf f " \ n < path >% a < analysis name " =\ witness " \>% a </ analysis ></ path " > Spec . D . printXml x R . printXml r in iter ' print_one x let join_reduce a = let rec loop js = function | [ ] -> js | ( x , xr ) :: xs -> let ( ( j , jr ) , r ) = List . fold_left ( fun ( ( j , jr ) , r ) ( x , xr ) -> if Spec . should_join x j then ( Spec . D . join x j , R . join xr jr ) , r else ( j , jr ) , ( x , xr ) :: r ) ( ( x , xr ) , [ ] ) xs in loop ( ( j , jr ) :: js ) r in apply_list ( loop [ ] ) a let leq a b = leq a b || leq ( join_reduce a ) ( join_reduce b ) let binop op a b = op a b |> join_reduce let join = binop join let meet = binop meet let widen = binop widen let narrow = binop narrow let invariant c s = let ( d , _ ) = List . find ( fun ( x , _ ) -> I . to_int x = c . Invariant . i ) ( elements s ) in Spec . D . invariant c d end module SyncSet = HoareDomain . Set ( Spec . D ) module Sync = HoareDomain . MapBot ( Spec . D ) ( SyncSet ) module D = struct include Lattice . Prod ( Dom ) ( Sync ) let printXml f ( d , _ ) = Dom . printXml f d end module G = Spec . G module C = Spec . C module V = Spec . V let name ( ) = " PathSensitive3 ( " ^ Spec . name ( ) " ) " ^ type marshal = Spec . marshal let init = Spec . init let finalize = Spec . finalize let should_join x y = true let exitstate v = ( Dom . singleton ( Spec . exitstate v ) ( R . bot ( ) ) , Sync . bot ( ) ) let startstate v = ( Dom . singleton ( Spec . startstate v ) ( R . bot ( ) ) , Sync . bot ( ) ) let morphstate v ( d , _ ) = ( Dom . map ( Spec . morphstate v ) d , Sync . bot ( ) ) let call_descr = Spec . call_descr let context fd ( l , _ ) = if Dom . cardinal l <> 1 then failwith " PathSensitive3 . context must be called with a singleton set . " else Spec . context fd @@ Dom . choose l let conv ctx x = let rec ctx ' = { ctx with ask = ( fun ( type a ) ( q : a Queries . t ) -> Spec . query ctx ' q ) ; local = x ; split = ( ctx . split % ( fun x -> ( Dom . singleton x ( R . bot ( ) ) , Sync . bot ( ) ) ) ) } in ctx ' let step n c i e = R . singleton ( ` Lifted ( ( n , c , i ) , e ) ) let step n c i e sync = SyncSet . fold ( fun xsync acc -> R . join acc ( step n c xsync e ) ) ( Sync . find i sync ) ( R . bot ( ) ) let step_ctx ctx x e = try step ctx . prev_node ( ctx . context ( ) ) x e ( snd ctx . local ) with Ctx_failure _ -> R . bot ( ) let step_ctx_edge ctx x = step_ctx ctx x ( CFGEdge ctx . edge ) let map ctx f g = let h x xs = try Dom . add ( g ( f ( conv ctx x ) ) ) ( step_ctx_edge ctx x ) xs with Deadcode -> xs in let d = Dom . fold h ( fst ctx . local ) ( Dom . empty ( ) ) |> Dom . reduce in if Dom . is_bot d then raise Deadcode else ( d , Sync . bot ( ) ) let fold ' ctx f g h a = let k x a = try h a x @@ g @@ f @@ conv ctx x with Deadcode -> a in Dom . fold k ( fst ctx . local ) a let fold ' ' ctx f g h a = let k x r a = try h a x r @@ g @@ f @@ conv ctx x with Deadcode -> a in Dom . fold ' k ( fst ctx . local ) a let assign ctx l e = map ctx Spec . assign ( fun h -> h l e ) let vdecl ctx v = map ctx Spec . vdecl ( fun h -> h v ) let body ctx f = map ctx Spec . body ( fun h -> h f ) let return ctx e f = map ctx Spec . return ( fun h -> h e f ) let branch ctx e tv = map ctx Spec . branch ( fun h -> h e tv ) let asm ctx = map ctx Spec . asm identity let skip ctx = map ctx Spec . skip identity let special ctx l f a = map ctx Spec . special ( fun h -> h l f a ) let threadenter ctx lval f args = let g xs x ' ys = let ys ' = List . map ( fun y -> let yr = R . bot ( ) in ( Dom . singleton y yr , Sync . bot ( ) ) ) ys in ys ' @ xs in fold ' ctx Spec . threadenter ( fun h -> h lval f args ) g [ ] let threadspawn ctx lval f args fctx = let fd1 = Dom . choose ( fst fctx . local ) in map ctx Spec . threadspawn ( fun h -> h lval f args ( conv fctx fd1 ) ) let sync ctx reason = fold ' ' ctx Spec . sync ( fun h -> h reason ) ( fun ( a , async ) x r a ' -> ( Dom . add a ' r a , Sync . add a ' ( SyncSet . singleton x ) async ) ) ( Dom . empty ( ) , Sync . bot ( ) ) let query ctx ( type a ) ( q : a Queries . t ) : a Queries . result = match q with | Queries . IterPrevVars f -> Dom . iter ' ( fun x r -> R . iter ( function | ` Lifted ( ( n , c , j ) , e ) -> f ( I . to_int x ) ( n , Obj . repr c , I . to_int j ) e | ` Bot -> failwith " PathSensitive3 . query : range contains bot " ) r ) ( fst ctx . local ) ; begin match ctx . node with | Function _ -> ( ) | _ -> assert ( Sync . is_bot ( snd ctx . local ) ) ; end ; ( ) | Queries . IterVars f -> Dom . iter ' ( fun x r -> f ( I . to_int x ) ) ( fst ctx . local ) ; ( ) | _ -> let module Result = ( val Queries . Result . lattice q ) in fold ' ctx Spec . query identity ( fun x _ f -> Result . join x ( f q ) ) ( Result . bot ( ) ) let should_inline f = not ( Svcomp . is_special_function f ) || Svcomp . is_error_function f ) * true let enter ctx l f a = let g xs x ' ys = let ys ' = List . map ( fun ( x , y ) -> let yr = if should_inline f then step_ctx ctx x ' ( InlineEntry a ) else R . bot ( ) in ( ( Dom . singleton x ( R . bot ( ) ) , snd ctx . local ) , ( Dom . singleton y yr , Sync . bot ( ) ) ) ) ys in ys ' @ xs in fold ' ctx Spec . enter ( fun h -> h l f a ) g [ ] let combine ctx l fe f a fc d = assert ( Dom . cardinal ( fst ctx . local ) = 1 ) ; let cd = Dom . choose ( fst ctx . local ) in let k x y = let r = if should_inline f then let nosync = ( Sync . singleton x ( SyncSet . singleton x ) ) in step ( Function f ) ( Option . get fc ) x ( InlineReturn l ) nosync else step_ctx_edge ctx cd in try Dom . add ( Spec . combine ( conv ctx cd ) l fe f a fc x ) r y with Deadcode -> y in let d = Dom . fold k ( fst d ) ( Dom . bot ( ) ) in if Dom . is_bot d then raise Deadcode else ( d , Sync . bot ( ) ) end
module NH = Hashtbl . Make ( Node )
module NS = Set . Make ( Node )
let find_main_entry entrystates = let ( main_entry_nodes , other_entry_nodes ) = entrystates |> List . map fst |> List . partition ( function | FunctionEntry f , _ -> f . svar . vname = " main " | _ , _ -> false ) in match main_entry_nodes , other_entry_nodes with | [ ] , _ -> failwith " no main_entry_nodes " | _ :: _ :: _ , _ -> failwith " multiple main_entry_nodes " | _ , _ :: _ -> failwith " some other_entry_nodes " | [ main_entry ] , [ ] -> main_entry