text
stringlengths
0
601k
let add = ( + )
let sub = ( - )
let mul = ( * )
let div = ( / )
let max x y = if x < y then y else x
let min x y = if x < y then x else y
let rec pow x i = if i = 0 then 1 else x * pow x ( i - 1 )
module Ops = struct let ( * ) = mul let ( / ) = div let ( + ) = add let ( - ) = sub let ( ** ) = pow end
let equal = ( = )
let lt = ( < )
let leq = ( <= )
let pp_micheline_size fmtr { traversal ; int_bytes ; string_bytes } = Format . fprintf fmtr " [ { @ traversal = % a ; ; @ int_bytes = % a ; ; @ string_bytes = % a ; , } ] " @@ pp traversal pp int_bytes pp string_bytes
let to_int x = x
let of_int x = x
let log2 x = Z . log2 ( Z . of_int x )
let unit : t = 1
let integer ( i : ' a Alpha_context . Script_int . num ) : t = Z . numbits ( Alpha_context . Script_int . to_zint i ) / 8
let bytes ( b : Bytes . t ) : t = Bytes . length b
let mutez ( _tez : Alpha_context . Tez . tez ) : t = 8
let bool ( _ : bool ) : t = 1
let signature ( _signature : Script_typed_ir . Script_signature . t ) : t = Script_typed_ir . Script_signature . size
let key_hash ( _keyhash : Signature . public_key_hash ) : t = Signature . Public_key_hash . size
let public_key ( public_key : Signature . public_key ) : t = Signature . Public_key . size public_key
let chain_id ( _chain_id : Script_typed_ir . Script_chain_id . t ) : t = Script_typed_ir . Script_chain_id . size
let address ( addr : Script_typed_ir . address ) : t = let entrypoint = addr . entrypoint in Signature . Public_key_hash . size + String . length ( Alpha_context . Entrypoint . to_string entrypoint )
let list ( list : ' a Script_typed_ir . boxed_list ) : t = list . Script_typed_ir . length
let set ( set : ' a Script_typed_ir . set ) : t = let res = Alpha_context . Script_int . to_int ( Script_set . size set ) in match res with None -> assert false | Some x -> x
let map ( map : ( ' a , ' b ) Script_typed_ir . map ) : t = let res = Alpha_context . Script_int . to_int ( Script_map . size map ) in match res with None -> assert false | Some x -> x
let timestamp ( tstamp : Alpha_context . Script_timestamp . t ) : t = Z . numbits ( Alpha_context . Script_timestamp . to_zint tstamp ) / 8
let micheline_zero = { traversal = 0 ; int_bytes = 0 ; string_bytes = 0 }
let ( ++ ) x y = { traversal = Ops . ( x . traversal + y . traversal ) ; int_bytes = Ops . ( x . int_bytes + y . int_bytes ) ; string_bytes = Ops . ( x . string_bytes + y . string_bytes ) ; }
let node leaves = let r = List . fold_left ( ++ ) micheline_zero leaves in { r with traversal = Ops . ( r . traversal + 1 ) }
let rec of_micheline ( x : ( ' a , ' b ) Micheline . node ) = match x with | Micheline . Int ( _loc , z ) -> let int_bytes = integer ( Alpha_context . Script_int . of_zint z ) in { traversal = 1 ; int_bytes ; string_bytes = 0 } | Micheline . String ( _loc , s ) -> let string_bytes = String . length s in { traversal = 1...
let of_encoded_value : type a . Alpha_context . t -> a Script_typed_ir . ty -> a -> micheline_size = fun ( type a ) ctxt ( ty : a Script_typed_ir . ty ) ( v : a ) -> let open Script_ir_translator in let script_res = Lwt_main . run ( unparse_data ctxt Optimized ty v ) in match script_res with | Ok ( node , _ctxt ) -> of...
let sapling_transaction_inputs : Alpha_context . Sapling . transaction -> t = fun tx -> List . length tx . Tezos_sapling . Core . Client . UTXO . inputs
let sapling_transaction_outputs : Alpha_context . Sapling . transaction -> t = fun tx -> List . length tx . Tezos_sapling . Core . Client . UTXO . outputs
module Dimensions = struct type t = { width : float ; height : float } end
module T = struct module State = struct type t = { mutable callback : width : float -> height : float -> unit ; mutable observer : ResizeObserver . resizeObserver Js . t option ; mutable last_width : float ; mutable last_height : float } end let observe node ( ~ state : State . t ) = let on_resize_observed entries _obs...
module Hook = Vdom . Attr . Hooks . Make ( T )
let on_change f = let f { Dimensions . width ; height } = f ~ width ~ height in Vdom . Attr . create_hook " size_tracker " ( Hook . create f ) ; ;
module For_testing = struct module Dimensions = Dimensions include Hook . For_testing end
let f_to_kir f l = app ( GlobalFun ( f . body , ( match snd f . ret_val with | Vector . Int32 _ -> " int " | Vector . Float32 _ -> " float " | Vector . Custom _ -> ( match fst f . ret_val with | CustomVar ( s , _ , _ ) -> " struct " ^ s " ^ _sarek " | _ -> assert false ) | _ -> " void " ) , " f " ) ) l
let map_skeleton f = spoc_gen_kernel ( params ( concat ( new_int_vec_var 3 " a " ) ( concat ( new_int_vec_var 4 " b " ) ( concat ( new_int_var 5 " i " ) ( empty_arg ( ) ) ) ) ) ) ( spoc_local_env ( spoc_declare ( new_int_var 7 " tid " ) ) ( seq ( spoc_set ( var 7 " tid " ) ( spoc_plus ( intrinsics " threadIdx . x " " (...
let zip_skeleton f = spoc_gen_kernel ( params ( concat ( new_int_vec_var 2 " a " ) ( concat ( new_int_vec_var 3 " b " ) ( concat ( new_int_vec_var 4 " c " ) ( concat ( new_int_var 5 " i " ) ( empty_arg ( ) ) ) ) ) ) ) ( spoc_local_env ( spoc_declare ( new_int_var 7 " tid " ) ) ( seq ( spoc_set ( var 7 " tid " ) ( spoc_...
let body_lookups = let offset = function | 2 -> 0 . , 3 . 5 , - 8 . | 3 -> 1 . , - 1 . , - 1 . 5 | i when i >= 4 -> 0 . , - 12 . , 7 . | 0 -> - 1 . , 0 . , - 2 . | _ -> 0 . , 0 . , - 3 . and curve = function | 0 -> Curvature . ( curve ~ well ( : spec ~ radius : 85 . ( Float . pi . / 12 . ) ~ tilt ( : Float . pi . / 24 ...
let thumb_lookups = let curve _ = Curvature . ( curve ~ fan { : angle = Float . pi . / 12 . 5 ; radius = 85 . ; tilt = 0 . } ( ) ) in Plate . Lookups . thumb ~ curve ( )
let plate_builder = Plate . make ~ n_body_cols : 5 ~ spacing : 1 . 5 ~ tent ( : Float . pi . / 10 . ) ~ body_lookups ~ thumb_lookups ~ thumb_offset ( :- 1 . , - 50 . , - 6 . ) ~ thumb_angle : Float . ( 0 . , pi . / - 4 . 3 , pi . / 6 . )
let wall_builder plate = Walls . { body = auto_body ~ n_steps ( ` : Flat 5 ) ~ n_facets : 5 ~ north_clearance : 1 . 5 ~ south_clearance : 1 . 5 ~ side_clearance : 1 . 5 plate ; thumb = auto_thumb ~ south_lookup ( : fun i -> if not ( i = 1 ) then Yes else No ) ~ east_lookup ( : fun _ -> No ) ~ west_lookup ( : fun _ -> E...
let base_connector = Connect . skeleton ~ height : 5 . ~ thumb_height : 9 . ~ east_link ( : Connect . snake ~ height : 9 . ~ scale : 1 . ~ d : 1 . 4 ( ) ) ~ west_link ( : Connect . cubic ~ height : 11 . ~ scale : 1 . 25 ~ d : 1 . ~ bow_out : false ( ) ) ~ cubic_d : 2 . ~ cubic_scale : 1 . ~ body_join_steps ( ` : Flat 5...
let ports_cutter = BastardShield . ( cutter ( make ( ) ) )
let build ? right_hand ? hotswap ( ) = let keyhole = Mx . make_hole ~ clearance : 2 . 75 ? hotswap ( ) in Case . make ? right_hand ~ plate_builder ~ plate_welder ~ wall_builder ~ base_connector ~ ports_cutter keyhole
let bastard_skelly = Scad . import_3d " . . / things / others / bastardkb_skeletyl_v3_v5 . stl " |> Scad . translate ( 87 . , 0 . , 25 . ) |> Scad . rotate ( Float . pi . / 2 . , 0 . , 0 . ) |> Scad . translate ( 0 . , - 2 . , 8 . ) |> Scad . color ~ alpha : 0 . 5 Color . DarkSlateBlue
let bastard_compare ( ) = Scad . union [ bastard_skelly ; Case . to_scad ~ show_caps : false ( build ( ) ) |> Scad . color ~ alpha : 0 . 5 Color . Yellow ]
let bk_skeletyl_w_shield ( ) = let shield = BastardShield . ( make ( ) ) in Scad . union [ bastard_skelly ; BastardShield . to_scad ~ show_screws : true shield |> Scad . translate ( - 6 . 71 , 35 . 2 , 2 . ) ]
let x = function | A , B -> 1 | BBB , _ -> 2 | CCCcccc , CCCCCCCC -> 3
let x = function A , B -> 1 | BBB , _ -> 2 | CCCcccc , CCCCCCCC -> 3
module S = struct let x = function | A , B -> 1 | BBB , _ -> 2 | CCCcccc , CCCCCCCC -> 3 [ @@ ocamlformat " disable " ] end
module S = struct let x = function | A , B -> 1 | BBB , _ -> 2 | CCCcccc , CCCCCCCC -> 3 let x = function | A , B -> 1 | BBB , _ -> 2 | CCCcccc , CCCCCCCC -> 3 [ @@@ ocamlformat " disable " ] let x = function | A , B -> 1 | BBB , _ -> 2 | CCCcccc , CCCCCCCC -> 3 [ @@@ ocamlformat " enable " ] let x = function | A , B -...
let x = function | A , B -> 1 | BBB , _ -> 2 | CCCcccc , CCCCCCCC -> 3
module type S = sig type t = int * int [ @@ ocamlformat " disable " ] [ @@@ ocamlformat " disable " ] val x : a : t -> b : t -> c : t -> unit end
let x = fun fc -> let x = 3 in match x , y with | Some _ , None -> test | None , Some _ -> test | Some _ , Some _ -> test | None , None -> test [ @@ ocamlformat " disable " ]
let x = fun [ @ ocamlformat " disable " ] fc -> let x = 3 in match x , y with | Some _ , None -> test | None , Some _ -> test | Some _ , Some _ -> test | None , None -> test
let _ = ( x [ @ ocamlformat " disable " ] [ @ test ? _ when e [ @ test 2 ] ] ) 3
let _ = let module X = struct let x = 4 end in X . x
let _ = let module X = struct let x = 4 end [ @ ocamlformat " disable " ] in X . x
let _ = let module X = struct module S = struct let x = 4 end [ @ ocamlformat " disable " ] end in X . x
module MyQuery = [ % graphql { | query ( $ var : Boolean ) ! { v1 : variousScalars { nullableString @ skip ( if : $ var ) string @ skip ( if : $ var ) } v2 : variousScalars { nullableString @ include ( if : $ var ) string @ include ( if : $ var ) } } } ] |
let pp formatter ( obj : qt ) = Format . fprintf formatter " < v1 = [ @<>< nullableString = % a ; string = % a ] >@ ; [ @<>< nullableString \ = % a ; string = % a ] >@ " > ( Format . pp_print_string |> pp_option ) obj . v1 . nullableString ( Format . pp_print_string |> pp_option ) obj . v1 . string ( Format . pp_print_...
let equal ( a : qt ) ( b : qt ) = a . v1 . nullableString = b . v1 . nullableString && a . v1 . string = b . v1 . string && a . v2 . nullableString = b . v2 . nullableString && a . v2 . string = b . v2 . string
let responds_with_none_to_nulled_fields ( ) = test_exp ( { { " | v1 " : { " nullableString " : null , " string " : null } , " v2 " : { " nullableString " : null , " string " : null } } } | |> Json . Read . from_string |> MyQuery . unsafe_fromJson |> MyQuery . parse ) { v1 = { nullableString = None ; string = None } ; v...
let responds_with_none_to_omitted_fields ( ) = test_exp ( { { " | v1 " : { } , " v2 " : { } } } | |> Json . Read . from_string |> MyQuery . unsafe_fromJson |> MyQuery . parse ) { v1 = { nullableString = None ; string = None } ; v2 = { nullableString = None ; string = None } ; } equal pp
let tests = [ ( " Responds with None to nulled fields " , responds_with_none_to_nulled_fields ) ; ( " Responds with None to omitted fields " , responds_with_none_to_omitted_fields ) ; ]
let usage ( ) = Printf . printf " % s < skybox - directory >\ n " Sys . argv . ( 0 ) ; exit 1 ; ;
let skybox_images_dir = if Array . length Sys . argv < 2 then usage ( ) ; Sys . argv . ( 1 ) ; ;
type image_data = { width : int ; height : int ; pixels : GL . image_data ; internal_format : GL . tex_internal_format ; pixel_data_format : pixel_data_format ; }
let load_textures ( ) = let src_img = [ | Filename . concat skybox_images_dir " negz . jpg " ; Filename . concat skybox_images_dir " negx . jpg " ; Filename . concat skybox_images_dir " posz . jpg " ; Filename . concat skybox_images_dir " posx . jpg " ; Filename . concat skybox_images_dir " posy . jpg " ; Filename . co...
let display_sky_box ~ size ~ textures = glEnable GL_TEXTURE_2D ; glColor3 1 . 0 1 . 0 1 . 0 ; glPushMatrix ( ) ; glScale ( - 1 . 0 ) 1 . 0 1 . 0 ; glBindTexture2D textures . ( 2 ) ; glBegin GL_QUADS ; glNormal3 ( 0 . 0 ) ( 0 . 0 ) ( - 1 . 0 ) ; glTexCoord2 0 . 0 0 . 0 ; glVertex3 ( . - size ) ( size ) ( size ) ; glTexC...
let b_down = ref false
let anglex = ref ( 0 )
let angley = ref ( 0 )
let xold = ref 0
let yold = ref 0
let list_id = ref 0
let compile_list ~ dirname = let textures = load_textures ( ) in glNewList ! list_id GL_COMPILE ; display_sky_box ~ size : 8 . ~ textures ; glEndList ( ) ; ; ;
let display ( ) = glClear ~ mask [ : GL_COLOR_BUFFER_BIT ; GL_DEPTH_BUFFER_BIT ] ; glLoadIdentity ( ) ; glRotate ~ angle ( : float ( - ! angley ) ) ~ x : 1 . 0 ~ y : 0 . 0 ~ z : 0 . 0 ; glRotate ~ angle ( : float ( - ! anglex ) ) ~ x : 0 . 0 ~ y : 1 . 0 ~ z : 0 . 0 ; glCallList ! list_id ; glFlush ( ) ; glutSwapBuffers...
let reshape ~ width ~ height = glMatrixMode GL_PROJECTION ; glLoadIdentity ( ) ; gluPerspective ~ aspect ( : float width . / float height ) ~ fovy : 80 . ~ zNear : 0 . 2 ~ zFar : 60 . ; glViewport 0 0 width height ; glMatrixMode GL_MODELVIEW ; glutPostRedisplay ( ) ; ; ;
let keyboard ~ key ~ x ~ y = match key with | ' \ 027 ' | ' q ' -> exit ( 0 ) | _ -> ( ) ; ;
let mouse ~ button ~ state ~ x ~ y = match button , state with | GLUT_LEFT_BUTTON , GLUT_DOWN -> b_down := true ; xold := x ; yold := y ; | GLUT_LEFT_BUTTON , GLUT_UP -> b_down := false ; | _ -> ( ) ; ;
let motion ~ x ~ y = if ! b_down then begin anglex := ! anglex + ( ! xold - x ) ; angley := ! angley + ( ! yold - y ) ; glutPostRedisplay ( ) ; end ; xold := x ; yold := y ; ; ;
let ( ) = ignore ( glutInit Sys . argv ) ; glutInitDisplayMode [ GLUT_RGB ; GLUT_DOUBLE ; GLUT_DEPTH ] ; glutInitWindowPosition ~ x : 200 ~ y : 200 ; glutInitWindowSize ~ width : 800 ~ height : 600 ; ignore ( glutCreateWindow ~ title ( " : Fly - Box " ^ skybox_images_dir ) ) ; glClearColor ~ r : 0 . 0 ~ g : 0 . 0 ~ b :...
type api_error = [ | ` Unhandled_error of string | ` Unknown_error ]
type parsed_api_error = [ | ` ParseFailure of string | api_error ]
type auth_error = [ | ` Not_authed | ` Invalid_auth | ` Account_inactive ]
type timestamp_error = [ | ` Invalid_ts_latest | ` Invalid_ts_oldest ]
type channel_error = [ | ` Channel_not_found ]
type user_error = [ | ` User_not_found ]
type invite_error = [ | ` Cant_invite_self | ` Cant_invite ]
type not_in_channel_error = [ | ` Not_in_channel ]
type already_in_channel_error = [ | ` Already_in_channel ]
type archive_error = [ | ` Is_archived ]