text stringlengths 12 786k |
|---|
let file_pos_nums = ( ref [ ] : ( string * int ) list ref ) |
let file_pos_num_cnt = ref 1 |
let reset_debug_info ( ) = file_pos_nums := [ ] ; file_pos_num_cnt := 1 |
let emit_debug_info_gen dbg file_emitter loc_emitter = if is_cfi_enabled ( ) && ( ! Clflags . debug || Config . with_frame_pointers ) then begin match List . rev dbg with | [ ] -> ( ) | { Debuginfo . dinfo_line = line ; dinfo_char_start = col ; dinfo_file = file_name ; } :: ... |
let emit_debug_info dbg = emit_debug_info_gen dbg ( fun ~ file_num ~ file_name -> emit_string " \ t . file \ t " ; emit_int file_num ; emit_char ' \ t ' ; emit_string_literal file_name ; emit_char ' \ n ' ; ) ( fun ~ file_num ~ line ~ col : _ -> emit_string " \ t . loc ... |
let reset ( ) = reset_debug_info ( ) ; frame_descriptors := [ ] |
let binary_backend_available = ref false |
let create_asm_file = ref true |
let report_error ppf = function | Stack_frame_too_large n -> Format . fprintf ppf " stack frame too large ( % d bytes ) " n |
type error = Not_compatible_32 of ( string * string ) |
let marshal_to_channel_with_possibly_32bit_compat ~ filename ~ kind outchan obj = try Marshal . to_channel outchan obj ( if ! Clflags . bytecode_compatible_32 then [ Marshal . Compat_32 ] else [ ] ) with Failure _ -> raise ( Error ( Not_compatible_32 ( filename , kind ) ) ) |
let report_error ppf ( file , kind ) = Format . fprintf ppf " Generated % s % S cannot be used on a 32 - bit platform " kind file |
let ( ) = Location . register_error_of_exn ( function | Error ( Not_compatible_32 info ) -> Some ( Location . error_of_printer_file report_error info ) | _ -> None ) |
let out_buffer = ref ( LongString . create 1024 ) |
let out_word b1 b2 b3 b4 = let p = ! out_position in if p >= LongString . length ! out_buffer then begin let len = LongString . length ! out_buffer in let new_buffer = LongString . create ( 2 * len ) in LongString . blit ! out_buffer 0 new_buffer 0 len ; out_buffer := new_buffer end ; Long... |
let out opcode = out_word opcode 0 0 0 |
let const_as_int = function | Const_base ( Const_int i ) -> i | Const_base ( Const_char c ) -> Char . code c | _ -> raise AsInt |
let is_immed i = immed_min <= i && i <= immed_max |
let is_immed_const k = try is_immed ( const_as_int k ) with | AsInt -> false |
let out_int n = out_word n ( n asr 8 ) ( n asr 16 ) ( n asr 24 ) |
let out_const c = try out_int ( const_as_int c ) with | AsInt -> Misc . fatal_error " Emitcode . const_as_int " |
type label_definition = Label_defined of int | Label_undefined of ( int * int ) list |
let label_table = ref ( [ | ] | : label_definition array ) |
let extend_label_table needed = let new_size = ref ( Array . length ! label_table ) in while needed >= ! new_size do new_size := 2 * ! new_size done ; let new_table = Array . make ! new_size ( Label_undefined [ ] ) in Array . blit ! label_table 0 new_table 0 ( Array . length ! lab... |
let backpatch ( pos , orig ) = let displ = ( ! out_position - orig ) asr 2 in LongString . set ! out_buffer pos ( Char . unsafe_chr displ ) ; LongString . set ! out_buffer ( pos + 1 ) ( Char . unsafe_chr ( displ asr 8 ) ) ; LongString . set ! out_buffer ( pos + 2 )... |
let define_label lbl = if lbl >= Array . length ! label_table then extend_label_table lbl ; match ( ! label_table ) . ( lbl ) with Label_defined _ -> fatal_error " Emitcode . define_label " | Label_undefined patchlist -> List . iter backpatch patchlist ; ( ! label_table ) . ( lb... |
let out_label_with_orig orig lbl = if lbl >= Array . length ! label_table then extend_label_table lbl ; match ( ! label_table ) . ( lbl ) with Label_defined def -> out_int ( ( def - orig ) asr 2 ) | Label_undefined patchlist -> ( ! label_table ) . ( lbl ) <- Label_undefined ( ... |
let out_label l = out_label_with_orig ! out_position l |
let reloc_info = ref ( [ ] : ( reloc_info * int ) list ) |
let enter info = reloc_info := ( info , ! out_position ) :: ! reloc_info |
let slot_for_literal sc = enter ( Reloc_literal sc ) ; out_int 0 enter ( Reloc_getglobal id ) ; out_int 0 enter ( Reloc_setglobal id ) ; out_int 0 enter ( Reloc_primitive name ) ; out_int 0 |
let events = ref ( [ ] : debug_event list ) |
let debug_dirs = ref String . Set . empty |
let record_event ev = let path = ev . ev_loc . Location . loc_start . Lexing . pos_fname in let abspath = Location . absolute_path path in debug_dirs := String . Set . add ( Filename . dirname abspath ) ! debug_dirs ; if Filename . is_relative path then begin let cwd = Location . rewri... |
let init ( ) = out_position := 0 ; label_table := Array . make 16 ( Label_undefined [ ] ) ; reloc_info := [ ] ; debug_dirs := String . Set . empty ; events := [ ] |
let emit_instr = function Klabel lbl -> define_label lbl | Kacc n -> if n < 8 then out ( opACC0 + n ) else ( out opACC ; out_int n ) | Kenvacc n -> if n >= 1 && n <= 4 then out ( opENVACC1 + n - 1 ) else ( out opENVACC ; out_int n ) | Kpush -> out opPUSH | Kpop n -> out opPOP ; ... |
let remerge_events ev1 = function | Kevent ev2 :: c -> Kevent ( Bytegen . merge_events ev1 ev2 ) :: c | c -> Kevent ev1 :: c |
let rec emit = function [ ] -> ( ) | Kpush :: Kconst k :: Kintcomp c :: Kbranchif lbl :: rem when is_immed_const k -> emit_branch_comp c ; out_const k ; out_label lbl ; emit rem | Kpush :: Kconst k :: Kintcomp c :: Kbranchifnot lbl :: rem when is_immed_const k -> emit_branch_comp ( negate_... |
let to_file outchan unit_name objfile ~ required_globals code = init ( ) ; output_string outchan cmo_magic_number ; let pos_depl = pos_out outchan in output_binary_int outchan 0 ; let pos_code = pos_out outchan in emit code ; LongString . output outchan ! out_buffer 0 ! out_position ; let ( po... |
let to_memory init_code fun_code = init ( ) ; emit init_code ; emit fun_code ; let code = LongString . create ! out_position in LongString . blit ! out_buffer 0 code 0 ! out_position ; let reloc = List . rev ! reloc_info in let events = ! events in init ( ) ; ( code , reloc , ev... |
let to_packed_file outchan code = init ( ) ; emit code ; LongString . output outchan ! out_buffer 0 ! out_position ; let reloc = ! reloc_info in init ( ) ; reloc |
let reset ( ) = out_buffer := LongString . create 1024 ; out_position := 0 ; label_table := [ | ] ; | reloc_info := [ ] |
let error s = error ( " Llvmemit : " ^ s ) |
let emit_nl s = emit_string ( s ^ " \ n " ) |
let counter = ref 0 |
let counter_inc ( ) = counter := ! counter + 1 |
let c ( ) = counter_inc ( ) ; " . " ^ string_of_int ! counter |
let types = Hashtbl . create 10 |
let emit_label lbl = emit_nl ( lbl ^ " " ) : |
let emit_instr instr = emit_nl ( " \ t " ^ instr ) |
let emit_op reg op typ args = emit_instr ( reg_name reg ^ " = " ^ op ^ " " ^ string_of_type typ ^ " " ^ String . concat " , " ( List . map reg_name args ) ) |
let arg_list args = String . concat " , " ( List . map string_of_reg args ) |
let emit_cast reg op value typ = emit_instr ( reg_name reg ^ " = " ^ op ^ " " ^ string_of_reg value ^ " to " ^ string_of_type ( typeof reg ) ) |
let rec instr_iter f instr = if instr . desc <> Lend then begin f instr ; instr_iter f instr . next end |
let emit_call res cc fn args = let fn = " " ^ reg_name fn ^ " ( " ^ Printlinearize . print_array string_of_reg args ^ " ) nounwind " in emit_instr ( ( if res <> Nothing then reg_name res ^ " = " else " " ) ^ " tail call " ^ cc ^ " " ^ ( if res <> Nothing then stri... |
let emit_llvm instr = let { desc = desc ; next = next ; arg = arg ; res = res ; dbg = dbg } = instr in begin match desc , arg , res with Lend , _ , _ -> ( ) | Lop op , [ | left ; right ] , | Reg ( _ , typ ) -> emit_op res ( string_of_binop op ) typ [ left ; ... |
let fundecl = function { fun_name = name ; fun_args = args ; fun_body = body } -> let args = String . concat " , " ( List . map string_of_reg args ) in emit_nl ( " define " ^ calling_conv ^ " " ^ string_of_type addr_type ^ " " @ ^ name ^ " ( " ^ args ^ " ) no... |
let header = let addr_type = string_of_type addr_type in [ " ; vim : set ft = llvm " : ; " % jump_buf_t = type [ 5 x " ^ addr_type ^ " ] " ; " declare i32 @ llvm . eh . sjlj . setjmp ( i8 * ) nounwind " ; " declare void @ llvm . eh . sjlj . longjmp ( i8 * ... |
let constants : string list ref = ref [ ] |
let functions : ( string * string * string * string list ) list ref = ref [ ] |
let local_functions = ref [ ] |
let add_const str = if List . exists ( fun x -> String . compare x str == 0 ) ! constants then ( ) else constants := str :: ! constants |
let add_function ( ret , cconv , str , args ) = if List . exists ( fun ( _ , _ , x , _ ) -> String . compare x str == 0 ) ! functions then ( ) else functions := ( string_of_type ret , cconv , str , List . map ( fun _ -> string_of_type addr_type ) args ) :: ! ... |
let emit_function_declarations ( ) = let fn ( ret_type , cconv , name , args ) = emit_nl ( " declare " ^ cconv ^ " " ^ ret_type ^ " " @ ^ name ^ " ( " ^ String . concat " , " args ^ " ) nounwind " ) in List . iter fn ( List . filter ( fun ( _ , _... |
let emit_constant_declarations ( ) = List . iter ( fun name -> if not ( List . mem name ( List . map ( fun ( _ , _ , x , _ ) -> x ) ! functions ) ) && not ( List . mem name ( List . map fst ! local_functions ) ) then emit_nl ( " " @ ^ name ^ " = externa... |
let begin_assembly ( ) = List . iter emit_nl header |
let end_assembly ( ) = emit_function_declarations ( ) ; emit_constant_declarations ( ) ; local_functions := [ ] |
module Model = struct type t = { entries : Entry . Model . t Entry_id . Map . t ; focus : ( Entry_id . t * Focus_point . t option ) option ; search_string : string ; visible_range : ( Entry_id . t * Entry_id . t ) option } [ @@ deriving fields , sexp , compare , equal ... |
module Action = struct type t = | Entry of ( Entry_id . t * Focus_point . t option ) option * Entry . Action . t | Set_outer_focus of Entry_id . t | Set_inner_focus of Focus_point . t | Move_outer_focus of focus_dir | Move_inner_focus of focus_dir | Set_search_string of string | Raise of Erro... |
module State = struct type t = unit end |
let do_kick_all ( model : Model . t ) = if Float . ( < ) ( Random . float 1 . ) 0 . 6 then model else ( let entries = Map . map model . entries ~ f : Entry . Model . kick in { model with entries } ) ; ; |
let do_kick_one ( model : Model . t ) = let pos = Random . int ( Map . length model . entries ) in match Map . nth model . entries pos with | None -> model | Some ( key , _ ) -> let entries = Map . change model . entries key ~ f ( : function | None -> None | Some x -> Some... |
let do_kick_n model n = Sequence . fold ~ init : model ( Sequence . range 0 n ) ~ f ( : fun old ( _ : int ) -> do_kick_one old ) ; ; |
let entry_apply ( m : Model . t ) entry_id focus_point action = let entries = Map . change m . entries entry_id ~ f ( : function | None -> None | Some m -> Some ( Entry . Action . apply action focus_point m ) ) in { m with entries } ; ; |
let move_inner_focus ( dir : focus_dir ) ( m : Model . t ) = let focus = match m . focus with | None -> None | Some ( entry_id , fp ) -> ( match Map . find m . entries entry_id with | None -> None | Some entry -> let fp = Entry . Model . move_focus entry fp dir in Some ( entry... |
let move_outer_focus dir ( m : Model . t ) = let outer , inner = match m . focus with | None -> None , None | Some ( outer , inner ) -> Some outer , inner in match move_map_focus ( Model . filtered_entries m ) outer dir with | None -> { m with focus = None } | Some new_outer ->... |
let set_outer_focus entry_id ( m : Model . t ) = let focus = match m . focus with | None -> Some ( entry_id , None ) | Some ( _ , focus_point ) -> Some ( entry_id , focus_point ) in { m with focus } ; ; |
let set_inner_focus fp ( m : Model . t ) = let focus = match m . focus with | None -> None | Some ( entry_id , _ ) -> Some ( entry_id , Some fp ) in { m with focus } ; ; |
let apply_action ( m : Model . t ) action _ ~ schedule_action : _ = match ( action : Action . t ) with | Move_outer_focus dir -> move_outer_focus dir m | Move_inner_focus dir -> move_inner_focus dir m | Set_outer_focus entry_id -> set_outer_focus entry_id m | Set_inner_focus fp -> set_inner_f... |
let on_startup ~ schedule_action ( _ : Model . t ) : State . t Deferred . t = Js_misc . scroll ( ) ; every ( Time_ns . Span . of_sec 1 . ) ( fun ( ) -> schedule_action ( Action . kick_n 150 ) ) ; return ( ) ; ; |
let in_range cmp ( lo , hi ) value = cmp lo value <= 0 && cmp hi value >= 0 |
let view ( m : Model . t Incr . t ) ~ inject = let open Vdom in let open Incr . Let_syntax in let set_inner_focus fp = inject ( Action . Set_inner_focus fp ) in let focus = m >>| Model . focus in let on_keydown = let % map focus = focus in Attr . on_keydown ( fun ev -> match Dom_html . ... |
let update_visibility m ~ schedule_action : _ = let filtered_entries = Model . filtered_entries m in let visible_range = Js_misc . find_visible_range ~ length ( : Map . length filtered_entries ) ~ nth_element_id ( : fun n -> Map . nth_exn filtered_entries n |> fst |> Entry_id . id_string ) ... |
let example ~ entries : Model . t = let entries = List . init entries ~ f ( : fun _ -> Entry . Model . example ( ) ) |> List . mapi ~ f ( : fun i x -> Entry_id . create i , x ) |> Entry_id . Map . of_alist_exn in let focus = match Map . min_elt entries with | Some ( k , ... |
let on_display ( ~ old_model : Model . t ) ( model : Model . t ) _ ~ schedule_action : _ = let get_focus ( m : Model . t ) = Option . map m . focus ~ f : fst in if not ( [ % equal : Entry_id . t option ] ( get_focus old_model ) ( get_focus model ) ) then Js_misc . ... |
let create model ~ old_model ~ inject = let open Incr . Let_syntax in let % map apply_action = let % map model = model in apply_action model and update_visibility = let % map model = model in update_visibility model and on_display = let % map old_model = old_model and model = model in on_display ~ old_... |
module Model = struct module Focusable_field = struct module T = struct type t = | Fnorb | Snoot | Blimp | Snip [ @@ deriving sexp , enumerate , compare ] end include T include Comparable . Make ( T ) let to_string t = sexp_of_t t |> Sexp . to_string let to_int = function | Fnorb -> 0 | ... |
module Action = struct type t = | Bump of bump_dir | Toggle_collapse [ @@ deriving sexp ] let apply t focus_point ( m : Model . t ) = match t with | Bump bdir -> let amt = match bdir with | Incr -> 0 . 01 | Decr -> - 0 . 01 in ( match focus_point with | None -> m | Some focus_point... |
type focus_state = | Unfocused | Focused of Focus_point . t option |
let field_is_focused ~ collapsed ( focus : focus_state ) pos = let focus_map = Model . focus_map ~ collapsed in match focus with | Unfocused -> false | Focused focus_point -> Some pos = Option . bind focus_point ~ f ( : fun x -> Map . find focus_map x ) ; ; |
let align_left ( f : Node . Aliases . node_creator ) attrs nodes = f ~ attr ( : Attr . many_without_merge ( Attr . create " align " " left " :: attrs ) ) nodes ; ; |
let th = align_left Node . th |
let td = align_left Node . td |
let maybe_fields ~ collapsed ff x = if collapsed && not ( Set . mem Model . collapsed_fields ff ) then [ ] else x ; ; |
let header ~ collapsed ~ set_inner_focus focus = let field_is_focused = field_is_focused ~ collapsed focus in let dstring = function | Buy -> " / b " | Sell -> " / s " in let live_header = let s = " live " in [ th [ ] [ Node . text ( s ^ dstring Buy ) ] ; th [ ] [ Node... |
let basic_data_and_header ~ set_inner_focus ~ focus ( basic : Model . Basic . t ) = let collapsed = basic . collapsed in let field_is_focused = field_is_focused ~ collapsed focus in let view_field ff = let num dir = Model . Basic . get basic ( ff , dir ) in maybe_fields ~ collapsed ff ( ... |
let live_data visible live = let open Incr . Let_syntax in Incr . if_ visible ~ then_ : ( let % map live = live in [ td [ ] [ Node . text ( Float . to_string_12 live . buy ) ] ; td [ ] [ Node . text ( Float . to_string_12 live . sell ) ] ] ) ~ else_ ( : Incr . ... |
let view ( m : Model . t Incr . t ) ( entry_id : Entry_id . t ) ~ visible ~ focus ~ focus_me ~ set_inner_focus = let open Incr . Let_syntax in let entry_id_attr = Attr . id ( Entry_id . id_string entry_id ) in let key_attr = Attr . string_property " key " ( Entry_id . id_strin... |
let globals = H . create 1 ; ; |
let glb_mutex = Mutex . create ( ) ; ; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.