text
stringlengths
12
786k
let is_pkg_system project pkg = Hashtbl . find project . project_dep_data pkg = System
let get_internal_library_deps project target = let internalDeps = Dag . getChildren project . project_targets_dag target . target_name in list_filter_map ( fun name -> match name with | Name . Lib lname -> Some lname | _ -> None ) internalDeps
let initializeSystemStdlib ocamlCfg = let ocaml_ver = Hashtbl . find ( Prog . getOcamlConfig ( ) ) " version " in let stdlibPath = fp ( get_ocaml_config_key_hashtbl " standard_library " ocamlCfg ) in let stdlibLibs = Filesystem . list_dir_pred_map ( fun n -> let ext = Filetype . of_filename n in if ext = Filetype . FileCMXA || ext = Filetype . FileCMA then Some n else None ) stdlibPath in let libs = list_uniq $ List . map ( fun f -> fn_to_string $ Filepath . chop_extension f ) stdlibLibs in List . iter ( fun lib -> if not ( string_endswith " . p " lib ) then ( verbose Verbose " initializing standard library : package % s \ n " lib ; let libCmxa = lib ^ " . cmxa " in let libCma = lib ^ " . cma " in let archives = ( if List . mem ( fn libCmxa ) stdlibLibs then [ ( [ Meta . Predicate . Native ] , libCmxa ) ] else [ ] ) @ ( if List . mem ( fn libCma ) stdlibLibs then [ ( [ Meta . Predicate . Byte ] , libCma ) ] else [ ] ) in let meta = { ( Meta . Pkg . make lib ) with Meta . Pkg . directory = fp_to_string stdlibPath ; Meta . Pkg . requires = [ ] ; Meta . Pkg . version = ocaml_ver ; Meta . Pkg . archives = archives } in Metacache . add lib ( stdlibPath </> fn ( " META " - ^ lib ) , meta ) ) ) libs
let readOcamlMkConfig filename = let lines = Utils . read_file_with ( function " " -> None | s when s . [ 0 ] = ' ' # -> None | s -> Some s ) ( filename ^ " / Makefile . config " ) in let h = Hashtbl . create 32 in List . iter ( fun l -> let ( k , v ) = Utils . toKVeq l in Hashtbl . add h ( String . lowercase k ) ( default " " v ) ) lines ; h
let prepare projFile user_flags = verbose Verbose " analyzing project \ n " ; %! let ocamlCfg = Prog . getOcamlConfig ( ) in let ocamlMkCfg = readOcamlMkConfig ( Hashtbl . find ocamlCfg " standard_library " ) in let depsTable = Hashtbl . create 16 in let cpkgsTable = Hashtbl . create 1 in let depsDag = Dag . init ( ) in let targetsDag = Dag . init ( ) in let missingDeps = ref StringSet . empty in initializeSystemStdlib ocamlCfg ; let ( ) = let stdlibPath = fp ( get_ocaml_config_key_hashtbl " standard_library " ocamlCfg ) in if not ( List . exists ( fun p -> string_startswith ( fp_to_string p ) ( fp_to_string stdlibPath ) ) ( FindlibConf . get_paths ( ) ) ) then ( Meta . path_warning := true ) in let allTargets = Project . get_all_buildable_targets projFile user_flags in let internalLibs = List . map ( fun lib -> lib . Project . Library . name . Libname . main_name ) projFile . Project . libs in let isInternal lib = List . mem lib . Libname . main_name internalLibs in List . iter ( fun target -> Dag . addNode target . target_name targetsDag ; List . iter ( fun ( dep , _ ) -> if isInternal dep then ( verbose Debug " internal depends : % s \ n " ( Libname . to_string dep ) ; Dag . addEdge target . target_name ( Name . Lib dep ) targetsDag ; ) ) ( Target . get_all_builddeps target ) ; ) allTargets ; let add_missing dep = missingDeps := StringSet . add dep ( ! missingDeps ) in let rec loop dep = let dataDep ( ) = if isInternal dep then ( let iLib = Project . find_lib projFile dep in let iLibDep = Dependency iLib . Project . Library . name in Dag . addNode iLibDep depsDag ; List . iter ( fun ( reqDep , _ ) -> verbose Debug " library % s depends on % s \ n " ( Libname . to_string iLib . Project . Library . name ) ( Libname . to_string reqDep ) ; Dag . addEdge iLibDep ( Dependency reqDep ) depsDag ; loop reqDep ) iLib . Project . Library . target . target_obits . target_builddeps ; Internal ) else ( try begin let ( _ , meta ) = Metacache . get dep . Libname . main_name in Dag . addNode ( Dependency dep ) depsDag ; let pkg = try Meta . Pkg . find dep . Libname . subnames meta with Not_found -> raise ( SublibraryDoesntExists dep ) | Meta . SubpackageNotFound _ -> raise ( SublibraryDoesntExists dep ) in List . iter ( fun ( preds , reqDeps ) -> match preds with | [ Meta . Predicate . Toploop ] -> ( ) | _ -> List . iter ( fun reqDep -> verbose Debug " library % s depends on % s \ n " ( Libname . to_string dep ) ( Libname . to_string reqDep ) ; Dag . addEdge ( Dependency dep ) ( Dependency reqDep ) depsDag ; loop reqDep ) reqDeps ) pkg . Meta . Pkg . requires ; System end with DependencyMissing dep -> ( add_missing dep ; System ) ) in if not ( Hashtbl . mem depsTable dep ) then ( Hashtbl . add depsTable dep ( dataDep ( ) ) ) ; ( ) in List . iter ( fun target -> verbose Debug " getting dependencies for target % s \ n " %! ( Target . get_target_name target ) ; let nodeTarget = Target target . target_name in Dag . addNode nodeTarget depsDag ; let insertEdgeForDependency = ( match target . target_name with | Name . Lib l -> Dag . addNode ( Dependency l ) depsDag ; Dag . addEdge ( Dependency l ) | _ -> fun _ _ -> ( ) ) in List . iter ( fun ( dep , constr ) -> maybe_unit ( fun c -> let ( _ , pkg ) = Metacache . get dep . Libname . main_name in if not ( Expr . eval pkg . Meta . Pkg . version c ) then raise ( Dependencies . BuildDepAnalyzeFailed ( Libname . to_string dep ^ " ( " ^ pkg . Meta . Pkg . version ^ " ) doesn ' t match the constraint " ^ ( Expr . to_string c ) ) ) ) constr ; Dag . addEdge nodeTarget ( Dependency dep ) depsDag ; insertEdgeForDependency ( Dependency dep ) depsDag ; loop dep ; ) ( Target . get_all_builddeps target ) ; if not ( StringSet . is_empty ! missingDeps ) then raise ( DependenciesMissing ( StringSet . to_list ! missingDeps ) ) ; List . iter ( fun ( cpkg , cconstr ) -> let ver = Prog . runPkgConfigVersion cpkg in ignore cconstr ; ignore ver ; let pkgIncludes = List . map fp ( Prog . runPkgConfigIncludes cpkg ) in let pkgLibs = Prog . runPkgConfigLibs cpkg in let pkgConf = { cpkg_conf_libs = pkgLibs ; cpkg_conf_includes = pkgIncludes } in Hashtbl . add cpkgsTable cpkg pkgConf ) target . target_cbits . target_cpkgs ) allTargets ; if gconf . dump_dot then ( let dotDir = Dist . create_build Dist . Dot in let path = dotDir </> fn " dependencies . dot " in let toString t = match t with | Target s -> " target ( " ^ Name . to_string s ^ " ) " | Dependency s -> Libname . to_string s in let dotContent = Dag . toDot toString " dependencies " true depsDag in Filesystem . writeFile path dotContent ; let ipath = dotDir </> fn " internal - dependencies . dot " in let dotIContent = Dag . toDot Name . to_string " internal - dependencies " true targetsDag in Filesystem . writeFile ipath dotIContent ; ) ; { project_dep_data = depsTable ; project_pkgdeps_dag = depsDag ; project_targets_dag = targetsDag ; project_all_deps = List . concat $ List . map ( fun target -> target . target_obits . target_builddeps ) allTargets ; project_ocamlcfg = ocamlCfg ; project_ocamlmkcfg = ocamlMkCfg ; project_file = projFile ; project_cpkgs = cpkgsTable }
module _ = struct let x = 13 , 37 end
module rec A : sig type t = B . t type t = A . t val x : int * int type t = B . t let x = 4 , 2 end type t type t let x = " foo " , " bar " end
let f ( module _ : S ) = ( )
type re = { mutable cell : string ; }
let s = { cell = " " }
module _ = struct let ( ) = s . cell <- " Hello World " ! end
let drop _ = ( )
let ( ) = drop s . cell
let malformed_string s = Format . kasprintf invalid_arg " Terminal . Ansi : malformed UTF - 8 string : % S " s
module Length_counter = struct type t = { mutable acc : int ; mutable state : [ ` Normal | ` Parsing_ansi_sequence | ` Ansi_parameter_bytes ] } let empty ( ) = { acc = 0 ; state = ` Normal } let is_initial_ansi_byte c = Char . equal c ' \ x1b ' let is_final_ansi_byte c = let c = Char . code c in c >= 0x40 && c <= 0x7e let guess_printed_char_length c = match Uucp . Break . tty_width_hint c with | - 1 -> 1 | n -> n let add t c = match Uchar . is_char c with | false -> t . acc <- t . acc + guess_printed_char_length c | true -> ( let c = Uchar . to_char c in match t . state with | ` Normal -> if is_initial_ansi_byte c then t . state <- ` Parsing_ansi_sequence else t . acc <- t . acc + 1 | ` Parsing_ansi_sequence -> if Char . equal c ' [ ' then t . state <- ` Ansi_parameter_bytes else t . state <- ` Normal | ` Ansi_parameter_bytes -> if is_final_ansi_byte c then t . state <- ` Normal ) let count t = t . acc end
let guess_printed_width s = let count = Length_counter . empty ( ) in Uutf . String . fold_utf_8 ( fun ( ) _ -> function | ` Malformed _ -> malformed_string s | ` Uchar c -> Length_counter . add count c ) ( ) s ; Length_counter . count count
let uchar_size u = match Uchar . to_int u with | u when u < 0 -> assert false | u when u <= 0x007F -> 1 | u when u <= 0x07FF -> 2 | u when u <= 0xFFFF -> 3 | u when u <= 0x10FFFF -> 4 | _ -> assert false
let string_equal : string -> string -> bool = ( = )
let truncate_to_width width s = if width < 0 then Format . kasprintf invalid_arg " Terminal . truncate_to_width : negative width % d requested " width ; let count = Length_counter . empty ( ) in try Uutf . String . fold_utf_8 ( fun ( ) i -> function | ` Malformed _ -> malformed_string s | ` Uchar c -> if Length_counter . count count = width then let display_reset = " \ 027 [ 0m " in if i + 4 <= String . length s && string_equal ( String . sub s ~ pos : i ~ len : 4 ) display_reset then raise ( Exit ( i + 4 ) ) else raise ( Exit i ) else ( Length_counter . add count c ; let count = Length_counter . count count in if count <= width then ( ) else raise ( Exit i ) ) ) ( ) s ; s with Exit len -> String . sub s ~ pos : 0 ~ len
let move_up ppf = function 0 -> ( ) | n -> Format . fprintf ppf " \ x1b [ % dA " n
let move_down ppf = function 0 -> ( ) | n -> Format . fprintf ppf " \ x1b [ % dB " n
let apigw_response = ( module struct type t = Http . api_gateway_proxy_response let pp formatter t = Format . pp_print_text formatter ( t |> Http . API_gateway_response . to_yojson |> Lwt_main . run |> Yojson . Safe . pretty_to_string ) let equal = ( = ) end : Alcotest . TESTABLE with type t = Http . api_gateway_proxy_response )
module Http_runtime = struct include Http type event = Http . API_gateway_request . t type response = Http . API_gateway_response . t end
let request = Test_common . make_test_request ( module Http . API_gateway_request ) " apigw_real "
let test_fixture = Test_common . test_fixture ( module Http . API_gateway_request )
let test_runtime = test_runtime_generic ( module Http_runtime ) ~ lift : Lwt . return request
let test_async_runtime = test_runtime_generic ( module Http_runtime ) ~ lift : id request
let response = Http . { status_code = 200 ; headers = StringMap . empty ; body = " Hello " ; is_base64_encoded = false }
let suite = [ " deserialize ( mock ) API Gateway Proxy Request " , ` Quick , test_fixture " apigw " ; ( " deserialize ( real world ) API Gateway Proxy Request " , ` Quick , test_fixture " apigw_real_trimmed " ) ; ( " successful handler invocation " , ` Quick , test_runtime ( fun _event _ctx -> Ok response ) ( fun output -> match output with | Ok result -> Alcotest . check apigw_response " runtime invoke output " response result | Error e -> Alcotest . fail e ) ) ; ( " failed handler invocation " , ` Quick , test_runtime ( fun _event _ctx -> Error " I failed " ) ( fun output -> match output with | Ok response -> let result_str = response |> Http . API_gateway_response . to_yojson |> Lwt_main . run |> Yojson . Safe . pretty_to_string in Alcotest . fail ( Printf . sprintf " Expected to get an error but the call succeeded with : % s " result_str ) | Error e -> Alcotest . ( check string " Runtime invoke error " " I failed " e ) ) ) ; ( " simple asynchronous handler invocation " , ` Quick , test_async_runtime ( fun _event _ctx -> Lwt_result . return response ) ( fun output -> match output with | Ok result -> Alcotest . check apigw_response " runtime invoke output " response result | Error e -> Alcotest . fail e ) ) ]
module Model = struct type t = unit [ @@ deriving sexp ] let init ( ) = ( ) let cutoff _ _ = true end
module Action = struct type t = unit [ @@ deriving sexp ] let should_log _ = true end
module State = struct type t = unit end
let apply_action _ _ _ ~ schedule_action : _ = ( )
let on_startup ~ schedule_action : _ _ = Async_kernel . return ( )
let view_resize_observer = let widget_id = Type_equal . Id . create ~ name " : my widget type " ( fun ( _ : ResizeObserver . resizeObserver Js . t * Dom_html . element Js . t ) -> Sexp . Atom " < resize - observer - widget " ) > in Vdom . Node . widget ~ id : widget_id ~ init ( : fun ( ) -> let div = Dom_html . document ## createElement ( Js . string " div " ) in div . ## className := Js . string " resize - div " ; let resize_observer = Js_of_ocaml . ResizeObserver . observe ~ box ( : Js . string " content - box " ) ~ node : div ~ f ( : fun entries _observer -> Js_of_ocaml . Js . to_array entries |> Array . to_list |> List . iter ~ f ( : fun entry -> let width = entry . ## contentRect . ## width |> Js . Optdef . to_option |> Option . value_exn in let height = entry . ## contentRect . ## height |> Js . Optdef . to_option |> Option . value_exn in div . ## textContent := Js . Opt . return ( Js . string ( sprintf " % f x % f " width height ) ) ) ) ( ) in resize_observer , div ) ~ destroy ( : fun resize_observer _dom_node -> resize_observer ## disconnect ) ( ) ; ;
let view_colorize_button = let widget_id = Type_equal . Id . create ~ name " : my widget type " ( fun _ -> Sexp . Atom " < my widget type " ) > in Vdom . Node . widget ~ id : widget_id ~ init ( : fun ( ) -> let button = Dom_html . document ## createElement ( " button " |> Js . string ) in button . ## innerHTML := " < b > I hearby agree to not use the widget API unless absolutely necessary </ b " > |> Js . string ; let colorify = Js . Unsafe . get Dom_html . window ( " colorify " |> Js . string ) in Js . Unsafe . fun_call colorify [ | Js . Unsafe . inject button ] | |> ignore ; ( ) , button ) ( ) ; ;
let raw_html = Vdom . Node . inner_html ~ tag " : div " ~ attr : Vdom . Attr . empty ~ this_html_is_sanitized_and_is_totally_safe_trust_me " :< b > bold </ b " > ; ;
let view _ ~ inject : _ = Incr . return ( Vdom . Node . div [ view_colorize_button ; view_resize_observer ; raw_html ] ) ; ;
let create model ~ old_model : _ ~ inject = let open Incr . Let_syntax in let % map apply_action = let % map model = model in apply_action model and view = view model ~ inject and model = model in Component . create ~ apply_action model view ; ;
type t = { k : Continuation . t ; args : Simple . t list ; trap_action : Trap_action . Option . t ; dbg : Debuginfo . t }
let print_or_elide_debuginfo ppf dbg = if Debuginfo . is_none dbg then Format . pp_print_string ppf " " else begin Format . pp_print_string ppf " " ; Debuginfo . print_compact ppf dbg end type nonrec t = t let [ @ ocamlformat " disable " ] print ppf { k ; args ; trap_action ; dbg ; } = let name , trap_action = match Continuation . sort k , trap_action , args with | Normal_or_exn , None , [ ] -> " goto " , None | Normal_or_exn , None , _ :: _ -> " apply_cont " , None | Normal_or_exn , Some ( Push _ ) , [ ] -> " goto " , trap_action | Normal_or_exn , Some ( Push _ ) , _ :: _ -> " apply_cont " , trap_action | Normal_or_exn , Some ( Pop { exn_handler ; _ } ) , _ -> if Continuation . equal k exn_handler then " raise " , trap_action else begin match args with | [ ] -> " goto " , trap_action | _ :: _ -> " apply_cont " , trap_action end | Return , None , [ ] -> " return " , None | Return , None , _ :: _ -> " return " , None | Return , Some trap_action , [ ] -> " return " , Some trap_action | Return , Some trap_action , _ :: _ -> " return " , Some trap_action | Define_root_symbol , None , [ ] -> " apply_cont " , None | Define_root_symbol , None , _ :: _ -> " apply_cont " , None | Define_root_symbol , Some trap_action , [ ] -> " apply_cont " , Some trap_action | Define_root_symbol , Some trap_action , _ :: _ -> " apply_cont " , Some trap_action | Toplevel_return , None , [ ] -> " module_init_end " , None | Toplevel_return , None , _ :: _ -> " module_init_end " , None | Toplevel_return , Some trap_action , [ ] -> " module_init_end " , Some trap_action | Toplevel_return , Some trap_action , _ :: _ -> " module_init_end " , Some trap_action in Format . fprintf ppf " [ @< hov 1 >% a @< 0 >% s % s @< 0 >% s % a " Trap_action . Option . print trap_action ( Flambda_colours . expr_keyword ( ) ) name ( Flambda_colours . normal ( ) ) Continuation . print k ; begin match args with | [ ] -> ( ) | args -> Format . fprintf ppf " % a " Simple . List . print args end ; Format . fprintf ppf " @< 0 >% s % a @< 0 >% s ] " @ ( Flambda_colours . elide ( ) ) print_or_elide_debuginfo dbg ( Flambda_colours . normal ( ) ) let hash _ = Misc . fatal_error " Not yet implemented " let compare { k = k1 ; args = args1 ; trap_action = trap_action1 ; dbg = _ } { k = k2 ; args = args2 ; trap_action = trap_action2 ; dbg = _ } = let c = Continuation . compare k1 k2 in if c <> 0 then c else let c = Misc . Stdlib . List . compare Simple . compare args1 args2 in if c <> 0 then c else Option . compare Trap_action . compare trap_action1 trap_action2 let equal t1 t2 = compare t1 t2 = 0 end )
let create ? trap_action k ~ args ~ dbg = { k ; args ; trap_action ; dbg }
let goto k = { k ; args = [ ] ; trap_action = None ; dbg = Debuginfo . none }
let continuation t = t . k
let args t = t . args
let trap_action t = t . trap_action
let debuginfo t = t . dbg
let free_names { k ; args ; trap_action ; dbg = _ } = let default = Simple . List . free_names args in match trap_action with | None -> Name_occurrences . add_continuation default k ~ has_traps : false | Some trap_action -> Name_occurrences . add_continuation ( Name_occurrences . union default ( Trap_action . free_names trap_action ) ) k ~ has_traps : true
let apply_renaming ( { k ; args ; trap_action ; dbg } as t ) perm = let k ' = Renaming . apply_continuation perm k in let args ' = Simple . List . apply_renaming args perm in let trap_action ' = Trap_action . Option . apply_renaming trap_action perm in if k == k ' && args == args ' && trap_action == trap_action ' then t else { k = k ' ; args = args ' ; trap_action = trap_action ' ; dbg }
let all_ids_for_export { k ; args ; trap_action ; dbg = _ } = List . fold_left ( fun ids arg -> Ids_for_export . add_simple ids arg ) ( Ids_for_export . add_continuation ( Trap_action . Option . all_ids_for_export trap_action ) k ) args
let update_continuation t continuation = { t with k = continuation }
let update_continuation_and_args t cont ~ args = if Continuation . equal t . k cont && args == t . args then t else { t with k = cont ; args }
let update_args t ~ args = if args == t . args then t else { t with args }
let with_debuginfo t ~ dbg = if dbg == t . dbg then t else { t with dbg }
let no_args t = match args t with [ ] -> true | _ :: _ -> false
let is_goto t = no_args t && Option . is_none ( trap_action t )
let is_goto_to t k = Continuation . equal ( continuation t ) k && is_goto t
let to_goto t = if no_args t && Option . is_none ( trap_action t ) then Some ( continuation t ) else None
let is_raise t = match t . trap_action with | Some ( Pop { exn_handler ; _ } ) -> Continuation . equal t . k exn_handler | Some ( Push _ ) | None -> false
let clear_trap_action t = { t with trap_action = None }
let to_one_arg_without_trap_action t = match t . trap_action with | Some _ -> None | None -> ( match t . args with [ arg ] -> Some arg | [ ] | _ :: _ :: _ -> None )
type used = | Used | Unused
type t = { original_params : Bound_parameters . t ; used_params : BP . Set . t ; used_extra_params : Bound_parameters . t ; extra_args : ( EA . t * used ) list Id . Map . t }
let print_used ppf = function | Used -> ( ) | Unused -> Format . fprintf ppf " @ unused "
let print_ea_used ppf t = Format . fprintf ppf " ( % a ) " ( Format . pp_print_list ~ pp_sep : Format . pp_print_space ( fun ppf ( ea , used ) -> Format . fprintf ppf " % a % a " EA . print ea print_used used ) ) t
let [ @ ocamlformat " disable " ] print ppf { original_params ; used_params ; used_extra_params ; extra_args ; } = Format . fprintf ppf " [ @< hov 1 ( >\ [ @< hov 1 ( > original_params @ ( % a ) ) ] @@ \ [ @< hov 1 ( > used_params @ % a ) ] @@ \ [ @< hov 1 ( > used_extra_params @ ( % a ) ) ] @@ \ [ @< hov 1 ( > extra_args @ % a ) ] @\ ) ] " @ Bound_parameters . print original_params BP . Set . print used_params Bound_parameters . print used_extra_params ( Id . Map . print print_ea_used ) extra_args
let does_nothing t = Bound_parameters . cardinal t . original_params = BP . Set . cardinal t . used_params && Id . Map . is_empty t . extra_args
let create ~ original_params ~ used_params ~ extra_params ~ extra_args ~ used_extra_params = Bound_parameters . check_no_duplicates original_params ; Bound_parameters . check_no_duplicates extra_params ; if Bound_parameters . cardinal original_params < BP . Set . cardinal used_params then Misc . fatal_errorf " Must have at least as many [ original_params ] ( % a ) @ as [ used_params ] ( % a ) " Bound_parameters . print original_params BP . Set . print used_params ; if Bound_parameters . cardinal extra_params < BP . Set . cardinal used_extra_params then Misc . fatal_errorf " Must have at least as many [ extra_params ] ( % a ) @ as [ used_extra_params ] \ ( % a ) " Bound_parameters . print extra_params BP . Set . print used_extra_params ; let extra_args = Id . Map . map ( fun extra_args -> if Bound_parameters . cardinal extra_params <> List . length extra_args then Misc . fatal_errorf " Lengths of [ extra_params ] ( % a ) @ and all [ extra_args ] ( e . g . % a ) \ should be equal " Bound_parameters . print extra_params Continuation_extra_params_and_args . Extra_arg . List . print extra_args ; let extra_params_and_args = List . combine ( Bound_parameters . to_list extra_params ) extra_args in List . map ( fun ( extra_param , extra_arg ) -> ( extra_arg , if BP . Set . mem extra_param used_extra_params then Used else Unused ) ) extra_params_and_args ) extra_args in let extra_args = if Id . Map . for_all ( fun _ l -> l = [ ] ) extra_args then Id . Map . empty else extra_args in let used_extra_params = Bound_parameters . filter ( fun extra_param -> BP . Set . mem extra_param used_extra_params ) extra_params in { original_params ; used_params ; used_extra_params ; extra_args }
let original_params t = t . original_params
let used_params t = t . used_params
let used_extra_params t = t . used_extra_params
let extra_args t id = match Id . Map . find id t . extra_args with | exception Not_found -> if not ( Bound_parameters . is_empty t . used_extra_params ) then Misc . fatal_errorf " This [ Apply_cont_rewrite ] does not have any @ extra arguments for use \ ID % a , but it has @ >= 1 extra parameter :@ % a " Id . print id print t ; [ ] | extra_args -> extra_args
let original_params_arity t = Bound_parameters . arity_with_subkinds ( original_params t )
module type Model = sig type t val cutoff : t -> t -> bool end
module type Action = sig type t [ @@ deriving sexp_of ] end
module type State = sig type t end
module type S = sig module Model : Model module Action : Action module State : State val on_startup : schedule_action ( : Action . t -> unit ) -> Model . t -> State . t Deferred . t Component . create ~ apply_action model view ; ; ] } The full code for this example can be found in examples / counter . ) * val create : Model . t Incr . t -> old_model : Model . t Incr . t -> inject ( : Action . t -> unit Vdom . Effect . t ) -> ( Action . t , Model . t , State . t ) Component . t Incr . t end
module Private = struct type ( ' state , ' model , ' action ) snapshot = { view : Vdom . Node . t ; apply_action : ' state -> schedule_event ( : unit Ui_effect . t -> unit ) -> ' model -> ' action -> ' model ; update_visibility : ' model -> schedule_event ( : unit Ui_effect . t -> unit ) -> ' model ; on_display : ' state -> schedule_event ( : unit Ui_effect . t -> unit ) -> unit } module type S_for_bonsai = sig module Model : Model module Action : Action module State : State val action_requires_stabilization : Action . t -> bool val on_startup : schedule_action ( : Action . t -> unit ) -> Model . t -> State . t Deferred . t val create : Model . t Incr . t -> old_model : Model . t Incr . t -> inject ( : Action . t -> unit Vdom . Effect . t ) -> ( State . t , Model . t , Action . t ) snapshot Incr . t end end
type t = { size : Dwarf_int . t ; values : Dwarf_value . t list }
let create ~ start_of_code_symbol ~ end_of_code_symbol ~ debug_info_label = let module V = Dwarf_value in let values = [ V . int16 ~ comment " : section version number " ( Int16 . of_int_exn 2 ) ; V . offset_into_debug_info ~ comment " : offset to compilation unit header " debug_info_label ; V . int8 ~ comment " : Dwarf_arch_sizes . size_addr " ( Int8 . of_int_exn Dwarf_arch_sizes . size_addr ) ; V . int8 ~ comment " : flat address space " Int8 . zero ; V . int16 ~ comment " : mystery value 1 " Int16 . zero ; V . int16 ~ comment " : mystery value 2 " Int16 . zero ; V . code_address_from_symbol start_of_code_symbol ; V . code_address_from_symbol_diff ~ comment " : length of code " ~ upper : end_of_code_symbol ~ lower : start_of_code_symbol ( ) ; V . absolute_address ~ comment " : terminator word 1 " Targetint . zero ; V . absolute_address ~ comment " : terminator word 2 " Targetint . zero ] in let size = List . fold_left ( fun size value -> Dwarf_int . add size ( V . size value ) ) ( Dwarf_int . zero ( ) ) values in { size ; values }
let size t = t . size
let emit ~ asm_directives t = Initial_length . emit ~ asm_directives ( Initial_length . create t . size ) ; List . iter ( fun v -> Dwarf_value . emit ~ asm_directives v ) t . values
let pic_code = ref true
let command_line_options = [ " - fPIC " , Arg . Set pic_code , " Generate position - independent machine code ( default ) " ; " - fno - PIC " , Arg . Clear pic_code , " Generate position - dependent machine code " ]
type specific_operation = Imultaddf | Imultsubf
type addressing_mode = | Iindexed of int | Iindexed2 of int
let identity_addressing = Iindexed 0
let offset_addressing addr delta = match addr with | Iindexed n -> Iindexed ( n + delta ) | Iindexed2 n -> Iindexed2 ( n + delta )
let num_args_addressing = function | Iindexed _ -> 1 | Iindexed2 _ -> 2
let print_addressing printreg addr ppf arg = match addr with | Iindexed n -> let idx = if n <> 0 then Printf . sprintf " + % i " n else " " in fprintf ppf " % a % s " printreg arg . ( 0 ) idx | Iindexed2 n -> let idx = if n <> 0 then Printf . sprintf " + % i " n else " " in fprintf ppf " % a + % a % s " printreg arg . ( 0 ) printreg arg . ( 1 ) idx
let print_specific_operation printreg op ppf arg = match op with | Imultaddf -> fprintf ppf " % a * f % a + f % a " printreg arg . ( 0 ) printreg arg . ( 1 ) printreg arg . ( 2 ) | Imultsubf -> fprintf ppf " % a * f % a - f % a " printreg arg . ( 0 ) printreg arg . ( 1 ) printreg arg . ( 2 )
let operation_is_pure _ = true
let operation_can_raise _ = false
type anon_fun = ( string -> unit )
type spec = | Unit of ( unit -> unit ) | Bool of ( bool -> unit ) | Set of bool ref | Clear of bool ref | String of ( string -> unit ) | Set_string of string ref | Int of ( int -> unit ) | Set_int of int ref | Float of ( float -> unit ) | Set_float of float ref | Tuple of spec list | Symbol of string list * ( string -> unit ) | Rest of ( string -> unit ) | Rest_all of ( string list -> unit ) | Expand of ( string -> string array )
type error = | Unknown of string | Wrong of string * string * string | Missing of string | Message of string
let rec assoc3 x l = match l with | [ ] -> raise Not_found | ( y1 , y2 , _ ) :: _ when y1 = x -> y2 | _ :: t -> assoc3 x t
let split s = let i = String . index s ' ' = in let len = String . length s in String . sub s 0 i , String . sub s ( i + 1 ) ( len ( - i + 1 ) )
let make_symlist prefix sep suffix l = match l with | [ ] -> " < none " > | h :: t -> ( List . fold_left ( fun x y -> x ^ sep ^ y ) ( prefix ^ h ) t ) ^ suffix
let print_spec buf ( key , spec , doc ) = if String . length doc > 0 then match spec with | Symbol ( l , _ ) -> bprintf buf " % s % s % s \ n " key ( make_symlist " { " " " | " } " l ) doc | _ -> bprintf buf " % s % s \ n " key doc