text
stringlengths
0
601k
let _ = test_tetris ( )
module Stable = struct module V1 = struct type t = Sgn_type . Sgn . Stable . V1 . t = Pos | Neg [ @@ deriving sexp , hash , compare , equal , yojson ] yojson let to_latest = Fn . id end end ] end
let gen = Quickcheck . Generator . map Bool . quickcheck_generator ~ f ( : fun b -> if b then Pos else Neg )
let negate = function Pos -> Neg | Neg -> Pos
let neg_one = Field ( . negate one ) one
let to_field = function Pos -> Field . one | Neg -> neg_one
let of_field_exn x = if Field . equal x Field . one then Pos else if Field . equal x neg_one then Neg else failwith " Sgn . of_field : Expected positive or negative 1 "
let typ : ( var , t ) t Typ . t = let open Typ in Typ { check = ( fun x -> assert_r1cs x x ( Field . Var . constant Field . one ) one ) one ; var_to_fields = ( fun t -> ( [ | t ] , | ( ) ) ) ; var_of_fields = ( fun ( ts , ( ) ) -> ts ( . 0 ) 0 ) 0 ; value_to_fields = ( fun t -> ( [ | to_field t ] , | ( ) ) ) ; value_of...
module Checked = struct let two = Field . of_int 2 let neg_two = Field . negate two let one_half = Field . inv two let neg_one_half = Field . negate one_half let is_pos ( v : var ) var = Boolean . Unsafe . of_cvar ( let open Field . Checked in one_half * ( v + Field . Var . constant Field . one ) one ) one let is_neg (...
type t = ( string * int * float ) float list
let raise_bad msg = raise ( Bad msg ) msg
let cmpsi ( s1 , i1 , _ ) _ ( s2 , i2 , _ ) _ = Stdlib . compare ( s1 , i1 ) i1 ( s2 , i2 ) i2
let of_list l = List . sort ~ compare : cmpsi l
let to_list t = t
let of_chr_lists l = let ans = List . map ~ f ( : fun ( a , l ) l -> List . map ~ f ( : fun ( b , c ) c -> a , b , c ) c l ) l l in let ans = List . concat ans in List . sort ~ compare : cmpsi ans
let npartition_exn ~ eq l = let open List in let insertl ll a = let rec loop prefix ll = match ll with | [ ] -> rev ( [ a ] a :: prefix ) prefix | l :: ll -> if eq a ( hd_exn l ) l then ( rev ( ( a :: l ) l :: prefix ) prefix ) prefix @ ll else loop ( l :: prefix ) prefix ll in loop [ ] ll in map ~ f : rev ( fold_left ...
let to_chr_lists t = let eq ( s1 , _ , _ ) _ ( s2 , _ , _ ) _ = String ( . s1 = s2 ) s2 in let ll = npartition_exn ~ eq t in let ll = List . map ~ f ( : fun l -> let x , _ , _ = List . hd_exn l in x , List . map ~ f ( : fun ( _ , b , c ) c -> b , c ) c l ) l ll in ll
let of_channel ( ? chr_map = Fun . id ) id ( ? increment_bp = 0 ) 0 cin = let parse_line ' delim line = match String . split line ~ on : delim with | [ c ; i ; f ] f -> chr_map c , int_of_string i + increment_bp , Float . of_string f | _ -> raise_bad " ill - formed line " in let parse_line line = try parse_line ' ' \ t...
let of_file ( ? chr_map = Fun . id ) id ( ? increment_bp = 0 ) 0 file = In_channel . with_file file ~ f ( : of_channel ~ chr_map ~ increment_bp ) increment_bp
let to_channel ( ? chr_map = Fun . id ) id ( ? increment_bp = 0 ) 0 t cout = let f ( s , i , v ) v = fprintf cout " % s \ t % d \ t % f \ n " ( chr_map s ) s ( i + increment_bp ) increment_bp v in List . iter ~ f t
let to_file ( ? chr_map = Fun . id ) id ( ? increment_bp = 0 ) 0 t file = Out_channel . with_file file ~ f ( : to_channel ~ chr_map ~ increment_bp t ) t
let sha_1 ( s : string ) : string = let sha_1_pad s = let len = String . length s in let blen = 8 * len in let rem = len mod 64 in let mlen = if rem > 55 then len + 128 - rem else len + 64 - rem in let m = Bytes . create mlen in Bytes . blit_string s 0 m 0 len ; Bytes . fill m len ( mlen - len ) ' \ x00 ' ; Bytes . set...
let rotate x n = or32 ( right32 x n ) ( left32 x ( 32 - n ) )
let shift x n = right32 x n
let ch x y z = xor32 ( and32 x y ) ( and32 ( not32 x ) z )
let maj x y z = xor32 ( and32 x y ) ( xor32 ( and32 x z ) ( and32 y z ) )
let sum0 x = xor32 ( rotate x 2 ) ( xor32 ( rotate x 13 ) ( rotate x 22 ) )
let sum1 x = xor32 ( rotate x 6 ) ( xor32 ( rotate x 11 ) ( rotate x 25 ) )
let rh00 x = xor32 ( rotate x 7 ) ( xor32 ( rotate x 18 ) ( shift x 3 ) )
let rh01 x = xor32 ( rotate x 17 ) ( xor32 ( rotate x 19 ) ( shift x 10 ) )
type ctx = { mutable total_length : Int64 . t ; mutable h : Int32 . t array }
let pack64 x = let b = Buffer . create 8 in for i = 0 to 7 do let shft = ( 7 - i ) * 8 in Buffer . add_char b ( char_of_int ( Int64 . to_int ( Int64 . logand ( Int64 . shift_right x shft ) 0xFFL ) ) ) done ; b
let pack x n = if n mod 8 = 0 then ( let n ' = n / 8 in let b = Buffer . create n ' in for i = 0 to n ' - 1 do let shft = ( n ' - 1 - i ) * 8 in Buffer . add_char b ( char_of_int ( Int32 . to_int ( Int32 . logand ( Int32 . shift_right x shft ) 0xFFl ) ) ) done ; b ) else raise ( Invalid_argument ( " pack : " ^ string_o...
let pack32 x = pack x 32
let as_bytes bits = match bits mod 8 with | 0 -> bits / 8 | _ -> failwith " as_bytes : bits must be multiple of 8 "
let as_bits bytes = bytes * 8
let bs_in_bytes = as_bytes 512
let k = [ | 0x428a2f98l ; 0x71374491l ; 0xb5c0fbcfl ; 0xe9b5dba5l ; 0x3956c25bl ; 0x59f111f1l ; 0x923f82a4l ; 0xab1c5ed5l ; 0xd807aa98l ; 0x12835b01l ; 0x243185bel ; 0x550c7dc3l ; 0x72be5d74l ; 0x80deb1fel ; 0x9bdc06a7l ; 0xc19bf174l ; 0xe49b69c1l ; 0xefbe4786l ; 0x0fc19dc6l ; 0x240ca1ccl ; 0x2de92c6fl ; 0x4a7484aal ; ...
let init ( ) = { total_length = 0L ; h = [ | 0x6a09e667l ; 0xbb67ae85l ; 0x3c6ef372l ; 0xa54ff53al ; 0x510e527fl ; 0x9b05688cl ; 0x1f83d9abl ; 0x5be0cd19l ] | }
let rec range i j = if i > j then [ ] else i :: range ( i + 1 ) j
let update ctx message = let sha = ctx . h in let message_bits = as_bits ( Buffer . length message ) in if message_bits <> bs_in_bits then failwith ( " update : message must be 512 bits ; got " ^ string_of_int message_bits ^ " bits " ) else ( let mm i = Buffer . nth message i in let w = Array . make bs_in_bytes 0l in f...
let sub_buf b pos len = let s = Buffer . sub b pos len in let b ' = Buffer . create ( String . length s ) in Buffer . add_string b ' s ; b '
let hexdigits64 m = let rec hexdigits_inner hx i = match i with | 64 -> hx | _ -> hexdigits_inner ( hx ^ Printf . sprintf " % 02x " ( int_of_char ( Buffer . nth m i ) ) ) ( i + 1 ) in hexdigits_inner " " 0
let pack_sha256 ctx = let h = ctx . h in let sha256 = Buffer . create ( as_bytes 256 ) in let rec pack_sha256_inner = function | 8 -> sha256 | i -> Buffer . add_buffer sha256 ( pack32 h . ( i ) ) ; pack_sha256_inner ( i + 1 ) in pack_sha256_inner 0
let final ctx message = let original_length = as_bits ( Buffer . length message ) in if original_length > bs_in_bits then failwith ( " error : final : must be called with message smaller than 512 bits ; " ^ " got " ^ string_of_int original_length ^ " bits " ) else ( let pad_blocks = if original_length mod bs_in_bits < ...
let digest message = let message_length = as_bits ( Buffer . length message ) in let ctx = init ( ) in let total_blocks = message_length / bs_in_bits in let last_block_pos = total_blocks * bs_in_bytes in let last_block_len = as_bytes message_length - last_block_pos in for blockno = 0 to total_blocks - 1 do update ctx (...
let hexdigits m = let rec hexdigits_inner hx = function | 32 -> hx | i -> hexdigits_inner ( hx ^ Printf . sprintf " % 02x " ( int_of_char ( Buffer . nth m i ) ) ) ( i + 1 ) in hexdigits_inner " " 0
let hexdigest s = let b = Buffer . create ( String . length s ) in Buffer . add_string b s ; hexdigits ( digest b )
let test ( ) = let rec run_tests = function | [ ] -> ( ) | ( msg , sum ) :: tests -> let result = hexdigest msg in if result = sum then Printf . printf " ok : sha256 ( ' % s ' ) = ' % s ' \ n " msg sum else Printf . printf " FAIL : sha256 ( ' % s ' ) != ' % s ' ; got ' % s ' \ n " msg sum result ; run_tests tests in ru...
let interpolate_rgb = " InterpolatedColor = VertexColor ; gl_Position = ModelViewProjectionMatrix * vec4 ( VertexPosition , 1 . 0 ) ; } " , Color = vec4 ( InterpolatedColor , 1 . 0 ) ; } "
let interpolate_uv = " InterpolatedUV = VertexUV ; gl_Position = ModelViewProjectionMatrix * vec4 ( VertexPosition , 1 . 0 ) ; } " , Color = texture ( texture0 , InterpolatedUV ) ; } "
let interpolate_uv_rgb = " InterpolatedUV = VertexUV ; InterpolatedColor = VertexColor ; gl_Position = ModelViewProjectionMatrix * vec4 ( VertexPosition , 1 . 0 ) ; } " , vec4 vert_color = vec4 ( InterpolatedColor , 1 . 0 ) ; vec4 tex_color = texture ( texture0 , InterpolatedUV ) ; if ( TexEnv == 0 ) { // MODULATE Colo...
let plain_color_vertex_shader = " gl_Position = ModelViewProjectionMatrix * vec4 ( VertexPosition , 1 . 0 ) ; } "
let plain_color3 ( r , g , b ) = plain_color_vertex_shader , Printf . sprintf Color = vec4 ( % f , % f , % f , 1 . 0 ) ;
let plain_color4 ( r , g , b , a ) = plain_color_vertex_shader , Printf . sprintf Color = vec4 ( % f , % f , % f , % f ) ;
let plain_varying_color = plain_color_vertex_shader , Color = vec4 ( PlainColor , 1 . 0 ) ; } "
let main ( ) = set_config_flags [ ConfigFlags . Msaa_4x_hint ; ConfigFlags . Window_resizable ] ; init_window width height " raylib [ shaders ] example - rlgl mesh instanced " ; let position = Vector3 . create 125 . 0 125 . 0 125 . 0 in let target = Vector3 . create 0 . 0 0 . 0 0 . 0 in let up = Vector3 . create 0 . 0 ...
let ( ) = main ( )
module Make_sure_val : sig val x : int let x = 3 open struct let x = ' c ' end end
type t = A type t = B end
module Make_sure_ec : sig type ext += C of int type ext += C of int open struct type ext += D of char end end
module M = struct type t = int end module M = struct type u = char end end
module type S = sig type t = int end module type S = sig type u = char end end class c = object method y = ' c ' end end class type ct = object method y : int end end
module type S = sig type t val unit : unit external e : unit -> unit = " % identity " module M : sig type t end module type T exception E type ext = . . type ext += C class c : object end class type ct = object end end ; ; [ %% expect { |
module type S = sig type t val unit : unit external e : unit -> unit = " % identity " module M : sig type t end module type T exception E type ext = . . type ext += C class c : object end class type ct = object end end } ] |
module type SS = sig include S include S end ; ; [ %% expect { |
module type SS = sig type t val unit : unit external e : unit -> unit = " % identity " module M : sig type t end module type T exception E type ext = . . type ext += C class c : object end class type ct = object end end } ] |
module type Type = sig include S type u = t include S end ; ; [ %% expect { |
module type Type = sig type u type t val unit : unit external e : unit -> unit = " % identity " module M : sig type t end module type T exception E type ext = . . type ext += C class c : object end class type ct = object end end } ] |
module type Type_fail = sig include S val ignore : t -> unit include S end ; ; [ %% expect { | ^^^^^^^^^ Line 2 , characters 2 - 11 : Type t / 144 came from this include Line 3 , characters 2 - 24 : The value ignore has no valid type if t / 144 is shadowed } ] |
module type Module = sig include S module N = M include S end ; ; [ %% expect { |
module type Module = sig module N : sig type t end type t val unit : unit external e : unit -> unit = " % identity " module M : sig type t end module type T exception E type ext = . . type ext += C class c : object end class type ct = object end end } ] |
module type Module_fail = sig include S val ignore : M . t -> unit include S end ; ; [ %% expect { | ^^^^^^^^^ Line 2 , characters 2 - 11 : Module M / 232 came from this include Line 3 , characters 2 - 26 : The value ignore has no valid type if M / 232 is shadowed } ] |
module type Module_type = sig include S module type U = T include S end ; ; [ %% expect { |
module type Module_type = sig module type U type t val unit : unit external e : unit -> unit = " % identity " module M : sig type t end module type T exception E type ext = . . type ext += C class c : object end class type ct = object end end } ] |
module type Module_type_fail = sig include S module F : functor ( _ : T ) -> sig end include S end ; ; [ %% expect { | ^^^^^^^^^ Line 2 , characters 2 - 11 : Module type T / 317 came from this include Line 3 , characters 2 - 39 : The module F has no valid type if T / 317 is shadowed } ] |
module type Extension = sig include S type ext += C2 include S end ; ; [ %% expect { | ^^^^^^^^^ Line 2 , characters 2 - 11 : Type ext / 352 came from this include Line 3 , characters 14 - 16 : The extension constructor C2 has no valid type if ext / 352 is shadowed } ] |
module type Class = sig include S class parametrized : int -> c include S end ; ; [ %% expect { |
module type Class = sig class parametrized : int -> object end type t val unit : unit external e : unit -> unit = " % identity " module M : sig type t end module type T exception E type ext = . . type ext += C class c : object end class type ct = object end end } ] |
module type Class_type = sig include S class type parametrized = ct include S end ; ; [ %% expect { |
module type Class_type = sig class type parametrized = object end type t val unit : unit external e : unit -> unit = " % identity " module M : sig type t end module type T exception E type ext = . . type ext += C class c : object end class type ct = object end end } ] |
module N = struct type t let unit = ( ) external e : unit -> unit = " % identity " module M = struct end module type T = sig end exception E type ext = . . type ext += C class c = object end class type ct = object end end ; ; [ %% expect { |
module N : sig type t val unit : unit external e : unit -> unit = " % identity " module M : sig end module type T = sig end exception E type ext = . . type ext += C class c : object end class type ct = object end end } ] |
module NN = struct include N include N end ; ; [ %% expect { |
module NN : sig type t = N . t val unit : unit external e : unit -> unit = " % identity " module M = N . M module type T = sig end exception E type ext = N . ext = . . type ext += C class c : object end class type ct = object end end } ] |
module Type = struct include N type u = t include N end ; ; [ %% expect { |
module Type : sig type u = N . t type t = N . t val unit : unit external e : unit -> unit = " % identity " module M = N . M module type T = sig end exception E type ext = N . ext = . . type ext += C class c : object end class type ct = object end end } ] |
module Module = struct include N module O = M include N end ; ; [ %% expect { |
module Module : sig module O = N . M type t = N . t val unit : unit external e : unit -> unit = " % identity " module M = N . M module type T = sig end exception E type ext = N . ext = . . type ext += C class c : object end class type ct = object end end } ] |
module Module_type = struct include N module type U = T include N end ; ; [ %% expect { |
module Module_type : sig module type U = sig end type t = N . t val unit : unit external e : unit -> unit = " % identity " module M = N . M module type T = sig end exception E type ext = N . ext = . . type ext += C class c : object end class type ct = object end end } ] |
module Exception = struct include N exception Exn = E include N end ; ; [ %% expect { |
module Exception : sig exception Exn type t = N . t val unit : unit external e : unit -> unit = " % identity " module M = N . M module type T = sig end exception E type ext = N . ext = . . type ext += C class c : object end class type ct = object end end } ] |
module Extension = struct include N type ext += C2 include N end ; ; [ %% expect { |
module Extension : sig type N . ext += C2 type t = N . t val unit : unit external e : unit -> unit = " % identity " module M = N . M module type T = sig end exception E type ext = N . ext = . . type ext += C class c : object end class type ct = object end end } ] |
module Class = struct include N class parametrized _ = c include N end ; ; [ %% expect { |
module Class : sig class parametrized : ' a -> object end type t = N . t val unit : unit external e : unit -> unit = " % identity " module M = N . M module type T = sig end exception E type ext = N . ext = . . type ext += C class c : object end class type ct = object end end } ] |
module Class_type = struct include N class type parametrized = ct include N end ; ; [ %% expect { |
module Class_type : sig class type parametrized = object end type t = N . t val unit : unit external e : unit -> unit = " % identity " module M = N . M module type T = sig end exception E type ext = N . ext = . . type ext += C class c : object end class type ct = object end end } ] |
type _ eff += Get : int eff | Set : int -> unit eff | Print : string -> unit eff