text stringlengths 12 786k |
|---|
let update_player delta ( { position ; speed ; can_jump } , env_items , c , m ) = let open Raylib in let x , y = Vector2 . ( x position , y position ) in let x = match ( is_key_down Key . Left , is_key_down Key . Right ) with | true , false -> x . - ( player_hor_speed .... |
let update_camera delta ( player , env_items , camera , mode ) = let open Raylib in let mode = if is_key_pressed Key . C then match mode with | Center -> CenterInsideMap | CenterInsideMap -> SmoothFollow | SmoothFollow -> EvenOutOnLanding ( false , 0 . 0 ) | EvenOutOnLanding _ -> Player... |
let draw_all ( player , env_items , camera , mode ) = let open Raylib in begin_drawing ( ) ; clear_background Color . raywhite ; begin_mode_2d camera ; List . iter ( fun item -> draw_rectangle_rec item . box item . color ) env_items ; draw_rectangle_rec ( player_rec player ) Colo... |
let rec loop state = let delta = Raylib . get_frame_time ( ) in match Raylib . window_should_close ( ) with | true -> Raylib . close_window ( ) | false -> state |> update_player delta |> update_camera delta |> draw_all |> loop |
let ( ) = setup ( ) |> loop |
type column_t = { height : float ; position : Raylib . Vector3 . t ; color : Raylib . Color . t ; } |
let setup ( ) = let open Raylib in init_window width height " raylib [ core ] example - 3d camera first person " ; let camera = Camera . create ( Vector3 . create 4 . 0 2 . 0 4 . 0 ) ( Vector3 . create 0 . 0 1 . 8 0 . 0 ) ( Vector3 . create 0 . 0 1 . 0 ... |
let draw_all camera columns = let open Raylib in begin_drawing ( ) ; clear_background Color . raywhite ; begin_mode_3d camera ; draw_plane ( Vector3 . create 0 . 0 0 . 0 0 . 0 ) ( Vector2 . create 32 . 0 32 . 0 ) Color . lightgray ; draw_cube ( Vector3 . create . ... |
let rec loop ( camera , columns ) = let open Raylib in if window_should_close ( ) then close_window ( ) else update_camera ( addr camera ) ; draw_all camera columns ; loop ( camera , columns ) |
let ( ) = setup ( ) |> loop |
type column_t = { height : float ; position : Raylib . Vector3 . t ; color : Raylib . Color . t ; } |
let cube_pos = Raylib . Vector3 . create 0 . 0 0 . 0 0 . 0 |
let setup ( ) = let open Raylib in init_window width height " raylib [ core ] example - 3d camera free " ; let camera = Camera . create ( Vector3 . create 10 . 0 10 . 0 10 . 0 ) ( Vector3 . create 0 . 0 0 . 0 0 . 0 ) ( Vector3 . create 0 . 0 1 . 0 0 .... |
let draw_all camera = let open Raylib in begin_drawing ( ) ; clear_background Color . raywhite ; begin_mode_3d camera ; draw_cube cube_pos 2 . 0 2 . 0 2 . 0 Color . red ; draw_cube_wires cube_pos 2 . 0 2 . 0 2 . 0 Color . maroon ; draw_grid 10 1 . 0 ; end_mode_3d ( ... |
let rec loop camera = let open Raylib in if window_should_close ( ) then close_window ( ) else let camera = if is_key_down Key . Z then Camera . ( create ( position camera ) ( Vector3 . create 0 . 0 0 . 0 0 . 0 ) ( up camera ) 45 . 0 CameraProjection . Perspective ) els... |
let ( ) = setup ( ) |> loop |
type column_t = { height : float ; position : Raylib . Vector3 . t ; color : Raylib . Color . t ; } |
let cube_pos = Raylib . Vector3 . create 0 . 0 1 . 0 0 . 0 |
let setup ( ) = let open Raylib in init_window width height " raylib [ core ] example - 3d camera mode " ; let camera = Camera . create ( Vector3 . create 10 . 0 10 . 0 10 . 0 ) ( Vector3 . create 0 . 0 0 . 0 0 . 0 ) ( Vector3 . create 0 . 0 1 . 0 0 .... |
let draw_all camera collision ray = let open Raylib in begin_drawing ( ) ; clear_background Color . raywhite ; begin_mode_3d camera ; if collision then ( draw_cube cube_pos 2 . 0 2 . 0 2 . 0 Color . red ; draw_cube_wires cube_pos 2 . 0 2 . 0 2 . 0 Color . maroon ; draw_cub... |
let rec loop camera collision ray = let open Raylib in if window_should_close ( ) then close_window ( ) else ( update_camera ( addr camera ) ; let collision , ray = match ( is_mouse_button_pressed MouseButton . Left , collision ) with | true , true -> ( false , None ) | true , f... |
let ( ) = let camera = setup ( ) in loop camera false None |
type state_t = Waiting | Loading of int | Finished |
let setup ( ) = Raylib . init_window 800 450 " raylib [ core ] example - loading thread " ; Raylib . set_target_fps 60 |
let data_progress = ref 0 |
let load_data_thread ( ) = let rec loop prev_time = let time = Raylib . get_time ( ) in data_progress := ! data_progress + Int . of_float ( 50 . 0 . * ( time . - prev_time ) ) ; Thread . delay 0 . 05 ; loop time in loop ( Raylib . get_time ( ) ) |
let rec loop state = match Raylib . window_should_close ( ) with | true -> Raylib . close_window ( ) | false -> let open Raylib in let state = match state with | Waiting -> if is_key_pressed Key . Enter then ( ignore ( Thread . create load_data_thread ( ) ) ; Loading 0 ) else Wait... |
let ( ) = setup ( ) ; loop Waiting |
let setup ( ) = let open Raylib in set_config_flags [ ConfigFlags . Msaa_4x_hint ] ; init_window width height " raylib [ core ] example - vr simulator " ; let hmd = VrDeviceInfo . create ( ) in VrDeviceInfo . ( set_h_resolution hmd 2160 ; set_v_resolution hmd 1200 ; set_h_screen... |
let rec loop ( distortion , cube_position , camera , config , target ) = match Raylib . window_should_close ( ) with | true -> let open Raylib in unload_shader distortion ; unload_vr_stereo_config config ; close_window ( ) | false -> let open Raylib in update_camera ( addr camera ) ; ... |
let ( ) = setup ( ) |> loop |
let clamp_value ( x , y ) ( mi_x , mi_y ) ( ma_x , ma_y ) = Float . ( max mi_x ( min ma_x x ) , max mi_y ( min ma_y y ) ) |
let origin = Raylib . Vector2 . create 0 . 0 0 . 0 |
let init_colors ( ) = let open Raylib in Array . init 10 ( fun _ -> Color . create ( get_random_value 100 250 ) ( get_random_value 50 150 ) ( get_random_value 10 100 ) 255 ) |
let setup ( ) = let open Raylib in set_config_flags [ ConfigFlags . Window_resizable ; ConfigFlags . Vsync_hint ] ; init_window 800 450 " raylib [ core ] example - window scale letterbox " ; set_window_min_size 320 240 ; let target = load_render_texture ( Int . of_float game_width... |
let draw ( target , colors ) = let open Raylib in let sx , sy = ( Float . of_int ( get_screen_width ( ) ) , Float . of_int ( get_screen_height ( ) ) ) in let scale = Float . min ( sx . / game_width ) ( sy . / game_height ) in let mouse_x , mouse_y = let mouse = g... |
let update ( target , colors ) = let open Raylib in let colors = if is_key_pressed Key . Space then init_colors ( ) else colors in ( target , colors ) |
let rec loop ( target , colors ) = match Raylib . window_should_close ( ) with | true -> Raylib . unload_render_texture target ; Raylib . close_window ( ) | false -> ( target , colors ) |> draw |> update |> loop |
let ( ) = setup ( ) |> loop |
type t = { size : Code_size . t ; removed : Removed_operations . t } |
type code_characteristics = { cost_metrics : t ; params_arity : int } |
let zero = { size = Code_size . zero ; removed = Removed_operations . zero } |
let size t = t . size |
let removed t = t . removed |
let print ppf t = Format . fprintf ppf " [ @< hov 1 > size : % a removed : { % a } ] " @ Code_size . print t . size Removed_operations . print t . removed |
let from_size size = { size ; removed = Removed_operations . zero } |
let notify_added ~ code_size t = { t with size = Code_size . ( + ) t . size code_size } |
let notify_removed ~ operation t = { t with removed = Removed_operations . ( + ) t . removed operation } |
let ( + ) a b = { size = Code_size . ( + ) a . size b . size ; removed = Removed_operations . ( + ) a . removed b . removed } |
let set_of_closures ~ find_code_characteristics set_of_closures = let func_decls = Set_of_closures . function_decls set_of_closures in let funs = Function_declarations . funs func_decls in let num_clos_vars = Set_of_closures . value_slots set_of_closures |> Value_slot . Map . cardinal in let cost_metric... |
let increase_due_to_let_expr ~ is_phantom ~ cost_metrics_of_defining_expr = if is_phantom then zero else cost_metrics_of_defining_expr |
let increase_due_to_let_cont_non_recursive ~ cost_metrics_of_handler = cost_metrics_of_handler |
let increase_due_to_let_cont_recursive ~ cost_metrics_of_handlers = cost_metrics_of_handlers |
let evaluate ~ args ( t : t ) = Code_size . evaluate ~ args t . size . - Removed_operations . evaluate ~ args t . removed |
let equal { size = size1 ; removed = removed1 } { size = size2 ; removed = removed2 } = Code_size . equal size1 size2 && Removed_operations . equal removed1 removed2 |
module Model = struct type t = { counters : int Int . Map . t } [ @@ deriving sexp , fields , equal ] let add_new t = let map_len = Map . length t . counters in print_s [ % message ( map_len : int ) ] ; if map_len >= maximum_data_points then t else { counters = Map . set t . ... |
module Action = struct type t = | New_counter | Update of { pos : int ; diff : int } [ @@ deriving sexp ] let should_log _ = true end |
module State = struct type t = unit end |
let apply_action model action _ ~ schedule_action : _ = match ( action : Action . t ) with | New_counter -> Model . add_new model | Update { pos ; diff } -> Model . update model ~ pos ~ diff ; ; |
let on_startup ~ schedule_action : _ _ = Async_kernel . return ( ) |
let view ( m : Model . t ) ( ~ inject : Action . t -> unit Vdom . Effect . t ) = let open Vdom in let on_add_new_click = Attr . on_click ( fun _ev -> inject New_counter ) in let add_new_counter_button = Node . div [ Node . button ~ attr : on_add_new_click [ Node . text " add... |
let create model ~ old_model : _ ~ inject = let open Incr . Let_syntax in let % map model = model in let apply_action = apply_action model in let view = view model ~ inject in Component . create ~ apply_action model view ; ; |
module Make ( Bits : sig val bits : int end ) = struct open Hardcaml . Signal module I = struct type ' a t = { data : ' a [ @ bits Bits . bits ] } [ @@ deriving sexp_of , hardcaml ] end module O = struct type ' a t = { count : ' a [ @ bits Int . ceil_log2 Bits . bits ] ... |
let command = Async . Command . async ~ summary " : count leading zeros logic " ( let open Command . Let_syntax in let % map_open ( ) = return ( ) and flags = Hardcaml_xilinx_reports . Command . Command_flags . flags and bits = flag " bits " ( required int ) ~ doc " : BITS N... |
let ref = ( 3 [ @ manual . ref " ch : pentatonic " ] ) ] } and that their values are consistent with the computed references for the payload labels ( e . g " sec : major " , " ch : pentatonic " ) present in the TeX auxiliary file [ tex . aux ] ) * |
type error = | Reference_mismatch of { loc : Location . t ; label : string ; ocaml : int list ; tex : int list } | Unknown_label of Location . t * string | Tuple_expected of Location . t | No_aux_file | Wrong_attribute_payload of Location . t |
let pp_ref ppf = Format . pp_print_list ~ pp_sep ( : fun ppf ( ) -> Format . pp_print_string ppf " . " ) Format . pp_print_int ppf |
let print_error error = Location . print_report Format . std_formatter @@ match error with | Tuple_expected loc -> Location . errorf ~ loc " Integer tuple expected after manual reference annotation . " @ | Unknown_label ( loc , label ) -> Location . errorf ~ loc " [ @< hov > Unknown m... |
type tex_reference = { label : string ; pos : int list ; level : string } |
type status = Ok | Bad | Unknown |
type ml_reference = { loc : Location . t ; pos : int list ; status : status } |
let check_consistency ( ref : tex_reference ) { loc ; pos ; _ } = if ref . pos = pos then { loc ; pos ; status = Ok } else begin print_error @@ Reference_mismatch { loc ; label = ref . label ; tex = ref . pos ; ocaml = pos } ; { loc ; pos ; status = Bad } end |
let rec check_final_status label error = function | { status = Ok ; _ } -> error | { status = Bad ; _ } -> true | { status = Unknown ; loc ; _ } -> print_error ( Unknown_label ( loc , label ) ) ; true |
module TeX = struct let scan s = try Scanf . sscanf s " \\ newlabel { % s } { { @% s } { @% _d } { % _s } { @% s . @% _s } { @% _s } } " @ ( fun label position_string level -> let pos = List . map int_of_string ( String . split_on_char ' . ' position_st... |
module OCaml_refs = struct let parse sourcefile = Pparse . parse_implementation ~ tool_name " : manual_cross_reference_check " sourcefile let manual_reference_attribute attr = let open Parsetree in if attr . attr_name . Location . txt <> " manual . ref " then None else begin match attr . attr_... |
let usage = " cross - reference - check - auxfile [ file . aux ] file_1 . . . file_n checks that \ the cross reference annotated with [ @ manual_cross_reference ] are consistent \ with the provided auxiliary TeX file " |
let aux_file = ref None |
let args = [ " - auxfile " , Arg . String ( fun s -> aux_file := Some s ) , " set the reference file " ] |
let ( ) = let m = ref Refs . empty in Arg . parse args ( OCaml_refs . from_file m ) usage ; match ! aux_file with | None -> print_error No_aux_file ; exit 2 | Some aux -> let error = TeX . check_all aux ! m in if error then exit 2 else exit 0 |
match op with | Iconst_float _ | Inegf | Iabsf | Iaddf | Isubf | Imulf | Idivf | Iintoffloat | Ifloatofint | Iload ( ( Single | Double ) , _ , _ ) -> Op_other | Ispecific ( Ilea _ ) -> Op_pure | Ispecific ( Istore_int ( _ , _ , is_asg ) ) -> Op_store is_asg | Ispecific... |
let fundecl f = ( new cse ) # fundecl f |
type op_class = | Op_pure | Op_checkbound | Op_load of Asttypes . mutable_flag | Op_store of bool | Op_other |
type rhs = operation * valnum array |
module Equations = struct module Rhs_map = Map . Make ( struct type t = rhs let compare = Stdlib . compare end ) type ' a t = { mutable_load_equations : ' a Rhs_map . t ; other_equations : ' a Rhs_map . t } let empty = { mutable_load_equations = Rhs_map . empty ; other_equations ... |
type numbering = { num_next : int ; num_eqs : valnum array Equations . t ; num_reg : valnum Reg . Map . t } |
let empty_numbering = { num_next = 0 ; num_eqs = Equations . empty ; num_reg = Reg . Map . empty } |
let fresh_valnum_reg n r = let v = n . num_next in ( { n with num_next = v + 1 ; num_reg = Reg . Map . add r v n . num_reg } , v ) |
let array_fold_transf ( f : numbering -> ' a -> numbering * ' b ) n ( a : ' a array ) : numbering * ' b array = match Array . length a with | 0 -> ( n , [ ] ) || | 1 -> let ( n ' , b ) = f n a . ( 0 ) in ( n ' , [ | b ] ) | | l -> let b = Array... |
let fresh_valnum_regs n rs = array_fold_transf fresh_valnum_reg n rs |
let valnum_reg n r = try ( n , Reg . Map . find r n . num_reg ) with Not_found -> fresh_valnum_reg n r |
let valnum_regs n rs = array_fold_transf valnum_reg n rs |
let find_equation op_class n rhs = try Some ( Equations . find op_class rhs n . num_eqs ) with Not_found -> None |
let find_reg_containing n v = Reg . Map . fold ( fun r v ' res -> if v ' = v then Some r else res ) n . num_reg None |
let find_regs_containing n vs = match Array . length vs with | 0 -> Some [ ] || | 1 -> begin match find_reg_containing n vs . ( 0 ) with | None -> None | Some r -> Some [ | r ] | end | l -> let rs = Array . make l Reg . dummy in begin try for i = 0 to l - 1 do match find_reg_co... |
let set_known_reg n r v = { n with num_reg = Reg . Map . add r v n . num_reg } |
let array_fold2 f n a1 a2 = let l = Array . length a1 in assert ( l = Array . length a2 ) ; let n = ref n in for i = 0 to l - 1 do n := f ! n a1 . ( i ) a2 . ( i ) done ; ! n |
let set_known_regs n rs vs = array_fold2 set_known_reg n rs vs |
let set_move n src dst = let ( n1 , v ) = valnum_reg n src in { n1 with num_reg = Reg . Map . add dst v n1 . num_reg } |
let set_fresh_regs n rs rhs op_class = let ( n1 , vs ) = fresh_valnum_regs n rs in { n1 with num_eqs = Equations . add op_class rhs vs n . num_eqs } |
let set_unknown_regs n rs = { n with num_reg = Array . fold_right Reg . Map . remove rs n . num_reg } |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.