text
stringlengths
0
601k
let template ~ ctxt ~ sp ( ? extra_headers [ ] ) = ~ title ~ div_id ctnt = let extra_headers = match ctxt . google_analytics_account with | Some code -> let js_code = Printf . sprintf " var _gaq = _gaq || [ ] ; \ n \ _gaq . push ( [ ' _setAccount ' , ' % s ' ] ) ; \ n \ _gaq . push ( [ ' _trackPageview ' ] ) ; \ n \ ( ...
module Default = struct let tables ( params : params ) ( code : Pla . t ) : Pla . t = let file = String . uppercase params . output in [ % pla { | <# code #> } ] | let header ( params : params ) ( code : Pla . t ) : Pla . t = let file = String . uppercase params . output in let tables = params . output in [ % pla { | <...
let apply ( params : params ) ( header_code : Pla . t ) ( impl_code : Pla . t ) ( tables : Pla . t ) : ( Pla . t * FileKind . t ) list = let template = match params . template with | " none " -> Default . get | " default " -> Default . get | " teensy " -> TeensyAudio . get | " pd " -> Pd . get | " max " -> Max . get | ...
type command = { name : string ; args : string list }
type action = | Run of command | Refmt of string list
type t = { message : string option ; actions : action list }
let command_to_string = function | { name ; args = [ ] } -> name | { name ; args } -> Printf . sprintf " % s % s " name ( String . concat " " args ) args
let of_dec ~ context ( dec_actions : Dec_template . Actions . t ) t = let message = match dec_actions . message with | Some message -> let evaluated = Template_expr . eval message ~ context in Some evaluated | None -> None in let actions = List . map ( function | Dec_template . Actions . Run { name ; args } -> Run { na...
let action_run ~ root_path cmd = Logs . debug ( fun m -> m " Running % s " ( command_to_string cmd ) cmd ) cmd ; Spawn . exec cmd . name cmd . args ~ cwd ( : Path root_path ) root_path |> Result . map_error ( fun err -> Spin_error . failed_to_generate ( Printf . sprintf " The command % s did not run successfully : % s ...
let action_refmt ~ root_path globs = let open Result . Syntax in let files = Sys . ls_dir root_path in Result . List . iter ( fun input_path -> let normalized_path = input_path |> Fpath . v |> ( fun p -> Option . get ( Fpath . rem_prefix ( Fpath . v root_path ) root_path p ) p ) p |> Fpath . to_string |> Str . global_r...
let run ~ path t = let open Result . Syntax in Option . iter ( fun msg -> Logs . app ( fun m -> m " % s " msg ) msg ) msg t . message ; let + ( ) = Result . List . fold_left ( fun _ el -> match el with | Run cmd -> action_run ~ root_path : path cmd | Refmt globs -> action_refmt ~ root_path : path globs ) globs ( ) t . ...
let of_decs_with_condition ~ context l = Template_expr . filter_map ~ context ~ condition ( : fun el -> el . Dec_template . Actions . enabled_if ) enabled_if ( of_dec ~ context ) context l
let validate_of_rule ~ context ~ config_name ( rule : Configuration . rule ) rule = let context_with_config = Hashtbl . copy context in fun ( v : string ) string -> Hashtbl . add context_with_config config_name v ; let result = Template_expr . to_result Template_expr . to_bool rule . expr ~ context : context_with_confi...
let prompt_config ( ? use_defaults = false ) false ~ context ( config : Configuration . t ) t = let open Result . Syntax in let * default = match config . default with | None -> Ok None | Some default -> let + result = Template_expr . to_result Template_expr . eval default ~ context in Some result in let validate = Lis...
let populate_context ( ? use_defaults = false ) false ~ context ( configurations : Dec_template . Configuration . t list ) list = let open Result . Syntax in Result . List . fold_left ( fun _ ( config : Configuration . t ) t -> if Hashtbl . mem context config . name then Result . ok ( ) else let env_var_name = Printf ....
let rec eval ~ context = function | Expr . Var name -> ( match Hashtbl . find_opt context name with | Some var -> var | None -> raise ( Invalid_expr ( Printf . sprintf " The context variable is missing : % s " name ) name ) name ) name | Expr . Function fn -> eval_fn fn ~ context | Expr . String s -> s let eval = eval ...
let to_result ~ context f expr = try f ~ context expr |> Result . ok with | Invalid_expr reason -> Error ( Spin_error . failed_to_generate reason ) reason | _ -> Error ( Spin_error . failed_to_generate " Failed to evaluate an expression for unknown reason ) "
let filter_map ~ context ~ condition f l = let open Result . Syntax in List . fold_right ( fun el acc -> let * acc = acc in match condition el with | None -> Result . ok ( f el :: acc ) acc | Some expr -> let + result = to_result to_bool expr ~ context in if result then f el :: acc else acc ) acc l ( Result . ok [ ] )
type template_item = | Const of string | Var of string
module Bindings = Map . Make ( String )
module Reader = Preface . Reader . Over ( struct type t = string Bindings . t end )
let transform_item = let open Reader in let open Bindings in function | Const s -> return s | Var s -> let * env = ask in return ( if mem s env then find s env else " N / A " ) ; ;
let rec transform = let open Reader in function | [ ] -> return " " | a :: l -> let * ta = transform_item a in let * tl = transform l in return ( ta ^ tl ) ; ;
let should_transform_constant ( ) = let expected = " Hello " and computed = Reader . run_identity ( transform [ Const " Hello " ] ) Bindings . empty in Alcotest . ( check string ) " transform_constant " expected computed ; ;
let should_transform_variable ( ) = let expected = " Alice " and computed = Reader . run_identity ( transform [ Var " name " ] ) ( Bindings . singleton " name " " Alice " ) in Alcotest . ( check string ) " transform_variable " expected computed ; ;
let should_not_transform_variable ( ) = let expected = " N / A " and computed = Reader . run_identity ( transform [ Var " name " ] ) Bindings . empty in Alcotest . ( check string ) " not_transform_variable " expected computed ; ;
let should_transform_constant_and_variable ( ) = let expected = " Hello , Alice " and computed = Reader . run_identity ( transform [ Const " Hello " ; Const " , " ; Var " name " ] ) ( Bindings . singleton " name " " Alice " ) in Alcotest . ( check string ) " transform_constant_and_variable " expected computed ; ;
let cases = let open Alcotest in [ ( " Templating using Reader " , [ test_case " Should transform a constant " ` Quick should_transform_constant ; test_case " Should transform a variable " ` Quick should_transform_variable ; test_case " Should not transform a variable " ` Quick should_not_transform_variable ; test_case...
module type Sig = sig val lifecycles : Sihl . Container . lifecycle list val register_migration : unit -> unit val register_cleaner : unit -> unit val get : ? ctx ( : string * string ) list -> string -> Sihl . Contract . Email_template . t option Lwt . t val get_by_label : ? ctx ( : string * string ) list -> ? language...
let template = let open Sihl . Contract . Email_template in let encode m = Ok ( m . id , ( m . label , ( m . language , ( m . text , ( m . html , ( m . created_at , m . updated_at ) ) ) ) ) ) in let decode ( id , ( label , ( language , ( text , ( html , ( created_at , updated_at ) ) ) ) ) ) = Ok { id ; label ; language...
module MakeMariaDb ( MigrationService : Sihl . Contract . Migration . Sig ) : Sig = struct let lifecycles = [ Sihl . Database . lifecycle ; MigrationService . lifecycle ] module Sql = struct module Model = Sihl . Contract . Email_template let get_request = let open Caqti_request . Infix in { sql | SELECT LOWER ( CONCAT...
module MakePostgreSql ( MigrationService : Sihl . Contract . Migration . Sig ) : Sig = struct let lifecycles = [ Sihl . Database . lifecycle ; MigrationService . lifecycle ] module Sql = struct module Model = Sihl . Contract . Email_template let get_request = let open Caqti_request . Infix in { sql | SELECT uuid , labe...
let transfer_data = ( Constant . bootstrap1 . alias , Tez . one , Constant . bootstrap2 . alias )
let default_overrides = [ ( [ " consensus_threshold " ] , Some " 6 " ) ; ]
let init ( ? overrides = default_overrides ) protocol = let * sandbox_node = Node . init [ Synchronisation_threshold 0 ; Private_mode ] in let sandbox_endpoint = Client . Node sandbox_node in let * sandbox_client = Client . init ~ endpoint : sandbox_endpoint ( ) in let * parameter_file = let base = Either . Right ( pro...
let bootstrap_accounts = List . tl Constant . all_secret_keys
let endorsers = [ Constant . bootstrap1 . alias ; Constant . bootstrap2 . alias ; Constant . bootstrap3 . alias ; Constant . bootstrap4 . alias ; Constant . bootstrap5 . alias ; ]
let endorse endpoint protocol client endorsers = Client . endorse_for ~ endpoint ~ protocol ~ key : endorsers ~ force : true client
let preendorse endpoint protocol client preendorsers = Client . preendorse_for ~ endpoint ~ protocol ~ key : preendorsers ~ force : true client
let test_bake_two = Protocol . register_test ~ __FILE__ ~ title " : Tenderbake transfer - baking 2 " ~ tags [ " : baking " ; " tenderbake " ] @@ fun protocol -> let * ( _proto_hash , endpoint , client ) = init protocol in let end_idx = List . length bootstrap_accounts in let rec loop i = if i = end_idx then Lwt . retur...
let test_low_level_commands = Protocol . register_test ~ __FILE__ ~ title " : Tenderbake low level commands " ~ tags [ " : propose " ; " endorse " ; " preendorse " ; " tenderbake " ; " low_level " ] @@ fun protocol -> let * ( _proto_hash , endpoint , client ) = init protocol in Log . info " Doing a propose -> preendors...
let test_repropose = Protocol . register_test ~ __FILE__ ~ title " : Tenderbake low level repropose " ~ tags : [ " propose " ; " endorse " ; " preendorse " ; " tenderbake " ; " low_level " ; " repropose " ; ] @@ fun protocol -> let * ( _proto_hash , endpoint , client ) = init protocol in Log . info " Doing a propose ->...
let register ~ protocols = test_bake_two ~ protocols ; test_low_level_commands ~ protocols ; test_repropose ~ protocols
type delegate_selection = ( Raw_level_repr . t * ( Round_repr . t * Signature . public_key_hash ) list ) list
module LevelRoundMap = Map . Make ( struct type t = Level_repr . t * Round_repr . t let compare ( l1 , r1 ) ( l2 , r2 ) = Stdlib . compare ( Raw_level_repr . to_int32 l1 . Level_repr . level , Round_repr . to_int32 r1 ) ( Raw_level_repr . to_int32 l2 . Level_repr . level , Round_repr . to_int32 r2 ) end )
let _ = Client_keys . register_signer ( module Tezos_signer_backends . Unencrypted )
let init_context ? constants_overrides_json ? bootstrap_accounts_json parameters = let parameters = Data_encoding . Binary . of_bytes_exn Mockup . M . parameters_encoding @@ Data_encoding . Binary . to_bytes_exn Mockup . Protocol_parameters . encoding parameters in Mockup . M . init ~ cctxt : Client_context . null_prin...
let change_seed ? initial_seed ctxt = let preserved = Constants_storage . preserved_cycles ctxt in List . fold_left_es ( fun ( c , ctxt ) seed -> let cycle = Cycle_repr . of_int32_exn ( Int32 . of_int c ) in Storage . Seed . For_cycle . remove_existing ctxt cycle >>=? fun ctxt -> Storage . Seed . For_cycle . init ctxt ...
let init ? constants_overrides_json ? bootstrap_accounts_json parameters = init_context ? constants_overrides_json ? bootstrap_accounts_json parameters >>=? fun ctxt -> let blocks_per_cycle = Constants_storage . blocks_per_cycle ctxt in let blocks_per_commitment = Constants_storage . blocks_per_commitment ctxt in let c...
let check ctxt ~ selection = Lwt . catch ( fun ( ) -> LevelRoundMap . fold_es ( fun ( level , round ) delegate ctxt -> Delegate_storage . baking_rights_owner ctxt level ~ round >|= Environment . wrap_tzresult >>=? fun ( ctxt , _ , ( _ , pkh ) ) -> if not ( Signature . Public_key_hash . equal delegate pkh ) then raise E...
let rnd_bytes32 ( ) = let b1 = Random . int64 Int64 . max_int in let b2 = Random . int64 Int64 . max_int in let b3 = Random . int64 Int64 . max_int in let b4 = Random . int64 Int64 . max_int in let b = Bytes . make 32 ' \ 000 ' in TzEndian . set_int64 b 0 b1 ; TzEndian . set_int64 b 8 b2 ; TzEndian . set_int64 b 16 b3 ...
let mk_selection_map cycle_eras selection = List . fold_left ( fun acc ( level , round_delegates ) -> let level = Level_repr . level_from_raw ~ cycle_eras level in List . fold_left ( fun acc ( round , delegate ) -> if LevelRoundMap . mem ( level , round ) acc then Stdlib . failwith " Duplicate level / round " ; LevelRo...
let bruteforce ( ? show_progress = false ) ( ? random_seed = 0 ) ? max ( ? parameters = Mockup . Protocol_parameters . default_value ) ? constants_overrides_json ? bootstrap_accounts_json selection = Random . init random_seed ; init ? constants_overrides_json ? bootstrap_accounts_json parameters >>=? fun ( ctxt , cycle...
let check_seed ( ? parameters = Mockup . Protocol_parameters . default_value ) ? constants_overrides_json ? bootstrap_accounts_json ~ seed selection = init ? constants_overrides_json ? bootstrap_accounts_json parameters >>=? fun ( ctxt , cycle_eras ) -> let selection = mk_selection_map cycle_eras selection in change_se...
let bootstrap_accounts = ref None
let constants_overrides = ref None
let selection = ref [ ]
let max = ref None
let random_seed = ref None
let report_err res = match res with | Error e -> Format . eprintf " \ n % a . " @ Error_monad . pp_print_trace e ; exit 2 | Ok res -> res
let delegate_encoding = let open Data_encoding in union [ case ~ title " : Public key hash " ( Tag 0 ) Signature . Public_key_hash . encoding ( function ` Pkh p -> Some p | _ -> None ) ( fun p -> ` Pkh p ) ; case ~ title " : Alias " ( Tag 1 ) string ( function ` Alias a -> Some a | _ -> None ) ( fun a -> ` Alias a ) ; ...
let selection_encoding = let open Data_encoding in list ( tup2 Raw_level_repr . encoding ( list ( tup2 Round_repr . encoding delegate_encoding ) ) )
let mk_bootstrap_aliases bootstrap_accounts_json = let parameters = Mockup . Protocol_parameters . default_value in let open Alpha_context . Parameters in match bootstrap_accounts_json with | None -> List . mapi ( fun i a -> ( Format . sprintf " bootstrap % d " i , a . public_key_hash ) ) parameters . bootstrap_account...
let selection_to_pkhs bootstrap_accounts_json selection = mk_bootstrap_aliases bootstrap_accounts_json >|=? fun bootstrap_aliases -> List . map ( fun ( level , l ) -> ( level , List . map ( fun ( round , d ) -> ( round , match d with | ` Pkh d -> d | ` Alias a -> ( match List . assoc ~ equal : String . equal a bootstra...
let parse_json_or_file s = Tezos_stdlib_unix . Lwt_utils_unix . Json . read_file s >|= function | Ok json -> Ok json | Error errs -> ( match Data_encoding . Json . from_string s with | Ok json -> Ok json | Error e -> Error ( Exn ( Failure e ) :: errs ) )
let set_selection s = Lwt_main . run ( parse_json_or_file s >|= report_err >|= fun json -> selection := Data_encoding . Json . destruct selection_encoding json )
let main ( ) = let thread = ( match ! bootstrap_accounts with | None -> return_none | Some read -> read >|=? Option . some ) >>=? fun bootstrap_accounts_json -> ( match ! constants_overrides with | None -> return_none | Some read -> read >|=? Option . some ) >>=? fun constants_overrides_json -> selection_to_pkhs bootst...
let specs = [ ( " -- max " , Arg . Int ( fun m -> max := Some m ) , " < m > set maximum number of tries to < m " > ) ; ( " -- random - seed " , Arg . Int ( fun i -> random_seed := Some i ) , " < i > initialize the random generator with < i > ( useful to spawn mutliple \ instances ) " ) ; ( " -- constants - overrides " ...
let usage = Format . sprintf { | usage : % s ' [ [ 1 , [ [ 0 , " tz1 . . . " ] , [ 1 , " tz1 . . . " ] ] ] , [ 2 , [ [ 0 , " tz1 . . . " ] ] ] ] ' } | Sys . argv . ( 0 )
let ( ) = Arg . parse ( Arg . align specs ) set_selection usage ; main ( )
let make_image ( ) = let image = GlPix . create ` ubyte ~ width : image_width ~ height : image_height ~ format ` : rgba in for i = 0 to image_width - 1 do for j = 0 to image_height - 1 do Raw . sets ( GlPix . to_raw image ) ~ pos ( : 4 ( * i * image_height + j ) ) ( if ( ( ( i land 6 ) = 6 ) or ( ( j land 6 ) = 6 ) ) t...
let make_image2 ( ) = let on_circle ( x0 , y0 ) ( x , y ) = let d = ( x . - x0 ) . * ( x . - x0 ) . + ( y . - y0 ) . * ( y . - y0 ) in ( ( d > 0 . 9 . * 0 . 9 ) && ( d < 1 . 1 . * 1 . 1 ) ) in let on_line ( x , y ) = if x <= . - 2 . 0 then on_circle ( . - 2 . 0 , 0 . 0 ) ( x , y ) else if x >= 2 . 0 then on_circle ( 2 ...
let ft x = x . * 0 . 03
let cw = ft ( 9 . 0 . + 4 . 5 )
let cl = ft 39 . 0
let sw = ft 9 . 0
let sl = ft 21 . 0
let square ( x1 , y1 ) ( x2 , y2 ) = List . iter ~ f : GlDraw . vertex2 [ x1 , y1 ; x2 , y1 ; x2 , y2 ; x1 , y2 ]
let collide ~ pos ~ vel ~ plane ~ func = let between ( a , b , x ) = let ( a , b ) = if a > b then ( b , a ) else ( a , b ) in ( x > a ) && ( x < b ) in let ( xpos , ypos , zpos ) = pos in let ( dx , dy , dz ) = vel in if dx = 0 . 0 then ( xpos , ypos . + dy , zpos . + dz ) else let ( ( x1 , y1 , z1 ) , ( x2 , y2 , z2 ...
let main ( ) = let top = openTk ( ) in Wm . title_set top " Tennis Court " ; let f0 = Frame . create top in let court3d = Togl . create f0 ~ width : 600 ~ height : 600 ~ rgba : true ~ double : true ~ depth : true and f1 = Frame . create f0 in let court2d = Togl . create f1 ~ width : 200 ~ height : 200 ~ rgba : true ~ d...
let _ = main ( )
let set_float2 t i j value = float_set t [ i ; j ] value
let set_float1 t i value = float_set t [ i ] value
let set_int2 t i j value = int_set t [ i ; j ] value
let set_int1 t i value = int_set t [ i ] value
let get_float2 t i j = float_get t [ i ; j ]
let get_float1 t i = float_get t [ i ]
let get_int2 t i j = int_get t [ i ; j ]
let get_int1 t i = int_get t [ i ]
let ( . { } % ) = int_get
let ( . { } %<- ) = int_set
let ( . . { } % ) = float_get
let ( . . { } %<- ) = float_set
let ( . [ ] % ) = get_int1
let ( . [ ] %<- ) = set_int1
let ( . . [ ] % ) = get_float1
let ( . . [ ] %<- ) = set_float1
let no_grad_ t ~ f = if requires_grad t then ( let t = set_requires_grad t ~ r : false in Exn . protect ~ f ( : fun ( ) -> f t ) ~ finally ( : fun ( ) -> ignore ( set_requires_grad t ~ r : true : t ) ) ) else f t
let no_grad f = let prev = grad_set_enabled false in Exn . protect ~ f ~ finally ( : fun ( ) -> ignore ( grad_set_enabled prev : bool ) )
let zero_grad t = let grad = grad t in if defined grad then ( ignore ( detach_ grad : t ) ; ignore ( zero_ grad : t ) )