text
stringlengths
12
786k
let make = Variables . make ( " MAKE " , " Command used to invoke make " )
let ocamltest_response = Variables . make ( " ocamltest_response " , " File used by hooks to send back information . " )
let ocamltest_log = Variables . make ( " ocamltest_log " , " Path to log file for the current test " )
let output = Variables . make ( " output " , " Where the output of executing the program is saved " )
let program = Variables . make ( " program " , " Name of program produced by ocamlc . byte and ocamlopt . byte " )
let program2 = Variables . make ( " program2 " , " Name of program produced by ocamlc . opt and ocamlopt . opt " )
let promote = Variables . make ( " promote " , " Set to " \ true " \ to overwrite reference files with the test output " )
let reason = Variables . make ( " reason " , " Let a test report why it passed / skipped / failed . " )
let reference = Variables . make ( " reference " , " Path of file to which program output should be compared " )
let skip_header_lines = Variables . make ( " skip_header_lines " , " The number of lines to skip when comparing program output \ with the reference file " )
let skip_header_bytes = Variables . make ( " skip_header_bytes " , " The number of bytes to skip when comparing program output \ with the reference file " )
let script = Variables . make ( " script " , " External script to run " )
let stdin = Variables . make ( " stdin " , " Default standard input " )
let stdout = Variables . make ( " stdout " , " Default standard output " )
let stderr = Variables . make ( " stderr " , " Default standard error " )
let test_build_directory = Variables . make ( " test_build_directory " , " Directory for files produced during a test " )
let test_build_directory_prefix = Variables . make ( " test_build_directory_prefix " , " Directory under which all test directories should be created " )
let test_file = Variables . make ( " test_file " , " Name of file containing the specification of which tests to run " )
let test_source_directory = Variables . make ( " test_source_directory " , " Directory containing the test source files " )
let test_pass = Variables . make ( " TEST_PASS " , " Exit code to let a script report success " )
let test_skip = Variables . make ( " TEST_SKIP " , " Exit code to let a script report skipping " )
let test_fail = Variables . make ( " TEST_FAIL " , " Exit code to let a script report failure " )
let _ = List . iter Variables . register_variable [ arguments ; cwd ; commandline ; exit_status ; files ; make ; ocamltest_response ; ocamltest_log ; output ; program ; program2 ; reason ; reference ; skip_header_lines ; skip_header_bytes ; script ; stdin ; stdout ; stderr ; ...
let label_counter = ref 0
let new_label ( ) = incr label_counter ; ! label_counter
let empty_env = { ce_stack = Ident . empty ; ce_heap = Ident . empty ; ce_rec = Ident . empty }
let add_var id pos env = { ce_stack = Ident . add id pos env . ce_stack ; ce_heap = env . ce_heap ; ce_rec = env . ce_rec }
let rec add_vars idlist pos env = match idlist with [ ] -> env | id :: rem -> add_vars rem ( pos + 1 ) ( add_var id pos env )
let label_code = function Kbranch lbl :: _ as cont -> ( lbl , cont ) | Klabel lbl :: _ as cont -> ( lbl , cont ) | cont -> let lbl = new_label ( ) in ( lbl , Klabel lbl :: cont )
let rec make_branch_2 lbl n cont = function Kreturn m :: _ -> ( Kreturn ( n + m ) , cont ) | Klabel _ :: c -> make_branch_2 lbl n cont c | Kpop m :: c -> make_branch_2 lbl ( n + m ) cont c | _ -> match lbl with Some lbl -> ( Kbranch lbl , cont ) | None -> let lbl = new_label ( ...
let make_branch cont = match cont with ( Kbranch _ as branch ) :: _ -> ( branch , cont ) | ( Kreturn _ as return ) :: _ -> ( return , cont ) | Kraise k :: _ -> ( Kraise k , cont ) | Klabel lbl :: _ -> make_branch_2 ( Some lbl ) 0 cont cont | _ -> make_branch_2 ( Non...
let branch_to label cont = match cont with
let rec discard_dead_code = function [ ] -> [ ] | ( Klabel _ | Krestart | Ksetglobal _ ) :: _ as cont -> cont | _ :: cont -> discard_dead_code cont
let rec is_tailcall = function Kreturn _ :: _ -> true | Klabel _ :: c -> is_tailcall c | Kpop _ :: c -> is_tailcall c | _ -> false
let preserve_tailcall_for_prim = function Pidentity | Popaque | Pdirapply _ | Prevapply _ | Psequor | Psequand -> true | Pbytes_to_string | Pbytes_of_string | Pignore | Pgetglobal _ | Psetglobal _ | Pmakeblock _ | Pmakefloatblock _ | Pfield _ | Pfield_computed _ | Psetfield _ | Psetfield_comp...
let rec add_pop n cont = if n = 0 then cont else match cont with Kpop m :: cont -> add_pop ( n + m ) cont | Kreturn m :: cont -> Kreturn ( n + m ) :: cont | Kraise _ :: _ -> cont | _ -> Kpop n :: cont
let add_const_unit = function ( Kacc _ | Kconst _ | Kgetglobal _ | Kpush_retaddr _ ) :: _ as cont -> cont | cont -> Kconst const_unit :: cont
let rec push_dummies n k = match n with
type rhs_kind = | RHS_block of int | RHS_infix of { blocksize : int ; offset : int } | RHS_floatblock of int | RHS_nonrec | RHS_function of int * int ; ;
let rec check_recordwith_updates id e = match e with | Lsequence ( Lprim ( ( Psetfield _ | Psetfloatfield _ ) , [ Lvar id2 ; _ ] , _ ) , cont ) -> id2 = id && check_recordwith_updates id cont | Lvar id2 -> id2 = id | _ -> false ; ;
let rec size_of_lambda env = function | Lvar id -> begin try Ident . find_same id env with Not_found -> RHS_nonrec end | Lfunction { params } as funct -> RHS_function ( 2 + Ident . Set . cardinal ( free_variables funct ) , List . length params ) | Llet ( Strict , _k , id , Lprim ...
let copy_event ev kind info repr = { ev with ev_pos = 0 ; ev_kind = kind ; ev_info = info ; ev_repr = repr }
let merge_infos ev ev ' = match ev . ev_info , ev ' . ev_info with Event_other , info -> info | info , Event_other -> info | _ -> fatal_error " Bytegen . merge_infos "
let merge_repr ev ev ' = match ev . ev_repr , ev ' . ev_repr with Event_none , x -> x | x , Event_none -> x | Event_parent r , Event_child r ' when r == r ' && ! r = 1 -> Event_none | Event_child r , Event_parent r ' when r == r ' -> Event_parent r | _ , _ -> fatal_error " ...
let merge_events ev ev ' = let ( maj , min ) = match ev . ev_kind , ev ' . ev_kind with Event_pseudo , _ -> ev ' , ev | _ , Event_pseudo -> ev , ev ' | Event_before , ( Event_after _ | Event_before ) -> ev ' , ev | Event_after _ , ( Event_after _ | Event_before )...
let weaken_event ev cont = match ev . ev_kind with Event_after _ -> begin match cont with Kpush :: Kevent ( { ev_repr = Event_none } as ev ' ) :: c -> begin match ev . ev_info with Event_return _ -> let repr = ref 1 in let ev = copy_event ev Event_pseudo ev . ev_info ( Event_parent repr ) ...
let add_event ev = function Kevent ev ' :: cont -> weaken_event ( merge_events ev ev ' ) cont | cont -> weaken_event ev cont
let add_pseudo_event loc modname c = if ! Clflags . debug then let ev_defname = string_of_scoped_location loc in let ev = { ev_pos = 0 ; ev_module = modname ; ev_loc = to_location loc ; ev_defname ; ev_kind = Event_pseudo ; ev_info = Event_other ; ev_typenv = Env . Env_empty ; ev_typsubst...
let try_blocks = ref [ ]
let sz_static_raises = ref [ ]
let push_static_raise i lbl_handler sz = sz_static_raises := ( i , ( lbl_handler , sz , ! try_blocks ) ) :: ! sz_static_raises
let find_raise_label i = try List . assoc i ! sz_static_raises with | Not_found -> Misc . fatal_error ( " exit ( " ^ Int . to_string i " ) ^ outside appropriated catch " )
let code_as_jump l sz = match l with let label , size , tb = find_raise_label i in if sz = size && tb == ! try_blocks then Some label else None
type function_to_compile = { params : Ident . t list ; body : lambda ; label : label ; free_vars : Ident . t list ; num_defs : int ; rec_vars : Ident . t list ; rec_pos : int }
let functions_to_compile = ( Stack . create ( ) : function_to_compile Stack . t )
let compunit_name = ref " "
let max_stack_used = ref 0
let comp_bint_primitive bi suff args = let pref = match bi with Pnativeint -> " caml_nativeint_ " | Pint32 -> " caml_int32_ " | Pint64 -> " caml_int64_ " in Kccall ( pref ^ suff , List . length args )
let comp_primitive p args = match p with Pgetglobal id -> Kgetglobal id | Psetglobal id -> Ksetglobal id | Pintcomp cmp -> Kintcomp cmp | Pcompare_ints -> Kccall ( " caml_int_compare " , 2 ) | Pcompare_floats -> Kccall ( " caml_float_compare " , 2 ) | Pcompare_bints bi -> comp_bint_pri...
let is_immed n = immed_min <= n && n <= immed_max
module Storer = Switch . Store ( struct type t = lambda type key = lambda let compare_key = Stdlib . compare let make_key = Lambda . make_key end )
let rec comp_expr env exp sz cont = if sz > ! max_stack_used then max_stack_used := sz ; match exp with Lvar id -> begin try let pos = Ident . find_same id env . ce_stack in Kacc ( sz - pos ) :: cont with Not_found -> try let pos = Ident . find_same id env . ce_heap in Kenvacc ( pos ) :: co...
let comp_block env exp sz cont = max_stack_used := 0 ; let code = comp_expr env exp sz cont in let used_safe = ! max_stack_used + Config . stack_safety_margin in if used_safe > Config . stack_threshold then Kconst ( Const_base ( Const_int used_safe ) ) :: Kccall ( " caml_ensure_stack_capacity...
let comp_function tc cont = let arity = List . length tc . params in let rec positions pos delta = function [ ] -> Ident . empty | id :: rem -> Ident . add id pos ( positions ( pos + delta ) delta rem ) in let env = { ce_stack = positions arity ( - 1 ) tc . params ; ce_heap = ...
let comp_remainder cont = let c = ref cont in begin try while true do c := comp_function ( Stack . pop functions_to_compile ) ! c done with Stack . Empty -> ( ) end ; ! c
let compile_implementation modulename expr = Stack . clear functions_to_compile ; label_counter := 0 ; sz_static_raises := [ ] ; compunit_name := modulename ; let init_code = comp_block empty_env expr 0 [ ] in if Stack . length functions_to_compile > 0 then begin let lbl_init = new_label (...
let compile_phrase expr = Stack . clear functions_to_compile ; label_counter := 0 ; sz_static_raises := [ ] ; let init_code = comp_block empty_env expr 1 [ Kreturn 1 ] in let fun_code = comp_remainder [ ] in ( init_code , fun_code )
let reset ( ) = label_counter := 0 ; sz_static_raises := [ ] ; compunit_name := " " ; Stack . clear functions_to_compile ; max_stack_used := 0
type error = File_not_found of string | Not_an_object_file of string
let copy_compunit ic oc compunit = seek_in ic compunit . cu_pos ; compunit . cu_pos <- pos_out oc ; compunit . cu_force_link <- compunit . cu_force_link || ! Clflags . link_everything ; copy_file_chunk ic oc compunit . cu_codesize ; if compunit . cu_debug > 0 then begin seek_in ic compunit ...
let lib_ccobjs = ref [ ]
let lib_ccopts = ref [ ]
let lib_dllibs = ref [ ]
let add_ccobjs l = if not ! Clflags . no_auto_link then begin if l . lib_custom then Clflags . custom_runtime := true ; lib_ccobjs := ! lib_ccobjs @ l . lib_ccobjs ; lib_ccopts := ! lib_ccopts @ l . lib_ccopts ; lib_dllibs := ! lib_dllibs @ l . lib_dllibs end
let copy_object_file oc name = let file_name = try Load_path . find name with Not_found -> raise ( Error ( File_not_found name ) ) in let ic = open_in_bin file_name in try let buffer = really_input_string ic ( String . length cmo_magic_number ) in if buffer = cmo_magic_number then begin let compun...
let create_archive file_list lib_name = let outchan = open_out_bin lib_name in Misc . try_finally ~ always ( : fun ( ) -> close_out outchan ) ~ exceptionally ( : fun ( ) -> remove_file lib_name ) ( fun ( ) -> output_string outchan cma_magic_number ; let ofs_pos_toc = pos_out outchan ...
let report_error ppf = function | File_not_found name -> fprintf ppf " Cannot find file % s " name | Not_an_object_file name -> fprintf ppf " The file % a is not a bytecode object file " Location . print_filename name
let ( ) = Location . register_error_of_exn ( function | Error err -> Some ( Location . error_of_printer_file report_error err ) | _ -> None )
let reset ( ) = lib_ccobjs := [ ] ; lib_ccopts := [ ] ; lib_dllibs := [ ]
type error = | File_not_found of filepath | Not_an_object_file of filepath | Wrong_object_name of filepath | Symbol_error of filepath * Symtable . error | Inconsistent_import of modname * filepath * filepath | Custom_runtime | File_exists of filepath | Cannot_open_dll of filepath | Required_module_unavai...
type link_action = Link_object of string * compilation_unit | Link_archive of string * compilation_unit list
let lib_ccobjs = ref [ ]
let lib_ccopts = ref [ ]
let lib_dllibs = ref [ ]
let add_ccobjs origin l = if not ! Clflags . no_auto_link then begin if String . length ! Clflags . use_runtime = 0 && String . length ! Clflags . use_prims = 0 then begin if l . lib_custom then Clflags . custom_runtime := true ; lib_ccobjs := l . lib_ccobjs @ ! lib_ccobjs ; let replace...
let missing_globals = ref Ident . Map . empty
let is_required ( rel , _pos ) = match rel with Reloc_setglobal id -> Ident . Map . mem id ! missing_globals | _ -> false
let add_required compunit = let add id = missing_globals := Ident . Map . add id compunit . cu_name ! missing_globals in List . iter add ( Symtable . required_globals compunit . cu_reloc ) ; List . iter add compunit . cu_required_globals
let remove_required ( rel , _pos ) = match rel with Reloc_setglobal id -> missing_globals := Ident . Map . remove id ! missing_globals | _ -> ( )
let scan_file obj_name tolink = let file_name = try Load_path . find obj_name with Not_found -> raise ( Error ( File_not_found obj_name ) ) in let ic = open_in_bin file_name in try let buffer = really_input_string ic ( String . length cmo_magic_number ) in if buffer = cmo_magic_number then begin l...
module Consistbl = Consistbl . Make ( Misc . Stdlib . String )
let crc_interfaces = Consistbl . create ( )
let interfaces = ref ( [ ] : string list )
let implementations_defined = ref ( [ ] : ( string * string ) list )
let check_consistency file_name cu = begin try List . iter ( fun ( name , crco ) -> interfaces := name :: ! interfaces ; match crco with None -> ( ) | Some crc -> if name = cu . cu_name then Consistbl . set crc_interfaces name crc file_name else Consistbl . check crc_interfaces name crc f...
let extract_crc_interfaces ( ) = Consistbl . extract ! interfaces crc_interfaces
let clear_crc_interfaces ( ) = Consistbl . clear crc_interfaces ; interfaces := [ ]
let debug_info = ref ( [ ] : ( int * Instruct . debug_event list * string list ) list )
let link_compunit output_fun currpos_fun inchan file_name compunit = check_consistency file_name compunit ; seek_in inchan compunit . cu_pos ; let code_block = LongString . input_bytes inchan compunit . cu_codesize in Symtable . patch_object code_block compunit . cu_reloc ; if ! Clflags . debug &&...
let link_object output_fun currpos_fun file_name compunit = let inchan = open_in_bin file_name in try link_compunit output_fun currpos_fun inchan file_name compunit ; close_in inchan with Symtable . Error msg -> close_in inchan ; raise ( Error ( Symbol_error ( file_name , msg ) ) ) | x -> close...