text stringlengths 12 786k |
|---|
let transl_class_rebind cl vf = try let obj_init = Ident . create_local " obj_init " and self = Ident . create_local " self " in let obj_init0 = lapply { ap_should_be_tailcall = false ; ap_loc = Location . none ; ap_func = Lvar obj_init ; ap_args [ = Lvar self ] ; ap_inlined = Defau... |
let rec module_path = function Lvar id -> let s = Ident . name id in s <> " " && s . [ 0 ] >= ' A ' && s . [ 0 ] <= ' Z ' | Lprim ( Pfield _ , [ p ] , _ ) -> module_path p | Lprim ( Pgetglobal _ , [ ] , _ ) -> true | _ -> false |
let const_path local = function Lvar id -> not ( List . mem id local ) | Lconst _ -> true | Lfunction { kind = Curried ; body } -> let fv = free_variables body in List . for_all ( fun x -> not ( Ident . Set . mem x fv ) ) local | p -> module_path p |
let rec builtin_meths self env env2 body = let const_path = const_path ( env :: self ) in let conv = function | p when const_path p -> " const " , [ p ] | Lprim ( Parrayrefu _ , [ Lvar s ; Lvar n ] , _ ) when List . mem s self -> " var " , [ Lvar n ] | Lprim ( Pfield... |
module M = struct open CamlinternalOO let builtin_meths self env env2 body = let builtin , args = builtin_meths self env env2 body in let tag = match builtin with " get_const " -> GetConst | " get_var " -> GetVar | " get_env " -> GetEnv | " get_meth " -> GetMeth | " set_var " -> SetVa... |
let free_methods l = let fv = ref Ident . Set . empty in let rec free l = Lambda . iter_head_constructor free l ; match l with | Lsend ( Self , Lvar meth , _ , _ , _ ) -> fv := Ident . Set . add meth ! fv | Lsend _ -> ( ) | Lfunction { params } -> List . iter ( fun ( ... |
let transl_class ids cl_id pub_meths cl vflag = let rebind = transl_class_rebind cl vflag in if rebind <> lambda_unit then rebind else let tables = Ident . create_local ( Ident . name cl_id ^ " _tables " ) in let ( top_env , req ) = oo_add_class tables in let top = not req in let cl_env , ll... |
let transl_class ids id pub_meths cl vf = oo_wrap cl . cl_env false ( transl_class ids id pub_meths cl ) vf |
let ( ) = transl_object := ( fun id meths cl -> transl_class [ ] id meths cl Concrete ) |
let report_error ppf = function | Tags ( lab1 , lab2 ) -> fprintf ppf " Method labels ` % s ' and ` % s ' are incompatible . @ % s " lab1 lab2 " Change one of them . " |
let ( ) = Location . register_error_of_exn ( function | Error ( loc , err ) -> Some ( Location . error_of_printer ~ loc report_error err ) | _ -> None ) |
let int n = Lconst ( Const_base ( Const_int n ) ) |
type binding = { let_kind : let_kind ; value_kind : value_kind ; var : Ident . t ; init : lambda } |
let binding let_kind value_kind var init = { let_kind ; value_kind ; var ; init } |
let gen_binding { let_kind ; value_kind ; var ; init } body = Llet ( let_kind , value_kind , var , init , body ) |
let gen_bindings bindings body = List . fold_right gen_binding bindings body |
let valuekind_of_arraykind = function | Pgenarray -> Pgenval | Paddrarray | Pintarray -> Pintval | Pfloatarray -> Pfloatval |
let transl_arr_clause ~ transl_exp ~ scopes ~ loc clause body = let len_var = Ident . create_local " len_var " in let bindings , for_ = match clause with | In ( pat , e2 ) -> let in_var = Ident . create_local " in_var " in let in_kind = Typeopt . array_kind e2 in let in_binding = bindin... |
let iterate_arr_block ~ transl_exp ~ loc ~ scopes { clauses ; guard } length_var body = let body = match guard with | None -> body | Some guard -> Lifthenelse ( transl_exp ~ scopes guard , body , lambda_unit , Pintval ) in let body , length_opt , bindings = List . fold_left ( fun ( ... |
let make_array_prim ~ loc size init = let prim = Primitive . simple ~ name " : caml_make_vect " ~ arity : 2 ~ alloc : true in Lprim ( Pccall prim , [ size ; init ] , loc ) |
let make_floatarray_prim ~ loc size = let prim = Primitive . simple ~ name " : caml_make_float_vect " ~ arity : 1 ~ alloc : true in Lprim ( Pccall prim , [ size ] , loc ) |
let blit_array_prim ~ loc src src_pos dst dst_pos len = let prim_blit_arr = Primitive . simple ~ name " : caml_array_blit " ~ arity : 5 ~ alloc : true in Lprim ( Pccall prim_blit_arr , [ src ; src_pos ; dst ; dst_pos ; len ] , loc ) |
let make_array ~ loc ~ kind ~ size ~ array = match kind with | Pgenarray -> let init = Lprim ( Pmakearray ( Pgenarray , Immutable , alloc_heap ) , [ ] , loc ) in binding Variable Pgenval array init | Pintarray | Paddrarray -> let init = make_array_prim ~ loc size ( int 0 ) in bindi... |
let init_array_elem ~ loc ~ kind ~ size ~ array ~ index ~ value = let set_elem = Lprim ( Parraysetu kind , [ Lvar array ; Lvar index ; Lvar value ] , loc ) in match kind with | Pgenarray -> let is_first_iteration = Lprim ( Pintcomp Ceq , [ Lvar index ; int 0 ] , loc ) in let ma... |
let init_array_elems ~ loc ~ kind ~ size ~ array ~ index ~ src ~ len = let blit = blit_array_prim ~ loc ( Lvar src ) ( int 0 ) ( Lvar array ) ( Lvar index ) ( Lvar len ) in match kind with | Pgenarray -> let is_first_iteration = Lprim ( Pintcomp Ceq , [ Lvar index ; int 0 ] ... |
let make_counter counter = binding Variable Pintval counter ( int 0 ) |
let increment_counter ~ loc counter step = Lassign ( counter , Lprim ( Paddint , [ Lvar counter ; step ] , loc ) ) |
type block_lambda = | Without_size of { body : lambda } | With_size of { body : lambda ; raise_count : int } |
let transl_arr_block ~ transl_exp ~ loc ~ scopes global_counter body array_kind value_kind block = let length_var = Ident . create_local " len " in let size = match body with | Without_size _ -> Lvar length_var | With_size _ -> Lprim ( Pmulint , [ Lvar length_var ; int 2 ] , loc ) in le... |
let sub_array ~ loc src src_pos len = let prim = Primitive . simple ~ name " : caml_array_sub " ~ arity : 3 ~ alloc : true in Lprim ( Pccall prim , [ src ; src_pos ; len ] , loc ) |
let transl_single_arr_block ~ transl_exp ~ loc ~ scopes block body array_kind value_kind = let body = transl_arr_block ~ transl_exp ~ loc ~ scopes None ( Without_size { body } ) array_kind value_kind block in match body with | Without_size { body } -> body | With_size { body ; raise_count } ... |
type intermediate_array_shape = | Array_of_elements | Array_of_arrays of intermediate_array_shape | Array_of_filtered_arrays of intermediate_array_shape |
let concat_arrays ~ loc arr kind shape global_count_var = let res_var = Ident . create_local " res " in let res_binding = make_array ~ loc ~ kind ~ size ( : Lvar global_count_var ) ~ array : res_var in let counter_var = Ident . create_local " counter " in let counter_binding = make_counter c... |
let transl_arr_comprehension ~ transl_exp ~ loc ~ scopes ~ array_kind exp blocks = let body = transl_exp ~ scopes exp in let value_kind = Typeopt . value_kind exp . exp_env exp . exp_type in match blocks with | [ ] -> assert false | [ block ] -> transl_single_arr_block ~ transl_exp ~ loc ~ ... |
let from_to_comp_prim ~ dir = let function_name = match dir with | Upto -> " map_from_to_cons " | Downto -> " map_from_downto_cons " in Lambda . transl_prim " CamlinternalComprehension " function_name |
let in_comp_prim ( ) = Lambda . transl_prim " CamlinternalComprehension " " map_cons " |
let comp_rev ( ) = Lambda . transl_prim " CamlinternalComprehension " " rev " |
let transl_list_comp type_comp body acc_var mats ~ transl_exp ~ scopes ~ loc = let new_acc = Ident . create_local " acc " in let param , pval , args , func , body , mats = match type_comp with | From_to ( param , _ , e2 , e3 , dir ) -> let pval = Pintval in let from_var = Ident . ... |
let transl_list_comprehension ~ transl_exp ~ loc ~ scopes body blocks = let acc_var = Ident . create_local " acc " in let value_kind = Typeopt . value_kind body . exp_env body . exp_type in let bdy = Lprim ( Pmakeblock ( 0 , Immutable , None , alloc_heap ) , [ ( transl_exp ~ scope... |
type error = Free_super_var | Unreachable_reached |
let transl_module = ref ( ( fun _cc _rootpath _modl -> assert false ) : module_coercion -> Path . t option -> module_expr -> lambda ) |
let transl_object = ref ( fun _id _s _cl -> assert false : Ident . t -> string list -> class_expr -> lambda ) |
let prim_fresh_oo_id = Pccall ( Primitive . simple ~ name " : caml_fresh_oo_id " ~ arity : 1 ~ alloc : false ) |
let transl_extension_constructor env path ext = let path = Printtyp . wrap_printing_env env ~ error : true ( fun ( ) -> Option . map ( Printtyp . rewrite_double_underscore_paths env ) path ) in let name = match path , ! Clflags . for_package with None , _ -> Ident . name ext . ext_i... |
let extract_constant = function Lconst sc -> sc | _ -> raise Not_constant |
let extract_float = function Const_base ( Const_float f ) -> f | _ -> fatal_error " Translcore . extract_float " |
type binding = | Bind_value of value_binding list | Bind_module of Ident . t * string option loc * module_presence * module_expr |
let rec push_defaults loc bindings cases partial = match cases with [ { c_lhs = pat ; c_guard = None ; c_rhs { = exp_desc = Texp_function { arg_label ; param ; cases ; partial ; } } as exp } ] -> let cases = push_defaults exp . exp_loc bindings cases partial in [ { c_lhs = pat ... |
let event_function exp lam = if ! Clflags . debug && not ! Clflags . native_code then let repr = Some ( ref 0 ) in let ( info , body ) = lam repr in ( info , Levent ( body , { lev_loc = exp . exp_loc ; lev_kind = Lev_function ; lev_repr = repr ; lev_env = exp . exp_env } )... |
let assert_failed exp = let slot = transl_extension_path Location . none Env . initial_safe_string Predef . path_assert_failure in let ( fname , line , char ) = Location . get_pos_info exp . exp_loc . Location . loc_start in Lprim ( Praise Raise_regular , [ event_after exp ( Lprim ( P... |
let rec cut n l = if n = 0 then ( [ ] , l ) else match l with [ ] -> failwith " Translcore . cut " | a :: l -> let ( l1 , l2 ) = cut ( n - 1 ) l in ( a :: l1 , l2 ) |
let rec iter_exn_names f pat = match pat . pat_desc with | Tpat_var ( id , _ ) -> f id | Tpat_alias ( p , id , _ ) -> f id ; iter_exn_names f p | _ -> ( ) |
let transl_ident loc env ty path desc = match desc . val_kind with | Val_prim p -> Translprim . transl_primitive loc p env ty ( Some path ) | Val_anc _ -> raise ( Error ( loc , Free_super_var ) ) | Val_reg | Val_self _ -> transl_value_path loc env path | _ -> fatal_error " Translcore . ... |
let rec transl_exp e = List . iter ( Translattribute . check_attribute e ) e . exp_attributes ; let eval_once = match e . exp_desc with Texp_function _ | Texp_for _ | Texp_while _ -> false | _ -> true in if eval_once then transl_exp0 e else Translobj . oo_wrap e . exp_env true transl_exp0 e... |
let report_error ppf = function | Free_super_var -> fprintf ppf " Ancestor names can only be used to select inherited methods " | Unreachable_reached -> fprintf ppf " Unreachable expression was reached " |
let ( ) = Location . register_error_of_exn ( function | Error ( loc , err ) -> Some ( Location . error_of_printer ~ loc report_error err ) | _ -> None ) |
type unsafe_component = | Unsafe_module_binding | Unsafe_functor | Unsafe_non_function | Unsafe_typext |
type unsafe_info = | Unsafe of { reason : unsafe_component ; loc : Location . t ; subid : Ident . t } | Unnamed |
type error = Circular_dependency of ( Ident . t * unsafe_info ) list |
let cons_opt x_opt xs = match x_opt with | None -> xs | Some x -> x :: xs |
let global_path glob = Some ( Pident glob ) |
let functor_path path param = match path with None -> None | Some p -> Some ( Papply ( p , Pident param ) ) |
let field_path path field = match path with None -> None | Some p -> Some ( Pdot ( p , Ident . name field ) ) |
let transl_type_extension env rootpath tyext body = List . fold_right ( fun ext body -> let lam = transl_extension_constructor env ( field_path rootpath ext . ext_id ) ext in Llet ( Strict , Pgenval , ext . ext_id , lam , body ) ) tyext . tyext_constructors body |
let rec apply_coercion loc strict restr arg = match restr with Tcoerce_none -> arg | Tcoerce_structure ( pos_cc_list , id_pos_list ) -> name_lambda strict arg ( fun id -> let get_field pos = if pos < 0 then lambda_unit else Lprim ( Pfield pos , [ Lvar id ] , loc ) in let lam = Lprim ( Pma... |
let rec compose_coercions c1 c2 = match ( c1 , c2 ) with ( Tcoerce_none , c2 ) -> c2 | ( c1 , Tcoerce_none ) -> c1 | ( Tcoerce_structure ( pc1 , ids1 ) , Tcoerce_structure ( pc2 , ids2 ) ) -> let v2 = Array . of_list pc2 in let ids1 = List . map ( fun ( id , pos1 , ... |
let primitive_declarations = ref ( [ ] : Primitive . description list ) |
let record_primitive = function | { val_kind = Val_prim p ; val_loc } -> Translprim . check_primitive_arity val_loc p ; primitive_declarations := p :: ! primitive_declarations | _ -> ( ) |
let mod_prim = Lambda . transl_prim " CamlinternalMod " |
let undefined_location loc = let ( fname , line , char ) = Location . get_pos_info loc . Location . loc_start in Lconst ( Const_block ( 0 , [ Const_base ( Const_string ( fname , None ) ) ; Const_base ( Const_int line ) ; Const_base ( Const_int char ) ] ) ) |
let init_shape id modl = let rec init_shape_mod subid loc env mty = match Mtype . scrape env mty with Mty_ident _ | Mty_alias _ -> raise ( Initialization_failure ( Unsafe { reason = Unsafe_module_binding ; loc ; subid } ) ) | Mty_signature sg -> Const_block ( 0 , [ Const_block ( 0 ,... |
type binding_status = | Undefined | Inprogress of int option | Defined |
type id_or_ignore_loc = | Id of Ident . t | Ignore_loc of Location . t |
let extract_unsafe_cycle id status init cycle_start = let info i = match init . ( i ) with | Result . Error r -> begin match id . ( i ) with | Id id -> id , r | Ignore_loc _ -> assert false end | Ok _ -> assert false in let rec collect stop l i = match status . ( i ) with | Inprogres... |
let reorder_rec_bindings bindings = let id = Array . of_list ( List . map ( fun ( id , _ , _ , _ ) -> id ) bindings ) and loc = Array . of_list ( List . map ( fun ( _ , loc , _ , _ ) -> loc ) bindings ) and init = Array . of_list ( List . map ( fun ( _ ... |
let eval_rec_bindings bindings cont = let rec bind_inits = function [ ] -> bind_strict bindings | ( Ignore_loc _ , _ , _ ) :: rem | ( _ , None , _ ) :: rem -> bind_inits rem | ( Id id , Some ( loc , shape ) , _rhs ) :: rem -> Llet ( Strict , Pgenval , id , Lapp... |
let compile_recmodule compile_rhs bindings cont = eval_rec_bindings ( reorder_rec_bindings ( List . map ( fun { mb_id = id ; mb_name ; mb_expr = modl ; mb_loc = loc ; _ } -> let id_or_ignore_loc , shape = match id with | None -> Ignore_loc mb_name . loc , Result . Error Unnamed | S... |
let transl_class_bindings cl_list = let ids = List . map ( fun ( ci , _ ) -> ci . ci_id_class ) cl_list in ( ids , List . map ( fun ( { ci_id_class = id ; ci_expr = cl ; ci_virt = vf } , meths ) -> ( id , transl_class ids id meths cl vf ) ) cl_list ) |
let merge_inline_attributes attr1 attr2 loc = match Lambda . merge_inline_attributes attr1 attr2 with | Some attr -> attr | None -> raise ( Error ( loc , Conflicting_inline_attributes ) ) |
let merge_functors mexp coercion root_path = let rec merge mexp coercion path acc inline_attribute = let finished = acc , mexp , path , coercion , inline_attribute in match mexp . mod_desc with | Tmod_functor ( param , body ) -> let inline_attribute ' = Translattribute . get_inline_attribute m... |
let rec compile_functor mexp coercion root_path loc = let functor_params_rev , body , body_path , res_coercion , inline_attribute = merge_functors mexp coercion root_path in assert ( List . length functor_params_rev >= 1 ) ; let params , body = List . fold_left ( fun ( params , body ) (... |
let _ = Translcore . transl_module := transl_module |
let scan_used_globals lam = let globals = ref Ident . Set . empty in let rec scan lam = Lambda . iter_head_constructor scan lam ; match lam with Lprim ( ( Pgetglobal id | Psetglobal id ) , _ , _ ) -> globals := Ident . Set . add id ! globals | _ -> ( ) in scan lam ; ! globals |
let required_globals ~ flambda body = let globals = scan_used_globals body in let add_global id req = if not flambda && Ident . Set . mem id globals then req else Ident . Set . add id req in let required = List . fold_left ( fun acc path -> add_global ( Path . head path ) acc ) ( if flambda... |
let transl_implementation_flambda module_name ( str , cc ) = reset_labels ( ) ; primitive_declarations := [ ] ; Translprim . clear_used_primitives ( ) ; let module_id = Ident . create_persistent module_name in let body , size = Translobj . transl_label_init ( fun ( ) -> transl... |
let transl_implementation module_name ( str , cc ) = let implementation = transl_implementation_flambda module_name ( str , cc ) in let code = Lprim ( Psetglobal implementation . module_ident , [ implementation . code ] , Location . none ) in { implementation with code } |
let rec defined_idents = function [ ] -> [ ] | item :: rem -> match item . str_desc with | Tstr_eval _ -> defined_idents rem | Tstr_value ( _rec_flag , pat_expr_list ) -> let_bound_idents pat_expr_list @ defined_idents rem | Tstr_primitive _ -> defined_idents rem | Tstr_type _ -> defin... |
let rec more_idents = function [ ] -> [ ] | item :: rem -> match item . str_desc with | Tstr_eval _ -> more_idents rem | Tstr_value _ -> more_idents rem | Tstr_primitive _ -> more_idents rem | Tstr_type _ -> more_idents rem | Tstr_typext _ -> more_idents rem | Tstr_exception _ -> more_i... |
let transl_store_subst = ref Ident . Map . empty |
let nat_toplevel_name id = try match Ident . Map . find id ! transl_store_subst with | Lprim ( Pfield pos , [ Lprim ( Pgetglobal glob , [ ] , _ ) ] , _ ) -> ( glob , pos ) | _ -> raise Not_found with Not_found -> fatal_error ( " Translmod . nat_toplevel_name : " ^ I... |
let field_of_str loc str = let ids = Array . of_list ( defined_idents str . str_items ) in fun ( pos , cc ) -> match cc with | Tcoerce_primitive { pc_loc ; pc_desc ; pc_env ; pc_type ; } -> Translprim . transl_primitive pc_loc pc_desc pc_env pc_type None | Tcoerce_alias ( env , pat... |
let transl_store_structure glob map prims aliases str = let no_env_update _ _ env = env in let rec transl_store rootpath subst cont = function [ ] -> transl_store_subst := subst ; Lambda . subst no_env_update subst cont | item :: rem -> match item . str_desc with | Tstr_eval ( expr , _attrs ) ... |
let build_ident_map restr idlist more_ids = let rec natural_map pos map prims aliases = function | [ ] -> ( map , prims , aliases , pos ) | id :: rem -> natural_map ( pos + 1 ) ( Ident . add id ( pos , Tcoerce_none ) map ) prims aliases rem in let ( map , prims , aliases , ... |
let transl_store_gen module_name ( { str_items = str } , restr ) topl = reset_labels ( ) ; primitive_declarations := [ ] ; Translprim . clear_used_primitives ( ) ; let module_id = Ident . create_persistent module_name in let ( map , prims , aliases , size ) = build_ident_m... |
let transl_store_phrases module_name str = transl_store_gen module_name ( str , Tcoerce_none ) true |
let transl_store_implementation module_name ( str , restr ) = let s = ! transl_store_subst in transl_store_subst := Ident . Map . empty ; let ( i , code ) = transl_store_gen module_name ( str , restr ) false in transl_store_subst := s ; { Lambda . main_module_block_size = i ; code... |
let toploop_ident = Ident . create_persistent " Toploop " |
let aliased_idents = ref Ident . empty |
let set_toplevel_unique_name id = aliased_idents := Ident . add id ( Ident . unique_toplevel_name id ) ! aliased_idents |
let toplevel_name id = try Ident . find_same id ! aliased_idents with Not_found -> Ident . name id |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.