text
stringlengths 12
786k
|
---|
module Fetch = Current_sesame . Make_watch ( Sesame . Utils . Dir ( C ) )
|
module Html = Current_sesame . Make ( Sesame . Utils . List ( H ) )
|
module Index = struct let to_html ( ts : C . t list Current . t ) = let open Current . Syntax in Current . component " Index File " |> let > ts = ts in let head = Components . simple_head ~ t " : Blog Posts " in let body = [ Components . navbar ; Components . section [ div ~ a [ : a_class [ " content " ; " columns " ] ] [ div ~ a [ : a_class [ " column " ; " is - 8 " ; " is - offset - 2 " ] ] [ ul ( List . map ( fun ( t : C . t ) -> let path = Fpath . ( v " " / / Conf . tutorial_dir / Fpath . filename ( Sesame . Utils . filename_to_html @@ Fpath . v t . path ) ) in li ~ a [ : a_style " list - style : none " ] [ a ~ a [ : a_href ( Fpath . to_string path ) ] [ h3 [ txt t . meta . title ] ; p [ txt t . meta . description ] ; ] ; ] ) ts ) ; ] ; ] ; ] ; ] in let html = Components . html_doc ~ head body |> Fmt . str " % a " ( Tyxml . Html . pp ( ) ) in Current_incr . const ( Ok html , None ) end
|
module State = struct module Clock_map = Map . Make ( Orx . Clock ) type t = Orx . Object . t Clock_map . t ref let state : t = ref Clock_map . empty let get ( ) = ! state let add ( clock : Orx . Clock . t ) ( o : Orx . Object . t ) : unit = state := Clock_map . add clock o ! state end
|
let update ( clock_info : Orx . Clock . Info . t ) = Orx . Config . push_section " Main " ; if Orx . Config . get_bool " DisplayLog " then Orx . Log . log " <% s >: Time = . % 3f / DT = . % 3f " ( Orx . Clock . get_name ( Orx . Clock . Info . get_clock clock_info |> Option . get ) ) ( Orx . Clock . Info . get_time clock_info ) ( Orx . Clock . Info . get_dt clock_info ) ; Orx . Config . pop_section ( ) ; let clock = Orx . Clock . Info . get_clock clock_info |> Option . get in let obj = State . Clock_map . find clock ( State . get ( ) ) in Orx . Object . set_rotation obj ( Float . pi . * Orx . Clock . Info . get_time clock_info )
|
let input_update ( _clock_info : Orx . Clock . Info . t ) = Orx . Config . push_section " Main " ; if Orx . Input . has_been_activated " Log " then Orx . Config . set_bool " DisplayLog " ( not ( Orx . Config . get_bool " DisplayLog " ) ) ; Orx . Config . pop_section ( ) ; match Orx . Clock . get " Clock1 " with | None -> ( ) | Some clock -> if Orx . Input . is_active " Faster " then Orx . Clock . set_modifier clock Multiply 4 . 0 else if Orx . Input . is_active " Slower " then Orx . Clock . set_modifier clock Multiply 0 . 25 else if Orx . Input . is_active " Normal " then Orx . Clock . set_modifier clock Multiply 0 . 0
|
let init ( ) = let get_name ( binding : string ) : string = let ( type_ , id , mode ) = Orx . Input . get_binding binding 0 |> Result . get_ok in Orx . Input . get_binding_name type_ id mode in Orx . Log . log ( " . @- Press ' % s ' to toggle log display . " @ ^^ " - To stretch time for the first clock ( updating the box ) . " :@ ^^ " . Press numpad ' % s ' to set it 4 times faster . " @ ^^ " . Press numpad ' % s ' to set it 4 times slower . " @ ^^ " . Press numpad ' % s ' to set it back to normal " ) ( get_name " Log " ) ( get_name " Faster " ) ( get_name " Slower " ) ( get_name " Normal " ) ; let ( _viewport : Orx . Viewport . t ) = Orx . Viewport . create_from_config_exn " Viewport " in let object1 = Orx . Object . create_from_config_exn " Object1 " in let object2 = Orx . Object . create_from_config_exn " Object2 " in let clock1 = Orx . Clock . create_from_config_exn " Clock1 " in let clock2 = Orx . Clock . create_from_config_exn " Clock2 " in State . add clock1 object1 ; State . add clock2 object2 ; Orx . Clock . register clock1 update ; Orx . Clock . register clock2 update ; let main_clock = Orx . Clock . get_core ( ) in Orx . Clock . register main_clock input_update ; Ok ( )
|
let run ( ) = if Orx . Input . is_active " Quit " then Orx . Status . error else Orx . Status . ok
|
let ( ) = Orx . Main . start ~ config_dir " : examples / tutorial / data " ~ init ~ run " 02_Clock "
|
module State = struct type t = { soldier : Orx . Object . t ; music : Orx . Sound . t ; } let state : t option ref = ref None let get ( ) = Option . get ! state end
|
let event_message ( event : Orx . Event . t ) ( sound_event_payload : Orx . Sound_event . payload ) kind = let sound = Orx . Sound_event . get_sound sound_event_payload in let recipient = Orx . Event . get_recipient_object event |> Option . get in Orx . Log . log " Sound [ % s ] [ @@% s ] has % s " ( Orx . Sound . get_name sound ) ( Orx . Object . get_name recipient ) kind
|
let event_handler ( event : Orx . Event . t ) ( sound_event : Orx . Sound_event . t ) ( payload : Orx . Sound_event . payload ) = let state = State . get ( ) in match Orx . Event . get_recipient_object event with | None -> Error ` Orx | Some recipient -> if Orx . Object . equal state . soldier recipient then ( match sound_event with | Start -> event_message event payload " started " | Stop -> event_message event payload " stopped " | _ -> ( ) ) ; Ok ( )
|
let update_state ( state : State . t ) ( clock_info : Orx . Clock . Info . t ) = if Orx . Input . has_been_activated " RandomSFX " then ( Orx . Object . add_sound_exn state . soldier " RandomBip " ; Orx . Config . push_section " Tutorial " ; Orx . Object . set_rgb state . soldier ( Orx . Config . get_vector " RandomColor " ) ; Orx . Object . set_alpha state . soldier 1 . 0 ; Orx . Config . pop_section ( ) ) ; if Orx . Input . has_been_activated " DefaultSFX " then ( Orx . Object . add_sound_exn state . soldier " DefaultBip " ; Orx . Object . set_rgb state . soldier ( Orx . Vector . make ~ x : 1 . 0 ~ y : 1 . 0 ~ z : 1 . 0 ) ) ; if Orx . Input . is_active " PitchUp " then ( Orx . Sound . set_pitch state . music ( min ( Orx . Sound . get_pitch state . music . + 0 . 01 ) 1 . 0 ) ; Orx . Object . set_rotation state . soldier ( Orx . Object . get_rotation state . soldier . + ( 4 . 0 . * Orx . Clock . Info . get_dt clock_info ) ) ) ; if Orx . Input . is_active " PitchDown " then ( Orx . Sound . set_pitch state . music ( max ( Orx . Sound . get_pitch state . music . - 0 . 01 ) 0 . 0 ) ; Orx . Object . set_rotation state . soldier ( Orx . Object . get_rotation state . soldier . - ( 4 . 0 . * Orx . Clock . Info . get_dt clock_info ) ) ) ; if Orx . Input . is_active " VolumeDown " then ( Orx . Sound . set_volume state . music ( max ( Orx . Sound . get_volume state . music . - 0 . 05 ) 0 . 0 ) ; Orx . Object . set_scale state . soldier ( Orx . Vector . mulf ( Orx . Object . get_scale state . soldier ) 0 . 98 ) ) ; if Orx . Input . is_active " VolumeUp " then ( Orx . Sound . set_volume state . music ( min ( Orx . Sound . get_volume state . music . + 0 . 05 ) 1 . 0 ) ; Orx . Object . set_scale state . soldier ( Orx . Vector . mulf ( Orx . Object . get_scale state . soldier ) 1 . 02 ) )
|
let update ( clock_info : Orx . Clock . Info . t ) = let state = State . get ( ) in if Orx . Input . has_been_activated " ToggleMusic " then Orx . Object . enable state . soldier ( not ( Orx . Object . is_enabled state . soldier ) ) ; if Orx . Object . is_enabled state . soldier then update_state state clock_info
|
let init ( ) = let get_name ( binding : string ) : string = let ( type_ , id , mode ) = Orx . Input . get_binding binding 0 |> Result . get_ok in Orx . Input . get_binding_name type_ id mode in Orx . Log . log ( " . @- ' % s ' & ' % s ' will change the music volume ( + soldier size ) . " @ ^^ " - ' % s ' & ' % s ' will change the music pitch ( + soldier rotation ) . " @ ^^ " - ' % s ' will toggle music ( + soldier display ) . " @ ^^ " - ' % s ' will play a random SFX on the soldier ( + change its color ) . " @ ^^ " - ' % s ' will the default SFX on the soldier ( + restore its color ) . " @ ^^ " ! The sound effect will be played only if the soldier is active " ) ( get_name " VolumeUp " ) ( get_name " VolumeDown " ) ( get_name " PitchUp " ) ( get_name " PitchDown " ) ( get_name " ToggleMusic " ) ( get_name " RandomSFX " ) ( get_name " DefaultSFX " ) ; let ( _viewport : Orx . Viewport . t ) = Orx . Viewport . create_from_config_exn " Viewport " in let soldier = Orx . Object . create_from_config_exn " Soldier " in let clock = Orx . Clock . get_core ( ) in Orx . Object . add_sound_exn soldier " Music " ; let music = Orx . Object . get_last_added_sound soldier |> Option . get in Orx . Sound . play music ; Orx . Clock . register clock update ; Orx . Event . add_handler Sound event_handler ; State . state := Some { soldier ; music } ; Ok ( )
|
let run ( ) = if Orx . Input . is_active " Quit " then Orx . Status . error else Orx . Status . ok
|
let ( ) = Orx . Main . start ~ config_dir " : examples / tutorial / data " ~ init ~ run " 06_Sound "
|
module State = struct type t = { soldier : Orx . Object . t ; mutable soldier_fx_lock : bool ; box : Orx . Object . t ; mutable selected_fx : string ; } let state : t option ref = ref None let get ( ) = Option . get ! state end
|
let input_event_handler ( _event : Orx . Event . t ) ( _input : Orx . Input_event . t ) ( _payload : Orx . Input_event . payload ) = Ok ( )
|
let fx_event_handler ( event : Orx . Event . t ) ( fx_event : Orx . Fx_event . t ) ( payload : Orx . Fx_event . payload ) = let state = State . get ( ) in let recipient = Orx . Event . get_recipient_object event |> Option . get in ( match fx_event with | Start -> Orx . Log . log " FX <% s >@<% s > has started " ! ( Orx . Fx_event . get_name payload ) ( Orx . Object . get_name recipient ) ; if Orx . Object . equal recipient state . soldier then state . soldier_fx_lock <- true | Stop -> Orx . Log . log " FX <% s >@<% s > has stopped " ! ( Orx . Fx_event . get_name payload ) ( Orx . Object . get_name recipient ) ; if Orx . Object . equal recipient state . soldier then state . soldier_fx_lock <- false | Add | Remove | Loop -> ( ) ) ; Ok ( )
|
let update ( _clock_info : Orx . Clock . Info . t ) = let state = State . get ( ) in let possible_fx_inputs = [ ( " SelectMultiFX " , " MultiFX " ) ; ( " SelectWobble " , " WobbleFX " ) ; ( " SelectCircle " , " CircleFX " ) ; ( " SelectFade " , " FadeFX " ) ; ( " SelectFlash " , " FlashFX " ) ; ( " SelectMove " , " MoveFX " ) ; ( " SelectFlip " , " FlipFX " ) ; ] in let found = List . find_opt ( fun ( input , _fx ) -> Orx . Input . is_active input ) possible_fx_inputs in ( match found with | None -> ( ) | Some ( _input , fx_name ) -> state . selected_fx <- fx_name ) ; if not state . soldier_fx_lock then if Orx . Input . has_been_activated " ApplyFX " then Orx . Object . add_unique_fx_exn state . soldier state . selected_fx
|
let init ( ) = let get_name ( binding : string ) : string = let ( type_ , id , mode ) = Orx . Input . get_binding binding 0 |> Result . get_ok in Orx . Input . get_binding_name type_ id mode in Orx . Log . log ( " . @- To select the FX to apply . " :@ ^^ " . ' % s ' => Wobble . " @ ^^ " . ' % s ' => Circle . " @ ^^ " . ' % s ' => Fade . " @ ^^ " . ' % s ' => Flash . " @ ^^ " . ' % s ' => Move . " @ ^^ " . ' % s ' => Flip . " @ ^^ " . ' % s ' => MultiFX that contains the slots of 4 of the above FXs . " @ ^^ " - ' % s ' will apply the current selected FX on soldier . " @ ^^ " * Only once FX will be applied at a time in this tutorial . " @ ^^ " * However an object can support up to 8 FXs at the same time . " @ ^^ " * Box has a looping rotating FX applied directly from config , \ requiring no code " ) ( get_name " SelectWobble " ) ( get_name " SelectCircle " ) ( get_name " SelectFade " ) ( get_name " SelectFlash " ) ( get_name " SelectMove " ) ( get_name " SelectFlip " ) ( get_name " SelectMultiFX " ) ( get_name " ApplyFX " ) ; let ( _viewport : Orx . Viewport . t ) = Orx . Viewport . create_from_config_exn " Viewport " in let soldier = Orx . Object . create_from_config_exn " Soldier " in let box = Orx . Object . create_from_config_exn " Box " in State . state := Some { soldier ; box ; soldier_fx_lock = false ; selected_fx = " WobbleFX " } ; let clock = Orx . Clock . get_core ( ) in Orx . Clock . register clock update ; Orx . Event . add_handler Fx fx_event_handler ; Orx . Event . add_handler Input input_event_handler ; Ok ( )
|
let run ( ) = if Orx . Input . is_active " Quit " then Orx . Status . error else Orx . Status . ok
|
let ( ) = Orx . Main . start ~ config_dir " : examples / tutorial / data " ~ init ~ run " 07_FX "
|
module State = struct type t = Orx . Camera . t let state : t option ref = ref None let get ( ) = Option . get ! state end
|
let event_handler ( event : Orx . Event . t ) ( physics : Orx . Physics_event . t ) ( _payload : Orx . Physics_event . payload ) = ( match physics with | Contact_remove -> ( ) | Contact_add -> let sender = Orx . Event . get_sender_object event |> Option . get in let recipient = Orx . Event . get_recipient_object event |> Option . get in Orx . Object . add_fx sender " Bump " |> ignore ; Orx . Object . add_fx recipient " Bump " |> ignore ) ; Ok ( )
|
let update ( clock_info : Orx . Clock . Info . t ) = let camera = State . get ( ) in let delta_rotation = if Orx . Input . is_active " RotateLeft " then Some ( 4 . 0 . * Orx . Clock . Info . get_dt clock_info ) else if Orx . Input . is_active " RotateRight " then Some ( - 4 . 0 . * Orx . Clock . Info . get_dt clock_info ) else None in match delta_rotation with | None -> ( ) | Some delta -> let current_rotation = Orx . Camera . get_rotation camera in Orx . Camera . set_rotation camera ( current_rotation . + delta ) ; let gravity = Orx . Vector . rotate_2d ( Orx . Physics . get_gravity ( ) ) delta in Orx . Physics . set_gravity gravity
|
let init ( ) = let ( type_ , id , mode ) = Orx . Input . get_binding " RotateLeft " 0 |> Result . get_ok in let input_rotate_left = Orx . Input . get_binding_name type_ id mode in let ( type_ , id , mode ) = Orx . Input . get_binding " RotateRight " 0 |> Result . get_ok in let input_rotate_right = Orx . Input . get_binding_name type_ id mode in Orx . Log . log ( " . @- ' % s ' & ' % s ' will rotate the camera . " @ ^^ " * Gravity will follow the camera . " @ ^^ " * a bump visual FX is played on objects that collide " ) input_rotate_left input_rotate_right ; let viewport = Orx . Viewport . create_from_config_exn " Viewport " in let camera = Orx . Viewport . get_camera viewport |> Option . get in let clock = Orx . Clock . get_core ( ) in Orx . Clock . register clock update ; State . state := Some camera ; Orx . Event . add_handler Physics event_handler ; let ( _scene : Orx . Object . t ) = Orx . Object . create_from_config_exn " Scene " in Ok ( )
|
let run ( ) = if Orx . Input . is_active " Quit " then Orx . Status . error else Orx . Status . ok
|
let ( ) = Orx . Main . start ~ config_dir " : examples / tutorial / data " ~ init ~ run " 08_Physics "
|
module State = struct type t = Orx . Camera . t let state : t option ref = ref None let get ( ) = Option . get ! state end
|
let update ( clock_info : Orx . Clock . Info . t ) = let camera = State . get ( ) in Orx . Config . push_section " Tutorial " ; let scroll_speed = Orx . Config . get_vector " ScrollSpeed " in Orx . Config . pop_section ( ) ; let scroll_speed = Orx . Vector . mulf scroll_speed ( Orx . Clock . Info . get_dt clock_info ) in let move_x = if Orx . Input . is_active " CameraRight " then Orx . Vector . get_x scroll_speed else if Orx . Input . is_active " CameraLeft " then . - Orx . Vector . get_x scroll_speed else 0 . 0 in let move_y = if Orx . Input . is_active " CameraUp " then . - Orx . Vector . get_y scroll_speed else if Orx . Input . is_active " CameraDown " then Orx . Vector . get_y scroll_speed else 0 . 0 in let move_z = if Orx . Input . is_active " CameraZoomIn " then Orx . Vector . get_z scroll_speed else if Orx . Input . is_active " CameraZoomOut " then . - Orx . Vector . get_z scroll_speed else 0 . 0 in let move = Orx . Vector . make ~ x : move_x ~ y : move_y ~ z : move_z in let camera_position = Orx . Camera . get_position camera in Orx . Camera . set_position camera ( Orx . Vector . add camera_position move )
|
let init ( ) = let get_name ( binding : string ) : string = let ( type_ , id , mode ) = Orx . Input . get_binding binding 0 |> Result . get_ok in Orx . Input . get_binding_name type_ id mode in Orx . Log . log ( " . @- ' % s ' , ' % s ' , ' % s ' & ' % s ' will move the camera . " @ ^^ " - ' % s ' & ' % s ' will zoom in / out . " @ ^^ " * The scrolling and auto - scaling of objects is data - driven , no code \ required . " @ ^^ " * The sky background will follow the camera ( parent / child frame \ relation ) " ) ( get_name " CameraUp " ) ( get_name " CameraLeft " ) ( get_name " CameraDown " ) ( get_name " CameraRight " ) ( get_name " CameraZoomIn " ) ( get_name " CameraZoomOut " ) ; let viewport = Orx . Viewport . create_from_config_exn " Viewport " in let camera = Orx . Viewport . get_camera viewport |> Option . get in State . state := Some camera ; let clock = Orx . Clock . get_core ( ) in Orx . Clock . register clock update ; let _scene : Orx . Object . t = Orx . Object . create_from_config_exn " Scene " in Ok ( )
|
let run ( ) = if Orx . Input . is_active " Quit " then Orx . Status . error else Orx . Status . ok
|
let ( ) = Orx . Main . start ~ config_dir " : examples / tutorial / data " ~ init ~ run " 09_Scrolling "
|
let cautious f ppf arg = try f ppf arg with Ellipsis -> fprintf ppf " . . . "
|
let rec print_ident ppf = function Oide_ident s -> pp_print_string ppf s | Oide_dot ( id , s ) s -> print_ident ppf id ; pp_print_char ppf ' . ' ; pp_print_string ppf s | Oide_apply ( id1 , id2 ) id2 -> fprintf ppf " % a ( a % a ) a " print_ident id1 print_ident id2 # else
|
let rec print_ident ppf = function Oide_ident s -> ! Oprint . out_ident ppf s | Oide_dot ( id , s ) s -> print_ident ppf id ; pp_print_char ppf ' . ' ; ! Oprint . out_ident ppf s | Oide_apply ( id1 , id2 ) id2 -> fprintf ppf " % a ( a % a ) a " print_ident id1 print_ident id2 # end
|
let parenthesized_ident name = ( List . mem name [ " or " ; " mod " ; " land " ; " lor " ; " lxor " ; " lsl " ; " lsr " ; " asr ] ) " || ( match name [ . 0 ] 0 with ' a ' . . ' z ' | ' A ' . . ' Z ' | ' \ 223 ' . . ' \ 246 ' | ' \ 248 ' . . ' \ 255 ' | ' _ ' -> false | _ -> true ) true
|
let value_ident ppf name = if parenthesized_ident name then fprintf ppf ( " % s ) " ( Reason_syntax_util . ml_to_reason_swap name ) name else pp_print_string ppf name
|
let valid_float_lexeme s = let l = String . length s in let rec loop i = if i >= l then s ^ " . " else match s [ . i ] i with | ' 0 ' . . ' 9 ' | ' - ' -> loop ( i + 1 ) 1 | _ -> s in loop 0
|
let float_repres f = match classify_float f with FP_nan -> " nan " | FP_infinite -> if f < 0 . 0 then " neg_infinity " else " infinity " | _ -> let float_val = let s1 = Printf . sprintf " . % 12g " f in if f = float_of_string s1 then s1 else let s2 = Printf . sprintf " . % 15g " f in if f = float_of_string s2 then s2 else Printf . sprintf " . % 18g " f in valid_float_lexeme float_val
|
let parenthesize_if_neg ppf fmt v isneg = if isneg then pp_print_char ppf ' ( ' ' ; fprintf ppf fmt v ; if isneg then pp_print_char ppf ' ) ' '
|
let print_out_value ppf tree = let rec print_tree_1 ppf = function | Oval_constr ( name , [ Oval_constr ( ( Oide_ident ( ) ) " " , [ ] ) ] ) -> fprintf ppf [ " @< 1 >% a ( a ) a ] " @ print_ident name | Oval_constr ( name , [ param ] param ) param -> fprintf ppf [ " @< 1 >% a ( a % a ) a ] " @ print_ident name print_constr_param param | Oval_constr ( name , ( _ :: _ as params ) params ) params -> fprintf ppf [ " @< 1 >% a ( a % a ) a ] " @ print_ident name ( print_tree_list print_tree_1 ) " , " params | Oval_variant ( name , Some ( Oval_constr ( ( Oide_ident ( ) ) " " , [ ] ) ) ) -> fprintf ppf [ " @< 2 ` >% s ( s ) s ] " @ name | Oval_variant ( name , Some param ) param -> fprintf ppf [ " @< 2 ` >% s ( s % a ) a ] " @ name print_constr_param param | tree -> print_simple_tree ppf tree and print_constr_param ppf = function | Oval_int i -> parenthesize_if_neg ppf " % i " i ( i < 0 ) 0 | Oval_int32 i -> parenthesize_if_neg ppf " % lil " i ( i < 0l ) 0l | Oval_int64 i -> parenthesize_if_neg ppf " % LiL " i ( i < 0L ) 0L | Oval_nativeint i -> parenthesize_if_neg ppf " % nin " i ( i < 0n ) 0n | Oval_float f -> parenthesize_if_neg ppf " % s " ( float_repres f ) f ( f < 0 . 0 ) 0 | tree -> print_simple_tree ppf tree and print_simple_tree ppf = function Oval_int i -> fprintf ppf " % i " i | Oval_int32 i -> fprintf ppf " % lil " i | Oval_int64 i -> fprintf ppf " % LiL " i | Oval_nativeint i -> fprintf ppf " % nin " i | Oval_float f -> pp_print_string ppf ( float_repres f ) f | Oval_char c -> fprintf ppf " % C " c | Oval_string s -> begin try fprintf ppf " " \% s " " \ ( Reason_syntax_util . escape_string s ) s with Invalid_argument " String . create " -> fprintf ppf " < huge string " > end | Oval_list tl -> fprintf ppf [ " @< 1 [ >% a ] a ] " @ ( print_tree_list print_tree_1 ) " , " tl | Oval_array tl -> fprintf ppf [ " @< 2 [ >|% a ] ] " |@ ( print_tree_list print_tree_1 ) " , " tl | Oval_constr ( name , [ ] ) -> print_ident ppf name | Oval_variant ( name , None ) None -> fprintf ppf " ` % s " name | Oval_stuff s -> pp_print_string ppf s | Oval_record fel -> fprintf ppf [ " @< 1 { >% a } a ] " @ ( cautious ( print_fields true ) true ) true fel | Oval_ellipsis -> raise Ellipsis | Oval_printer f -> f ppf | Oval_tuple tree_list -> fprintf ppf [ " @< 1 ( >% a ) a ] " @ ( print_tree_list print_tree_1 ) " , " tree_list | tree -> fprintf ppf [ " @< 1 ( >% a ) a ] " @ ( cautious print_tree_1 ) print_tree_1 tree and print_fields first ppf = function [ ] -> ( ) | ( name , tree ) tree :: fields -> if not first then fprintf ppf " , @ " ; fprintf ppf [ " @< 1 >% a :@ % a ] " @ print_ident name ( cautious print_tree_1 ) print_tree_1 tree ; print_fields false ppf fields and print_tree_list print_item sep ppf tree_list = let rec print_list first ppf = function [ ] -> ( ) | tree :: tree_list -> if not first then fprintf ppf " % s @ " sep ; print_item ppf tree ; print_list false ppf tree_list in cautious ( print_list true ) true ppf tree_list in cautious print_tree_1 ppf tree
|
let rec print_list_init pr sep ppf = function [ ] -> ( ) | a :: l -> sep ppf ; pr ppf a ; print_list_init pr sep ppf l
|
let rec print_list pr sep ppf = function [ ] -> ( ) | [ a ] a -> pr ppf a | a :: l -> pr ppf a ; sep ppf ; print_list pr sep ppf l
|
let pr_present = print_list ( fun ppf s -> fprintf ppf " ` % s " s ) s ( fun ppf -> fprintf ppf " @ ) "
|
let pr_vars = print_list ( fun ppf s -> fprintf ppf " ' % s " s ) s ( fun ppf -> fprintf ppf " @ ) "
|
type label = | Nonlabeled | Labeled of string | Optional of string
|
let get_label lbl = if lbl = " " then Nonlabeled else if String . get lbl 0 = ' ? ' then Optional ( String . sub lbl 1 @@ String . length lbl - 1 ) 1 else Labeled lbl
|
let rec print_out_type ppf = function | Otyp_alias ( ty , s ) s -> fprintf ppf [ " @% a @ as ' % s ] " @ print_out_type ty s | Otyp_poly ( sl , ty ) ty -> fprintf ppf [ " @< hov 2 >% a . @ % a ] " @ pr_vars sl print_out_type ty | ty -> print_out_type_1 ~ uncurried : false ppf ty let suffix = match get_label lab with | Nonlabeled -> " " | Labeled lab -> pp_print_string ppf " " ; ~ pp_print_string ppf lab ; pp_print_string ppf " : " ; " " | Optional lab -> pp_print_string ppf " " ; ~ pp_print_string ppf lab ; pp_print_string ppf " : " ; " " =? in print_out_type_2 ppf typ ; pp_print_string ppf suffix ; function Otyp_arrow ( lab , ty1 , ty2 ) ty2 -> let rec collect_args args typ = match typ with | Otyp_arrow ( lab , ty1 , ty2 ) ty2 -> collect_args ( args @ [ ( lab , ty1 ) ty1 ] ty1 ) ty1 ty2 | _ -> ( args , typ ) typ in pp_open_box ppf 0 ; let ( args , result ) result = collect_args [ ( lab , ty1 ) ty1 ] ty1 ty2 in let should_wrap_with_parens = match ( uncurried , args ) args with | ( false , [ ( _ , Otyp_tuple _ ) _ ] _ ) _ -> true | ( false , [ ( " " , typ ) typ ] typ ) typ -> false | ( _ , args ) args -> true in if should_wrap_with_parens then pp_print_string ppf ( " " ; if uncurried then fprintf ppf " . @ " ; print_list print_arg ( fun ppf -> fprintf ppf " , @ ) " ppf args ; if should_wrap_with_parens then pp_print_string ppf ) " " ; pp_print_string ppf " " ; => pp_print_space ppf ( ) ; print_out_type_1 ~ uncurried ppf result ; pp_close_box ppf ( ) | ty -> print_out_type_2 ppf ty function Otyp_tuple tyl -> fprintf ppf [ " @< 0 ( >% a ) a ] " @ ( print_typlist print_simple_out_type ) " , " tyl | ty -> print_simple_out_type ppf ty function Otyp_class ( ng , id , tyl ) tyl -> fprintf ppf [ " @% s #% a % a ] " @ ( if ng then " _ " else ) " " print_ident id print_typargs tyl | Otyp_constr ( ( Oide_dot ( ( Oide_dot ( ( Oide_ident " Js ) " , " Internal ) " | Oide_ident " Js_internal ) " , ( " fn " | " meth " as name ) name ) as id ) id , ( [ Otyp_variant ( Otyp_variant_ , Ovar_fields [ variant , _ , tys ] tys , _ , _ ) _ ; result ] result as tyl ) tyl ) -> let make tys result = if tys = [ ] then Otyp_arrow ( " " , Otyp_constr ( Oide_ident " unit " , [ ] ) , result ) result else match tys with | [ Otyp_tuple tys as single ] single -> if variant = " Arity_1 " then Otyp_arrow ( " " , single , result ) result else List . fold_right ( fun x acc -> Otyp_arrow ( " " , x , acc ) acc ) acc tys result | [ single ] single -> Otyp_arrow ( " " , single , result ) result | _ -> raise_notrace Not_found in begin match ( make tys result ) result with | exception _ -> begin pp_open_box ppf 0 ; print_typargs ppf tyl ; print_ident ppf id ; pp_close_box ppf ( ) end | res -> begin match name with | " fn " -> print_out_type_1 ~ uncurried : true ppf res | " meth " -> fprintf ppf [ " @< 0 ( >% a ) a @ [ @ bs . meth ] meth ] " @ ( print_out_type_1 ~ uncurried : false ) false res | _ -> assert false end end | Otyp_constr ( ( Oide_dot ( ( Oide_dot ( ( Oide_ident " Js ) " , " Internal ) " | Oide_ident " Js_internal ) " , " meth_callback " ) as id ) , ( [ Otyp_variant ( Otyp_variant_ , Ovar_fields [ variant , _ , tys ] tys , _ , _ ) _ ; result ] result as tyl ) tyl ) -> let make tys result = match tys with | [ Otyp_tuple tys as single ] single -> if variant = " Arity_1 " then Otyp_arrow ( " " , single , result ) result else List . fold_right ( fun x acc -> Otyp_arrow ( Otyp_arrow " " , x , acc ) acc ) tys result | [ single ] single -> Otyp_arrow ( " " , single , result ) result | _ -> raise_notrace Not_found in begin match ( make tys result ) result with | exception _ -> begin pp_open_box ppf 0 ; print_typargs ppf tyl ; print_ident ppf id ; pp_close_box ppf ( ) end | res -> fprintf ppf [ " @< 0 ( >% a ) a @ [ @ bs . this ] this ] " @ ( print_out_type_1 ~ uncurried : false ) false res end | Otyp_constr ( ( Oide_dot ( ( Oide_ident " Js ) " , " t ) ) " , [ Otyp_object ( fields , rest ) rest ] rest ) -> let dot = match rest with Some non_gen -> ( if non_gen then " _ " else ) " " ^ " . . " | None -> " . " in fprintf ppf [ " @< 2 { >% s % a } a ] " @ dot ( print_object_fields ~ quote_fields : true ) true fields | Otyp_constr ( id , tyl ) tyl -> pp_open_box ppf 0 ; print_ident ppf id ; begin match tyl with | [ ] -> ( ) | _ -> print_typargs ppf tyl ; end ; pp_close_box ppf ( ) | Otyp_object ( fields , rest ) rest -> let dot = match rest with Some non_gen -> ( if non_gen then " _ " else ) " " ^ " . . " | None -> " . " in fprintf ppf [ " @< 2 { >% s % a } a ] " @ dot ( print_object_fields ~ quote_fields : false ) false fields | Otyp_stuff s -> pp_print_string ppf s | Otyp_var ( ng , s ) s -> fprintf ppf " ' % s % s " ( if ng then " _ " else ) " " s | Otyp_variant ( non_gen , row_fields , closed , tags ) tags -> let print_present ppf = function None | Some [ ] -> ( ) | Some l -> fprintf ppf " ; @< 1 - 2 >> [ @< hov >% a ] " @ pr_present l in let print_fields ppf = function Ovar_fields fields -> print_list print_row_field ( fun ppf -> fprintf ppf " ; @< 1 - 2 >| ) " ppf fields | Ovar_name ( id , tyl ) tyl -> fprintf ppf [ " @% a % a ] " @ print_typargs tyl print_ident id in fprintf ppf " % s [ s % s [ @< hv [ >@< hv >% a ] @% a ] ] " @ ( if non_gen then " _ " else ) " " ( if closed then if tags = None then " " else " < " else if tags = None then " > " else " ? ) " print_fields row_fields print_present tags | Otyp_alias _ | Otyp_poly _ as ty -> fprintf ppf [ " @< 1 ( >% a ) a ] " @ print_out_type ty ; | Otyp_tuple _ | Otyp_arrow _ as ty -> fprintf ppf [ " @< 1 >% a ] " @ print_out_type ty ; | Otyp_abstract | Otyp_open | Otyp_sum _ | Otyp_record _ | Otyp_manifest ( _ , _ ) _ -> ( ) | Otyp_module ( p , n , tyl ) tyl -> fprintf ppf [ " @< 1 ( > module % s " p ; let first = ref true in List . iter2 ( fun s t -> let sep = if ! first then ( first := false ; " with ) " else " and " in fprintf ppf " % s type % s = % a " sep s print_out_type t ) n tyl ; fprintf ppf ) ] " " @ | Otyp_attribute ( t , attr ) attr -> fprintf ppf [ " @< 1 ( >% a [ @@% s ] s ) s ] " @ print_out_type t attr . oattr_name # end function [ ] -> ( ) | [ field , typ ] typ -> let field = ( if quote_fields then " " " \ ^ field ^ " " " \ else field ) field in fprintf ppf " % s : % a " field print_out_type typ ; ( print_object_fields ~ quote_fields ) quote_fields ppf [ ] | ( field , typ ) typ :: rest -> let field = ( if quote_fields then " " " \ ^ field ^ " " " \ else field ) field in fprintf ppf " % s : % a , @ % a " field print_out_type typ ( print_object_fields ~ quote_fields ) quote_fields rest let pr_of ppf = if opt_amp then fprintf ppf " &@ " else fprintf ppf " " in let parens = match tyl with | [ ( Otyp_tuple _ ) _ ] -> false | [ _ ] -> true | _ -> false in fprintf ppf [ " @< hv 2 ` >% s % t % s % a % s ] " @ l pr_of ( if parens then ( " " else ) " " ( print_typlist print_out_type " ) " & tyl ( if parens then ) " " else ) " " function [ ] -> ( ) | [ ty ] ty -> print_elem ppf ty | ty :: tyl -> print_elem ppf ty ; pp_print_string ppf sep ; pp_print_space ppf ( ) ; print_typlist print_elem sep ppf tyl function | ( Otyp_constr ( id , _ :: _ ) _ ) _ as ty -> print_out_type ppf ty | ty -> print_simple_out_type ppf ty function [ ] -> ( ) | [ ty1 ] ty1 -> pp_print_string ppf ( " " ; print_out_wrap_type ppf ty1 ; pp_print_string ppf ) " " | tyl -> pp_print_string ppf ( " " ; pp_open_box ppf 1 ; print_typlist print_out_wrap_type " , " ppf tyl ; pp_close_box ppf ( ) ; pp_print_string ppf ) " "
|
let out_type = ref print_out_type
|
let type_parameter ppf ( ty , ( co , cn ) cn ) cn = fprintf ppf " % s % s " ( if not cn then " " + else if not co then " " - else ) " " ( if ty = " _ " then ty else " ' " ^ ty ) ty
|
let print_out_class_params ppf = function [ ] -> ( ) | tyl -> fprintf ppf ( [ " @< 1 >% a ] ) @@ " ( print_list type_parameter ( fun ppf -> fprintf ppf " , @ ) ) " tyl
|
let rec print_out_class_type ppf = function Octy_constr ( id , tyl ) tyl -> let pr_tyl ppf = function [ ] -> ( ) | tyl -> fprintf ppf [ " @< 1 > % a ] " @ ( print_typlist print_out_wrap_type ) " " tyl in fprintf ppf [ " @% a % a ] " @ print_ident id pr_tyl tyl | Octy_arrow ( lab , argument_type , return_class_type ) return_class_type -> let rec print_class_type_arguments_that_might_be_arrow ppf = function | Otyp_arrow ( " " , typ1 , typ2 ) typ2 -> fprintf ppf [ " @% a , @ % a ] " @ print_out_type typ1 print_class_type_arguments_that_might_be_arrow typ2 | Otyp_arrow ( actual_label , typ1 , typ2 ) typ2 -> fprintf ppf [ " @~% s : % a , @ % a ] " @ lab print_out_type typ1 print_class_type_arguments_that_might_be_arrow typ2 | argument_not_arrow -> fprintf ppf " % a " print_out_type argument_not_arrow in fprintf ppf [ ( " @% a ) a =>@ % a ] " @ print_class_type_arguments_that_might_be_arrow argument_type print_out_class_type return_class_type | Octy_signature ( self_ty , csil ) csil -> let pr_param ppf = function Some ty -> fprintf ppf " @ [ ( @% a ) a ] " @ print_out_type ty | None -> ( ) in fprintf ppf [ " @< hv 2 [ >@< 2 { >% a ] @@ % a ; @< 1 - 2 } ] " >@ pr_param self_ty ( print_list print_out_class_sig_item ( fun ppf -> fprintf ppf " ; @ ) ) " csil function Ocsg_constraint ( ty1 , ty2 ) ty2 -> fprintf ppf [ " @< 2 > as % a =@ % a ] " @ print_out_type ty1 print_out_type ty2 | Ocsg_method ( name , priv , virt , ty ) ty -> fprintf ppf [ " @< 2 >% s % s % s :@ % a ] " @ ( if priv then " pri " else " pub ) " ( if virt then " virtual " else ) " " name print_out_type ty | Ocsg_value ( name , mut , vr , ty ) ty -> fprintf ppf [ " @< 2 > val % s % s % s :@ % a ] " @ ( if mut then " mutable " else ) " " ( if vr then " virtual " else ) " " name print_out_type ty
|
let is_rec_next = function | Osig_class ( _ , _ , _ , _ , Orec_next ) Orec_next :: _ | Osig_class_type ( _ , _ , _ , _ , Orec_next ) Orec_next :: _ | Osig_module ( _ , _ , Orec_next ) Orec_next :: _ | Osig_type ( _ , Orec_next ) Orec_next :: _ -> true | _ -> false
|
let rec print_out_functor ppf = function Omty_functor ( _ , None , mty_res ) mty_res -> fprintf ppf ( ) " % a " print_out_functor mty_res | Omty_functor ( name , Some mty_arg , mty_res ) mty_res -> fprintf ppf ( " % s : % a ) a => % a " name print_out_module_type mty_arg print_out_functor mty_res | m -> fprintf ppf " % a " print_out_module_type m function Omty_abstract -> ( ) | Omty_functor _ as t -> fprintf ppf [ " @< 2 >% a ] " @ print_out_functor t | Omty_ident id -> fprintf ppf " % a " print_ident id | Omty_signature sg -> fprintf ppf [ " @< hv 2 { >@ % a ; @< 1 - 2 } ] " >@ print_out_signature sg | Omty_alias id -> fprintf ppf ( " module % a ) a " print_ident id function [ ] -> ( ) | [ item ] item -> fprintf ppf " % a ; " print_out_sig_item item | Osig_typext ( Osig_typextext , Oext_first ) Oext_first :: items -> let rec gather_extensions acc items = match items with Osig_typext ( Osig_typextext , Oext_next ) Oext_next :: items -> gather_extensions ( ( ext . oext_name , ext . oext_args , ext . oext_ret_type ) oext_ret_type :: acc ) acc items | _ -> ( List . rev acc , items ) items in let exts , items = gather_extensions [ ( ext . oext_name , ext . oext_args , ext . oext_ret_type ) oext_ret_type ] oext_ret_type items in let te = { otyext_name = ext . oext_type_name ; otyext_params = ext . oext_type_params ; otyext_constructors = exts ; otyext_private = ext . oext_private } in let sep = if is_rec_next items then " " else " ; " in fprintf ppf " % a % s @ % a " print_out_type_extension te sep print_out_signature items | item :: items -> let sep = if is_rec_next items then " " else " ; " in fprintf ppf " % a % s @ % a " print_out_sig_item item sep print_out_signature items function Osig_class ( vir_flag , name , params , clt , rs ) rs -> fprintf ppf [ " @< 2 >% s % s @ % s % a , @:@ % a ] " @ ( if rs = Orec_next then " and " else " class ) " ( if vir_flag then " virtual " else ) " " name print_out_class_params params print_out_class_type clt | Osig_class_type ( vir_flag , name , params , clt , rs ) rs -> fprintf ppf [ " @< 2 >% s % s @ % s % a , @=@ % a ] " @ ( if rs = Orec_next then " and " else " class type ) " ( if vir_flag then " virtual " else ) " " name print_out_class_params params print_out_class_type clt | Osig_typext ( ext , Oext_exception ) Oext_exception -> fprintf ppf [ " @< 2 > exception % a ] " @ print_out_constr ( ext . oext_name , ext . oext_args , ext . oext_ret_type ) oext_ret_type | Osig_typext ( ext , es ) es -> print_out_extension_constructor ppf ext | Osig_modtype ( name , Omty_abstract ) Omty_abstract -> fprintf ppf [ " @< 2 > module type % s ] " @ name | Osig_modtype ( name , mty ) mty -> fprintf ppf [ " @< 2 > module type % s =@ % a ] " @ name print_out_module_type mty | Osig_module ( name , Omty_alias id , _ ) _ -> fprintf ppf [ " @< 2 > module % s =@ % a ] " @ name print_ident id | Osig_module ( name , mty , rs ) rs -> fprintf ppf [ " @< 2 >% s % s :@ % a ] " @ ( match rs with Orec_not -> " module " | Orec_first -> " module rec " | Orec_next -> " and ) " name print_out_module_type mty | Osig_type ( Osig_typetd , rs ) rs -> print_out_type_decl ( match rs with | Orec_not -> " type nonrec " | Orec_first -> " type " | Orec_next -> " and ) " ppf td | Osig_ellipsis -> fprintf ppf " . . . " | Osig_value { oval_name ; oval_type ; oval_prims ; oval_attributes } oval_attributes -> let printAttributes ppf = List . iter ( fun a -> fprintf ppf [ " @@% s ] s " a . oattr_name ) oattr_name in # else | Osig_value ( Osig_valueoval_name , oval_type , oval_prims ) oval_prims -> let printAttributes ppf attrs = ( ) in let oval_attributes = [ ] in # end let keyword = if oval_prims = [ ] then " let " else " external " in let ( hackyBucklescriptExternalAnnotation , rhsValues ) rhsValues = List . partition ( fun item -> String . length item >= 3 && item [ . 0 ] 0 = ' B ' && item [ . 1 ] 1 = ' S ' && item [ . 2 ] 2 = ' : ' ) oval_prims in let print_right_hand_side ppf = function [ ] -> ( ) | s :: sl -> fprintf ppf " @ = " \% s " " \ s ; List . iter ( fun s -> fprintf ppf " @ " \% s " " \ s ) s sl in fprintf ppf [ " @< 2 >% a % a % s % a :@ % a % a ] " @ ( fun ppf -> List . iter ( fun _ -> fprintf ppf [ " @@ bs ] . . . @ ) ) " hackyBucklescriptExternalAnnotation printAttributes oval_attributes keyword value_ident oval_name ! out_type oval_type print_right_hand_side rhsValues let print_constraints ppf = List . iter ( fun ( ty1 , ty2 ) ty2 -> fprintf ppf " @ [ @< 2 > constraint % a =@ % a ] " @ print_out_type ty1 print_out_type ty2 ) ty2 td . otype_cstrs in let type_defined ppf = match td . otype_params with [ ] -> pp_print_string ppf td . otype_name | [ param ] param -> fprintf ppf [ " @% s ( s % a ) a ] " @ td . otype_name type_parameter param | _ -> fprintf ppf [ " @% s ( s [ @% a ] ) ] " @@ td . otype_name ( print_list type_parameter ( fun ppf -> fprintf ppf " , @ ) ) " td . otype_params in let print_manifest ppf = function Otyp_manifest ( ty , _ ) _ -> fprintf ppf " =@ % a " print_out_type ty | _ -> ( ) in let print_name_params ppf = fprintf ppf " % s % t % a " kwd type_defined print_manifest td . otype_type in let ty = match td . otype_type with Otyp_manifest ( _ , ty ) ty -> ty | _ -> td . otype_type in let print_private ppf = function Asttypes . Private -> fprintf ppf " pri " | Asttypes . Public -> ( ) in let print_out_tkind ppf = function | Otyp_abstract -> ( ) | Otyp_record lbls -> fprintf ppf " =% a { % a ; @< 1 - 2 } " > print_private td . otype_private ( print_list_init print_out_label ( fun ppf -> fprintf ppf " @ ) ) " lbls | Otyp_sum constrs -> fprintf ppf " =% a ; @< 1 2 >% a " print_private td . otype_private ( print_list print_out_constr ( fun ppf -> fprintf ppf " @ | ) ) " constrs | Otyp_open -> fprintf ppf " = . . " | ty -> fprintf ppf " =% a ; @< 1 2 >% a " print_private td . otype_private print_out_type ty in fprintf ppf [ " @< 2 [ >@< hv 2 >% t % a ] @% t ] " @ print_name_params print_out_tkind ty print_constraints match ret_type_opt with | None -> begin match tyl with | [ ] -> pp_print_string ppf name | _ -> fprintf ppf [ " @< 2 >% s ( s % a ) a ] " @ name ( print_typlist print_simple_out_type ) " , " tyl end | Some ret_type -> begin match tyl with | [ ] -> fprintf ppf [ " @< 2 >% s :@ % a ] " @ name print_simple_out_type ret_type | _ -> fprintf ppf [ " @< 2 >% s ( s % a ) a :% a ] " @ name ( print_typlist print_simple_out_type ) " , " tyl print_simple_out_type ret_type end fprintf ppf [ " @< 2 >% s % s :@ % a ] , " @ ( if mut then " mutable " else ) " " name print_out_type arg let print_extended_type ppf = let print_type_parameter ppf ty = fprintf ppf " % s " ( if ty = " _ " then ty else " ' " ^ ty ) ty in match ext . oext_type_params with [ ] -> fprintf ppf " % s " ext . oext_type_name | [ ty_param ] ty_param -> fprintf ppf [ " @% a @ % s ] " @ print_type_parameter ty_param ext . oext_type_name | _ -> fprintf ppf [ ( [ " @@% a ) a ] @@ % s ] " @ ( print_list print_type_parameter ( fun ppf -> fprintf ppf " , @ ) ) " ext . oext_type_params ext . oext_type_name in fprintf ppf [ " @< hv 2 > type % t +=% s ; @< 1 2 >% a ] " @ print_extended_type ( if ext . oext_private = Asttypes . Private then " pri " else ) " " print_out_constr ( ext . oext_name , ext . oext_args , ext . oext_ret_type ) oext_ret_type let print_extended_type ppf = let print_type_parameter ppf ty = fprintf ppf " % s " ( if ty = " _ " then ty else " ' " ^ ty ) ty in match te . otyext_params with [ ] -> fprintf ppf " % s " te . otyext_name | [ param ] param -> fprintf ppf [ " @% a @ % s ] " @ print_type_parameter param te . otyext_name | _ -> fprintf ppf [ ( [ " @@% a ) a ] @@ % s ] " @ ( print_list print_type_parameter ( fun ppf -> fprintf ppf " , @ ) ) " te . otyext_params te . otyext_name in fprintf ppf [ " @< hv 2 > type % t +=% s ; @< 1 2 >% a ] " @ print_extended_type ( if te . otyext_private = Asttypes . Private then " pri " else ) " " ( print_list print_out_constr ( fun ppf -> fprintf ppf " @ | ) ) " te . otyext_constructors
|
let print_out_exception ppf exn outv = match exn with Sys . Break -> fprintf ppf " Interrupted . . " @ | Out_of_memory -> fprintf ppf " Out of memory during evaluation . . " @ | Stack_overflow -> fprintf ppf " Stack overflow during evaluation ( looping recursion ) . . " ?@ | _ -> fprintf ppf [ " @ Exception :@ % a ] . . " @@ print_out_value outv
|
let rec print_items ppf = function [ ] -> ( ) | ( Osig_typext ( Osig_typextext , Oext_first ) Oext_first , None ) None :: items -> let rec gather_extensions acc items = match items with ( Osig_typext ( Osig_typextext , Oext_next ) Oext_next , None ) None :: items -> gather_extensions ( ( ext . oext_name , ext . oext_args , ext . oext_ret_type ) oext_ret_type :: acc ) acc items | _ -> ( List . rev acc , items ) items in let exts , items = gather_extensions [ ( ext . oext_name , ext . oext_args , ext . oext_ret_type ) oext_ret_type ] oext_ret_type items in let te = { otyext_name = ext . oext_type_name ; otyext_params = ext . oext_type_params ; otyext_constructors = exts ; otyext_private = ext . oext_private } in fprintf ppf [ " @% a ] " @ print_out_type_extension te ; if items <> [ ] then fprintf ppf " @ % a " print_items items | ( tree , valopt ) valopt :: items -> begin match valopt with Some v -> fprintf ppf [ " @< 2 >% a =@ % a ] ; " @ print_out_sig_item tree print_out_value v | None -> fprintf ppf [ " @% a ] ; " @ print_out_sig_item tree end ; if items <> [ ] then fprintf ppf " @ % a " print_items items
|
let print_out_phrase ppf = function Ophr_eval ( outv , ty ) ty -> fprintf ppf [ " @- : % a @ =@ % a ] . " @@ print_out_type ty print_out_value outv | Ophr_signature [ ] -> ( ) | Ophr_signature items -> fprintf ppf [ " @< v >% a ] . " @@ print_items items | Ophr_exception ( exn , outv ) outv -> print_out_exception ppf exn outv
|
module Fq = Make_fp ( N ) ( struct let order = N . of_string " 28948022309329048855892746252171976963322203655954433126947083963168578338817 " end )
|
module Fp = Make_fp ( N ) ( struct let order = N . of_string " 28948022309329048855892746252171976963322203655955319056773317069363642105857 " end )
|
module Dee = struct module Params = struct let a = Fq . of_string " 0 " let b = Fq . of_string " 5 " end include Elliptic_curve . Make ( N ) ( Fq ) ( Params ) let one = of_affine ( Fq . of_string " 1 " , Fq . of_string " 14240188643175251183985684255458419213835105645119662786317263805424119994471 " ) end
|
module Dum = struct module Params = struct let a = Fp . of_string " 0 " let b = Fp . of_string " 5 " end include Elliptic_curve . Make ( N ) ( Fp ) ( Params ) let one = of_affine ( Fp . of_string " 1 " , Fp . of_string " 385654983219305453067387443941241858913435815837190103938162313975739315615 " ) end
|
let ( ) |> x f = f x
|
let identity x = x
|
module Make ( A : sig type ' a _r val ( ) >>= : ' a _r -> ( ' a -> ' b _r ) -> ' b _r val return : ' a -> ' a _r val account_sid : string val send : Http_client . http_call -> http_call_result _r module Request = Twilio_rest_request . Make ( struct type ' a _r = ' a A . _r let return = A . return let account_sid = A . account_sid end ) let ( ) >>= = A . ( ) >>= let add_auth http_call = http_call let send_delete url = failwith " TODO " let send_get url = new Http_client . get url |> add_auth |> A . send let send_post ( url , args ) = new Http_client . post url args |> add_auth |> A . send let return of_string s = A . return ( match s with | ` Success s -> ( try ` Success ( of_string s ) with e -> print_endline ( Printexc . to_string e ) ; print_endline ( Printexc . get_backtrace ( ) ) ; ` Parse_error ( e , s ) ) | ` Unserved -> ` Unserved | ` Http_protocol_error e -> ` Http_protocol_error e | ` Redirection -> ` Redirection | ` Client_error -> ` Client_error | ` Server_error -> ` Server_error | ` Timeout -> ` Timeout ) module Available_phone_numbers = struct open Request . Available_phone_numbers module Local = struct let get ? area_code ? contains ? in_region ? in_postal_code iso_code = Local . get ? area_code ? contains ? in_region ? in_postal_code iso_code >>= send_get >>= return Available_phone_numbers_local_j . response_of_string end module Toll_free = struct let get ? contains iso_code = Toll_free . get ? contains iso_code >>= send_get >>= return Available_phone_numbers_tollfree_j . response_of_string end end module Outgoing_caller_ids = struct open Request . Outgoing_caller_ids open Outgoing_caller_ids_j module Sid = struct let delete sid = Sid . delete sid >>= send_delete >>= return identity let get sid = Sid . get sid >>= send_get >>= return t_of_string let post friendly_name sid = Sid . post friendly_name sid >>= send_post >>= return post_result_of_string end let get ? phone_number ? friendly_name ( ) = get ? phone_number ? friendly_name ( ) >>= send_get >>= return page_of_string let post ? friendly_name ? call_delay ? extension phone_number = post ? friendly_name ? call_delay ? extension phone_number >>= send_post >>= return post_result_of_string end module Incoming_phone_numbers = struct open Request . Incoming_phone_numbers open Incoming_phone_numbers_j module Sid = struct let delete sid = Sid . delete sid >>= send_delete >>= return identity let get sid = Sid . get sid >>= send_get >>= return t_of_string let post ? friendly_name ? api_version ? voice_handler ? status_callback ? voice_callerid_lookup ? sms_handler ? account_sid sid = Sid . post ? friendly_name ? api_version ? voice_handler ? status_callback ? voice_callerid_lookup ? sms_handler ? account_sid sid >>= send_post >>= return t_of_string end let get ? phone_number ? friendly_name ( ) = get ? phone_number ? friendly_name ( ) >>= send_get >>= return page_of_string let post ? friendly_name ? voice_handler ? status_callback ? voice_callerid_lookup ? sms_handler number = post ? friendly_name ? voice_handler ? status_callback ? voice_callerid_lookup ? sms_handler number >>= send_post >>= return t_of_string module Local = struct let get ? phone_number ? friendly_name ( ) = Local . get ? phone_number ? friendly_name ( ) >>= send_get >>= return page_of_string let post ? friendly_name ? voice_handler ? status_callback ? voice_callerid_lookup ? sms_handler number = Local . post ? friendly_name ? voice_handler ? status_callback ? voice_callerid_lookup ? sms_handler number >>= send_post >>= return t_of_string end module Toll_free = struct let get ? phone_number ? friendly_name ( ) = Toll_free . get ? phone_number ? friendly_name ( ) >>= send_get >>= return page_of_string let post ? friendly_name ? voice_handler ? status_callback ? voice_callerid_lookup ? sms_handler number = Toll_free . post ? friendly_name ? voice_handler ? status_callback ? voice_callerid_lookup ? sms_handler number >>= send_post >>= return t_of_string end end module Applications = struct open Request . Applications open Applications_j module Sid = struct let delete sid = Sid . delete sid >>= send_delete >>= return identity let get sid = Sid . get sid >>= send_get >>= return t_of_string let post ? friendly_name ? api_version ? voice_callback ? status_callback ? voice_callerid_lookup ? sms_callback sid = Sid . post ? friendly_name ? api_version ? voice_callback ? status_callback ? voice_callerid_lookup ? sms_callback sid >>= send_post >>= return t_of_string end let get ? friendly_name ( ) = get ? friendly_name ( ) >>= send_get >>= return page_of_string let post ? api_version ? voice_callback ? status_callback ? voice_callerid_lookup ? sms_callback friendly_name = post ? api_version ? voice_callback ? status_callback ? voice_callerid_lookup ? sms_callback friendly_name >>= send_post >>= return t_of_string end module Connect_apps = struct open Request . Connect_apps open Connect_apps_j module Sid = struct let post ? friendly_name ? authorized_redirect_url ? deauthorize_callback ? permissions ? description ? company_name ? homepage_url sid = Sid . post ? friendly_name ? authorized_redirect_url ? deauthorize_callback ? permissions ? description ? company_name ? homepage_url sid >>= send_post >>= return t_of_string end let get ( ) = get ( ) >>= send_get >>= return page_of_string end module Authorized_connect_apps = struct open Request . Authorized_connect_apps open Authorized_connect_apps_j module Sid = struct let get sid = Sid . get sid >>= send_get >>= return t_of_string end let get ( ) = get ( ) >>= send_get >>= return page_of_string end module Transcriptions = struct open Request . Transcriptions open Transcriptions_j module Sid = struct let get format sid = let of_string s = match format with | ` Json -> ` Json ( t_of_string s ) | ` Txt -> ` Txt s in Sid . get format sid >>= send_get >>= return of_string end let get ( ) = get ( ) >>= send_get >>= return page_of_string end module Recordings = struct open Request . Recordings open Recordings_j module Sid = struct let get format sid = let of_string s = match format with | ` Wav -> ` Wav s | ` Mp3 -> ` Mp3 s | ` Txt -> ` Txt s | ` Xml -> ` Xml s in Sid . get format sid >>= send_get >>= return of_string let delete sid = Sid . delete sid >>= send_delete >>= return identity end let get ? call_sid ? date_created ( ) = get ? call_sid ? date_created ( ) >>= send_get >>= return t_of_string module Transcriptions = struct open Transcriptions_j let get sid = Transcriptions . get sid >>= send_get >>= return t_of_string end end module Notifications = struct open Request . Notifications open Notifications_j module Sid = struct let get sid = Sid . get sid >>= send_get >>= return t_of_string let delete sid = Sid . delete sid >>= send_delete >>= return identity end let get ? log ? message_date ( ) = get ? log ? message_date ( ) >>= send_get >>= return t_of_string end module Calls = struct open Request . Calls open Calls_j module Sid = struct let get sid = Sid . get sid >>= send_get >>= return t_of_string let delete sid = Sid . delete sid >>= send_delete >>= return identity let post ? twiml_url ? meth ? status sid = Sid . post ? twiml_url ? meth ? status sid >>= send_post >>= return t_of_string end let get ? to_number ? from_number ? status ? start_time ( ) = get ? to_number ? from_number ? status ? start_time ( ) >>= send_get >>= return t_of_string let post ? status_callback ? send_digits ? if_machine ? timeout ~ handler ~ from_number ~ to_number ( ) = post ? status_callback ? send_digits ? if_machine ? timeout ~ handler ~ from_number ~ to_number ( ) >>= send_post >>= return t_of_string module Recordings = struct open Recordings_j let get ? date_created sid = Recordings . get ? date_created sid >>= send_get >>= return t_of_string end module Notifications = struct open Notifications_j let get ? log ? message_date sid = Notifications . get ? log ? message_date sid >>= send_get >>= return t_of_string end end module Sms = struct module Messages = struct open Request . Sms . Messages open Sms_messages_j module Sid = struct let get sid = Sid . get sid >>= send_get >>= return t_of_string end let get ? from_number ? to_number ? date_sent ( ) = get ? from_number ? to_number ? date_sent ( ) >>= send_get >>= return page_of_string let post ? callback ~ from_number ~ to_number ~ body ( ) = post ? callback ~ from_number ~ to_number ~ body ( ) >>= send_post >>= return t_of_string end end end
|
let set_event_system ( pipeline : Http_client . pipeline ) = pipeline # set_event_system
|
module Make ( A : sig val account_sid : string val auth_token : string val timeout : float let pipeline = ref None include Twilio_rest . Make ( struct type ' a _r = ' a Lwt . t let ( ) >>= = Lwt . ( ) >>= let return = Lwt . return let account_sid = A . account_sid let auth_token = A . auth_token let send http_call = match ! pipeline with | None -> Lwt . fail ( Failure " Forgot to call init in Twilio_rest_lwt " ) | Some pipeline -> let returned = ref false in let result = let thread , wakeup = Lwt . wait ( ) in pipeline # add_with_callback http_call ( fun http_call -> Lwt . wakeup wakeup http_call ) ; thread >>= ( fun call -> returned := true ; return ( Twilio_util . result_of_http_call call ) ) in let timeout_thread = Lwt_unix . sleep A . timeout >>= ( fun ( ) -> Lwt . return ` Timeout ) in Lwt . choose [ result ; timeout_thread ] end ) let init ( ? debug = false ) synchronization connections esys = let p = new Http_client . pipeline in Twilio_util . prep_pipeline A . account_sid A . auth_token p ; pipeline := ( Some p ) ; p # set_options { p # get_options with Http_client . synchronization = Http_client . Pipeline synchronization ; Http_client . number_of_parallel_connections = connections ; } ; if debug then p # set_options { p # get_options with Http_client . connection_timeout = 36000 . 0 ; verbose_status = true ; verbose_request_header = true ; verbose_request_contents = true ; verbose_response_header = true ; verbose_response_contents = true ; verbose_connection = false ; } ; end )
|
let ( ) |> x f = f x
|
let option_map f = function | Some x -> Some ( f x ) | None -> None
|
let string_of_method = function | ` Get -> " GET " | ` Post -> " POST "
|
let map_api_version = function | ` V2010_04_01 -> " 2010 - 04 - 01 " | ` V2008_08_01 -> " 2008 - 08 - 01 "
|
let add ( name : string ) ( value : string option ) lst = match value with | Some s -> ( name , s ) :: lst | None -> lst
|
let with_optional_args url args = match List . fold_left ( fun args ( name , optional_value ) -> add name optional_value args ) [ ] args with | [ ] -> url | args -> url ^ " " ? ^ Netencoding . Url . mk_url_encoded_parameters args
|
let add_callback prefix ( url , meth ) lst = ( prefix ^ " Url " , url ) :: ( prefix ^ " Method " , string_of_method meth ) :: lst
|
let add_fallback prefix ( callback , fallback ) lst = let lst = add_callback prefix callback lst in match fallback with | Some cb -> add_callback ( prefix ^ " Fallback " ) cb lst | None -> lst
|
let add_handler prefix handler lst = match handler with | Some ( ` Application sid ) -> ( prefix ^ " ApplicationSid " , sid ) :: lst | Some ( ` Callback fallback ) -> add_fallback prefix fallback lst | None -> lst
|
let url_sid url sid = url ^ " " / ^ sid
|
module Make ( A : sig type ' a _r val return : ' a -> ' a _r val account_sid : string let url = " https :// api . twilio . com / 2010 - 04 - 01 / Accounts " / ^ A . account_sid let return_delete s = A . return s let return_get s = A . return ( s ^ " . json " ) let return_post ( sa : string * ( string * string ) list ) = let ( s , a ) = sa in A . return ( ( s ^ " . json " ) , a ) module Available_phone_numbers = struct let url = url ^ " / AvailablePhoneNumbers " module Local = struct let get ? area_code ? contains ? in_region ? in_postal_code iso_code = return_get ( with_optional_args ( url ^ " " / ^ iso_code ^ " / Local " ) [ " AreaCode " , area_code ; " Contains " , contains ; " InRegion " , in_region ; " InPostalCode " , in_postal_code ] ) end module Toll_free = struct let get ? contains iso_code = return_get ( with_optional_args ( url ^ " " / ^ iso_code ^ " / TollFree " ) [ " Contains " , contains ; ] ) end end module Outgoing_caller_ids = struct let url = url ^ " / OutgoingCallerIds " module Sid = struct let delete sid = return_delete ( url_sid url sid ) let get sid = return_get ( url_sid url sid ) let post friendly_name sid = return_post ( ( url_sid url sid ) , [ " FriendlyName " , friendly_name ] ) end let get ? phone_number ? friendly_name ( ) = return_get ( with_optional_args url [ " PhoneNumber " , phone_number ; " FriendlyName " , friendly_name ; ] ) let post ? friendly_name ? call_delay ? extension phone_number = let args = ( " PhoneNumber " , phone_number ) :: add " FriendlyName " friendly_name [ ] |> add " CallDelay " call_delay |> add " Extension " extension in return_post ( url , args ) end module Incoming_phone_numbers = struct let url = url ^ " / IncomingPhoneNumbers " let post_args ? friendly_name ? api_version ? voice_handler ? status_callback ? voice_callerid_lookup ? sms_handler ? account_sid ( ) = add " FriendlyName " friendly_name [ ] |> add " ApiVersion " ( option_map map_api_version api_version ) |> add_handler " Voice " voice_handler |> ( fun lst -> match status_callback with | Some ( url , m ) -> ( " StatusCallback " , url ) :: ( " StatusCallbackMethod " , string_of_method m ) :: lst | None -> lst ) |> add " VoiceCallerIdLookup " ( option_map string_of_bool voice_callerid_lookup ) |> add_handler " Sms " sms_handler |> add " AccountSid " account_sid module Sid = struct let delete sid = return_delete ( url_sid url sid ) let get sid = return_get ( url_sid url sid ) let post ? friendly_name ? api_version ? voice_handler ? status_callback ? voice_callerid_lookup ? sms_handler ? account_sid sid = return_post ( url_sid url sid , post_args ? friendly_name ? api_version ? voice_handler ? status_callback ? voice_callerid_lookup ? sms_handler ? account_sid ( ) ) end let get_common url ? phone_number ? friendly_name ( ) = return_get ( with_optional_args url [ " PhoneNumber " , phone_number ; " FriendlyName " , friendly_name ; ] ) let number_arg = function | ` PhoneNumber s -> " PhoneNumber " , s | ` AreaCode s -> " AreaCode " , s let get = get_common url let post ? friendly_name ? voice_handler ? status_callback ? voice_callerid_lookup ? sms_handler number = let args = number_arg number :: post_args ? friendly_name ? voice_handler ? status_callback ? voice_callerid_lookup ? sms_handler ( ) in return_post ( url , args ) module Local = struct let url = url ^ " / Local " let get = get_common url let post ? friendly_name ? voice_handler ? status_callback ? voice_callerid_lookup ? sms_handler number = let args = number_arg number :: post_args ? friendly_name ? voice_handler ? status_callback ? voice_callerid_lookup ? sms_handler ( ) in return_post ( url , args ) end module Toll_free = struct let url = url ^ " / TollFree " let get = get_common url let post ? friendly_name ? voice_handler ? status_callback ? voice_callerid_lookup ? sms_handler phone_number = let args = ( " PhoneNumber " , phone_number ) :: post_args ? friendly_name ? voice_handler ? status_callback ? voice_callerid_lookup ? sms_handler ( ) in return_post ( url , args ) end end module Applications = struct let url = url ^ " / Applications " module Sid = struct let delete sid = return_delete ( url_sid url sid ) let get sid = return_get ( url_sid url sid ) let post ? friendly_name ? api_version ? voice_callback ? status_callback ? voice_callerid_lookup ? sms_callback sid = let voice_handler = option_map ( fun cb -> ` Callback cb ) voice_callback in let sms_handler = option_map ( fun cb -> ` Callback cb ) sms_callback in let args = Incoming_phone_numbers . post_args ? friendly_name ? api_version ? voice_handler ? status_callback ? voice_callerid_lookup ? sms_handler ( ) in return_post ( ( url_sid url sid ) , args ) end let get ? friendly_name ( ) = return_get ( with_optional_args url [ " FriendlyName " , friendly_name ] ) let post ? api_version ? voice_callback ? status_callback ? voice_callerid_lookup ? sms_callback friendly_name = let voice_handler = option_map ( fun cb -> ` Callback cb ) voice_callback in let sms_handler = option_map ( fun cb -> ` Callback cb ) sms_callback in let args = Incoming_phone_numbers . post_args ~ friendly_name ? api_version ? voice_handler ? status_callback ? voice_callerid_lookup ? sms_handler ( ) in return_post ( url , args ) end module Connect_apps = struct let url = url ^ " / ConnectApps " let string_of_permissions permissions = String . concat " , " ( List . map ( function | ` Get_all -> " get - all " | ` Post_all -> " post - all " ) permissions ) module Sid = struct let get_sid = url_sid url let post ? friendly_name ? authorized_redirect_url ? deauthorize_callback ? permissions ? description ? company_name ? homepage_url sid = let args = add " FriendlyName " friendly_name [ ] |> add " AuthorizedRedirectUrl " authorized_redirect_url |> ( match deauthorize_callback with | Some cb -> add_callback " DeauthorizeCallback " cb | None -> ( fun x -> x ) ) |> add " Permissions " ( option_map string_of_permissions permissions ) |> add " Description " description |> add " CompanyName " company_name |> add " HomepageUrl " homepage_url in return_post ( url_sid url sid , args ) end let get ( ) = return_get url end module Authorized_connect_apps = struct let url = url ^ " / AuthorizedConnectApps " module Sid = struct let get sid = return_get ( url_sid url sid ) end let get ( ) = return_get url end module Transcriptions = struct let url = url ^ " / Transcriptions " module Sid = struct let get format sid = let sid = sid ^ " . " ^ ( match format with | ` Json -> " json " | ` Txt -> " txt " ) in A . return ( url_sid url sid ) end let get ( ) = return_get url end module Recordings = struct let suffix = " / Recordings " module Sid = struct let get format sid = let sid = sid ^ " . " ^ ( match format with | ` Wav -> " wav " | ` Mp3 -> " mp3 " | ` Txt -> " txt " | ` Xml -> " xml " ) in return_get ( url_sid ( url ^ suffix ) sid ) let delete sid = return_delete ( url_sid url sid ) end let list_common ? call_sid ? date_created url = with_optional_args url [ " CallSid " , call_sid ; " DateCreated " , date_created ; ] let get ? call_sid ? date_created ( ) = return_get ( list_common ? call_sid ? date_created ( url ^ suffix ) ) module Transcriptions = struct let get sid = return_get ( url ^ " " / ^ sid ^ " / Transcriptions " ) end end module Notifications = struct let url = url ^ " / Notifications " module Sid = struct let get sid = return_get ( url_sid url sid ) let delete sid = return_get ( url_sid url sid ) end let list_common ? log ? message_date url = with_optional_args url [ " Log " , log ; " MessageDate " , message_date ; ] let get ? log ? message_date ( ) = return_get ( list_common ? log ? message_date url ) end module Calls = struct let url = url ^ " / Calls " module Sid = struct let get sid = return_get ( url_sid url sid ) let delete sid = return_delete ( url_sid url sid ) let post ? twiml_url ? meth ? status sid = let status = option_map ( function ` Canceled -> " canceled " | ` Completed -> " completed " ) status in let args = add " Url " twiml_url [ ] |> add " Method " meth |> add " Status " status in return_post ( url_sid url sid , args ) end let get ? to_number ? from_number ? status ? start_time ( ) = let status = option_map ( function | ` Ringing -> " ringing " | ` In_progress -> " in - progress " | ` Completed -> " completed " | ` Failed -> " failed " | ` Busy -> " busy " | ` No_answer -> " no - answer " ) status in return_get ( with_optional_args url [ " To " , to_number ; " From " , from_number ; " Status " , status ; " StartTime " , start_time ; ] ) let post ? status_callback ? send_digits ? if_machine ? timeout ~ handler ~ from_number ~ to_number ( ) = let status_callback = match status_callback with | Some ( url , meth ) -> ( " StatusCallback " , url ) :: [ " StatusCallbackMethod " , ( string_of_method meth ) ] | None -> [ ] in let args = add_handler " " ( Some handler ) ( [ " FromNumber " , from_number ; " ToNumber " , to_number ] @ status_callback ) |> add " SendDigits " send_digits |> add " IfMachine " ( option_map string_of_bool if_machine ) |> add " Timeout " ( option_map string_of_int timeout ) in return_post ( url , args ) module Recordings = struct let get ? date_created sid = return_get ( Recordings . list_common ? date_created ( url ^ " " / ^ sid ^ " / Recordings " ) ) end module Notifications = struct let get ? log ? message_date sid = return_get ( Notifications . list_common ? log ? message_date ( url_sid url sid ^ " / Notifications " ) ) end end module Sms = struct let url = url ^ " / SMS " module Messages = struct let url = url ^ " / Messages " module Sid = struct let get sid = return_get ( url_sid url sid ) end let get ? from_number ? to_number ? date_sent ( ) = return_get ( with_optional_args url [ " From " , from_number ; " To " , to_number ; " DateSent " , date_sent ; ] ) let post ? callback ~ from_number ~ to_number ~ body ( ) = let ( args : ( string * string ) list ) = [ " From " , from_number ; " To " , to_number ; " Body " , body ; ] in let ( args : ( string * string ) list ) = match callback with | Some ( ` StatusCallback url ) -> ( " StatusCallback " , url ) :: args | Some ( ` ApplicationSid sid ) -> ( " ApplicationSid " , sid ) :: args | None -> args in return_post ( url , args ) end end end
|
let pi = 4 . 0 . * atan 1 . 0
|
let toid1_points = let arr = [ | ( - 1 . 1 , 0 . 0 ) ; ( - 1 . 0 , 0 . 0 ) ; ( 0 . 0 , 0 . 0 ) ; ( 1 . 0 , 0 . 0 ) ; ( 1 . 1 , 0 . 0 ) ; ] | in let arr = Array . map ( fun ( x , y ) -> [ | tscale . * ( x ) ; tscale . * ( y ) ; tscale . * ( 0 . 0 ) ] ) | arr in ( ba2_glefloat_of_array arr )
|
let toid1_colors = ba2_float32_of_array [ | [ | 0 . 8 ; 0 . 8 ; 0 . 5 ] ; | [ | 0 . 8 ; 0 . 4 ; 0 . 5 ] ; | [ | 0 . 8 ; 0 . 8 ; 0 . 3 ] ; | [ | 0 . 4 ; 0 . 4 ; 0 . 5 ] ; | [ | 0 . 8 ; 0 . 8 ; 0 . 5 ] ; | ] |
|
let toid1_twists = ba1_glefloat_of_array [ | 0 . 0 ; 0 . 0 ; 0 . 0 ; 0 . 0 ; 0 . 0 ] |
|
let tpts i ( x , y ) = toid1_points . { i , 0 } <- tscale . * ( x ) ; toid1_points . { i , 1 } <- tscale . * ( y ) ; toid1_points . { i , 2 } <- tscale . * ( 0 . 0 ) ; ; ;
|
let twistation = ba2_glefloat_create num_twis_pts 2
|
let twist_normal = ba2_glefloat_create num_twis_pts 2
|
let twist i ( x , y ) = twistation . { i , 0 } <- scale . * ( x ) ; twistation . { i , 1 } <- scale . * ( y ) ; if i <> 0 then begin let ax = twistation . { i , 0 } . - twistation . { i - 1 , 0 } and ay = twistation . { i , 1 } . - twistation . { i - 1 , 1 } in let alen = 1 . 0 . / sqrt ( ax . * ax . + ay . * ay ) in let ax = ax . * alen and ay = ay . * alen in twist_normal . { i - 1 , 0 } <- . - ay ; twist_normal . { i - 1 , 1 } <- ax ; end ; ; ;
|
let init_tripples ( ) = for i = 0 to pred num_twis_pts do if i < 11 then begin let angle = pi . * ( float i ) . / 10 . 0 in let co = cos angle and si = sin angle in twist i ( ( - 7 . 0 . - 3 . 0 . * co ) , 1 . 8 . * si ) ; end else begin twist i ( ( - 10 . 0 . ( + float i ) ) , 0 . 0 ) ; twist i ( ( - 9 . 5 . ( + float i ) ) , 1 . 0 ) ; end ; done ; ; ;
|
let draw_stuff ( ) = toid1_twists . { 2 } <- ( float ! lastx . - 121 . 0 ) . / 8 . 0 ; tpts 3 ( 1 . 0 , . - ( float ! lasty . - 121 . 0 ) . / 200 . 0 ) ; tpts 4 ( 1 . 1 , - 1 . 1 . * ( float ! lasty . - 121 . 0 ) . / 200 . 0 ) ; glClear [ GL_COLOR_BUFFER_BIT ; GL_DEPTH_BUFFER_BIT ] ; glPushMatrix ( ) ; glTranslatev ( 0 . 0 , 0 . 0 , - 80 . 0 ) ; glRotatev 43 . 0 ( 1 . 0 , 0 . 0 , 0 . 0 ) ; glRotatev 43 . 0 ( 0 . 0 , 1 . 0 , 0 . 0 ) ; glScalev ( 1 . 8 , 1 . 8 , 1 . 8 ) ; if mono_color then begin glColor3c ' \ 178 ' ' \ 178 ' ' \ 204 ' ; gleTwistExtrusion twistation twist_normal None toid1_points colors_none toid1_twists ; end else begin gleTwistExtrusion twistation twist_normal None toid1_points toid1_colors toid1_twists ; end ; glPopMatrix ( ) ; glutSwapBuffers ( ) ; ; ;
|
let exclude v li = let rec aux acc = function | [ ] -> List . rev acc | x :: xs when x = v -> aux acc xs | x :: xs -> aux ( x :: acc ) xs in aux [ ] li ; ;
|
let init_stuff ( ) = init_tripples ( ) ; ; ;
|
type reconnect_policy = { max_tries : int ; initial_reconnect_interval : float ; }
|
let url_of_stream_type = function | ` Firehose -> " http :// stream . twitter . com / 1 / statuses / firehose . json " | ` Sample -> " http :// stream . twitter . com / 1 / statuses / sample . json " | ` Custom url -> url
|
let stream_of_channel chan = let lines = Lwt_io . read_lines chan in let map_line line = return ( Twitterstream_message . of_json_string line ) in Lwt_stream . map_s map_line lines
|
let connect ( user , pass ) stream_type = let ( input , output ) = Lwt_io . pipe ( ) in let stream = stream_of_channel input in let t = begin let userpass_str = Base64 . str_encode ( user ^ " " : ^ pass ) in let headers = [ " Host " , " stream . twitter . com " ; " Authorization " , " Basic " ^ userpass_str ] in let url = url_of_stream_type stream_type in try_lwt Http_client . get_to_chan url ~ headers output >> return ( ) with | Http_client . Tcp_error ( source , _ ) -> fail Stream_tcp_error | Http_client . Http_error ( code , _ , _ ) -> fail ( Stream_http_error code ) finally Lwt_io . close output end in t , stream
|
let reconnect max_tries initial_reconnect_interval auth stream_type = let stream , push = Lwt_stream . create ( ) in let throttle = Twitterstream_throttle . make ~ initial_reconnect_interval ~ max_attempts : max_tries in let rec go throttle = try_lwt let ( t , stream ) = connect auth stream_type in let iter_t = Lwt_stream . iter ( fun item -> push ( Some item ) ) stream in join [ iter_t ; t ] with | exc -> lwt throttle ' = Twitterstream_throttle . wait throttle in match throttle ' with | Some throttle ' -> go throttle ' | None -> ( push None ; fail exc ) in go throttle , stream
|
let open_stream ( ? max_tries = 1 ) ( ? initial_reconnect_interval = 1 . ) auth stream_type = reconnect max_tries initial_reconnect_interval auth stream_type
|
let ( << ) x y = left32 x y
|
let ( >> ) x y = right32 x y
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.