text stringlengths 12 786k |
|---|
let initial_pos filename = { Lexing . pos_fname = filename ; pos_lnum = 1 ; pos_bol = 0 ; pos_cnum = 0 } |
let run_parser ~ start_symbol ~ start_pos ( lb : Lexing . lexbuf ) = let supplier = Parser . MenhirInterpreter . lexer_lexbuf_to_supplier Lex . token lb in let pos = initial_pos Lexing . ( start_pos . pos_fname ) in let start = start_symbol pos in try Parser . MenhirInterpreter . loop_han... |
let run_parser_on_file ~ start_symbol filename = let ic = open_in filename in Misc . try_finally ~ always ( : fun ( ) -> close_in ic ) ( fun ( ) -> let start_pos = initial_pos filename in let lb = Lexing . from_channel ic in run_parser ~ start_symbol ~ start_pos lb ) |
let parse_fexpr filename = run_parser_on_file ~ start_symbol : Parser . Incremental . flambda_unit filename |
let parse_expect_test_spec filename = run_parser_on_file ~ start_symbol : Parser . Incremental . expect_test_spec filename |
let text_of_reversed_lines rev_lines = let rev_lines = " " :: rev_lines in String . concat " \ n " ( List . rev rev_lines ) |
let after_line ~ length ( pos : Lexing . position ) = let pos_bol = pos . pos_bol + length in { pos with pos_lnum = pos . pos_lnum + 1 ; pos_bol ; pos_cnum = pos_bol } |
let read_lines ~ until ~ pos ic = let rec loop pos rev_lines = match input_line ic with | line -> let pos = after_line pos ~ length ( : String . length line ) in if String . equal line until then true , pos , text_of_reversed_lines rev_lines else loop pos ( line :: rev_lines ) | exception End... |
let parse_markdown_doc filename = let ic = open_in filename in Misc . try_finally ~ always ( : fun ( ) -> close_in ic ) ( fun ( ) -> let rec read_text pos rev_nodes = let matched_block_start , pos , text = read_lines ic ~ until " ` ` ` : flexpect " ~ pos in let rev_nodes = matc... |
let make_compilation_unit ~ extension ~ filename ( ? tag = " " ) ( ) = let basename = Filename . chop_suffix filename extension |> Filename . basename in let name = String . capitalize_ascii basename ^ tag in let linkage_name = Linkage_name . create ( " caml " ^ name ) in Compilat... |
let parse ~ symbol_for_global filename = parse_fexpr filename |> Result . map ( fun fexpr -> let comp_unit = make_compilation_unit ~ extension " . : fl " ~ filename ( ) in let old_comp_unit = Compilation_unit . get_current ( ) in Compilation_unit . set_current comp_unit ; let module_ide... |
let pos ( ) = pos_in c |
let read8u ( ) = input_byte c |
let read8s ( ) = let i = read8u ( ) in if i > 0x7f then 0x100 - i else i |
let read16u ( ) = let i1 = input_byte c in let i0 = input_byte c in ( i1 lsl 8 ) lor i0 |
let read16s ( ) = let i = read16u ( ) in if i > 0x7fff then 0x10000 - i else i |
let read32u ( ) = let i3 = input_byte c in let i2 = input_byte c in let i1 = input_byte c in let i0 = input_byte c in ( i3 lsl 24 ) lor ( i2 lsl 16 ) lor ( i1 lsl 8 ) lor i0 |
let read32s ( ) = let i = read32u ( ) in if i > 0x7fffffff then 0x100000000 - i else i |
let read64u ( ) = let i1 = read32u ( ) in let i0 = read32u ( ) in ( i1 lsl 32 ) lor i0 |
let readstr len = really_input_string c len |
type desc = | Block of int * t array * int | Int of int | String of string | Ref of int | Float of float | Int64 of Int64 . t | Int32 of Int32 . t | Nativeint of Nativeint . t |
let double_little ( ) = let start = pos ( ) in let a = ref 0L in for i = 0 to 7 do a := Int64 . logor ! a ( Int64 . shift_left ( Int64 . of_int ( read8u ( ) ) ) ( ( 7 - i ) * 8 ) ) done ; let fin = pos ( ) in { desc = Float ( Int64 . to_float ! a ) ; ... |
let double_big ( ) = let start = pos ( ) in let a = ref 0L in for i = 0 to 7 do a := Int64 . logor ! a ( Int64 . shift_left ( Int64 . of_int ( read8u ( ) ) ) ( i * 8 ) ) done ; let fin = pos ( ) in { desc = Float ( Int64 . to_float ! a ) ; start ; fin } ... |
let intern ( ) = let magic = read32u ( ) in let block_len = read32u ( ) in let num_objects = read32u ( ) in let size_32 = read32u ( ) in let size_64 = read32u ( ) in assert ( magic = 0x8495a6be ) ; ignore ( size_32 , size_64 , block_len , num_objects ) ; let obj_counter... |
let rec is_list v = match v . desc with | Block ( 0 , [ | _ ; r ] , | _ ) -> r . desc = Int 0 || is_list r | _ -> false |
let rec print f v = if is_list v then match v . desc with | Block ( _ , a , _ ) -> Format . fprintf f " [ @< 1 [ >% a % a ] #% d ] " @ print a . ( 0 ) print_list a . ( 1 ) ( v . fin - v . start ) | _ -> assert false else match v . desc with | Block ( t ,... |
let _ = let v = intern ( ) in match v . desc with | Block ( 0 , [ | mark ; v ] , | _ ) -> ( Format . printf " ZZ mark . " ; @ Format . printf " [ @% a ] . " @@ print mark ; match v . desc with | Block ( 0 , [ | global_data ; request_data ; event_h... |
let cstruct_to_string c = String . escaped ( Cstruct . to_string c ) |
let create ( ) = let _ = Create_vhd . disk in ( ) |
let diff ( ) = let _ = Diff_vhd . disk in ( ) |
let disk_name_stem = tmp_file_dir ^ " / parse_test . " |
let make_new_filename = let counter = ref 0 in fun ( ) -> let this = ! counter in incr counter ; disk_name_stem ^ ( string_of_int this ) ^ disk_suffix |
let fill_sector_with pattern = let b = Io_page . ( to_cstruct ( get 1 ) ) in let b = Cstruct . sub b 0 512 in for i = 0 to 511 do Cstruct . set_char b i ( pattern . [ i mod ( String . length pattern ) ] ) done ; b |
let check_empty_disk size = let filename = make_new_filename ( ) in Vhd_IO . create_dynamic ~ filename ~ size ( ) >>= fun vhd -> Vhd_IO . openchain filename false >>= fun vhd ' -> assert_equal ~ printer : Header . to_string ~ cmp : Header . equal vhd . Vhd . header vhd ' . Vhd . ... |
let check_resize size = let newsize = max 0L ( Int64 . pred size ) in let filename = make_new_filename ( ) in Vhd_IO . create_dynamic ~ filename ~ size ( ) >>= fun vhd -> let vhd = Vhd . resize vhd newsize in Vhd_IO . close vhd >>= fun ( ) -> Vhd_IO . openchain filename false >>= f... |
let check_empty_snapshot size = let filename = make_new_filename ( ) in Vhd_IO . create_dynamic ~ filename ~ size ( ) >>= fun vhd -> let filename = make_new_filename ( ) in Vhd_IO . create_difference ~ filename ~ parent : vhd ( ) >>= fun vhd ' -> Vhd_IO . openchain filename false >>... |
let check_reparent ( ) = let all_ones = fill_sector_with " 1 " in let all_twos = fill_sector_with " 2 " in let p1 = make_new_filename ( ) in let size = Int64 . mul 1024L 1024L in Vhd_IO . create_dynamic ~ filename : p1 ~ size ( ) >>= fun vhd -> Vhd_IO . write vhd 0L [ all_ones... |
let check_parent_parent_dir ( ) = let filename = make_new_filename ( ) in Vhd_IO . create_dynamic ~ filename ~ size : 0L ( ) >>= fun vhd -> let leaf_path = Filename . ( concat ( concat tmp_file_dir " leaves " ) " leaf . vhd " ) in let leaf_dir = Filename . dirname leaf_path... |
let check_readonly ( ) = let filename = make_new_filename ( ) in Vhd_IO . create_dynamic ~ filename ~ size : 0L ( ) >>= fun vhd -> Vhd_IO . close vhd >>= fun ( ) -> Unix . chmod filename 0o444 ; Vhd_IO . openchain filename false >>= fun vhd -> Vhd_IO . close vhd |
let absolute_sector_of vhd { block ; sector } = if vhd . Vhd . header . Header . max_table_entries = 0 then None else let block = match block with | First -> 0 | Last -> vhd . Vhd . header . Header . max_table_entries - 1 in let sectors_per_block = 1 lsl vhd . Vhd . header . Hea... |
let cstruct_to_string c = String . escaped ( Cstruct . to_string c ) |
type state = { to_close : fd Vhd . t list ; to_unlink : string list ; child : fd Vhd . t option ; contents : ( int64 * Cstruct . t ) list ; } |
let initial = { to_close = [ ] ; to_unlink = [ ] ; child = None ; contents = [ ] ; } |
let sectors = Hashtbl . create 16 |
let sector_lookup message = if Hashtbl . mem sectors message then Hashtbl . find sectors message else let data = fill_sector_with message in Hashtbl . replace sectors message data ; data |
let execute state = function | Create size -> let filename = make_new_filename ( ) in Vhd_IO . create_dynamic ~ filename ~ size ( ) >>= fun vhd -> return { to_close = vhd :: state . to_close ; to_unlink = filename :: state . to_unlink ; child = Some vhd ; contents = [ ] ; } ... |
let verify state = match state . child with | None -> return ( ) | Some t -> verify t state . contents |
let stream_vhd filename = Vhd_format_lwt . IO . openfile filename false >>= fun fd -> let rec loop = function | End -> return ( ) | Cons ( _hd , tl ) -> tl ( ) >>= fun x -> loop x in Vhd_format_lwt . IO . get_file_size filename >>= fun size -> openstream ( Some size ) ( Input . ... |
let stream_test state = Lwt_list . iter_s stream_vhd state . to_unlink |
let cleanup state = List . iter Unix . unlink state . to_unlink ; Lwt . return ( ) |
let run program = let single_instruction state x = execute state x >>= fun state ' -> verify state ' >>= fun ( ) -> return state ' in Lwt_list . fold_left_s single_instruction initial program >>= fun final_state -> Lwt_list . iter_s Vhd_IO . close final_state . to_close >>= fun ( ) -> Lw... |
let all_program_tests = List . map ( fun p -> ( string_of_program p ) >:: ( fun ( ) -> Lwt_main . run ( run p ) ) |
let _ = let verbose = ref false in Arg . parse [ " - verbose " , Arg . Unit ( fun _ -> verbose := true ) , " Run in verbose mode " ; ] ( fun x -> Printf . fprintf stderr " Ignoring argument : % s " x ) " Test vhd parser " ; let check_empty_disk size = Printf . spri... |
type parser_env = { mutable s_stack : int array ; mutable v_stack : Obj . t array ; mutable symb_start_stack : position array ; mutable symb_end_stack : position array ; mutable stacksize : int ; mutable stackbase : int ; mutable curr_char : int ; mutable lval : Obj . t ; mutable symb_sta... |
type parse_tables = { actions : ( parser_env -> Obj . t ) array ; transl_const : int array ; transl_block : int array ; lhs : string ; len : string ; defred : string ; dgoto : string ; sindex : string ; rindex : string ; gindex : string ; tablesize : int ; table : string ; ... |
type parser_input = Start | Token_read | Stacks_grown_1 | Stacks_grown_2 | Semantic_action_computed | Error_detected |
type parser_output = Read_token | Raise_parse_error | Grow_stacks_1 | Grow_stacks_2 | Compute_semantic_action | Call_error_function |
let _ = [ Read_token ; Raise_parse_error ; Grow_stacks_1 ; Grow_stacks_2 ; Compute_semantic_action ; Call_error_function ] parse_tables -> parser_env -> parser_input -> Obj . t -> parser_output = " caml_parse_engine " = " caml_set_parser_trace " |
let env = { s_stack = Array . make 100 0 ; v_stack = Array . make 100 ( Obj . repr ( ) ) ; symb_start_stack = Array . make 100 dummy_pos ; symb_end_stack = Array . make 100 dummy_pos ; stacksize = 100 ; stackbase = 0 ; curr_char = 0 ; lval = Obj . repr ( ) ; sy... |
let grow_stacks ( ) = let oldsize = env . stacksize in let newsize = oldsize * 2 in let new_s = Array . make newsize 0 and new_v = Array . make newsize ( Obj . repr ( ) ) and new_start = Array . make newsize dummy_pos and new_end = Array . make newsize dummy_pos in Array . blit env .... |
let clear_parser ( ) = Array . fill env . v_stack 0 env . stacksize ( Obj . repr ( ) ) ; env . lval <- Obj . repr ( ) |
let current_lookahead_fun = ref ( fun ( _ : Obj . t ) -> false ) |
let yyparse tables start lexer lexbuf = let rec loop cmd arg = match parse_engine tables env cmd arg with Read_token -> let t = Obj . repr ( lexer lexbuf ) in env . symb_start <- lexbuf . lex_start_p ; env . symb_end <- lexbuf . lex_curr_p ; loop Token_read t | Raise_parse_error -> raise Parse... |
let peek_val env n = Obj . magic env . v_stack . ( env . asp - n ) |
let symbol_start_pos ( ) = let rec loop i = if i <= 0 then env . symb_end_stack . ( env . asp ) else begin let st = env . symb_start_stack . ( env . asp - i + 1 ) in let en = env . symb_end_stack . ( env . asp - i + 1 ) in if st <> en then st else loop ( i - 1 ) end ... |
let symbol_end_pos ( ) = env . symb_end_stack . ( env . asp ) |
let rhs_start_pos n = env . symb_start_stack . ( env . asp - ( env . rule_len - n ) ) |
let rhs_end_pos n = env . symb_end_stack . ( env . asp - ( env . rule_len - n ) ) |
let symbol_start ( ) = ( symbol_start_pos ( ) ) . pos_cnum |
let symbol_end ( ) = ( symbol_end_pos ( ) ) . pos_cnum |
let rhs_start n = ( rhs_start_pos n ) . pos_cnum |
let rhs_end n = ( rhs_end_pos n ) . pos_cnum |
let is_current_lookahead tok = ( ! current_lookahead_fun ) ( Obj . repr tok ) |
let parse_error ( _ : string ) = ( ) |
type type_expr = | TEint | TEbool | TEunit | TEref of type_expr | TEarrow of type_expr * type_expr | TEproduct of type_expr * type_expr | TEunion of type_expr * type_expr |
type formals = ( var * type_expr ) list |
type oper = ADD | MUL | DIV | SUB | LT | AND | OR | EQ | EQB | EQI |
type unary_oper = NEG | NOT |
type expr = | Unit of loc | What of loc | Var of loc * var | Integer of loc * int | Boolean of loc * bool | UnaryOp of loc * unary_oper * expr | Op of loc * expr * oper * expr | If of loc * expr * expr * expr | Pair of loc * expr * expr | Fst of loc * expr | Snd of loc * expr | Inl of loc *... |
let loc_of_expr = function | Unit loc -> loc | What loc -> loc | Var ( loc , _ ) -> loc | Integer ( loc , _ ) -> loc | Boolean ( loc , _ ) -> loc | UnaryOp ( loc , _ , _ ) -> loc | Op ( loc , _ , _ , _ ) -> loc | If ( loc , _ , _ , _ ) -> loc | ... |
let string_of_loc loc = " line " ^ ( string_of_int ( loc . Lexing . pos_lnum ) ) ^ " , " ^ " position " ^ ( string_of_int ( ( loc . Lexing . pos_cnum - loc . Lexing . pos_bol ) + 1 ) ) |
let rec pp_type = function | TEint -> " int " | TEbool -> " bool " | TEunit -> " unit " | TEref t -> " ( " ^ ( pp_type t ) ^ " ref ) " | TEarrow ( t1 , t2 ) -> " ( " ^ ( pp_type t1 ) ^ " -> " ^ ( pp_type t2 ) ^ " ) " | TEproduct ( t1 , t2 ... |
let pp_uop = function | NEG -> " " - | NOT -> " " ~ |
let pp_bop = function | ADD -> " " + | MUL -> " " * | DIV -> " " / | SUB -> " " - | LT -> " " < | EQ -> " " = | EQI -> " eqi " | EQB -> " eqb " | AND -> " " && | OR -> " " || |
let fstring ppf s = fprintf ppf " % s " s |
let pp_type ppf t = fstring ppf ( pp_type t ) |
let pp_unary ppf op = fstring ppf ( pp_uop op ) |
let pp_binary ppf op = fstring ppf ( pp_bop op ) |
let rec pp_expr ppf = function | Unit _ -> fstring ppf " ( ) " | What _ -> fstring ppf " " ? | Var ( _ , x ) -> fstring ppf x | Integer ( _ , n ) -> fstring ppf ( string_of_int n ) | Boolean ( _ , b ) -> fstring ppf ( string_of_bool b ) | UnaryOp ( _ , op , ... |
let print_expr e = let _ = pp_expr std_formatter e in print_flush ( ) |
let eprint_expr e = let _ = pp_expr err_formatter e in print_flush ( ) |
let string_of_uop = function | NEG -> " NEG " | NOT -> " NOT " |
let string_of_bop = function | ADD -> " ADD " | MUL -> " MUL " | DIV -> " DIV " | SUB -> " SUB " | LT -> " LT " | EQ -> " EQ " | EQI -> " EQI " | EQB -> " EQB " | AND -> " AND " | OR -> " OR " |
let mk_con con l = let rec aux carry = function | [ ] -> carry ^ " ) " | [ s ] -> carry ^ s ^ " ) " | s :: rest -> aux ( carry ^ s ^ " , " ) rest in aux ( con ^ " ( " ) l |
let rec string_of_type = function | TEint -> " TEint " | TEbool -> " TEbool " | TEunit -> " TEunit " | TEref t -> mk_con " TEref " [ string_of_type t ] | TEarrow ( t1 , t2 ) -> mk_con " TEarrow " [ string_of_type t1 ; string_of_type t2 ] | TEproduct ( t1 , t2 ) -> ... |
let rec string_of_expr = function | Unit _ -> " Unit " | What _ -> " What " | Var ( _ , x ) -> mk_con " Var " [ x ] | Integer ( _ , n ) -> mk_con " Integer " [ string_of_int n ] | Boolean ( _ , b ) -> mk_con " Boolean " [ string_of_bool b ] | UnaryOp ( ... |
let translate_uop = function | Past . NEG -> Ast . NEG | Past . NOT -> Ast . NOT |
let translate_bop = function | Past . ADD -> Ast . ADD | Past . MUL -> Ast . MUL | Past . DIV -> Ast . DIV | Past . SUB -> Ast . SUB | Past . LT -> Ast . LT | Past . AND -> Ast . AND | Past . OR -> Ast . OR | Past . EQI -> Ast . EQI | Past . EQB -> Ast . EQB | Pas... |
let rec translate_expr = function | Past . Unit _ -> Ast . Unit | Past . What _ -> Ast . UnaryOp ( Ast . READ , Ast . Unit ) | Past . Var ( _ , x ) -> Ast . Var x | Past . Integer ( _ , n ) -> Ast . Integer n | Past . Boolean ( _ , b ) -> Ast . Boolean b ... |
let print_strings = List . print String . print |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.