text
stringlengths
12
786k
module Make_set ( T : Thing_no_hash ) = struct include Set . Make [ @ inlined hint ] ( T ) let [ @ ocamlformat " disable " ] print ppf s = let elts ppf s = iter ( fun e -> Format . fprintf ppf " @ % a " T . print e ) s in Format . fprintf ppf " [ @< 1 { [ >@% a @...
module Make ( T : Thing ) = struct module T = T include T module Set = Make_set ( T ) module Map = Make_map ( T ) ( Set ) end
module Make_pair ( T1 : S ) ( T2 : S ) = struct module Pair = Pair ( T1 . T ) ( T2 . T ) include Make ( Pair ) let create_from_cross_product t1_set t2_set = T1 . Set . fold ( fun t1 result -> T2 . Set . fold ( fun t2 result -> Set . add ( t1 , t2 ) result ) t2_set re...
module type Thing_no_hash = sig type t include Map . OrderedType with type t := t val print : Format . formatter -> t -> unit end
module type Thing = sig type t include Hashtbl . HashedType with type t := t include Map . OrderedType with type t := t val print : Format . formatter -> t -> unit end
module type Set = sig type elt type t val empty : t val is_empty : t -> bool val mem : elt -> t -> bool val add : elt -> t -> t val singleton : elt -> t val remove : elt -> t -> t val union : t -> t -> t val inter : t -> t -> t val disjoint : t -> t -> bool val diff : t -> t -> t val compare ...
module type Map = sig type key module Set : Set with type elt = key type ' +! a t val empty : ' a t val is_empty : ' a t -> bool val mem : key -> ' a t -> bool val add : key -> ' a -> ' a t -> ' a t val update : key -> ( ' a option -> ' a option ) -> ' a t -> ' a t val singl...
module type S = sig type t module T : Thing with type t = t include Thing with type t := T . t module Set : Set with type elt = t module Map : Map with type key = t and module Set = Set end
module type Set_plus_stdlib = sig include Set include Stdlib . Set . S with type elt := elt and type t := t end
module type Map_plus_stdlib = sig include Map include Stdlib . Map . S with type key := key and type ' a t := ' a t end
module type S_plus_stdlib = sig type t module T : Thing with type t = t include Thing with type t := T . t module Set : Set_plus_stdlib with type elt = t module Map : Map_plus_stdlib with type key = t and module Set = Set end
type t = { memory_limit_in_mb : int ; function_name : string ; function_version : string ; invoked_function_arn : string ; aws_request_id : string ; xray_trace_id : string option ; log_stream_name : string ; log_group_name : string ; client_context : Client . client_context option ; iden...
let make ~ invoked_function_arn ~ aws_request_id ~ xray_trace_id ~ client_context ~ identity ~ deadline settings = { memory_limit_in_mb = settings . Config . memory_size ; function_name = settings . function_name ; function_version = settings . version ; log_stream_name = settings . log_str...
let skip_user_input ( b : bool ) : json_spel = Json_spel . assoc [ Context . skip_user_input_lbl , Json_spel . bool b ]
let set_skip_user_input ( ctx : json_spel ) ( b : bool ) : json_spel = Json_spel . set ctx Context . skip_user_input_lbl ( ` Bool b )
let take_skip_user_input ( ctx : json_spel ) : json_spel * bool = begin match Json_spel . take ctx Context . skip_user_input_lbl with | ctx , Some ( ` Bool b ) -> ctx , b | _ -> ctx , false end
let actions ( acts : action list ) : json_spel = Json_spel . assoc [ Context . actions_lbl , Json_spel . list ( List . map Wcs . json_spel_of_action acts ) ]
let actions_def ( acts : action_def list ) : json_spel = Json_spel . assoc [ Context . actions_lbl , Json_spel . list ( List . map Wcs . json_spel_of_action_def acts ) ]
let json_spel_of_action ( act : action ) : json_spel = let json = Wcs . json_of_action act in let json_spel = Json_spel . of_json json in json_spel
let action_of_json_spel ( act : json_spel ) : action = Wcs_j . action_of_string ( Yojson . Basic . to_string ( Json_spel . to_json act ) )
let set_actions ctx ( acts : action list ) : json_spel = let js_acts = List . map json_spel_of_action acts in Json_spel . set ctx Context . actions_lbl ( ` List js_acts )
let take_actions ( ctx : json_spel ) : json_spel * action list option = begin match Json_spel . take ctx Context . actions_lbl with | ctx ' , Some ( ` List acts ) -> begin try ctx ' , Some ( List . map action_of_json_spel acts ) with _ -> Log . warning " Context_spel " ( Form...
let push_action ( ctx : json_spel ) ( act : action ) : json_spel = begin match take_actions ctx with | ctx , None -> set_actions ctx [ act ] | ctx , Some acts -> set_actions ctx ( acts @ [ act ] ) end
let pop_action ( ctx : json_spel ) : json_spel * action option = begin match take_actions ctx with | ctx ' , Some ( act :: acts ) -> set_actions ctx ' acts , Some act | _ -> ctx , None end
let set_continuation ( ctx : json_spel ) ( k : action ) : json_spel = Json_spel . set ctx Context . continuation_lbl ( json_spel_of_action k )
let take_continuation ( ctx : json_spel ) : json_spel * action option = begin match Json_spel . take ctx Context . continuation_lbl with | ctx ' , Some act -> begin try ctx ' , Some ( action_of_json_spel act ) with _ -> Log . warning " Context_spel " ( Format . sprintf " illed fo...
let get_continuation ( ctx : json_spel ) : action option = let _ , act = take_continuation ctx in act
let return ( v : json_spel ) : json_spel = Json_spel . assoc [ Context . return_lbl , v ]
let set_return ( ctx : json_spel ) ( x : json_spel ) : json_spel = Json_spel . set ctx Context . return_lbl x
let get_return ( ctx : json_spel ) : json_spel option = Json_spel . get ctx Context . return_lbl
let next_stamp = let next_stamp = ref 0 in fun ( ) -> incr next_stamp ; ! next_stamp
module Sort = struct type t = | Normal_or_exn | Return | Define_root_symbol | Toplevel_return let to_string t = match t with | Normal_or_exn -> " Normal_or_exn " | Return -> " Return " | Define_root_symbol -> " Define_root_symbol " | Toplevel_return -> " Toplevel_return " let print ppf t ...
module Data = struct type t = { compilation_unit : Compilation_unit . t ; previous_compilation_units : Compilation_unit . t list ; name : string ; name_stamp : int ; sort : Sort . t } let flags = continuation_flags let [ @ ocamlformat " disable " ] print ppf { compilation_unit ; n...
module Table = Table_by_int_id . Make ( Data )
let grand_table_of_continuations = ref ( Table . create ( ) )
let initialise ( ) = grand_table_of_continuations := Table . create ( )
let reset ( ) = initialise ( )
let create ? sort ? name ( ) : t = let sort = Option . value sort ~ default : Sort . Normal_or_exn in let name = Option . value name ~ default " : k " in let compilation_unit = Compilation_unit . get_current_exn ( ) in let previous_compilation_units = [ ] in let name_stamp = next_st...
let find_data t = Table . find ! grand_table_of_continuations t
let rename t = let { Data . name ; sort ; name_stamp = _ ; compilation_unit = _ ; previous_compilation_units = _ } = find_data t in create ~ sort ~ name ( )
let name t = ( find_data t ) . name
let name_stamp t = ( find_data t ) . name_stamp
let sort t = ( find_data t ) . sort type nonrec t = t let compare t1 t2 = Id . compare t1 t2 let equal t1 t2 = Id . equal t1 t2 let hash t = Hashtbl . hash t let print ppf t = Format . fprintf ppf " @< 0 >% s " ( Flambda_colours . continuation ( ) ) ; if String . equal ( name ...
module Tree = Patricia_tree . Make ( struct let print = print end )
let export t = find_data t
let import data = Table . add ! grand_table_of_continuations data
let map_compilation_unit f ( data : Data . t ) : Data . t = let new_compilation_unit = f data . compilation_unit in if Compilation_unit . equal new_compilation_unit data . compilation_unit then data else { data with compilation_unit = new_compilation_unit ; previous_compilation_units = data . ...
module Extra_arg = struct type t = | Already_in_scope of Simple . t | New_let_binding of Variable . t * Flambda_primitive . t | New_let_binding_with_named_args of Variable . t * ( Simple . t list -> Flambda_primitive . t ) let [ @ ocamlformat " disable " ] print ppf t = match t with |...
type t = { extra_params : Bound_parameters . t ; extra_args : Extra_arg . t list Apply_cont_rewrite_id . Map . t }
let [ @ ocamlformat " disable " ] print ppf { extra_params ; extra_args ; } = Format . fprintf ppf " [ @< hov 1 ( >\ [ @< hov 1 ( > extra_params @ % a ) ] @@ \ [ @< hov 1 ( > extra_args @ % a ) ] @\ ) ] " @ Bound_parameters . print extra_params ( Appl...
let empty = { extra_params = Bound_parameters . empty ; extra_args = Apply_cont_rewrite_id . Map . empty }
let is_empty t = if Bound_parameters . is_empty t . extra_params then ( assert ( Apply_cont_rewrite_id . Map . is_empty t . extra_args ) ; true ) else false
let add t ~ extra_param ~ extra_args = let extra_args = if Apply_cont_rewrite_id . Map . is_empty t . extra_args then Apply_cont_rewrite_id . Map . map ( fun extra_args -> [ extra_args ] ) extra_args else Apply_cont_rewrite_id . Map . merge ( fun id already_extra_args extra_args -> match a...
let concat t1 t2 = if is_empty t2 then t1 else if is_empty t1 then t2 else let extra_args = Apply_cont_rewrite_id . Map . merge ( fun id extra_args1 extra_args2 -> match extra_args1 , extra_args2 with | None , None -> None | Some _ , None | None , Some _ -> Misc . fatal_errorf " concat : mi...
let extra_params t = t . extra_params
type t = | Linearly_used_and_inlinable of { params : Bound_parameters . t ; handler : Rebuilt_expr . t ; free_names_of_handler : Name_occurrences . t ; cost_metrics_of_handler : Cost_metrics . t } | Non_inlinable_zero_arity of { handler : Rebuilt_expr . t Or_unknown . t } | Non_inlina...
let [ @ ocamlformat " disable " ] print are_rebuilding_terms ppf t = match t with | Linearly_used_and_inlinable { params ; handler ; free_names_of_handler ; cost_metrics_of_handler } -> Format . fprintf ppf " [ @< hov 1 ( > Linearly_used_and_inlinable @ \ [ @< hov 1 ( > params ...
let arity t = match t with | Linearly_used_and_inlinable { params ; handler = _ ; free_names_of_handler = _ ; cost_metrics_of_handler = _ } -> Bound_parameters . arity_with_subkinds params | Non_inlinable_zero_arity _ -> Flambda_arity . With_subkinds . nullary | Non_inlinable_non_zero_arity...
type t = { continuation : Continuation . t ; arity : Flambda_arity . t ; uses : U . t list }
let create continuation arity = { continuation ; arity ; uses = [ ] }
let [ @ ocamlformat " disable " ] print ppf { continuation ; arity ; uses ; } = Format . fprintf ppf " [ @< hov 1 ( >\ [ @< hov 1 ( > continuation @ % a ) ] @@ \ [ @< hov 1 ( > arity @ % a ) ] @@ \ [ @< hov 1 ( > uses @ % a ) ] @\ ) ] " @...
let add_use t kind ~ env_at_use id ~ arg_types = try let arity = T . arity_of_list arg_types in if not ( Flambda_arity . equal arity t . arity ) then Misc . fatal_errorf " Arity of use ( % a ) doesn ' t match continuation ' s arity ( % a ) " Flambda_arity . print arity Flambda_arity ...
let union t1 t2 = assert ( Continuation . equal t1 . continuation t2 . continuation ) ; assert ( Flambda_arity . equal t1 . arity t2 . arity ) ; { continuation = t1 . continuation ; arity = t1 . arity ; uses = t1 . uses @ t2 . uses }
let number_of_uses t = List . length t . uses
let arity t = t . arity
let get_uses t = t . uses
let get_arg_types_by_use_id t = List . fold_left ( fun args use -> List . map2 ( fun arg_map arg_type -> let env_at_use = U . env_at_use use in let typing_env = DE . typing_env env_at_use in let arg_at_use : Continuation_env_and_param_types . arg_at_use = { arg_type ; typing_env } in Apply_co...
let get_typing_env_no_more_than_one_use t = match t . uses with | [ ] -> None | [ use ] -> Some ( DE . typing_env ( U . env_at_use use ) ) | _ :: _ -> Misc . fatal_errorf " Only zero or one continuation use ( s ) expected :@ % a " print t
type t = { continuation_uses : Continuation_uses . t Continuation . Map . t }
let [ @ ocamlformat " disable " ] print ppf { continuation_uses ; } = Format . fprintf ppf " [ @< hov 1 ( >\ [ @< hov 1 ( > continuation_uses @ % a ) ] @\ ) ] " @ ( Continuation . Map . print Continuation_uses . print ) continuation_uses
let empty = { continuation_uses = Continuation . Map . empty }
let record_continuation_use t cont kind ~ env_at_use ~ arg_types = let id = Apply_cont_rewrite_id . create ( ) in let continuation_uses = Continuation . Map . update cont ( function | None -> let arity = T . arity_of_list arg_types in let uses = Continuation_uses . create cont arity in Some ( ...
let get_typing_env_no_more_than_one_use t k = match Continuation . Map . find k t . continuation_uses with | exception Not_found -> None | cont_uses -> Continuation_uses . get_typing_env_no_more_than_one_use cont_uses
let get_continuation_uses t cont = match Continuation . Map . find cont t . continuation_uses with | exception Not_found -> None | uses -> Some uses
let num_continuation_uses t cont = match Continuation . Map . find cont t . continuation_uses with | exception Not_found -> 0 | uses -> Continuation_uses . number_of_uses uses
let all_continuations_used t = Continuation . Map . keys t . continuation_uses
let union t1 t2 = let continuation_uses = Continuation . Map . union ( fun _ uses1 uses2 -> Some ( Continuation_uses . union uses1 uses2 ) ) t1 . continuation_uses t2 . continuation_uses in { continuation_uses }
let remove t cont = { continuation_uses = Continuation . Map . remove cont t . continuation_uses }
type state = { force_squared_check : bool ; spinner1_val : int ; mutable spinner_edit_mode : bool ; value_box_val : int ; mutable value_box_edit_mode : bool ; text_box_text : string ; mutable text_box_edit_mode : bool ; show_text_input_box : bool ; text_input_text : string ; combo_box_acti...
let setup ( ) = Raylib . init_window width height " raygui - controls test suite " ; Raylib . set_target_fps 60 ; { force_squared_check = false ; spinner1_val = 0 ; spinner_edit_mode = false ; value_box_edit_mode = false ; value_box_val = 50 ; text_box_text = " Text box " ; ...
let rec loop s = match Raylib . window_should_close ( ) with | true -> Raylib . close_window ( ) | false -> let open Raylib in let col = Raygui . ( get_style ( Control . Default ` Background_color ) ) |> get_color in begin_drawing ( ) ; clear_background col ; if s . show_text_...
let ( ) = setup ( ) |> loop
let convert_unsafety is_unsafe : Clambda_primitives . is_safe = if is_unsafe then Unsafe else Safe
let convert ( prim : Lambda . primitive ) : Clambda_primitives . primitive = match prim with | Pmakeblock ( tag , mutability , shape , mode ) -> Pmakeblock ( tag , mutability , shape , mode ) | Pmakefloatblock ( mutability , mode ) -> Pmakearray ( Pfloatarray , mutability , ...
let setup ( ) = let open Raylib in set_config_flags [ ConfigFlags . Window_resizable ] ; init_window width height " raylib [ core ] example - 2d camera " ; let player = Rectangle . create 400 . 0 280 . 0 40 . 0 40 . 0 in let spacing = ref 0 in let buildings = Array . ini...
let rec loop ( player , buildings , colors , camera ) = match Raylib . window_should_close ( ) with | true -> Raylib . close_window ( ) | false -> let open Raylib in ( if is_key_down Key . Right then Rectangle . ( set_x player ( x player . + 2 . 0 ) ) else if is_key_down ...
let ( ) = setup ( ) |> loop
type player_t = { position : Raylib . Vector2 . t ; speed : float ; can_jump : bool }
type env_item_t = { box : Raylib . Rectangle . t ; blocking : bool ; color : Raylib . Color . t ; }
type camera_mode_t = | Center | CenterInsideMap | SmoothFollow | EvenOutOnLanding of bool * float | PlayerBoundsPush
type state_t = player_t * env_item_t List . t * Raylib . Camera2D . t * camera_mode_t
let half_screen = Raylib . Vector2 . create ( Float . of_int width . / 2 . ) ( Float . of_int height . / 2 . )
let bbox_x , bbox_y = ( 0 . 2 , 0 . 2 )
type comparision_t = Higher | Lower | Equal
let compare tol a b = if Float . abs ( a . - b ) < tol then Equal else if a > b then Higher else Lower
let player_rec player = let open Raylib in let x , y , w , h = Vector2 . ( x player . position . - 20 . , y player . position . - 40 . , 40 . , 40 . ) in Rectangle . create x y w h
let camera_description = function | Center -> " Follow player center " | CenterInsideMap -> " Follow player center , but clamp to map edges " | SmoothFollow -> " Follow player center ; smoothed " | EvenOutOnLanding _ -> " Follow player center horizontally ; update player center vertically ...
let clamp_zoom z = if z > 3 . 0 then 3 . 0 else if z < 0 . 25 then 0 . 25 else z
let vy_of_float y = Raylib . Vector2 . create 0 . 0 y
let setup ( ) = let open Raylib in set_config_flags [ ConfigFlags . Window_resizable ] ; init_window width height " raylib [ core ] example - 2d camera " ; let player = { position = half_screen ; speed = 0 . 0 ; can_jump = false } in let env_items = [ { box = Rectangle . ...