text
stringlengths 0
601k
|
---|
let _ , _ , _ , bind_g = bind ~ directives [ : Comment " $ k " ] $ ~ file " : sect1 - bind . ladot " couple site_a site_b_x |
let add_state site state graph = let _ , graph = add_internal_state ~ directives [ : Direction se ] site state graph in ( [ ] , [ ] , [ ] ) , graph |
let activate ? directives ? file g s su sp = build_rule ? directives ? file g ( add_state s su ) ( add_state s sp ) |
let _ = let site_b_y , g = add_site agent_b b_y couple in let _ , g = add_bond site_a site_b_x g in activate ~ directives [ : Comment " $ kp " ] $ ~ file " : sect1 - phos . ladot " g site_b_y b_y_u b_y_p |
let refined_domain state = let s , g = add_site agent_b b_y couple in snd ( add_state s state g ) |
let _ , _ , _ , bind_u = bind ~ directives [ : Comment " $ k " ] $ ~ file " : sect1 - bind - ref - u . ladot " ( refined_domain b_y_u ) site_a site_b_x |
let _ , _ , _ , bind_p = bind ~ directives [ : Comment " $ k " ] $ ~ file " : sect1 - bind - ref - p . ladot " ( refined_domain b_y_p ) site_a site_b_x |
let ag , fictitious = add_empty_node 0 . 0 . signature |
let sigmafu , _ , bind_u = let g = move_remanent_right_to 0 . 2 bind_u fictitious in disjoint_union fictitious g |
let sigmafu = lift_agent sigmafu |
let sigmafp , _ , bind_p = let g = move_remanent_right_to 0 . 2 bind_p fictitious in disjoint_union fictitious g |
let sigmafp = lift_agent sigmafp |
let sigmad , sigmau , bindup = let bind_u = move_remanent_above 0 . 5 bind_u bind_p in disjoint_union bind_u bind_p |
let sigmad = lift_agent sigmad |
let sigmau = lift_agent sigmau |
let _ , sigmaf , bind_g = let g = move_remanent_right_to 0 . 2 fictitious bind_g in disjoint_union bind_g g |
let sigmaf = lift_agent sigmaf |
let sigmal , sigmar , graph = let g = move_remanent_right_to 1 . 5 bindup bind_g in disjoint_union ( translate_graph { abscisse = 0 . ; ordinate = 0 . 45 } bind_g ) g |
let sigmal = lift_agent sigmal |
let sigmar = lift_agent sigmar |
let fl = sigmal ( sigmaf ( ag ) ) |
let fu = sigmar ( sigmafu ( sigmau ag ) ) |
let fp = sigmar ( sigmafp ( sigmad ag ) ) |
let sigmau x = sigmar ( sigmaf ( sigmau x ) ) |
let graph = add_proj ~ color " : black " [ fl , fp ; fl , fu ] graph |
let _ = dump " ref . ladot " graph let [ a , [ a_n , [ ] ; a_e , [ u ; p ] ; ] ] , signature = add_in_signature [ " $\ text { \ agent { A } { } } " , $ [ Shape " circle " ; Width ( 0 . 13 . * config . agent_width ) ; Height ( 0 . 16 . * config . agent_width ) ] , [ " $\ text { \ site { n } { } { } } " , [ $ Direction n ] , [ ] ; " $\ text { \ site { n } { } { } } " , [ $ Direction e ] , [ " u " , [ Direction ne ] ; " p " , [ Direction ne ] ] ] ] ( snd ( init config ) ) let [ a , [ sn , _ ; se_ , _ ] ; a ' , [ sn ' , _ ; se ' , _ ] ; a ' ' , [ sn ' ' , _ ; se ' ' , _ ] ; a ' ' ' , [ sn ' ' ' , _ ; se ' ' ' , _ ] ] , g = add_in_graph [ a , 0 . , 0 . , [ ] , [ a_n , [ ] , [ ] ; a_e , [ ] , [ Internal_state ( u , [ ] ) ] ; ] ; a , 0 . 6 , 0 . , [ ] , [ a_n , [ ] , [ ] ; a_e , [ ] , [ Internal_state ( u , [ ] ) ] ] ; a , 1 . 2 , 0 . , [ ] , [ a_n , [ ] , [ Free_site [ ] ] ; a_e , [ ] , [ Internal_state ( u , [ ] ) ] ] ; a , 1 . 8 , 0 . , [ ] , [ a_n , [ ] , [ Free_site [ ] ] ; a_e , [ ] , [ ] ] ; ] signature |
let left g = let _ , g = add_free_list [ sn , [ ] ; sn ' , [ ] ] g in let _ , g = add_internal_state se ' ' ' u g in ( [ ] , [ ] , [ ] ) , g |
let right g = let g = add_link_list [ sn , sn ' ] g in let _ , g = add_internal_state se ' ' ' p g in ( [ ] , [ ] , [ ] ) , g |
let _ = build_rule ~ file " : auto . ladot " ~ directives [ : Comment " $ k " ] $ g left right let [ a , [ a_x , [ ] ; a_y , [ ] ; ] ; ] , signature = add_in_signature [ " $\ text { \ agent { A } { } } " , [ $ Shape " rectangle " ; Width ( 0 . 10 . * config . agent_width ) ; Height ( 0 . 16 . * config . agent_width ) ] , [ " $\ text { \ site { a } { } { } } " , $ [ Direction ne ] , [ ] ; " $\ text { \ site { b } { } { } } " , [ $ Direction se ] , [ ] ] ] ( snd ( init config ) ) |
let [ agent_a , [ site_a , _ ; site_b , _ ] ; agent_a ' , [ site_a ' , _ ; site_b ' , _ ] ] , dimer = add_in_graph [ a , 0 . , 0 . , [ ] , [ a_x , [ ] , [ ] ; a_y , [ ] , [ ] ] ; a , 0 . 6 , 0 . , [ ] , [ a_x , [ Direction nw ] , [ ] ; a_y , [ Direction sw ] , [ ] ] ; ] signature |
let build_rule b1 b2 g = let sx , sy , s = if b1 then site_a , site_b , " t " else site_b , site_a , " f " in let sx ' , sy ' , s ' = if b2 then site_a ' , site_b ' , " t " else site_b ' , site_a ' , " f " in let n = if b1 && b2 then " 1 " else if b1 then " 3 " else if b2 then " 4 " else " 2 " in let file = " sym " ^ s ^ s ' " . ^ ladot " in let _ , domain = add_free_list [ sy , [ ] ; sy ' , [ ] ] g in let free g = ( [ ] , [ ] , [ ] ) , snd ( add_free_list [ sx , [ ] ; sx ' , [ ] ] g ) in let bind g = ( [ ] , [ ] , [ ] ) , add_link_list [ sx , sx ' ] g in build_rule ~ file ~ directives [ : Comment ( " $ k_ " ^ n " " ) ] ^$ domain free bind |
let _ = build_rule true true dimer |
let _ = build_rule false false dimer |
let _ = build_rule true false dimer |
module Meta = struct type user = [ ` beginner ] [ @@ deriving yaml ] let user_to_string = function ` beginner -> " beginner " type t = { title : string ; description : string ; date : string ; users : user list ; } [ @@ deriving yaml ] end |
module H = struct include Sesame . Collection . Html ( Meta ) let build ( t : Input . t ) = let { Meta . title ; users ; description ; _ } = t . meta in let users = div ~ a [ : a_class [ " user - list " ] ] ( List . map ( fun u -> span ~ a [ : a_class [ " tag " ; " is - danger " ] ] [ txt ( Meta . user_to_string u ) ] ) users ) in let conf = Bos . OS . Dir . create ( Fpath . v " ocaml . org / tutorials / images " ) |> ignore ; Sesame . Transformer . Image . v ~ quality : 60 ~ path ( : Fpath . v t . path ) ~ dst ( : Fpath . v " ocaml . org / tutorials / images " ) Sesame . Responsive . Images . ( MaxWidth ( 660 , 400 , Default 800 ) ) in let omd = Omd . of_string t . body |> Sesame . Transformer . Image . transform conf in let content = [ Components . navbar ; Components . hero ~ medium : false ~ title description ; section ~ a [ : a_class [ " section " ] ] [ div ~ a [ : a_class [ " content " ; " columns " ; " is - centered " ] ] [ div ~ a [ : a_class [ " column " ; " is - half - desktop " ] ] [ div [ users ; Unsafe . data Omd . ( to_html omd ) ] ] ; ] ; ] ; ] in Components . ( html_doc ~ head ( : simple_head ~ t : t . meta . title ) content ) |> fun html -> { path = t . path ; html = Fmt . str " % a " ( Tyxml . Html . pp ( ) ) html } |> Lwt_result . return end |
module C = Sesame . Collection . Make ( Meta ) |
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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.