text
stringlengths
12
786k
let parse name s = match Token . lexer s with | [ ] -> raise ExpressionEmpty | constraints -> parse_constraints name constraints
let parse_builddep s = match Token . lexer s with | [ ] -> raise ExpressionEmpty | Token . ID name :: constraints -> ( name , ( parse_constraints name constraints ) ) | x :: _ -> raise ( InvalidDependencyName ( Token . to_string x ) )
module FV = Camlp4 . Struct . FreeVars . Make Ast ;
module S = FV . S ; let list = [ " " ; + " " ; - " " ; / " " * ] in List . fold_right S . add list S . empty ; object ( self ) inherit FV . fold_free_vars [ S . t ] S . add ~ env_init : pervasives S . empty as super ; value free_sets = [ ] ; method ...
type let_creation_result = | Defining_expr_deleted_at_compile_time | Defining_expr_deleted_at_runtime | Nothing_deleted_at_runtime
let equal_let_creation_results r1 r2 = match r1 , r2 with | Defining_expr_deleted_at_compile_time , Defining_expr_deleted_at_compile_time | Defining_expr_deleted_at_runtime , Defining_expr_deleted_at_runtime | Nothing_deleted_at_runtime , Nothing_deleted_at_runtime -> true | ( ( Defining_expr_deleted_...
let add_set_of_closures_offsets ~ is_phantom named uacc = let add_set uacc set_of_closures = match UA . slot_offsets uacc with | Unknown -> uacc | Known slot_offsets -> let slot_offsets = Slot_offsets . add_set_of_closures slot_offsets ~ is_phantom set_of_closures in UA . with_slot_offsets uacc ( Known...
let create_let uacc ( bound_vars : Bound_pattern . t ) ( defining_expr : Named . t ) ~ free_names_of_defining_expr ~ body ~ cost_metrics_of_defining_expr = let generate_phantom_lets = UA . generate_phantom_lets uacc in let free_names_of_body = UA . name_occurrences uacc in let bound_vars , kee...
let create_coerced_singleton_let uacc var defining_expr ~ coercion_from_defining_expr_to_var ~ free_names_of_defining_expr ~ body ~ cost_metrics_of_defining_expr = if Coercion . is_id coercion_from_defining_expr_to_var then create_let uacc ( Bound_pattern . singleton var ) defining_expr ~ free_names_of_de...
let make_new_let_bindings uacc ( ~ bindings_outermost_first : Simplify_named_result . binding_to_place list ) ~ body = ListLabels . fold_left ( List . rev bindings_outermost_first ) ~ init ( : body , uacc ) ~ f ( : fun ( expr , uacc ) ( { let_bound ; simplified_defining_expr ; ...
let create_raw_let_symbol uacc bound_static static_consts ~ body = let bindable = Bound_pattern . static bound_static in let free_names_of_static_consts = Rebuilt_static_const . Group . free_names static_consts in let free_names_of_body = UA . name_occurrences uacc in let free_names_of_let = let name_occu...
let create_let_symbol0 uacc ( bound_static : Bound_static . t ) ( static_consts : Rebuilt_static_const . Group . t ) ~ body = let will_bind_code = Bound_static . binds_code bound_static in let code_ids_to_make_deleted = if not will_bind_code then Code_id . Set . empty else let all_code_ids_bou...
let remove_unused_value_slots uacc static_const = Rebuilt_static_const . map_set_of_closures static_const ~ f ( : fun set_of_closures -> let name_occurrences = UA . used_value_slots uacc in let value_slots = Value_slot . Map . filter ( fun value_slot _ -> Name_occurrences . value_slot_is_used_or_i...
let create_let_symbols uacc lifted_constant ~ body = let bound_static = LC . bound_static lifted_constant in let symbol_projections = LC . symbol_projections lifted_constant in let static_consts = Rebuilt_static_const . Group . map ( LC . defining_exprs lifted_constant ) ~ f ( : remove_unused_val...
let place_lifted_constants uacc ~ lifted_constants_from_defining_expr ~ lifted_constants_from_body ~ put_bindings_around_body ~ body = let uacc = UA . with_lifted_constants uacc LCS . empty in let place_constants uacc ~ around constants = LCS . fold_innermost_first constants ~ init ( : around , uacc...
let create_switch uacc ~ condition_dbg ~ scrutinee ~ arms = if Targetint_31_63 . Map . cardinal arms < 1 then ( RE . create_invalid Zero_switch_arms , UA . notify_added ~ code_size : Code_size . invalid uacc ) else let change_to_apply_cont action = let uacc = UA . add_free_names uacc ( App...
let rebuild_invalid uacc reason ~ after_rebuild = after_rebuild ( RE . create_invalid reason ) uacc
type rewrite_use_ctx = | Apply_cont | Apply_expr of Simple . t list
type rewrite_use_result = | Apply_cont of Apply_cont . t | Expr of ( apply_cont_to_expr : ( Apply_cont . t -> RE . t * Cost_metrics . t * Name_occurrences . t ) -> RE . t * Cost_metrics . t * Name_occurrences . t )
let no_rewrite apply_cont = Apply_cont apply_cont
let rewrite_use uacc rewrite ~ ctx id apply_cont : rewrite_use_result = let args = Apply_cont . args apply_cont in let original_params ' = Apply_cont_rewrite . original_params rewrite in let original_params = Bound_parameters . to_list original_params ' in if List . compare_lengths args original_param...
let rewrite_exn_continuation rewrite id exn_cont = let exn_cont_arity = Exn_continuation . arity exn_cont in let original_params ' = Apply_cont_rewrite . original_params rewrite in let original_params = Bound_parameters . to_list original_params ' in let original_params_arity = Bound_parameters . arity...
type add_wrapper_for_fixed_arity_continuation0_result = | This_continuation of Continuation . t | Apply_cont of Apply_cont . t | New_wrapper of Continuation . t * RE . Continuation_handler . t * Name_occurrences . t * Cost_metrics . t
type cont_or_apply_cont = | Continuation of Continuation . t | Apply_cont of Apply_cont . t
let add_wrapper_for_fixed_arity_continuation0 uacc cont_or_apply_cont ~ use_id arity : add_wrapper_for_fixed_arity_continuation0_result = let uenv = UA . uenv uacc in let cont = match cont_or_apply_cont with | Continuation cont -> cont | Apply_cont apply_cont -> Apply_cont . continuation apply_cont in let ...
type add_wrapper_for_switch_arm_result = | Apply_cont of Apply_cont . t | New_wrapper of Continuation . t * RE . Continuation_handler . t * Name_occurrences . t * Cost_metrics . t
let add_wrapper_for_switch_arm uacc apply_cont ~ use_id arity : add_wrapper_for_switch_arm_result = match add_wrapper_for_fixed_arity_continuation0 uacc ( Apply_cont apply_cont ) ~ use_id arity with | This_continuation cont -> Apply_cont ( Apply_cont . update_continuation apply_cont cont ) | Apply_cont...
let add_wrapper_for_fixed_arity_continuation uacc cont ~ use_id arity ~ around = match add_wrapper_for_fixed_arity_continuation0 uacc ( Continuation cont ) ~ use_id arity with | This_continuation cont -> around uacc cont | Apply_cont _ -> assert false | New_wrapper ( new_cont , new_handler , free_na...
let add_wrapper_for_fixed_arity_apply uacc ~ use_id arity apply = match Apply . continuation apply with | Never_returns -> let uacc = UA . add_free_names uacc ( Apply . free_names apply ) |> UA . notify_added ~ code_size ( : Code_size . apply apply ) in RE . create_apply ( UA . are_rebui...
let verbose = ref true
let string_of_list f l = let rec aux f = function | [ ] -> " " | [ t ] -> ( f t ) | t :: rest -> ( f t ) ^ " ; " ^ ( aux f rest ) in " [ " ^ ( aux f l ) ^ " ] "
type expr = | INT of int | PLUS of expr * expr | SUBT of expr * expr | MULT of expr * expr
let test1 = PLUS ( INT 1 , PLUS ( INT 2 , PLUS ( INT 3 , PLUS ( INT 4 , INT 5 ) ) ) )
let test2 = PLUS ( PLUS ( PLUS ( PLUS ( INT 1 , INT 2 ) , INT 3 ) , INT 4 ) , INT 5 )
let rec string_of_expr = function | INT a -> string_of_int a | PLUS ( e1 , e2 ) -> " ( " ^ ( string_of_expr e1 ) ^ " + " ^ ( string_of_expr e2 ) ^ " ) " | SUBT ( e1 , e2 ) -> " ( " ^ ( string_of_expr e1 ) ^ " - " ^ ( string_of_expr e2 ) ^ " ) " ...
let rec eval = function | INT a -> a | PLUS ( e1 , e2 ) -> ( eval e1 ) + ( eval e2 ) | SUBT ( e1 , e2 ) -> ( eval e1 ) - ( eval e2 ) | MULT ( e1 , e2 ) -> ( eval e1 ) * ( eval e2 )
type cnt_2 = int -> int
type state_2 = expr * cnt_2
let rec eval_aux_2 ( e , cnt ) = match e with | INT a -> cnt a | PLUS ( e1 , e2 ) -> eval_aux_2 ( e1 , fun v1 -> eval_aux_2 ( e2 , fun v2 -> cnt ( v1 + v2 ) ) ) | SUBT ( e1 , e2 ) -> eval_aux_2 ( e1 , fun v1 -> eval_aux_2 ( e2 , fun v2 -> cnt ( v1 - v2 ) ) ) ...
let id_cnt ( x : int ) = x
let eval_2 e = eval_aux_2 ( e , id_cnt )
type cnt_3 = | ID | OUTER_PLUS of expr * cnt_3 | OUTER_SUBT of expr * cnt_3 | OUTER_MULT of expr * cnt_3 | INNER_PLUS of int * cnt_3 | INNER_SUBT of int * cnt_3 | INNER_MULT of int * cnt_3
type state_3 = expr * cnt_3
let rec apply_3 = function | ( ID , v ) -> v | ( OUTER_PLUS ( e2 , cnt ) , v1 ) -> eval_aux_3 ( e2 , INNER_PLUS ( v1 , cnt ) ) | ( OUTER_SUBT ( e2 , cnt ) , v1 ) -> eval_aux_3 ( e2 , INNER_SUBT ( v1 , cnt ) ) | ( OUTER_MULT ( e2 , cnt ) , v1 ) -...
let eval_3 e = eval_aux_3 ( e , ID )
type tag = | O_PLUS of expr | I_PLUS of int | O_SUBT of expr | I_SUBT of int | O_MULT of expr | I_MULT of int
let string_of_tag = function | O_PLUS e -> " O ( " + ^ ( string_of_expr e ) ^ " ) " | I_PLUS n -> " I ( " + ^ ( string_of_int n ) ^ " ) " | O_SUBT e -> " O ( " - ^ ( string_of_expr e ) ^ " ) " | I_SUBT n -> " I ( " - ^ ( string_of_int n ) ^ ...
type cnt_4 = tag list
type state_4 = expr * cnt_4
let rec apply_4 = function | ( [ ] , v ) -> v | ( ( O_PLUS e2 ) :: cnt , v1 ) -> eval_aux_4 ( e2 , ( I_PLUS v1 ) :: cnt ) | ( ( O_SUBT e2 ) :: cnt , v1 ) -> eval_aux_4 ( e2 , ( I_SUBT v1 ) :: cnt ) | ( ( O_MULT e2 ) :: cnt , v1 ) -> eval_aux_4 ( ...
let eval_4 e = eval_aux_4 ( e , [ ] )
type state_5 = APPLY of cnt_4 * int | EVAL of cnt_4 * expr
let string_of_state5 n = function | EVAL ( cnt , e ) -> " step " ^ ( string_of_int n ) ^ " \ ncnt = " ^ ( string_of_list string_of_tag ( List . rev cnt ) ) ^ " \ nexpr = " ^ ( string_of_expr e ) ^ " \ n " | APPLY ( cnt , m ) -> " step " ^ ( string_of_...
let step_5 = function | EVAL ( cnt , INT m ) -> APPLY ( cnt , m ) | EVAL ( cnt , PLUS ( e1 , e2 ) ) -> EVAL ( ( O_PLUS e2 ) :: cnt , e1 ) | EVAL ( cnt , SUBT ( e1 , e2 ) ) -> EVAL ( ( O_SUBT e2 ) :: cnt , e1 ) | EVAL ( cnt , MULT ( e1 , e2 ) ) ...
let rec driver_5 n state = let _ = if ! verbose then print_string ( string_of_state5 n state ) else ( ) in match state with | APPLY ( [ ] , v ) -> v | _ -> driver_5 ( n + 1 ) ( step_5 state )
let eval_5 e = driver_5 1 ( EVAL ( [ ] , e ) )
type directive = | E of expr | DO_PLUS | DO_SUBT | DO_MULT
type directive_stack = directive list
type value_stack = int list
type state_6 = directive_stack * value_stack
let string_of_directive = function | E e -> string_of_expr e | DO_PLUS -> " DO " + | DO_SUBT -> " DO " - | DO_MULT -> " DO " *
let string_of_state6 n = function | ( ds , vs ) -> " state " ^ ( string_of_int n ) ^ " \ nDS = " ^ ( string_of_list string_of_directive ( List . rev ds ) ) ^ " \ nVS = " ^ ( string_of_list string_of_int ( List . rev vs ) ) ^ " \ n "
let step_6 = function | ( E ( INT v ) :: ds , vs ) -> ( ds , v :: vs ) | ( E ( PLUS ( e1 , e2 ) ) :: ds , vs ) -> ( ( E e1 ) :: ( E e2 ) :: DO_PLUS :: ds , vs ) | ( E ( SUBT ( e1 , e2 ) ) :: ds , vs ) -> ( ( E e1 ) :: ( E e2 ) :: DO...
let rec driver_6 n state = let _ = if ! verbose then print_string ( string_of_state6 n state ) else ( ) in match state with | ( [ ] , [ v ] ) -> v | _ -> driver_6 ( n + 1 ) ( step_6 state )
let eval_6 e = driver_6 1 ( [ E e ] , [ ] )
type instr = | Ipush of int | Iplus | Isubt | Imult
type code = instr list
type state_7 = code * value_stack
let rec compile = function | INT a -> [ Ipush a ] | PLUS ( e1 , e2 ) -> ( compile e1 ) @ ( compile e2 ) @ [ Iplus ] | SUBT ( e1 , e2 ) -> ( compile e1 ) @ ( compile e2 ) @ [ Isubt ] | MULT ( e1 , e2 ) -> ( compile e1 ) @ ( compile e2 ) @ [ Imult ]
let step_7 = function | ( Ipush v :: is , vs ) -> ( is , v :: vs ) | ( Iplus :: is , v2 :: v1 :: vs ) -> ( is , ( v1 + v2 ) :: vs ) | ( Isubt :: is , v2 :: v1 :: vs ) -> ( is , ( v1 - v2 ) :: vs ) | ( Imult :: is , v2 :: v1 :: vs ) -> ( is , ...
let rec string_of_instr = function | Ipush a -> " push " ^ ( string_of_int a ) | Iplus -> " add " | Isubt -> " sub " | Imult -> " mul "
let string_of_state7 n = function | ( is , vs ) -> " state " ^ ( string_of_int n ) ^ " \ nIS = " ^ ( string_of_list string_of_instr ( List . rev is ) ) ^ " \ nVS = " ^ ( string_of_list string_of_int ( List . rev vs ) ) ^ " \ n "
let rec driver_7 n state = let _ = if ! verbose then print_string ( string_of_state7 n state ) else ( ) in match state with | ( [ ] , [ v ] ) -> v | _ -> driver_7 ( n + 1 ) ( step_7 state )
let eval_7 e = driver_7 1 ( compile e , [ ] )
module StringSet = Set . Make ( struct type t = string let compare = compare end )
let to_keep = ref StringSet . empty
let expunge_map tbl = Symtable . filter_global_map ( fun id -> StringSet . mem ( Ident . name id ) ! to_keep ) tbl
let expunge_crcs tbl = List . filter ( fun ( unit , crc ) -> StringSet . mem unit ! to_keep ) tbl
let main ( ) = let input_name = Sys . argv . ( 1 ) in let output_name = Sys . argv . ( 2 ) in Array . iter ( fun exn -> to_keep := StringSet . add exn ! to_keep ) Runtimedef . builtin_exceptions ; for i = 3 to Array . length Sys . argv - 1 do to_keep := StringSet . add...
let _ = Printexc . catch main ( ) ; exit 0
type extension_expr = { clauses : comprehension_clause list ; guard : expression option } expression * Asttypes . direction_flag
type error = | Extension_not_existent of string | Illegal_comprehension_extension_construct
let structure_item_of_expr_desc ~ loc expr_desc = let expr = { pexp_desc = expr_desc ; pexp_loc = loc ; pexp_loc_stack [ ] ; = pexp_attributes [ ] ; = } in Ast_helper . Str . eval ~ loc expr
let structure_item_of_expr ~ loc expr = { pstr_desc = Pstr_eval ( expr , [ ] ) ; pstr_loc = loc ; }
let map_comprehension ~ loc : orig_loc extension_name body comp_list : extension = let loc = { orig_loc with Location . loc_ghost = true } in let unreachable = { pexp_desc = Pexp_unreachable ; pexp_loc = loc ; pexp_loc_stack [ ] ; = pexp_attributes [ ] ; = } in let list = List . ...
let unwrap_expression ~ loc = function
let unwrap_extension ~ loc = function
let unwrap_structure ~ loc = function
let unmap_comprehension ~ loc payload = let str = unwrap_structure ~ loc payload in let get_hd_and_tl = function | [ ] -> Misc . fatal_error " Unexpected structure in comprehension extension . " | hd :: tl -> hd , tl in let str_hd , str_tl = get_hd_and_tl str in let body = unwrap_expression ...
let payload_of_extension_expr ~ loc = function | Eexp_list_comprehension ( body , comp_list ) -> map_comprehension ~ loc " extension . list_comprehension " body comp_list | Eexp_arr_comprehension ( body , comp_list ) -> map_comprehension ~ loc " extension . arr_comprehension " body comp_...
let extension_expr_of_payload ~ loc ( ( name , payload ) : extension ) = match name . txt with | " extension . list_comprehension " -> let body , comp = unmap_comprehension ~ loc payload in Eexp_list_comprehension ( body , comp ) | " extension . arr_comprehension " -> let body ,...
let report_error ~ loc = function | Extension_not_existent extension_name -> Location . errorf ~ loc " Extension % s does not exist . " extension_name | Illegal_comprehension_extension_construct -> Location . errorf ~ loc " Wrong extension syntax for comprehensions . "
let ( ) = Location . register_error_of_exn ( function | Error ( loc , err ) -> Some ( report_error ~ loc err ) | _ -> None )
let foo = Extensions . Foo . { bar = Some 5 ; extensions ' = Ocaml_protoc_plugin . Extensions . default } in let foo = Extensions . Baz ' . set foo ( Some 7 ) in let baz = Extensions . Baz ' . get foo in print_endline ( [ % show : Extensions . Baz . t Ocaml_protoc_plugin...
let test_recursive_meet ( ) = let env = TE . create ~ resolver ( : fun _ -> None ) ~ get_imported_names ( : fun ( ) -> Name . Set . empty ) in let var_x = Variable . create " x " in let var_y = Variable . create " y " in let var_z = Variable . create " z " in let var_...
let test_bottom_detection ( ) = let env = TE . create ~ resolver ( : fun _ -> None ) ~ get_imported_names ( : fun ( ) -> Name . Set . empty ) in let var_x = Variable . create " x " in let n_x = Name . var var_x in let nb_x = Bound_name . create n_x Name_mode . normal in let...
let test_bottom_recursive ( ) = let env = TE . create ~ resolver ( : fun _ -> None ) ~ get_imported_names ( : fun ( ) -> Name . Set . empty ) in let var_x = Variable . create " x " in let n_x = Name . var var_x in let nb_x = Bound_name . create n_x Name_mode . normal in let...
let test_double_recursion ( ) = let env = TE . create ~ resolver ( : fun _ -> None ) ~ get_imported_names ( : fun ( ) -> Name . Set . empty ) in let var_x = Variable . create " x " in let var_y = Variable . create " y " in let var_z = Variable . create " z " in let n_...
let _ = let comp_unit = let id = Ident . create_persistent " Test " in let linkage_name = Linkage_name . create " camlTest " in Compilation_unit . create id linkage_name in Compilation_unit . set_current comp_unit ; test_double_recursion ( )
type t = { start : int64 ; length : int64 ;