text stringlengths 12 786k |
|---|
let transl_prim mod_name name = let pers = Ident . create_persistent mod_name in let env = Env . add_persistent_structure pers Env . empty in let lid = Longident . Ldot ( Longident . Lident mod_name , name ) in match Env . find_value_by_name lid env with | path , _ -> transl_value_path Loc_un... |
let rec make_sequence fn = function [ ] -> lambda_unit | [ x ] -> fn x | x :: rem -> let lam = fn x in Lsequence ( lam , make_sequence fn rem ) |
let subst update_env ( ? freshen_bound_variables = false ) s input_lam = let bind id l = let id ' = if not freshen_bound_variables then id else Ident . rename id in id ' , Ident . Map . add id id ' l in let bind_many ids l = List . fold_right ( fun ( id , rhs ) ( ids ' , l ) -... |
let rename idmap lam = let update_env oldid vd env = let newid = Ident . Map . find oldid idmap in Env . add_value newid vd env in let s = Ident . Map . map ( fun new_id -> Lvar new_id ) idmap in subst update_env s lam |
let duplicate lam = subst ( fun _ _ env -> env ) ~ freshen_bound_variables : true Ident . Map . empty lam |
let shallow_map ~ tail ~ non_tail : f = function | Lvar _ | Lconst _ as lam -> lam | Lapply { ap_func ; ap_args ; ap_region_close ; ap_mode ; ap_loc ; ap_tailcall ; ap_inlined ; ap_specialised ; ap_probe } -> Lapply { ap_func = f ap_func ; ap_args = List . map f ap_args ; ap_reg... |
let map f = let rec g lam = f ( shallow_map ~ tail : g ~ non_tail : g lam ) in g |
let bind_with_value_kind str ( var , kind ) exp body = match exp with Lvar var ' when Ident . same var var ' -> body | _ -> Llet ( str , kind , var , exp , body ) |
let bind str var exp body = bind_with_value_kind str ( var , Pgenval ) exp body |
let negate_integer_comparison = function | Ceq -> Cne | Cne -> Ceq | Clt -> Cge | Cle -> Cgt | Cgt -> Cle | Cge -> Clt |
let swap_integer_comparison = function | Ceq -> Ceq | Cne -> Cne | Clt -> Cgt | Cle -> Cge | Cgt -> Clt | Cge -> Cle |
let negate_float_comparison = function | CFeq -> CFneq | CFneq -> CFeq | CFlt -> CFnlt | CFnlt -> CFlt | CFgt -> CFngt | CFngt -> CFgt | CFle -> CFnle | CFnle -> CFle | CFge -> CFnge | CFnge -> CFge |
let swap_float_comparison = function | CFeq -> CFeq | CFneq -> CFneq | CFlt -> CFgt | CFnlt -> CFngt | CFle -> CFge | CFnle -> CFnge | CFgt -> CFlt | CFngt -> CFnlt | CFge -> CFle | CFnge -> CFnle |
let raise_kind = function | Raise_regular -> " raise " | Raise_reraise -> " reraise " | Raise_notrace -> " raise_notrace " |
let merge_inline_attributes attr1 attr2 = match attr1 , attr2 with | Default_inline , _ -> Some attr2 | _ , Default_inline -> Some attr1 | _ , _ -> if attr1 = attr2 then Some attr1 else None |
let max_arity ( ) = if ! Clflags . native_code then 126 else max_int |
let reset ( ) = raise_count := 0 |
let mod_field ( ? read_semantics = Reads_agree ) pos = Pfield ( pos , read_semantics ) |
let mod_setfield pos = Psetfield ( pos , Pointer , Root_initialization ) |
let primitive_may_allocate : primitive -> alloc_mode option = function | Pidentity | Pbytes_to_string | Pbytes_of_string | Pignore -> None | Prevapply _ | Pdirapply _ -> Some alloc_local | Pgetglobal _ | Psetglobal _ -> None | Pmakeblock ( _ , _ , _ , m ) -> Some m | Pmakefloatblock ( ... |
type lambda = Lambda of string * lambda | Var of string | Apply of lambda * lambda |
let ( ) = Format . set_margin 20 |
let sample_data = Lambda ( " n " , ( Lambda ( " f " , ( Lambda ( ) ) ) ) ) ) |
let rec pr_exp0 ppf = function | Var s -> ident ppf s | lam -> fprintf ppf " [ @< 1 ( >% a ) ] " @ pr_lambda lam | e -> fprintf ppf " [ @< 2 >% a ] " @ pr_other_applications e match f with | Apply ( f , arg ) -> fprintf ppf " % a @ % a " pr_app f pr_exp0 arg | f -> pr... |
let print_lambda x = pr_lambda std_formatter x ; pp_print_flush std_formatter ( ) |
let ( ) = print_endline " Example from \ http :// caml . inria . fr / resources / doc / guides / format . html # example " ; print_lambda sample_data ; print_newline ( ) |
let p1 = { label with indent_after_label = 1 } |
let p2 = { label with indent_after_label = 2 } |
let paren_style = { list with space_after_opening = false ; space_before_closing = false ; align_closing = false } |
let rec exp0_node = function Var s -> Atom ( s , atom ) | lam -> List ( ( " ( " , " " , " ) " , paren_style ) , [ lambda_node lam ] ) Apply ( f , arg ) -> Label ( ( app_node f , p2 ) , exp0_node arg ) | f -> exp0_node f Lambda ( s , lam ) -> Labe... |
let ( ) = print_endline " Same , using Easy_format " ; : Pretty . to_stdout ( lambda_node sample_data ) ; print_newline ( ) |
module S = Set . Make String ; |
type term = [ Lambda of string and term | Atom of string | App of term and term | Opt of term and option term and term ] ; let rec fv t env free = match t with [ Lambda x t -> fv t ( S . add x env ) free | Atom x -> if S . mem x env then free else S . add x free | App t1 t2 -> fv t1 env ( ... |
module Env : sig type t val create : current_unit_id : Ident . t -> return_continuation : Continuation . t -> exn_continuation : Continuation . t -> t val current_unit_id : t -> Ident . t val is_mutable : t -> Ident . t -> bool val register_mutable_variable : t -> Ident . t -> Lambda . val... |
type primitive_transform_result = | Primitive of L . primitive * L . lambda list * L . scoped_location | Transformed of L . lambda |
let print_compact_location ppf ( loc : Location . t ) = if loc . loc_start . pos_fname = " // toplevel " // then ( ) else let file , line , startchar = Location . get_pos_info loc . loc_start in let endchar = loc . loc_end . pos_cnum - loc . loc_start . pos_cnum + startchar in... |
let name_for_function ( func : Lambda . lfunction ) = match func . loc with | Loc_unknown -> " anon - fn " | Loc_known { loc ; _ } -> Format . asprintf " anon - fn [ % a ] " print_compact_location loc |
let extra_args_for_exn_continuation env exn_handler = let more_extra_args = Env . extra_args_for_continuation_with_kinds env exn_handler in List . map ( fun ( arg , kind ) : ( IR . simple * _ ) -> Var arg , kind ) more_extra_args |
let _print_stack ppf stack = Format . fprintf ppf " % a " ( Format . pp_print_list ~ pp_sep ( : fun ppf ( ) -> Format . fprintf ppf " ; " ) ( fun ppf ( _id , cont ) -> Format . fprintf ppf " % a " Continuation . print cont ) ) stack |
let compile_staticfail acc env ccenv ( ~ continuation : Continuation . t ) ~ args : Acc . t * Expr_with_acc . t = let try_stack_at_handler = Env . get_try_stack_at_handler env continuation in let try_stack_now = Env . get_try_stack env in let dbg = Debuginfo . none in if List . length try_sta... |
let switch_for_if_then_else ~ cond ~ ifso ~ ifnot ~ kind = let switch : Lambda . lambda_switch = { sw_numconsts = 2 ; sw_consts = [ 0 , ifnot ; 1 , ifso ] ; sw_numblocks = 0 ; sw_blocks = [ ] ; sw_failaction = None } in L . Lswitch ( cond , switch , Loc_unknown , ki... |
let transform_primitive env ( prim : L . primitive ) args loc = match prim , args with | Psequor , [ arg1 ; arg2 ] -> let const_true = Ident . create_local " const_true " in let cond = Ident . create_local " cond_sequor " in Transformed ( L . Llet ( Strict , Pgenval , const_t... |
let rec_catch_for_while_loop env cond body = let cont = L . next_raise_count ( ) in let env = Env . mark_as_recursive_static_catch env cont in let cond_result = Ident . create_local " while_cond_result " in let lam : L . lambda = Lstaticcatch ( Lstaticraise ( cont , [ ] ) , ( cont ... |
let rec_catch_for_for_loop env ident start stop ( dir : Asttypes . direction_flag ) body = let cont = L . next_raise_count ( ) in let env = Env . mark_as_recursive_static_catch env cont in let start_ident = Ident . create_local " for_start " in let stop_ident = Ident . create_local " for_s... |
let let_cont_nonrecursive_with_extra_params acc env ccenv ~ is_exn_handler ~ params ( ~ body : Acc . t -> Env . t -> CCenv . t -> Continuation . t -> Acc . t * Expr_with_acc . t ) ( ~ handler : Acc . t -> Env . t -> CCenv . t -> Acc . t * Expr_with_acc . t ) : Acc . t * ... |
let restore_continuation_context acc env ccenv cont ~ close_early body = match Env . pop_regions_to_context env cont with | None -> body acc ccenv cont | Some region -> if close_early then CC . close_let acc ccenv ( Ident . create_local " unit " ) Not_user_visible ( End_region region ) ~ body (... |
let apply_cont_with_extra_args acc env ccenv ~ dbg cont traps args = let extra_args = List . map ( fun var : IR . simple -> Var var ) ( Env . extra_args_for_continuation env cont ) in restore_continuation_context acc env ccenv cont ~ close_early : false ( fun acc ccenv cont -> CC . close_apply... |
let wrap_return_continuation acc env ccenv ( apply : IR . apply ) = let extra_args = Env . extra_args_for_continuation env apply . continuation in let body acc ccenv continuation = match extra_args with | [ ] -> CC . close_apply acc ccenv { apply with continuation } | _ :: _ -> let wrappe... |
let primitive_can_raise ( prim : Lambda . primitive ) = match prim with | Pccall _ | Praise _ | Parrayrefs _ | Parraysets _ | Pmodint _ | Pdivint _ | Pstringrefs | Pbytesrefs | Pbytessets | Pstring_load_16 false | Pstring_load_32 ( false , _ ) | Pstring_load_64 ( false , _ ) | P... |
let rec cps_non_tail acc env ccenv ( lam : L . lambda ) ( k : Acc . t -> Env . t -> CCenv . t -> Ident . t -> Acc . t * Expr_with_acc . t ) ( k_exn : Continuation . t ) : Acc . t * Expr_with_acc . t = match lam with | Lvar id -> if Env . is_mutable env id then name_then_cp... |
let lambda_to_flambda ~ symbol_for_global ~ big_endian ~ cmx_loader ~ module_ident ~ module_block_size_in_words ( lam : Lambda . lambda ) : Flambda_unit . t * Exported_code . t * Flambda_cmx_format . t option * Exported_offsets . t = let current_unit_id = Compilation_unit . get_persistent_id... |
let convert_block_of_values_field ( value_kind : L . value_kind ) : P . Block_of_values_field . t = match value_kind with | Pgenval -> Any_value | Pfloatval -> Boxed_float | Pboxedintval Pint32 -> Boxed_int32 | Pboxedintval Pint64 -> Boxed_int64 | Pboxedintval Pnativeint -> Boxed_nativeint | Pin... |
let convert_integer_comparison_prim ( comp : L . integer_comparison ) : P . binary_primitive = match comp with | Ceq -> Phys_equal ( K . value , Eq ) | Cne -> Phys_equal ( K . value , Neq ) | Clt -> Int_comp ( Tagged_immediate , Signed , Yielding_bool Lt ) | Cgt -> Int_comp ( ... |
let convert_boxed_integer_comparison_prim ( kind : L . boxed_integer ) ( comp : L . integer_comparison ) : P . binary_primitive = match kind , comp with | Pint32 , Ceq -> Phys_equal ( K . naked_int32 , Eq ) | Pint32 , Cne -> Phys_equal ( K . naked_int32 , Neq ) | Pint32 , ... |
let convert_float_comparison ( comp : L . float_comparison ) : P . comparison = match comp with | CFeq -> Eq | CFneq -> Neq | CFlt -> Lt | CFgt -> Gt | CFle -> Le | CFge -> Ge | CFnlt | CFngt | CFnle | CFnge -> Misc . fatal_error " Negated floating - point comparisons should have been r... |
let boxable_number_of_boxed_integer ( bint : L . boxed_integer ) : Flambda_kind . Boxable_number . t = match bint with | Pnativeint -> Naked_nativeint | Pint32 -> Naked_int32 | Pint64 -> Naked_int64 |
let standard_int_of_boxed_integer ( bint : L . boxed_integer ) : Flambda_kind . Standard_int . t = match bint with | Pnativeint -> Naked_nativeint | Pint32 -> Naked_int32 | Pint64 -> Naked_int64 |
let standard_int_or_float_of_boxed_integer ( bint : L . boxed_integer ) : Flambda_kind . Standard_int_or_float . t = match bint with | Pnativeint -> Naked_nativeint | Pint32 -> Naked_int32 | Pint64 -> Naked_int64 |
let convert_block_access_field_kind i_or_p : P . Block_access_field_kind . t = match i_or_p with L . Immediate -> Immediate | L . Pointer -> Any_value |
let convert_init_or_assign ( i_or_a : L . initialization_or_assignment ) : P . Init_or_assign . t = match i_or_a with | Assignment mode -> Assignment ( Alloc_mode . from_lambda mode ) | Heap_initialization -> Initialization | Root_initialization -> Misc . fatal_error " [ Root_initializati... |
let convert_block_shape ( shape : L . block_shape ) ~ num_fields = match shape with | None -> List . init num_fields ( fun _field : P . Block_of_values_field . t -> Any_value ) | Some shape -> let shape_length = List . length shape in if num_fields <> shape_length then Misc . fatal_error... |
let check_float_array_optimisation_enabled ( ) = if not ( Flambda_features . flat_float_array ( ) ) then Misc . fatal_error " [ Pgenarray ] is not expected when the float array optimisation is \ disabled " |
type converted_array_kind = | Array_kind of P . Array_kind . t | Float_array_opt_dynamic |
let convert_array_kind ( kind : L . array_kind ) : converted_array_kind = match kind with | Pgenarray -> check_float_array_optimisation_enabled ( ) ; Float_array_opt_dynamic | Paddrarray -> Array_kind Values | Pintarray -> Array_kind Immediates | Pfloatarray -> Array_kind Naked_floats |
type converted_duplicate_array_kind = | Duplicate_array_kind of P . Duplicate_array_kind . t | Float_array_opt_dynamic |
let convert_array_kind_to_duplicate_array_kind ( kind : L . array_kind ) : converted_duplicate_array_kind = match kind with | Pgenarray -> check_float_array_optimisation_enabled ( ) ; Float_array_opt_dynamic | Paddrarray -> Duplicate_array_kind Values | Pintarray -> Duplicate_array_kind Immediates ... |
let convert_field_read_semantics ( sem : L . field_read_semantics ) : Mutability . t = match sem with Reads_agree -> Immutable | Reads_vary -> Mutable |
let bigarray_dim_bound b dimension = H . Prim ( Unary ( Bigarray_length { dimension } , b ) ) |
let tag_int ( arg : H . expr_primitive ) : H . expr_primitive = Unary ( Tag_immediate , Prim arg ) |
let untag_int ( arg : H . simple_or_prim ) : H . simple_or_prim = Prim ( Unary ( Untag_immediate , arg ) ) |
let box_float ( mode : L . alloc_mode ) ( arg : H . expr_primitive ) : H . expr_primitive = Unary ( Box_number ( Flambda_kind . Boxable_number . Naked_float , Alloc_mode . from_lambda mode ) , Prim arg ) |
let unbox_float ( arg : H . simple_or_prim ) : H . simple_or_prim = Prim ( Unary ( Unbox_number Flambda_kind . Boxable_number . Naked_float , arg ) ) |
let box_bint bi mode ( arg : H . expr_primitive ) : H . expr_primitive = Unary ( Box_number ( boxable_number_of_boxed_integer bi , Alloc_mode . from_lambda mode ) , Prim arg ) |
let unbox_bint bi ( arg : H . simple_or_prim ) : H . simple_or_prim = Prim ( Unary ( Unbox_number ( boxable_number_of_boxed_integer bi ) , arg ) ) |
let bint_unary_prim bi mode prim arg1 = box_bint bi mode ( Unary ( Int_arith ( standard_int_of_boxed_integer bi , prim ) , unbox_bint bi arg1 ) ) |
let bint_binary_prim bi mode prim arg1 arg2 = box_bint bi mode ( Binary ( Int_arith ( standard_int_of_boxed_integer bi , prim ) , unbox_bint bi arg1 , unbox_bint bi arg2 ) ) |
let bint_shift bi mode prim arg1 arg2 = box_bint bi mode ( Binary ( Int_shift ( standard_int_of_boxed_integer bi , prim ) , unbox_bint bi arg1 , untag_int arg2 ) ) |
let check_non_negative_imm imm prim_name = if not ( Targetint_31_63 . is_non_negative imm ) then Misc . fatal_errorf " % s with negative index % a " prim_name Targetint_31_63 . print imm |
let checked_access ~ dbg ~ primitive ~ conditions : H . expr_primitive = Checked { primitive ; validity_conditions = conditions ; failure = Index_out_of_bounds ; dbg } |
let check_bound_tagged tagged_index bound : H . expr_primitive = Binary ( Int_comp ( I . Naked_immediate , Unsigned , Yielding_bool Lt ) , untag_int tagged_index , bound ) |
let max_with_zero ~ size_int x = let register_bitsize_minus_one = H . Simple ( Simple . const ( Reg_width_const . naked_immediate ( Targetint_31_63 . int ( Targetint_31_63 . Imm . of_int ( ( size_int * 8 ) - 1 ) ) ) ) ) in let sign = H . Prim ( Binary ( Int_shift ( Na... |
let actual_max_length_for_string_like_access ~ size_int ~ access_size length = let length_offset_of_size size = let offset = match ( size : Flambda_primitive . string_accessor_width ) with | Eight -> 0 | Sixteen -> 1 | Thirty_two -> 3 | Sixty_four -> 7 in Targetint_31_63 . int ( Targetint_31... |
let string_like_access_validity_condition ~ size_int ~ access_size ~ length index : H . expr_primitive = check_bound_tagged index ( actual_max_length_for_string_like_access ~ size_int ~ access_size length ) |
let string_or_bytes_access_validity_condition ~ size_int str kind access_size index : H . expr_primitive = string_like_access_validity_condition index ~ size_int ~ access_size ~ length ( : Prim ( Unary ( String_length kind , str ) ) ) |
let bigstring_access_validity_condition ~ size_int big_str access_size index : H . expr_primitive = string_like_access_validity_condition index ~ size_int ~ access_size ~ length ( : bigarray_dim_bound big_str 1 ) |
let checked_string_or_bytes_access ~ dbg ~ size_int ~ access_size ~ primitive kind string index = checked_access ~ dbg ~ primitive ~ conditions : [ string_or_bytes_access_validity_condition ~ size_int string kind access_size index ] |
let checked_bigstring_access ~ dbg ~ size_int ~ access_size ~ primitive arg1 arg2 = checked_access ~ dbg ~ primitive ~ conditions : [ bigstring_access_validity_condition ~ size_int arg1 access_size arg2 ] |
let string_like_load_unsafe ~ access_size kind mode string index = let wrap = match ( access_size : Flambda_primitive . string_accessor_width ) , mode with | ( Eight | Sixteen ) , None -> tag_int | Thirty_two , Some mode -> box_bint Pint32 mode | Sixty_four , Some mode -> box_bint Pint64 mo... |
let string_like_load_safe ~ dbg ~ size_int ~ access_size kind mode str index = match ( kind : P . string_like_value ) with | String -> checked_string_or_bytes_access ~ dbg ~ size_int ~ access_size String ~ primitive ( : string_like_load_unsafe ~ access_size String mode str index ) str index | By... |
let bytes_like_set_unsafe ~ access_size kind bytes index new_value = let wrap = match ( access_size : Flambda_primitive . string_accessor_width ) with | Eight | Sixteen -> untag_int | Thirty_two -> unbox_bint Pint32 | Sixty_four -> unbox_bint Pint64 in H . Ternary ( Bytes_or_bigstring_set ( kind ... |
let bytes_like_set_safe ~ dbg ~ size_int ~ access_size kind bytes index new_value = match ( kind : P . bytes_like_value ) with | Bytes -> checked_string_or_bytes_access ~ dbg ~ size_int ~ access_size Bytes ~ primitive : ( bytes_like_set_unsafe ~ access_size Bytes bytes index new_value ) bytes ind... |
let bigarray_box_or_tag_raw_value_to_read kind alloc_mode = let error what = Misc . fatal_errorf " Don ' t know how to box % s after reading it in a bigarray " what in match P . element_kind_of_bigarray_kind kind with | Value -> Fun . id | Naked_number Naked_immediate -> fun arg -> H . Unary ( T... |
let bigarray_unbox_or_untag_value_to_store kind = let error what = Misc . fatal_errorf " Don ' t know how to unbox % s to store it in a bigarray " what in match P . element_kind_of_bigarray_kind kind with | Value -> Fun . id | Naked_number Naked_immediate -> fun arg -> H . Prim ( Unary ( Untag... |
let bigarray_indexing layout b args = let num_dim = List . length args in let rec aux dim delta_dim = function | [ ] -> assert false | [ idx ] -> let bound = bigarray_dim_bound b dim in let check = check_bound_tagged idx bound in [ check ] , idx | idx :: r -> let checks , rem = aux ( di... |
let bigarray_access ~ dbg ~ unsafe ~ access layout b indexes = let num_dim = List . length indexes in let checks , offset = bigarray_indexing layout b indexes in let primitive = access num_dim offset in if unsafe then primitive else checked_access ~ dbg ~ conditions : checks ~ primitive |
let bigarray_load ~ dbg ~ unsafe kind layout b indexes = let access num_dim offset = H . Binary ( Bigarray_load ( num_dim , kind , layout ) , b , offset ) in bigarray_access ~ dbg ~ unsafe ~ access layout b indexes |
let bigarray_set ~ dbg ~ unsafe kind layout b indexes value = let access num_dim offset = H . Ternary ( Bigarray_set ( num_dim , kind , layout ) , b , offset , value ) in bigarray_access ~ dbg ~ unsafe ~ access layout b indexes |
let array_access_validity_condition array index = [ H . Binary ( Int_comp ( Tagged_immediate , Unsigned , Yielding_bool Lt ) , index , Prim ( Unary ( Array_length , array ) ) ) ] |
let check_array_access ~ dbg ~ array ~ index primitive : H . expr_primitive = checked_access ~ primitive ~ conditions ( : array_access_validity_condition array index ) ~ dbg |
let array_load_unsafe ~ array ~ index ( array_kind : P . Array_kind . t ) : H . expr_primitive = match array_kind with | Immediates | Values -> Binary ( Array_load ( array_kind , Mutable ) , array , index ) | Naked_floats -> box_float L . alloc_heap ( Binary ( Array_load ( Nake... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.