text
stringlengths
12
786k
let all_ids_for_export { var ; name_mode = _ } = Ids_for_export . add_variable Ids_for_export . empty var
let renaming { var ; name_mode = _ } ~ guaranteed_fresh = let { var = guaranteed_fresh ; name_mode = _ } = guaranteed_fresh in Renaming . add_fresh_variable Renaming . empty var ~ guaranteed_fresh
let error_occurred = ref false
let function_tested = ref " "
let testing_function s = function_tested := s ; print_newline ( ) ; print_string s ; print_newline ( )
let test test_number answer correct_answer = flush stdout ; flush stderr ; if answer <> correct_answer then begin eprintf " *** Bad result ( % s , test % d ) \ n " ! function_tested test_number ; flush stderr ; error_occurred := true end else begin printf " % d . . . " test_number end
module type TESTSIG = sig type t module Ops : sig val neg : t -> t val add : t -> t -> t val sub : t -> t -> t val mul : t -> t -> t val div : t -> t -> t val unsigned_div : t -> t -> t val rem : t -> t -> t val logand : t -> t -> t val logor : t -> t -> t val logxor : t -> t -> t val shift_left : t -> int -> t val shift_right : t -> int -> t val shift_right_logical : t -> int -> t val of_int : int -> t val to_int : t -> int val unsigned_to_int : t -> int option val of_float : float -> t val to_float : t -> float val zero : t val one : t val minus_one : t val min_int : t val max_int : t val format : string -> t -> string val to_string : t -> string val of_string : string -> t end val testcomp : t -> t -> bool * bool * bool * bool * bool * bool * int * int val skip_float_tests : bool end
module Test32 ( M : TESTSIG ) = struct open M open Ops let _ = testing_function " of_int , to_int " ; test 1 ( to_int ( of_int 0 ) ) 0 ; test 2 ( to_int ( of_int 123 ) ) 123 ; test 3 ( to_int ( of_int ( - 456 ) ) ) ( - 456 ) ; test 4 ( to_int ( of_int 0x3FFFFFFF ) ) 0x3FFFFFFF ; test 5 ( to_int ( of_int ( - 0x40000000 ) ) ) ( - 0x40000000 ) ; testing_function " unsigned_to_int " ; test 1 ( unsigned_to_int ( of_int 0 ) ) ( Some 0 ) ; test 2 ( unsigned_to_int ( of_int 123 ) ) ( Some 123 ) ; test 3 ( unsigned_to_int minus_one ) ( match Sys . word_size with | 32 -> None | 64 -> Some ( int_of_string " 0xFFFFFFFF " ) | _ -> assert false ) ; test 4 ( unsigned_to_int max_int ) ( match Sys . word_size with | 32 -> None | 64 -> Some ( to_int max_int ) | _ -> assert false ) ; test 5 ( unsigned_to_int min_int ) ( match Sys . word_size with | 32 -> None | 64 -> Some ( int_of_string " 0x80000000 " ) | _ -> assert false ) ; test 6 ( unsigned_to_int ( of_int Stdlib . max_int ) ) ( match Sys . word_size with | 32 -> Some Stdlib . max_int | 64 -> Some ( int_of_string " 0xFFFFFFFF " ) | _ -> assert false ) ; testing_function " of_string " ; test 1 ( of_string " 0 " ) ( of_int 0 ) ; test 2 ( of_string " 123 " ) ( of_int 123 ) ; test 3 ( of_string " - 456 " ) ( of_int ( - 456 ) ) ; test 4 ( of_string " 123456789 " ) ( of_int 123456789 ) ; test 5 ( of_string " 0xABCDEF " ) ( of_int 0xABCDEF ) ; test 6 ( of_string " - 0o1234567012 " ) ( of_int ( - 0o1234567012 ) ) ; test 7 ( of_string " 0b01010111111000001100 " ) ( of_int 0b01010111111000001100 ) ; test 8 ( of_string " 0x7FFFFFFF " ) max_int ; test 9 ( of_string " - 0x80000000 " ) min_int ; test 10 ( of_string " 0x80000000 " ) min_int ; test 11 ( of_string " 0xFFFFFFFF " ) minus_one ; testing_function " to_string , format " ; List . iter ( fun ( n , s ) -> test n ( to_string ( of_string s ) ) s ) [ 1 , " 0 " ; 2 , " 123 " ; 3 , " - 456 " ; 4 , " 1234567890 " ; 5 , " 1073741824 " ; 6 , " 2147483647 " ; 7 , " - 2147483648 " ] ; List . iter ( fun ( n , s ) -> test n ( format " 0x % X " ( of_string s ) ) s ) [ 8 , " 0x0 " ; 9 , " 0x123 " ; 10 , " 0xABCDEF " ; 11 , " 0x12345678 " ; 12 , " 0x7FFFFFFF " ; 13 , " 0x80000000 " ; 14 , " 0xFFFFFFFF " ] ; test 15 ( to_string max_int ) " 2147483647 " ; test 16 ( to_string min_int ) " - 2147483648 " ; test 17 ( to_string zero ) " 0 " ; test 18 ( to_string one ) " 1 " ; test 19 ( to_string minus_one ) " - 1 " ; testing_function " neg " ; test 1 ( neg ( of_int 0 ) ) ( of_int 0 ) ; test 2 ( neg ( of_int 123 ) ) ( of_int ( - 123 ) ) ; test 3 ( neg ( of_int ( - 456 ) ) ) ( of_int 456 ) ; test 4 ( neg ( of_int 123456789 ) ) ( of_int ( - 123456789 ) ) ; test 5 ( neg max_int ) ( of_string " - 0x7FFFFFFF " ) ; test 6 ( neg min_int ) min_int ; testing_function " add " ; test 1 ( add ( of_int 0 ) ( of_int 0 ) ) ( of_int 0 ) ; test 2 ( add ( of_int 123 ) ( of_int 0 ) ) ( of_int 123 ) ; test 3 ( add ( of_int 0 ) ( of_int 456 ) ) ( of_int 456 ) ; test 4 ( add ( of_int 123 ) ( of_int 456 ) ) ( of_int 579 ) ; test 5 ( add ( of_int ( - 123 ) ) ( of_int 456 ) ) ( of_int 333 ) ; test 6 ( add ( of_int 123 ) ( of_int ( - 456 ) ) ) ( of_int ( - 333 ) ) ; test 7 ( add ( of_int ( - 123 ) ) ( of_int ( - 456 ) ) ) ( of_int ( - 579 ) ) ; test 8 ( add ( of_string " 0x12345678 " ) ( of_string " 0x9ABCDEF " ) ) ( of_string " 0x1be02467 " ) ; test 9 ( add max_int max_int ) ( of_int ( - 2 ) ) ; test 10 ( add min_int min_int ) zero ; test 11 ( add max_int one ) min_int ; test 12 ( add min_int minus_one ) max_int ; test 13 ( add max_int min_int ) minus_one ; testing_function " sub " ; test 1 ( sub ( of_int 0 ) ( of_int 0 ) ) ( of_int 0 ) ; test 2 ( sub ( of_int 123 ) ( of_int 0 ) ) ( of_int 123 ) ; test 3 ( sub ( of_int 0 ) ( of_int 456 ) ) ( of_int ( - 456 ) ) ; test 4 ( sub ( of_int 123 ) ( of_int 456 ) ) ( of_int ( - 333 ) ) ; test 5 ( sub ( of_int ( - 123 ) ) ( of_int 456 ) ) ( of_int ( - 579 ) ) ; test 6 ( sub ( of_int 123 ) ( of_int ( - 456 ) ) ) ( of_int 579 ) ; test 7 ( sub ( of_int ( - 123 ) ) ( of_int ( - 456 ) ) ) ( of_int 333 ) ; test 8 ( sub ( of_string " 0x12345678 " ) ( of_string " 0x9ABCDEF " ) ) ( of_string " 0x8888889 " ) ; test 9 ( sub max_int min_int ) minus_one ; test 10 ( sub min_int max_int ) one ; test 11 ( sub min_int one ) max_int ; test 12 ( sub max_int minus_one ) min_int ; testing_function " mul " ; test 1 ( mul ( of_int 0 ) ( of_int 0 ) ) ( of_int 0 ) ; test 2 ( mul ( of_int 123 ) ( of_int 0 ) ) ( of_int 0 ) ; test 3 ( mul ( of_int 0 ) ( of_int ( - 456 ) ) ) ( of_int 0 ) ; test 4 ( mul ( of_int 123 ) ( of_int 1 ) ) ( of_int 123 ) ; test 5 ( mul ( of_int 1 ) ( of_int ( - 456 ) ) ) ( of_int ( - 456 ) ) ; test 6 ( mul ( of_int 123 ) ( of_int ( - 1 ) ) ) ( of_int ( - 123 ) ) ; test 7 ( mul ( of_int ( - 1 ) ) ( of_int ( - 456 ) ) ) ( of_int 456 ) ; test 8 ( mul ( of_int 123 ) ( of_int 456 ) ) ( of_int 56088 ) ; test 9 ( mul ( of_int ( - 123 ) ) ( of_int 456 ) ) ( of_int ( - 56088 ) ) ; test 10 ( mul ( of_int 123 ) ( of_int ( - 456 ) ) ) ( of_int ( - 56088 ) ) ; test 11 ( mul ( of_int ( - 123 ) ) ( of_int ( - 456 ) ) ) ( of_int 56088 ) ; test 12 ( mul ( of_string " 0x12345678 " ) ( of_string " 0x9ABCDEF " ) ) ( of_string " 0xe242d208 " ) ; test 13 ( mul max_int max_int ) one ; testing_function " div " ; List . iter ( fun ( n , a , b ) -> test n ( div ( of_int a ) ( of_int b ) ) ( of_int ( a / b ) ) ) [ 1 , 0 , 2 ; 2 , 123 , 1 ; 3 , - 123 , 1 ; 4 , 123 , - 1 ; 5 , - 123 , - 1 ; 6 , 127531236 , 365 ; 7 , 16384 , 256 ; 8 , - 127531236 , 365 ; 9 , 127531236 , - 365 ; 10 , 1234567 , 12345678 ; 11 , 1234567 , - 12345678 ] ; test 12 ( div min_int ( of_int ( - 1 ) ) ) min_int ; testing_function " unsigned_div " ; List . iter ( fun ( n , a , b , c ) -> test n ( unsigned_div a b ) c ) [ 1 , of_int 0 , of_int 2 , of_int 0 ; 2 , of_int 123 , of_int 1 , of_int 123 ; 3 , of_int ( - 123 ) , of_int 1 , of_int ( - 123 ) ; 4 , of_int ( 123 ) , of_int ( - 1 ) , of_int 0 ; 5 , of_int ( - 123 ) , of_int ( - 1 ) , of_int 0 ; 6 , of_int 127531236 , of_int 365 , of_int ( 127531236 / 365 ) ; 7 , of_int 16384 , of_int 256 , of_int ( 16384 / 256 ) ; 8 , of_int ( - 1 ) , of_int 2 , max_int ; 9 , of_int ( - 1 ) , max_int , of_int 2 ; 10 , min_int , of_int 2 , shift_left ( of_int 1 ) 30 ; 11 , of_int ( - 1 ) , of_int 8 , shift_right_logical ( of_int ( - 1 ) ) 3 ] ; testing_function " mod " ; List . iter ( fun ( n , a , b ) -> test n ( rem ( of_int a ) ( of_int b ) ) ( of_int ( a mod b ) ) ) [ 1 , 0 , 2 ; 2 , 123 , 1 ; 3 , - 123 , 1 ; 4 , 123 , - 1 ; 5 , - 123 , - 1 ; 6 , 127531236 , 365 ; 7 , 16384 , 256 ; 8 , - 127531236 , 365 ; 9 , 127531236 , - 365 ; 10 , 1234567 , 12345678 ; 11 , 1234567 , - 12345678 ] ; test 12 ( rem min_int ( of_int ( - 1 ) ) ) ( of_int 0 ) ; testing_function " and " ; List . iter ( fun ( n , a , b , c ) -> test n ( logand ( of_string a ) ( of_string b ) ) ( of_string c ) ) [ 1 , " 0x12345678 " , " 0x9abcdef0 " , " 0x12345670 " ; 2 , " 0x12345678 " , " 0x0fedcba9 " , " 0x2244228 " ; 3 , " 0xFFFFFFFF " , " 0x12345678 " , " 0x12345678 " ; 4 , " 0 " , " 0x12345678 " , " 0 " ; 5 , " 0x55555555 " , " 0xAAAAAAAA " , " 0 " ] ; testing_function " or " ; List . iter ( fun ( n , a , b , c ) -> test n ( logor ( of_string a ) ( of_string b ) ) ( of_string c ) ) [ 1 , " 0x12345678 " , " 0x9abcdef0 " , " 0x9abcdef8 " ; 2 , " 0x12345678 " , " 0x0fedcba9 " , " 0x1ffddff9 " ; 3 , " 0xFFFFFFFF " , " 0x12345678 " , " 0xFFFFFFFF " ; 4 , " 0 " , " 0x12345678 " , " 0x12345678 " ; 5 , " 0x55555555 " , " 0xAAAAAAAA " , " 0xFFFFFFFF " ] ; testing_function " xor " ; List . iter ( fun ( n , a , b , c ) -> test n ( logxor ( of_string a ) ( of_string b ) ) ( of_string c ) ) [ 1 , " 0x12345678 " , " 0x9abcdef0 " , " 0x88888888 " ; 2 , " 0x12345678 " , " 0x0fedcba9 " , " 0x1dd99dd1 " ; 3 , " 0xFFFFFFFF " , " 0x12345678 " , " 0xedcba987 " ; 4 , " 0 " , " 0x12345678 " , " 0x12345678 " ; 5 , " 0x55555555 " , " 0xAAAAAAAA " , " 0xFFFFFFFF " ] ; testing_function " shift_left " ; List . iter ( fun ( n , a , b , c ) -> test n ( shift_left ( of_string a ) b ) ( of_string c ) ) [ 1 , " 1 " , 1 , " 2 " ; 2 , " 1 " , 2 , " 4 " ; 3 , " 1 " , 4 , " 0x10 " ; 4 , " 1 " , 30 , " 0x40000000 " ; 5 , " 1 " , 31 , " 0x80000000 " ; 6 , " 0x16236 " , 7 , " 0xb11b00 " ; 7 , " 0x10 " , 27 , " 0x80000000 " ; 8 , " 0x10 " , 28 , " 0 " ] ; testing_function " shift_right " ; List . iter ( fun ( n , a , b , c ) -> test n ( shift_right ( of_string a ) b ) ( of_string c ) ) [ 1 , " 2 " , 1 , " 1 " ; 2 , " 4 " , 2 , " 1 " ; 3 , " 0x10 " , 4 , " 1 " ; 4 , " 0x40000000 " , 10 , " 0x100000 " ; 5 , " 0x80000000 " , 31 , " - 1 " ; 6 , " 0xb11b00 " , 7 , " 0x16236 " ; 7 , " - 0xb11b00 " , 7 , " - 90678 " ] ; testing_function " shift_right_logical " ; List . iter ( fun ( n , a , b , c ) -> test n ( shift_right_logical ( of_string a ) b ) ( of_string c ) ) [ 1 , " 2 " , 1 , " 1 " ; 2 , " 4 " , 2 , " 1 " ; 3 , " 0x10 " , 4 , " 1 " ; 4 , " 0x40000000 " , 10 , " 0x100000 " ; 5 , " 0x80000000 " , 31 , " 1 " ; 6 , " 0xb11b00 " , 7 , " 0x16236 " ; 7 , " - 0xb11b00 " , 7 , " 0x1fe9dca " ] ; if not ( skip_float_tests ) then begin testing_function " of_float " ; test 1 ( of_float 0 . 0 ) ( of_int 0 ) ; test 2 ( of_float 123 . 0 ) ( of_int 123 ) ; test 3 ( of_float 123 . 456 ) ( of_int 123 ) ; test 4 ( of_float 123 . 999 ) ( of_int 123 ) ; test 5 ( of_float ( - 456 . 0 ) ) ( of_int ( - 456 ) ) ; test 6 ( of_float ( - 456 . 123 ) ) ( of_int ( - 456 ) ) ; test 7 ( of_float ( - 456 . 789 ) ) ( of_int ( - 456 ) ) ; testing_function " to_float " ; test 1 ( to_float ( of_int 0 ) ) 0 . 0 ; test 2 ( to_float ( of_int 123 ) ) 123 . 0 ; test 3 ( to_float ( of_int ( - 456 ) ) ) ( - 456 . 0 ) ; test 4 ( to_float ( of_int 0x3FFFFFFF ) ) 1073741823 . 0 ; test 5 ( to_float ( of_int ( - 0x40000000 ) ) ) ( - 1073741824 . 0 ) end ; testing_function " Comparisons " ; test 1 ( testcomp ( of_int 0 ) ( of_int 0 ) ) ( true , false , false , false , true , true , 0 , 0 ) ; test 2 ( testcomp ( of_int 1234567 ) ( of_int 1234567 ) ) ( true , false , false , false , true , true , 0 , 0 ) ; test 3 ( testcomp ( of_int 0 ) ( of_int 1 ) ) ( false , true , true , false , true , false , - 1 , - 1 ) ; test 4 ( testcomp ( of_int ( - 1 ) ) ( of_int 0 ) ) ( false , true , true , false , true , false , - 1 , 1 ) ; test 5 ( testcomp ( of_int 1 ) ( of_int 0 ) ) ( false , true , false , true , false , true , 1 , 1 ) ; test 6 ( testcomp ( of_int 0 ) ( of_int ( - 1 ) ) ) ( false , true , false , true , false , true , 1 , - 1 ) ; test 7 ( testcomp max_int min_int ) ( false , true , false , true , false , true , 1 , - 1 ) ; ( ) end
module Test64 ( M : TESTSIG ) = struct open M open Ops let _ = testing_function " of_int , to_int " ; test 1 ( to_int ( of_int 0 ) ) 0 ; test 2 ( to_int ( of_int 123 ) ) 123 ; test 3 ( to_int ( of_int ( - 456 ) ) ) ( - 456 ) ; test 4 ( to_int ( of_int 0x3FFFFFFF ) ) 0x3FFFFFFF ; test 5 ( to_int ( of_int ( - 0x40000000 ) ) ) ( - 0x40000000 ) ; testing_function " unsigned_to_int " ; test 1 ( unsigned_to_int ( of_int 0 ) ) ( Some 0 ) ; test 2 ( unsigned_to_int ( of_int 123 ) ) ( Some 123 ) ; test 3 ( unsigned_to_int minus_one ) None ; test 4 ( unsigned_to_int max_int ) None ; test 5 ( unsigned_to_int min_int ) None ; test 6 ( unsigned_to_int ( of_int Stdlib . max_int ) ) ( Some Stdlib . max_int ) ; testing_function " of_string " ; test 1 ( of_string " 0 " ) ( of_int 0 ) ; test 2 ( of_string " 123 " ) ( of_int 123 ) ; test 3 ( of_string " - 456 " ) ( of_int ( - 456 ) ) ; test 4 ( of_string " 123456789 " ) ( of_int 123456789 ) ; test 5 ( of_string " 0xABCDEF " ) ( of_int 0xABCDEF ) ; test 6 ( of_string " - 0o1234567012 " ) ( of_int ( - 0o1234567012 ) ) ; test 7 ( of_string " 0b01010111111000001100 " ) ( of_int 0b01010111111000001100 ) ; test 8 ( of_string " 0x7FFFFFFFFFFFFFFF " ) max_int ; test 9 ( of_string " - 0x8000000000000000 " ) min_int ; test 10 ( of_string " 0x8000000000000000 " ) min_int ; test 11 ( of_string " 0xFFFFFFFFFFFFFFFF " ) minus_one ; testing_function " to_string , format " ; List . iter ( fun ( n , s ) -> test n ( to_string ( of_string s ) ) s ) [ 1 , " 0 " ; 2 , " 123 " ; 3 , " - 456 " ; 4 , " 1234567890 " ; 5 , " 1234567890123456789 " ; 6 , " 9223372036854775807 " ; 7 , " - 9223372036854775808 " ] ; List . iter ( fun ( n , s ) -> test n ( " 0x " ^ format " % X " ( of_string s ) ) s ) [ 8 , " 0x0 " ; 9 , " 0x123 " ; 10 , " 0xABCDEF " ; 11 , " 0x1234567812345678 " ; 12 , " 0x7FFFFFFFFFFFFFFF " ; 13 , " 0x8000000000000000 " ; 14 , " 0xFFFFFFFFFFFFFFFF " ] ; test 15 ( to_string max_int ) " 9223372036854775807 " ; test 16 ( to_string min_int ) " - 9223372036854775808 " ; test 17 ( to_string zero ) " 0 " ; test 18 ( to_string one ) " 1 " ; test 19 ( to_string minus_one ) " - 1 " ; testing_function " neg " ; test 1 ( neg ( of_int 0 ) ) ( of_int 0 ) ; test 2 ( neg ( of_int 123 ) ) ( of_int ( - 123 ) ) ; test 3 ( neg ( of_int ( - 456 ) ) ) ( of_int 456 ) ; test 4 ( neg ( of_int 123456789 ) ) ( of_int ( - 123456789 ) ) ; test 5 ( neg max_int ) ( of_string " - 0x7FFFFFFFFFFFFFFF " ) ; test 6 ( neg min_int ) min_int ; testing_function " add " ; test 1 ( add ( of_int 0 ) ( of_int 0 ) ) ( of_int 0 ) ; test 2 ( add ( of_int 123 ) ( of_int 0 ) ) ( of_int 123 ) ; test 3 ( add ( of_int 0 ) ( of_int 456 ) ) ( of_int 456 ) ; test 4 ( add ( of_int 123 ) ( of_int 456 ) ) ( of_int 579 ) ; test 5 ( add ( of_int ( - 123 ) ) ( of_int 456 ) ) ( of_int 333 ) ; test 6 ( add ( of_int 123 ) ( of_int ( - 456 ) ) ) ( of_int ( - 333 ) ) ; test 7 ( add ( of_int ( - 123 ) ) ( of_int ( - 456 ) ) ) ( of_int ( - 579 ) ) ; test 8 ( add ( of_string " 0x1234567812345678 " ) ( of_string " 0x9ABCDEF09ABCDEF " ) ) ( of_string " 0x1be024671be02467 " ) ; test 9 ( add max_int max_int ) ( of_int ( - 2 ) ) ; test 10 ( add min_int min_int ) zero ; test 11 ( add max_int one ) min_int ; test 12 ( add min_int minus_one ) max_int ; test 13 ( add max_int min_int ) minus_one ; testing_function " sub " ; test 1 ( sub ( of_int 0 ) ( of_int 0 ) ) ( of_int 0 ) ; test 2 ( sub ( of_int 123 ) ( of_int 0 ) ) ( of_int 123 ) ; test 3 ( sub ( of_int 0 ) ( of_int 456 ) ) ( of_int ( - 456 ) ) ; test 4 ( sub ( of_int 123 ) ( of_int 456 ) ) ( of_int ( - 333 ) ) ; test 5 ( sub ( of_int ( - 123 ) ) ( of_int 456 ) ) ( of_int ( - 579 ) ) ; test 6 ( sub ( of_int 123 ) ( of_int ( - 456 ) ) ) ( of_int 579 ) ; test 7 ( sub ( of_int ( - 123 ) ) ( of_int ( - 456 ) ) ) ( of_int 333 ) ; test 8 ( sub ( of_string " 0x1234567812345678 " ) ( of_string " 0x9ABCDEF09ABCDEF " ) ) ( of_string " 0x888888908888889 " ) ; test 9 ( sub max_int min_int ) minus_one ; test 10 ( sub min_int max_int ) one ; test 11 ( sub min_int one ) max_int ; test 12 ( sub max_int minus_one ) min_int ; testing_function " mul " ; test 1 ( mul ( of_int 0 ) ( of_int 0 ) ) ( of_int 0 ) ; test 2 ( mul ( of_int 123 ) ( of_int 0 ) ) ( of_int 0 ) ; test 3 ( mul ( of_int 0 ) ( of_int ( - 456 ) ) ) ( of_int 0 ) ; test 4 ( mul ( of_int 123 ) ( of_int 1 ) ) ( of_int 123 ) ; test 5 ( mul ( of_int 1 ) ( of_int ( - 456 ) ) ) ( of_int ( - 456 ) ) ; test 6 ( mul ( of_int 123 ) ( of_int ( - 1 ) ) ) ( of_int ( - 123 ) ) ; test 7 ( mul ( of_int ( - 1 ) ) ( of_int ( - 456 ) ) ) ( of_int 456 ) ; test 8 ( mul ( of_int 123 ) ( of_int 456 ) ) ( of_int 56088 ) ; test 9 ( mul ( of_int ( - 123 ) ) ( of_int 456 ) ) ( of_int ( - 56088 ) ) ; test 10 ( mul ( of_int 123 ) ( of_int ( - 456 ) ) ) ( of_int ( - 56088 ) ) ; test 11 ( mul ( of_int ( - 123 ) ) ( of_int ( - 456 ) ) ) ( of_int 56088 ) ; test 12 ( mul ( of_string " 0x12345678 " ) ( of_string " 0x9ABCDEF " ) ) ( of_string " 0xb00ea4e242d208 " ) ; test 13 ( mul max_int max_int ) one ; testing_function " div " ; List . iter ( fun ( n , a , b ) -> test n ( div ( of_int a ) ( of_int b ) ) ( of_int ( a / b ) ) ) [ 1 , 0 , 2 ; 2 , 123 , 1 ; 3 , - 123 , 1 ; 4 , 123 , - 1 ; 5 , - 123 , - 1 ; 6 , 127531236 , 365 ; 7 , 16384 , 256 ; 8 , - 127531236 , 365 ; 9 , 127531236 , - 365 ; 10 , 1234567 , 12345678 ; 11 , 1234567 , - 12345678 ] ; test 12 ( div min_int ( of_int ( - 1 ) ) ) min_int ; testing_function " unsigned_div " ; List . iter ( fun ( n , a , b , c ) -> test n ( unsigned_div a b ) c ) [ 1 , of_int 0 , of_int 2 , of_int 0 ; 2 , of_int 123 , of_int 1 , of_int 123 ; 3 , of_int ( - 123 ) , of_int 1 , of_int ( - 123 ) ; 4 , of_int ( 123 ) , of_int ( - 1 ) , of_int 0 ; 5 , of_int ( - 123 ) , of_int ( - 1 ) , of_int 0 ; 6 , of_int 127531236 , of_int 365 , of_int ( 127531236 / 365 ) ; 7 , of_int 16384 , of_int 256 , of_int ( 16384 / 256 ) ; 8 , of_int ( - 1 ) , of_int 2 , max_int ; 9 , of_int ( - 1 ) , max_int , of_int 2 ; 10 , min_int , of_int 2 , shift_left ( of_int 1 ) 62 ; 11 , of_int ( - 1 ) , of_int 8 , shift_right_logical ( of_int ( - 1 ) ) 3 ] ; testing_function " mod " ; List . iter ( fun ( n , a , b ) -> test n ( rem ( of_int a ) ( of_int b ) ) ( of_int ( a mod b ) ) ) [ 1 , 0 , 2 ; 2 , 123 , 1 ; 3 , - 123 , 1 ; 4 , 123 , - 1 ; 5 , - 123 , - 1 ; 6 , 127531236 , 365 ; 7 , 16384 , 256 ; 8 , - 127531236 , 365 ; 9 , 127531236 , - 365 ; 10 , 1234567 , 12345678 ; 11 , 1234567 , - 12345678 ] ; test 12 ( rem min_int ( of_int ( - 1 ) ) ) ( of_int 0 ) ; testing_function " and " ; List . iter ( fun ( n , a , b , c ) -> test n ( logand ( of_string a ) ( of_string b ) ) ( of_string c ) ) [ 1 , " 0x1234567812345678 " , " 0x9abcdef09abcdef0 " , " 0x1234567012345670 " ; 2 , " 0x1234567812345678 " , " 0x0fedcba90fedcba9 " , " 0x224422802244228 " ; 3 , " 0xFFFFFFFFFFFFFFFF " , " 0x1234000012345678 " , " 0x1234000012345678 " ; 4 , " 0 " , " 0x1234567812345678 " , " 0 " ; 5 , " 0x5555555555555555 " , " 0xAAAAAAAAAAAAAAAA " , " 0 " ] ; testing_function " or " ; List . iter ( fun ( n , a , b , c ) -> test n ( logor ( of_string a ) ( of_string b ) ) ( of_string c ) ) [ 1 , " 0x1234567812345678 " , " 0x9abcdef09abcdef0 " , " 0x9abcdef89abcdef8 " ; 2 , " 0x1234567812345678 " , " 0x0fedcba90fedcba9 " , " 0x1ffddff91ffddff9 " ; 3 , " 0xFFFFFFFFFFFFFFFF " , " 0x12345678 " , " 0xFFFFFFFFFFFFFFFF " ; 4 , " 0 " , " 0x1234567812340000 " , " 0x1234567812340000 " ; 5 , " 0x5555555555555555 " , " 0xAAAAAAAAAAAAAAAA " , " 0xFFFFFFFFFFFFFFFF " ] ; testing_function " xor " ; List . iter ( fun ( n , a , b , c ) -> test n ( logxor ( of_string a ) ( of_string b ) ) ( of_string c ) ) [ 1 , " 0x1234567812345678 " , " 0x9abcdef09abcdef0 " , " 0x8888888888888888 " ; 2 , " 0x1234567812345678 " , " 0x0fedcba90fedcba9 " , " 0x1dd99dd11dd99dd1 " ; 3 , " 0xFFFFFFFFFFFFFFFF " , " 0x123456789ABCDEF " , " 0xfedcba9876543210 " ; 4 , " 0 " , " 0x1234567812340000 " , " 0x1234567812340000 " ; 5 , " 0x5555555555555555 " , " 0xAAAAAAAAAAAAAAAA " , " 0xFFFFFFFFFFFFFFFF " ] ; testing_function " shift_left " ; List . iter ( fun ( n , a , b , c ) -> test n ( shift_left ( of_string a ) b ) ( of_string c ) ) [ 1 , " 1 " , 1 , " 2 " ; 2 , " 1 " , 2 , " 4 " ; 3 , " 1 " , 4 , " 0x10 " ; 4 , " 1 " , 62 , " 0x4000000000000000 " ; 5 , " 1 " , 63 , " 0x8000000000000000 " ; 6 , " 0x16236ABD45673 " , 7 , " 0xb11b55ea2b3980 " ; 7 , " 0x10 " , 59 , " 0x8000000000000000 " ; 8 , " 0x10 " , 60 , " 0 " ] ; testing_function " shift_right " ; List . iter ( fun ( n , a , b , c ) -> test n ( shift_right ( of_string a ) b ) ( of_string c ) ) [ 1 , " 2 " , 1 , " 1 " ; 2 , " 4 " , 2 , " 1 " ; 3 , " 0x10 " , 4 , " 1 " ; 4 , " 0x40000000 " , 10 , " 0x100000 " ; 5 , " 0x8000000000000000 " , 63 , " - 1 " ; 6 , " 0xb11b55ea2b3980 " , 7 , " 0x16236ABD45673 " ; 7 , " - 0xb11b55ea2b3980 " , 7 , " - 389461927286387 " ] ; testing_function " shift_right_logical " ; List . iter ( fun ( n , a , b , c ) -> test n ( shift_right_logical ( of_string a ) b ) ( of_string c ) ) [ 1 , " 2 " , 1 , " 1 " ; 2 , " 4 " , 2 , " 1 " ; 3 , " 0x10 " , 4 , " 1 " ; 4 , " 0x40000000 " , 10 , " 0x100000 " ; 5 , " 0x8000000000000000 " , 63 , " 1 " ; 6 , " 0xb11b55ea2b3980 " , 7 , " 0x16236ABD45673 " ; 7 , " - 0xb11b55ea2b3980 " , 7 , " 0x1fe9dc9542ba98d " ] ; testing_function " Comparisons " ; test 1 ( testcomp ( of_int 0 ) ( of_int 0 ) ) ( true , false , false , false , true , true , 0 , 0 ) ; test 2 ( testcomp ( of_int 1234567 ) ( of_int 1234567 ) ) ( true , false , false , false , true , true , 0 , 0 ) ; test 3 ( testcomp ( of_int 0 ) ( of_int 1 ) ) ( false , true , true , false , true , false , - 1 , - 1 ) ; test 4 ( testcomp ( of_int ( - 1 ) ) ( of_int 0 ) ) ( false , true , true , false , true , false , - 1 , 1 ) ; test 5 ( testcomp ( of_int 1 ) ( of_int 0 ) ) ( false , true , false , true , false , true , 1 , 1 ) ; test 6 ( testcomp ( of_int 0 ) ( of_int ( - 1 ) ) ) ( false , true , false , true , false , true , 1 , - 1 ) ; test 7 ( testcomp max_int min_int ) ( false , true , false , true , false , true , 1 , - 1 ) ; ( ) end
let testcomp_int32 ( a : int32 ) ( b : int32 ) = ( a = b , a <> b , a < b , a > b , a <= b , a >= b , compare a b , Int32 . unsigned_compare a b )
let testcomp_int64 ( a : int64 ) ( b : int64 ) = ( a = b , a <> b , a < b , a > b , a <= b , a >= b , compare a b , Int64 . unsigned_compare a b )
let testcomp_nativeint ( a : nativeint ) ( b : nativeint ) = ( a = b , a <> b , a < b , a > b , a <= b , a >= b , compare a b , Nativeint . unsigned_compare a b )
let _ = testing_function " -------- Int32 " ; -------- let module A = Test32 ( struct type t = int32 module Ops = Int32 let testcomp = testcomp_int32 let skip_float_tests = false end ) in print_newline ( ) ; testing_function " -------- Int64 " ; -------- let module B = Test64 ( struct type t = int64 module Ops = Int64 let testcomp = testcomp_int64 let skip_float_tests = false end ) in print_newline ( ) ; testing_function " -------- Nativeint " ; -------- begin match Sys . word_size with 32 -> let module C = Test32 ( struct type t = nativeint module Ops = Nativeint let testcomp = testcomp_nativeint let skip_float_tests = true end ) in ( ) | 64 -> let module C = Test64 ( struct type t = nativeint module Ops = Nativeint let testcomp = testcomp_nativeint let skip_float_tests = true end ) in ( ) | _ -> assert false end ; print_newline ( ) ; testing_function " --------- Conversions " ; ----------- testing_function " nativeint of / to int32 " ; test 1 ( Nativeint . of_int32 ( Int32 . of_string " 0x12345678 " ) ) ( Nativeint . of_string " 0x12345678 " ) ; test 2 ( Nativeint . to_int32 ( Nativeint . of_string " 0x12345678 " ) ) ( Int32 . of_string " 0x12345678 " ) ; if Sys . word_size = 64 then test 3 ( Nativeint . to_int32 ( Nativeint . of_string " 0x123456789ABCDEF0 " ) ) ( Int32 . of_string " 0x9ABCDEF0 " ) else test 3 0 0 ; testing_function " int64 of / to int32 " ; test 1 ( Int64 . of_int32 ( Int32 . of_string " - 0x12345678 " ) ) ( Int64 . of_string " - 0x12345678 " ) ; test 2 ( Int64 . to_int32 ( Int64 . of_string " - 0x12345678 " ) ) ( Int32 . of_string " - 0x12345678 " ) ; test 3 ( Int64 . to_int32 ( Int64 . of_string " 0x123456789ABCDEF0 " ) ) ( Int32 . of_string " 0x9ABCDEF0 " ) ; testing_function " int64 of / to nativeint " ; test 1 ( Int64 . of_nativeint ( Nativeint . of_string " 0x12345678 " ) ) ( Int64 . of_string " 0x12345678 " ) ; test 2 ( Int64 . to_nativeint ( Int64 . of_string " - 0x12345678 " ) ) ( Nativeint . of_string " - 0x12345678 " ) ; test 3 ( Int64 . to_nativeint ( Int64 . of_string " 0x123456789ABCDEF0 " ) ) ( if Sys . word_size = 64 then Nativeint . of_string " 0x123456789ABCDEF0 " else Nativeint . of_string " 0x9ABCDEF0 " )
let _ = print_newline ( ) ; if ! error_occurred then begin prerr_endline " ************* TEST FAILED " ; **************** exit 2 end else exit 0
type term = Var of int | Prop of head * term list { name : string ; mutable props : ( term * term ) list }
let rec print_term = function Var v -> print_string " v " ; print_int v | Prop ( head , argl ) -> print_string " ( " ; print_string head . name ; List . iter ( fun t -> print_string " " ; print_term t ) argl ; print_string " ) "
let lemmas = ref ( [ ] : head list )
let get name = let rec get_rec = function hd1 :: hdl -> if hd1 . name = name then hd1 else get_rec hdl | [ ] -> let entry = { name = name ; props = [ ] } in lemmas := entry :: ! lemmas ; entry in get_rec ! lemmas
let add_lemma = function | Prop ( _ , [ ( Prop ( headl , _ ) as left ) ; right ] ) -> headl . props <- ( left , right ) :: headl . props | _ -> assert false
type subst = Bind of int * term
let get_binding v list = let rec get_rec = function [ ] -> failwith " unbound " | Bind ( w , t ) :: rest -> if v = w then t else get_rec rest in get_rec list
let apply_subst alist term = let rec as_rec = function Var v -> begin try get_binding v alist with Failure _ -> term end | Prop ( head , argl ) -> Prop ( head , List . map as_rec argl ) in as_rec term
let rec unify term1 term2 = unify1 term1 term2 [ ] match term2 with Var v -> begin try if get_binding v unify_subst = term1 then unify_subst else raise Unify with Failure _ -> Bind ( v , term1 ) :: unify_subst end | Prop ( head2 , argl2 ) -> match term1 with Var _ -> raise Unify | Prop ( head1 , argl1 ) -> if head1 == head2 then unify1_lst argl1 argl2 unify_subst else raise Unify match ( l1 , l2 ) with ( [ ] , [ ] ) -> unify_subst | ( h1 :: r1 , h2 :: r2 ) -> unify1_lst r1 r2 ( unify1 h1 h2 unify_subst ) | _ -> raise Unify
let rec rewrite = function Var _ as term -> term | Prop ( head , argl ) -> rewrite_with_lemmas ( Prop ( head , List . map rewrite argl ) ) head . props match lemmas with [ ] -> term | ( t1 , t2 ) :: rest -> try rewrite ( apply_subst ( unify term t1 ) t2 ) with Unify -> rewrite_with_lemmas term rest
type cterm = CVar of int | CProp of string * cterm list
let rec cterm_to_term = function CVar v -> Var v | CProp ( p , l ) -> Prop ( get p , List . map cterm_to_term l )
let add t = add_lemma ( cterm_to_term t )
let _ = ( " equal " , [ CProp ( " compile " , [ CVar 5 ] ) ; CProp ( " reverse " , [ CProp ( " codegen " , [ CProp ( " optimize " , [ CVar 5 ] ) ; CProp ( " nil " , [ ] ) ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " eqp " , [ CVar 23 ; CVar 24 ] ) ; CProp ( " equal " , [ CProp ( " fix " , [ CVar 23 ] ) ; CProp ( " fix " , [ CVar 24 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " gt " , [ CVar 23 ; CVar 24 ] ) ; CProp ( " lt " , [ CVar 24 ; CVar 23 ] ) ] ) ) ; ( " equal " , [ CProp ( " le " , [ CVar 23 ; CVar 24 ] ) ; CProp ( " ge " , [ CVar 24 ; CVar 23 ] ) ] ) ) ; ( " equal " , [ CProp ( " ge " , [ CVar 23 ; CVar 24 ] ) ; CProp ( " le " , [ CVar 24 ; CVar 23 ] ) ] ) ) ; ( " equal " , [ CProp ( " boolean " , [ CVar 23 ] ) ; CProp ( " or " , [ CProp ( " equal " , [ CVar 23 ; CProp ( " true " , [ ] ) ] ) ; CProp ( " equal " , [ CVar 23 ; CProp ( " false " , [ ] ) ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " iff " , [ CVar 23 ; CVar 24 ] ) ; CProp ( " and " , [ CProp ( " implies " , [ CVar 23 ; CVar 24 ] ) ; CProp ( " implies " , [ CVar 24 ; CVar 23 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " even1 " , [ CVar 23 ] ) ; CProp ( " if " , [ CProp ( " zerop " , [ CVar 23 ] ) ; CProp ( " true " , [ ] ) ; CProp ( " odd " , [ CProp ( " sub1 " , [ CVar 23 ] ) ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " countps_ " , [ CVar 11 ; CVar 15 ] ) ; CProp ( " countps_loop " , [ CVar 11 ; CVar 15 ; CProp ( " zero " , [ ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " fact_ " , [ CVar 8 ] ) ; CProp ( " fact_loop " , [ CVar 8 ; CProp ( " one " , [ ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " reverse_ " , [ CVar 23 ] ) ; CProp ( " reverse_loop " , [ CVar 23 ; CProp ( " nil " , [ ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " divides " , [ CVar 23 ; CVar 24 ] ) ; CProp ( " zerop " , [ CProp ( " remainder " , [ CVar 24 ; CVar 23 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " assume_true " , [ CVar 21 ; CVar 0 ] ) ; CProp ( " cons " , [ CProp ( " cons " , [ CVar 21 ; CProp ( " true " , [ ] ) ] ) ; CVar 0 ] ) ] ) ) ; ( " equal " , [ CProp ( " assume_false " , [ CVar 21 ; CVar 0 ] ) ; CProp ( " cons " , [ CProp ( " cons " , [ CVar 21 ; CProp ( " false " , [ ] ) ] ) ; CVar 0 ] ) ] ) ) ; ( " equal " , [ CProp ( " tautology_checker " , [ CVar 23 ] ) ; CProp ( " tautologyp " , [ CProp ( " normalize " , [ CVar 23 ] ) ; CProp ( " nil " , [ ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " falsify " , [ CVar 23 ] ) ; CProp ( " falsify1 " , [ CProp ( " normalize " , [ CVar 23 ] ) ; CProp ( " nil " , [ ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " prime " , [ CVar 23 ] ) ; CProp ( " and " , [ CProp ( " not " , [ CProp ( " zerop " , [ CVar 23 ] ) ] ) ; CProp ( " not " , [ CProp ( " equal " , [ CVar 23 ; CProp ( " add1 " , [ CProp ( " zero " , [ ] ) ] ) ] ) ] ) ; CProp ( " prime1 " , [ CVar 23 ; CProp ( " sub1 " , [ CVar 23 ] ) ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " and " , [ CVar 15 ; CVar 16 ] ) ; CProp ( " if " , [ CVar 15 ; CProp ( " if " , [ CVar 16 ; CProp ( " true " , [ ] ) ; CProp ( " false " , [ ] ) ] ) ; CProp ( " false " , [ ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " or " , [ CVar 15 ; CVar 16 ] ) ; CProp ( " if " , [ CVar 15 ; CProp ( " true " , [ ] ) ; CProp ( " if " , [ CVar 16 ; CProp ( " true " , [ ] ) ; CProp ( " false " , [ ] ) ] ) ; CProp ( " false " , [ ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " not " , [ CVar 15 ] ) ; CProp ( " if " , [ CVar 15 ; CProp ( " false " , [ ] ) ; CProp ( " true " , [ ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " implies " , [ CVar 15 ; CVar 16 ] ) ; CProp ( " if " , [ CVar 15 ; CProp ( " if " , [ CVar 16 ; CProp ( " true " , [ ] ) ; CProp ( " false " , [ ] ) ] ) ; CProp ( " true " , [ ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " fix " , [ CVar 23 ] ) ; CProp ( " if " , [ CProp ( " numberp " , [ CVar 23 ] ) ; CVar 23 ; CProp ( " zero " , [ ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " if " , [ CProp ( " if " , [ CVar 0 ; CVar 1 ; CVar 2 ] ) ; CVar 3 ; CVar 4 ] ) ; CProp ( " if " , [ CVar 0 ; CProp ( " if " , [ CVar 1 ; CVar 3 ; CVar 4 ] ) ; CProp ( " if " , [ CVar 2 ; CVar 3 ; CVar 4 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " zerop " , [ CVar 23 ] ) ; CProp ( " or " , [ CProp ( " equal " , [ CVar 23 ; CProp ( " zero " , [ ] ) ] ) ; CProp ( " not " , [ CProp ( " numberp " , [ CVar 23 ] ) ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " plus " , [ CProp ( " plus " , [ CVar 23 ; CVar 24 ] ) ; CVar 25 ] ) ; CProp ( " plus " , [ CVar 23 ; CProp ( " plus " , [ CVar 24 ; CVar 25 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " equal " , [ CProp ( " plus " , [ CVar 0 ; CVar 1 ] ) ; CProp ( " zero " , [ ] ) ] ) ; CProp ( " and " , [ CProp ( " zerop " , [ CVar 0 ] ) ; CProp ( " zerop " , [ CVar 1 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " equal " , [ CProp ( " plus " , [ CVar 0 ; CVar 1 ] ) ; CProp ( " plus " , [ CVar 0 ; CVar 2 ] ) ] ) ; CProp ( " equal " , [ CProp ( " fix " , [ CVar 1 ] ) ; CProp ( " fix " , [ CVar 2 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " equal " , [ CProp ( " zero " , [ ] ) ; CProp ( " difference " , [ CVar 23 ; CVar 24 ] ) ] ) ; CProp ( " not " , [ CProp ( " gt " , [ CVar 24 ; CVar 23 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " equal " , [ CVar 23 ; CProp ( " difference " , [ CVar 23 ; CVar 24 ] ) ] ) ; CProp ( " and " , [ CProp ( " numberp " , [ CVar 23 ] ) ; CProp ( " or " , [ CProp ( " equal " , [ CVar 23 ; CProp ( " zero " , [ ] ) ] ) ; CProp ( " zerop " , [ CVar 24 ] ) ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " meaning " , [ CProp ( " plus_tree " , [ CProp ( " append " , [ CVar 23 ; CVar 24 ] ) ] ) ; CVar 0 ] ) ; CProp ( " plus " , [ CProp ( " meaning " , [ CProp ( " plus_tree " , [ CVar 23 ] ) ; CVar 0 ] ) ; CProp ( " meaning " , [ CProp ( " plus_tree " , [ CVar 24 ] ) ; CVar 0 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " meaning " , [ CProp ( " plus_tree " , [ CProp ( " plus_fringe " , [ CVar 23 ] ) ] ) ; CVar 0 ] ) ; CProp ( " fix " , [ CProp ( " meaning " , [ CVar 23 ; CVar 0 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " append " , [ CProp ( " append " , [ CVar 23 ; CVar 24 ] ) ; CVar 25 ] ) ; CProp ( " append " , [ CVar 23 ; CProp ( " append " , [ CVar 24 ; CVar 25 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " reverse " , [ CProp ( " append " , [ CVar 0 ; CVar 1 ] ) ] ) ; CProp ( " append " , [ CProp ( " reverse " , [ CVar 1 ] ) ; CProp ( " reverse " , [ CVar 0 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " times " , [ CVar 23 ; CProp ( " plus " , [ CVar 24 ; CVar 25 ] ) ] ) ; CProp ( " plus " , [ CProp ( " times " , [ CVar 23 ; CVar 24 ] ) ; CProp ( " times " , [ CVar 23 ; CVar 25 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " times " , [ CProp ( " times " , [ CVar 23 ; CVar 24 ] ) ; CVar 25 ] ) ; CProp ( " times " , [ CVar 23 ; CProp ( " times " , [ CVar 24 ; CVar 25 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " equal " , [ CProp ( " times " , [ CVar 23 ; CVar 24 ] ) ; CProp ( " zero " , [ ] ) ] ) ; CProp ( " or " , [ CProp ( " zerop " , [ CVar 23 ] ) ; CProp ( " zerop " , [ CVar 24 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " exec " , [ CProp ( " append " , [ CVar 23 ; CVar 24 ] ) ; CVar 15 ; CVar 4 ] ) ; CProp ( " exec " , [ CVar 24 ; CProp ( " exec " , [ CVar 23 ; CVar 15 ; CVar 4 ] ) ; CVar 4 ] ) ] ) ) ; ( " equal " , [ CProp ( " mc_flatten " , [ CVar 23 ; CVar 24 ] ) ; CProp ( " append " , [ CProp ( " flatten " , [ CVar 23 ] ) ; CVar 24 ] ) ] ) ) ; ( " equal " , [ CProp ( " member " , [ CVar 23 ; CProp ( " append " , [ CVar 0 ; CVar 1 ] ) ] ) ; CProp ( " or " , [ CProp ( " member " , [ CVar 23 ; CVar 0 ] ) ; CProp ( " member " , [ CVar 23 ; CVar 1 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " member " , [ CVar 23 ; CProp ( " reverse " , [ CVar 24 ] ) ] ) ; CProp ( " member " , [ CVar 23 ; CVar 24 ] ) ] ) ) ; ( " equal " , [ CProp ( " length " , [ CProp ( " reverse " , [ CVar 23 ] ) ] ) ; CProp ( " length " , [ CVar 23 ] ) ] ) ) ; ( " equal " , [ CProp ( " member " , [ CVar 0 ; CProp ( " intersect " , [ CVar 1 ; CVar 2 ] ) ] ) ; CProp ( " and " , [ CProp ( " member " , [ CVar 0 ; CVar 1 ] ) ; CProp ( " member " , [ CVar 0 ; CVar 2 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " exp " , [ CVar 8 ; CProp ( " plus " , [ CVar 9 ; CVar 10 ] ) ] ) ; CProp ( " times " , [ CProp ( " exp " , [ CVar 8 ; CVar 9 ] ) ; CProp ( " exp " , [ CVar 8 ; CVar 10 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " exp " , [ CVar 8 ; CProp ( " times " , [ CVar 9 ; CVar 10 ] ) ] ) ; CProp ( " exp " , [ CProp ( " exp " , [ CVar 8 ; CVar 9 ] ) ; CVar 10 ] ) ] ) ) ; ( " equal " , [ CProp ( " reverse_loop " , [ CVar 23 ; CVar 24 ] ) ; CProp ( " append " , [ CProp ( " reverse " , [ CVar 23 ] ) ; CVar 24 ] ) ] ) ) ; ( " equal " , [ CProp ( " reverse_loop " , [ CVar 23 ; CProp ( " nil " , [ ] ) ] ) ; CProp ( " reverse " , [ CVar 23 ] ) ] ) ) ; ( " equal " , [ CProp ( " count_list " , [ CVar 25 ; CProp ( " sort_lp " , [ CVar 23 ; CVar 24 ] ) ] ) ; CProp ( " plus " , [ CProp ( " count_list " , [ CVar 25 ; CVar 23 ] ) ; CProp ( " count_list " , [ CVar 25 ; CVar 24 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " equal " , [ CProp ( " append " , [ CVar 0 ; CVar 1 ] ) ; CProp ( " append " , [ CVar 0 ; CVar 2 ] ) ] ) ; CProp ( " equal " , [ CVar 1 ; CVar 2 ] ) ] ) ) ; ( " equal " , [ CProp ( " plus " , [ CProp ( " remainder " , [ CVar 23 ; CVar 24 ] ) ; CProp ( " times " , [ CVar 24 ; CProp ( " quotient " , [ CVar 23 ; CVar 24 ] ) ] ) ] ) ; CProp ( " fix " , [ CVar 23 ] ) ] ) ) ; ( " equal " , [ CProp ( " power_eval " , [ CProp ( " big_plus " , [ CVar 11 ; CVar 8 ; CVar 1 ] ) ; CVar 1 ] ) ; CProp ( " plus " , [ CProp ( " power_eval " , [ CVar 11 ; CVar 1 ] ) ; CVar 8 ] ) ] ) ) ; ( " equal " , [ CProp ( " power_eval " , [ CProp ( " big_plus " , [ CVar 23 ; CVar 24 ; CVar 8 ; CVar 1 ] ) ; CVar 1 ] ) ; CProp ( " plus " , [ CVar 8 ; CProp ( " plus " , [ CProp ( " power_eval " , [ CVar 23 ; CVar 1 ] ) ; CProp ( " power_eval " , [ CVar 24 ; CVar 1 ] ) ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " remainder " , [ CVar 24 ; CProp ( " one " , [ ] ) ] ) ; CProp ( " zero " , [ ] ) ] ) ) ; ( " equal " , [ CProp ( " lt " , [ CProp ( " remainder " , [ CVar 23 ; CVar 24 ] ) ; CVar 24 ] ) ; CProp ( " not " , [ CProp ( " zerop " , [ CVar 24 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " lt " , [ CProp ( " quotient " , [ CVar 8 ; CVar 9 ] ) ; CVar 8 ] ) ; CProp ( " and " , [ CProp ( " not " , [ CProp ( " zerop " , [ CVar 8 ] ) ] ) ; CProp ( " or " , [ CProp ( " zerop " , [ CVar 9 ] ) ; CProp ( " not " , [ CProp ( " equal " , [ CVar 9 ; CProp ( " one " , [ ] ) ] ) ] ) ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " lt " , [ CProp ( " remainder " , [ CVar 23 ; CVar 24 ] ) ; CVar 23 ] ) ; CProp ( " and " , [ CProp ( " not " , [ CProp ( " zerop " , [ CVar 24 ] ) ] ) ; CProp ( " not " , [ CProp ( " zerop " , [ CVar 23 ] ) ] ) ; CProp ( " not " , [ CProp ( " lt " , [ CVar 23 ; CVar 24 ] ) ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " power_eval " , [ CProp ( " power_rep " , [ CVar 8 ; CVar 1 ] ) ; CVar 1 ] ) ; CProp ( " fix " , [ CVar 8 ] ) ] ) ) ; ( " equal " , [ CProp ( " power_eval " , [ CProp ( " big_plus " , [ CProp ( " power_rep " , [ CVar 8 ; CVar 1 ] ) ; CProp ( " power_rep " , [ CVar 9 ; CVar 1 ] ) ; CProp ( " zero " , [ ] ) ; CVar 1 ] ) ; CVar 1 ] ) ; CProp ( " plus " , [ CVar 8 ; CVar 9 ] ) ] ) ) ; ( " equal " , [ CProp ( " gcd " , [ CVar 23 ; CVar 24 ] ) ; CProp ( " gcd " , [ CVar 24 ; CVar 23 ] ) ] ) ) ; ( " equal " , [ CProp ( " nth " , [ CProp ( " append " , [ CVar 0 ; CVar 1 ] ) ; CVar 8 ] ) ; CProp ( " append " , [ CProp ( " nth " , [ CVar 0 ; CVar 8 ] ) ; CProp ( " nth " , [ CVar 1 ; CProp ( " difference " , [ CVar 8 ; CProp ( " length " , [ CVar 0 ] ) ] ) ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " difference " , [ CProp ( " plus " , [ CVar 23 ; CVar 24 ] ) ; CVar 23 ] ) ; CProp ( " fix " , [ CVar 24 ] ) ] ) ) ; ( " equal " , [ CProp ( " difference " , [ CProp ( " plus " , [ CVar 24 ; CVar 23 ] ) ; CVar 23 ] ) ; CProp ( " fix " , [ CVar 24 ] ) ] ) ) ; ( " equal " , [ CProp ( " difference " , [ CProp ( " plus " , [ CVar 23 ; CVar 24 ] ) ; CProp ( " plus " , [ CVar 23 ; CVar 25 ] ) ] ) ; CProp ( " difference " , [ CVar 24 ; CVar 25 ] ) ] ) ) ; ( " equal " , [ CProp ( " times " , [ CVar 23 ; CProp ( " difference " , [ CVar 2 ; CVar 22 ] ) ] ) ; CProp ( " difference " , [ CProp ( " times " , [ CVar 2 ; CVar 23 ] ) ; CProp ( " times " , [ CVar 22 ; CVar 23 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " remainder " , [ CProp ( " times " , [ CVar 23 ; CVar 25 ] ) ; CVar 25 ] ) ; CProp ( " zero " , [ ] ) ] ) ) ; ( " equal " , [ CProp ( " difference " , [ CProp ( " plus " , [ CVar 1 ; CProp ( " plus " , [ CVar 0 ; CVar 2 ] ) ] ) ; CVar 0 ] ) ; CProp ( " plus " , [ CVar 1 ; CVar 2 ] ) ] ) ) ; ( " equal " , [ CProp ( " difference " , [ CProp ( " add1 " , [ CProp ( " plus " , [ CVar 24 ; CVar 25 ] ) ] ) ; CVar 25 ] ) ; CProp ( " add1 " , [ CVar 24 ] ) ] ) ) ; ( " equal " , [ CProp ( " lt " , [ CProp ( " plus " , [ CVar 23 ; CVar 24 ] ) ; CProp ( " plus " , [ CVar 23 ; CVar 25 ] ) ] ) ; CProp ( " lt " , [ CVar 24 ; CVar 25 ] ) ] ) ) ; ( " equal " , [ CProp ( " lt " , [ CProp ( " times " , [ CVar 23 ; CVar 25 ] ) ; CProp ( " times " , [ CVar 24 ; CVar 25 ] ) ] ) ; CProp ( " and " , [ CProp ( " not " , [ CProp ( " zerop " , [ CVar 25 ] ) ] ) ; CProp ( " lt " , [ CVar 23 ; CVar 24 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " lt " , [ CVar 24 ; CProp ( " plus " , [ CVar 23 ; CVar 24 ] ) ] ) ; CProp ( " not " , [ CProp ( " zerop " , [ CVar 23 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " gcd " , [ CProp ( " times " , [ CVar 23 ; CVar 25 ] ) ; CProp ( " times " , [ CVar 24 ; CVar 25 ] ) ] ) ; CProp ( " times " , [ CVar 25 ; CProp ( " gcd " , [ CVar 23 ; CVar 24 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " value " , [ CProp ( " normalize " , [ CVar 23 ] ) ; CVar 0 ] ) ; CProp ( " value " , [ CVar 23 ; CVar 0 ] ) ] ) ) ; ( " equal " , [ CProp ( " equal " , [ CProp ( " flatten " , [ CVar 23 ] ) ; CProp ( " cons " , [ CVar 24 ; CProp ( " nil " , [ ] ) ] ) ] ) ; CProp ( " and " , [ CProp ( " nlistp " , [ CVar 23 ] ) ; CProp ( " equal " , [ CVar 23 ; CVar 24 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " listp " , [ CProp ( " gother " , [ CVar 23 ] ) ] ) ; CProp ( " listp " , [ CVar 23 ] ) ] ) ) ; ( " equal " , [ CProp ( " samefringe " , [ CVar 23 ; CVar 24 ] ) ; CProp ( " equal " , [ CProp ( " flatten " , [ CVar 23 ] ) ; CProp ( " flatten " , [ CVar 24 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " equal " , [ CProp ( " greatest_factor " , [ CVar 23 ; CVar 24 ] ) ; CProp ( " zero " , [ ] ) ] ) ; CProp ( " and " , [ CProp ( " or " , [ CProp ( " zerop " , [ CVar 24 ] ) ; CProp ( " equal " , [ CVar 24 ; CProp ( " one " , [ ] ) ] ) ] ) ; CProp ( " equal " , [ CVar 23 ; CProp ( " zero " , [ ] ) ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " equal " , [ CProp ( " greatest_factor " , [ CVar 23 ; CVar 24 ] ) ; CProp ( " one " , [ ] ) ] ) ; CProp ( " equal " , [ CVar 23 ; CProp ( " one " , [ ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " numberp " , [ CProp ( " greatest_factor " , [ CVar 23 ; CVar 24 ] ) ] ) ; CProp ( " not " , [ CProp ( " and " , [ CProp ( " or " , [ CProp ( " zerop " , [ CVar 24 ] ) ; CProp ( " equal " , [ CVar 24 ; CProp ( " one " , [ ] ) ] ) ] ) ; CProp ( " not " , [ CProp ( " numberp " , [ CVar 23 ] ) ] ) ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " times_list " , [ CProp ( " append " , [ CVar 23 ; CVar 24 ] ) ] ) ; CProp ( " times " , [ CProp ( " times_list " , [ CVar 23 ] ) ; CProp ( " times_list " , [ CVar 24 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " prime_list " , [ CProp ( " append " , [ CVar 23 ; CVar 24 ] ) ] ) ; CProp ( " and " , [ CProp ( " prime_list " , [ CVar 23 ] ) ; CProp ( " prime_list " , [ CVar 24 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " equal " , [ CVar 25 ; CProp ( " times " , [ CVar 22 ; CVar 25 ] ) ] ) ; CProp ( " and " , [ CProp ( " numberp " , [ CVar 25 ] ) ; CProp ( " or " , [ CProp ( " equal " , [ CVar 25 ; CProp ( " zero " , [ ] ) ] ) ; CProp ( " equal " , [ CVar 22 ; CProp ( " one " , [ ] ) ] ) ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " ge " , [ CVar 23 ; CVar 24 ] ) ; CProp ( " not " , [ CProp ( " lt " , [ CVar 23 ; CVar 24 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " equal " , [ CVar 23 ; CProp ( " times " , [ CVar 23 ; CVar 24 ] ) ] ) ; CProp ( " or " , [ CProp ( " equal " , [ CVar 23 ; CProp ( " zero " , [ ] ) ] ) ; CProp ( " and " , [ CProp ( " numberp " , [ CVar 23 ] ) ; CProp ( " equal " , [ CVar 24 ; CProp ( " one " , [ ] ) ] ) ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " remainder " , [ CProp ( " times " , [ CVar 24 ; CVar 23 ] ) ; CVar 24 ] ) ; CProp ( " zero " , [ ] ) ] ) ) ; ( " equal " , [ CProp ( " equal " , [ CProp ( " times " , [ CVar 0 ; CVar 1 ] ) ; CProp ( " one " , [ ] ) ] ) ; CProp ( " and " , [ CProp ( " not " , [ CProp ( " equal " , [ CVar 0 ; CProp ( " zero " , [ ] ) ] ) ] ) ; CProp ( " not " , [ CProp ( " equal " , [ CVar 1 ; CProp ( " zero " , [ ] ) ] ) ] ) ; CProp ( " numberp " , [ CVar 0 ] ) ; CProp ( " numberp " , [ CVar 1 ] ) ; CProp ( " equal " , [ CProp ( " sub1 " , [ CVar 0 ] ) ; CProp ( " zero " , [ ] ) ] ) ; CProp ( " equal " , [ CProp ( " sub1 " , [ CVar 1 ] ) ; CProp ( " zero " , [ ] ) ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " lt " , [ CProp ( " length " , [ CProp ( " delete " , [ CVar 23 ; CVar 11 ] ) ] ) ; CProp ( " length " , [ CVar 11 ] ) ] ) ; CProp ( " member " , [ CVar 23 ; CVar 11 ] ) ] ) ) ; ( " equal " , [ CProp ( " sort2 " , [ CProp ( " delete " , [ CVar 23 ; CVar 11 ] ) ] ) ; CProp ( " delete " , [ CVar 23 ; CProp ( " sort2 " , [ CVar 11 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " length " , [ CProp ( " cons " , [ CVar 0 ; CProp ( " cons " , [ CVar 1 ; CProp ( " cons " , [ CVar 2 ; CProp ( " cons " , [ CVar 3 ; CProp ( " cons " , [ CVar 4 ; CProp ( " cons " , [ CVar 5 ; CVar 6 ] ) ] ) ] ) ] ) ] ) ] ) ] ) ; CProp ( " plus " , [ CProp ( " six " , [ ] ) ; CProp ( " length " , [ CVar 6 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " difference " , [ CProp ( " add1 " , [ CProp ( " add1 " , [ CVar 23 ] ) ] ) ; CProp ( " two " , [ ] ) ] ) ; CProp ( " fix " , [ CVar 23 ] ) ] ) ) ; ( " equal " , [ CProp ( " quotient " , [ CProp ( " plus " , [ CVar 23 ; CProp ( " plus " , [ CVar 23 ; CVar 24 ] ) ] ) ; CProp ( " two " , [ ] ) ] ) ; CProp ( " plus " , [ CVar 23 ; CProp ( " quotient " , [ CVar 24 ; CProp ( " two " , [ ] ) ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " sigma " , [ CProp ( " zero " , [ ] ) ; CVar 8 ] ) ; CProp ( " quotient " , [ CProp ( " times " , [ CVar 8 ; CProp ( " add1 " , [ CVar 8 ] ) ] ) ; CProp ( " two " , [ ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " plus " , [ CVar 23 ; CProp ( " add1 " , [ CVar 24 ] ) ] ) ; CProp ( " if " , [ CProp ( " numberp " , [ CVar 24 ] ) ; CProp ( " add1 " , [ CProp ( " plus " , [ CVar 23 ; CVar 24 ] ) ] ) ; CProp ( " add1 " , [ CVar 23 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " equal " , [ CProp ( " difference " , [ CVar 23 ; CVar 24 ] ) ; CProp ( " difference " , [ CVar 25 ; CVar 24 ] ) ] ) ; CProp ( " if " , [ CProp ( " lt " , [ CVar 23 ; CVar 24 ] ) ; CProp ( " not " , [ CProp ( " lt " , [ CVar 24 ; CVar 25 ] ) ] ) ; CProp ( " if " , [ CProp ( " lt " , [ CVar 25 ; CVar 24 ] ) ; CProp ( " not " , [ CProp ( " lt " , [ CVar 24 ; CVar 23 ] ) ] ) ; CProp ( " equal " , [ CProp ( " fix " , [ CVar 23 ] ) ; CProp ( " fix " , [ CVar 25 ] ) ] ) ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " meaning " , [ CProp ( " plus_tree " , [ CProp ( " delete " , [ CVar 23 ; CVar 24 ] ) ] ) ; CVar 0 ] ) ; CProp ( " if " , [ CProp ( " member " , [ CVar 23 ; CVar 24 ] ) ; CProp ( " difference " , [ CProp ( " meaning " , [ CProp ( " plus_tree " , [ CVar 24 ] ) ; CVar 0 ] ) ; CProp ( " meaning " , [ CVar 23 ; CVar 0 ] ) ] ) ; CProp ( " meaning " , [ CProp ( " plus_tree " , [ CVar 24 ] ) ; CVar 0 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " times " , [ CVar 23 ; CProp ( " add1 " , [ CVar 24 ] ) ] ) ; CProp ( " if " , [ CProp ( " numberp " , [ CVar 24 ] ) ; CProp ( " plus " , [ CVar 23 ; CProp ( " times " , [ CVar 23 ; CVar 24 ] ) ; CProp ( " fix " , [ CVar 23 ] ) ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " nth " , [ CProp ( " nil " , [ ] ) ; CVar 8 ] ) ; CProp ( " if " , [ CProp ( " zerop " , [ CVar 8 ] ) ; CProp ( " nil " , [ ] ) ; CProp ( " zero " , [ ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " last " , [ CProp ( " append " , [ CVar 0 ; CVar 1 ] ) ] ) ; CProp ( " if " , [ CProp ( " listp " , [ CVar 1 ] ) ; CProp ( " last " , [ CVar 1 ] ) ; CProp ( " if " , [ CProp ( " listp " , [ CVar 0 ] ) ; CProp ( " cons " , [ CProp ( " car " , [ CProp ( " last " , [ CVar 0 ] ) ] ) ; CVar 1 ] ) ; CVar 1 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " equal " , [ CProp ( " lt " , [ CVar 23 ; CVar 24 ] ) ; CVar 25 ] ) ; CProp ( " if " , [ CProp ( " lt " , [ CVar 23 ; CVar 24 ] ) ; CProp ( " equal " , [ CProp ( " true " , [ ] ) ; CVar 25 ] ) ; CProp ( " equal " , [ CProp ( " false " , [ ] ) ; CVar 25 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " assignment " , [ CVar 23 ; CProp ( " append " , [ CVar 0 ; CVar 1 ] ) ] ) ; CProp ( " if " , [ CProp ( " assignedp " , [ CVar 23 ; CVar 0 ] ) ; CProp ( " assignment " , [ CVar 23 ; CVar 0 ] ) ; CProp ( " assignment " , [ CVar 23 ; CVar 1 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " car " , [ CProp ( " gother " , [ CVar 23 ] ) ] ) ; CProp ( " if " , [ CProp ( " listp " , [ CVar 23 ] ) ; CProp ( " car " , [ CProp ( " flatten " , [ CVar 23 ] ) ] ) ; CProp ( " zero " , [ ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " flatten " , [ CProp ( " cdr " , [ CProp ( " gother " , [ CVar 23 ] ) ] ) ] ) ; CProp ( " if " , [ CProp ( " listp " , [ CVar 23 ] ) ; CProp ( " cdr " , [ CProp ( " flatten " , [ CVar 23 ] ) ] ) ; CProp ( " cons " , [ CProp ( " zero " , [ ] ) ; CProp ( " nil " , [ ] ) ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " quotient " , [ CProp ( " times " , [ CVar 24 ; CVar 23 ] ) ; CVar 24 ] ) ; CProp ( " if " , [ CProp ( " zerop " , [ CVar 24 ] ) ; CProp ( " zero " , [ ] ) ; CProp ( " fix " , [ CVar 23 ] ) ] ) ] ) ) ; ( " equal " , [ CProp ( " get " , [ CVar 9 ; CProp ( " set " , [ CVar 8 ; CVar 21 ; CVar 12 ] ) ] ) ; CProp ( " if " , [ CProp ( " eqp " , [ CVar 9 ; CVar 8 ] ) ; CVar 21 ; CProp ( " get " , [ CVar 9 ; CVar 12 ] ) ] ) ] ) )
let truep x lst = match x with Prop ( head , _ ) -> head . name = " true " || List . mem x lst | _ -> List . mem x lst match x with Prop ( head , _ ) -> head . name = " false " || List . mem x lst | _ -> List . mem x lst
let rec tautologyp x true_lst false_lst = if truep x true_lst then true else if falsep x false_lst then false else begin match x with Var _ -> false | Prop ( head , [ test ; yes ; no ] ) -> if head . name = " if " then if truep test true_lst then tautologyp yes true_lst false_lst else if falsep test false_lst then tautologyp no true_lst false_lst else tautologyp yes ( test :: true_lst ) false_lst && tautologyp no true_lst ( test :: false_lst ) else false | _ -> assert false end
let tautp x = let y = rewrite x in tautologyp y [ ] [ ]
let subst = CProp ( " f " , [ CProp ( " plus " , [ CProp ( " plus " , [ CVar 0 ; CVar 1 ] ) ; CProp ( " plus " , [ CVar 2 ; CProp ( " zero " , [ ] ) ] ) ] ) ] ) ) ) ; Bind ( 24 , cterm_to_term ( CProp ( " f " , [ CProp ( " times " , [ CProp ( " times " , [ CVar 0 ; CVar 1 ] ) ; CProp ( " plus " , [ CVar 2 ; CVar 3 ] ) ] ) ] ) ) ) ; Bind ( 25 , cterm_to_term ( CProp ( " f " , [ CProp ( " reverse " , [ CProp ( " append " , [ CProp ( " append " , [ CVar 0 ; CVar 1 ] ) ; CProp ( " nil " , [ ] ) ] ) ] ) ] ) ) ) ; Bind ( 20 , cterm_to_term ( CProp ( " equal " , [ CProp ( " plus " , [ CVar 0 ; CVar 1 ] ) ; CProp ( " difference " , [ CVar 23 ; CVar 24 ] ) ] ) ) ) ; Bind ( 22 , cterm_to_term ( CProp ( " lt " , [ CProp ( " remainder " , [ CVar 0 ; CVar 1 ] ) ; CProp ( " member " , [ CVar 0 ; CProp ( " length " , [ CVar 1 ] ) ] ) ] ) ) ) ]
let term = cterm_to_term ( CProp ( " implies " , [ CProp ( " and " , [ CProp ( " implies " , [ CVar 23 ; CVar 24 ] ) ; CProp ( " and " , [ CProp ( " implies " , [ CVar 24 ; CVar 25 ] ) ; CProp ( " and " , [ CProp ( " implies " , [ CVar 25 ; CVar 20 ] ) ; CProp ( " implies " , [ CVar 20 ; CVar 22 ] ) ] ) ] ) ] ) ; CProp ( " implies " , [ CVar 23 ; CVar 22 ] ) ] ) )
let _ = let ok = ref true in for i = 1 to 50 do if not ( tautp ( apply_subst subst term ) ) then ok := false done ; if ! ok then print_string " Proved !\ n " else print_string " Cannot prove !\ n " ; exit 0
module Make ( T : Branch_relaxation_intf . S ) = struct let label_map code = let map = Hashtbl . create 37 in let rec fill_map pc instr = match instr . desc with | Lend -> ( pc , map ) | Llabel lbl -> Hashtbl . add map lbl pc ; fill_map pc instr . next | op -> fill_map ( pc + T . instr_size op ) instr . next in fill_map 0 code let branch_overflows map pc_branch lbl_dest max_branch_offset = let pc_dest = Hashtbl . find map lbl_dest in let delta = pc_dest - ( pc_branch + T . offset_pc_at_branch ) in delta <= - max_branch_offset || delta >= max_branch_offset let opt_branch_overflows map pc_branch opt_lbl_dest max_branch_offset = match opt_lbl_dest with | None -> false | Some lbl_dest -> branch_overflows map pc_branch lbl_dest max_branch_offset let instr_overflows ~ code_size ~ max_out_of_line_code_offset instr map pc = match T . Cond_branch . classify_instr instr . desc with | None -> false | Some branch -> let max_branch_offset = T . Cond_branch . max_displacement branch - 12 in match instr . desc with | Lop ( Ialloc _ ) | Lop ( Iintop ( Icheckbound ) ) | Lop ( Iintop_imm ( Icheckbound , _ ) ) | Lop ( Ispecific _ ) -> code_size + max_out_of_line_code_offset - pc >= max_branch_offset | Lcondbranch ( _ , lbl ) -> branch_overflows map pc lbl max_branch_offset | Lcondbranch3 ( lbl0 , lbl1 , lbl2 ) -> opt_branch_overflows map pc lbl0 max_branch_offset || opt_branch_overflows map pc lbl1 max_branch_offset || opt_branch_overflows map pc lbl2 max_branch_offset | _ -> Misc . fatal_error " Unsupported instruction for branch relaxation " let fixup_branches ~ code_size ~ max_out_of_line_code_offset map code = let expand_optbranch lbl n arg next = match lbl with | None -> next | Some l -> instr_cons ( Lcondbranch ( Iinttest_imm ( Isigned Cmm . Ceq , n ) , l ) ) arg [ ] || next in let rec fixup did_fix pc instr = match instr . desc with | Lend -> did_fix | _ -> let overflows = instr_overflows ~ code_size ~ max_out_of_line_code_offset instr map pc in if not overflows then fixup did_fix ( pc + T . instr_size instr . desc ) instr . next else match instr . desc with | Lop ( Ialloc { bytes = num_bytes ; dbginfo } ) -> instr . desc <- T . relax_allocation ~ num_bytes ~ dbginfo ; fixup true ( pc + T . instr_size instr . desc ) instr . next | Lop ( Iintop ( Icheckbound ) ) -> instr . desc <- T . relax_intop_checkbound ( ) ; fixup true ( pc + T . instr_size instr . desc ) instr . next | Lop ( Iintop_imm ( Icheckbound , bound ) ) -> instr . desc <- T . relax_intop_imm_checkbound ~ bound ; fixup true ( pc + T . instr_size instr . desc ) instr . next | Lop ( Ispecific specific ) -> instr . desc <- T . relax_specific_op specific ; fixup true ( pc + T . instr_size instr . desc ) instr . next | Lcondbranch ( test , lbl ) -> let lbl2 = Cmm . new_label ( ) in let cont = instr_cons ( Lbranch lbl ) [ ] || [ ] || ( instr_cons ( Llabel lbl2 ) [ ] || [ ] || instr . next ) in instr . desc <- Lcondbranch ( invert_test test , lbl2 ) ; instr . next <- cont ; fixup true ( pc + T . instr_size instr . desc ) instr . next | Lcondbranch3 ( lbl0 , lbl1 , lbl2 ) -> let cont = expand_optbranch lbl0 0 instr . arg ( expand_optbranch lbl1 1 instr . arg ( expand_optbranch lbl2 2 instr . arg instr . next ) ) in instr . desc <- cont . desc ; instr . next <- cont . next ; fixup true pc instr | _ -> assert false in fixup false 0 code let rec relax code ~ max_out_of_line_code_offset = let min_of_max_branch_offsets = List . fold_left ( fun min_of_max_branch_offsets branch -> min min_of_max_branch_offsets ( T . Cond_branch . max_displacement branch ) ) max_int T . Cond_branch . all in let ( code_size , map ) = label_map code in if code_size >= min_of_max_branch_offsets && fixup_branches ~ code_size ~ max_out_of_line_code_offset map code then relax code ~ max_out_of_line_code_offset else ( ) end
module type S = sig type distance = int module Cond_branch : sig type t val all : t list val max_displacement : t -> distance val classify_instr : Linear . instruction_desc -> t option end val offset_pc_at_branch : distance val instr_size : Linear . instruction_desc -> distance val relax_allocation : num_bytes : int -> dbginfo : Debuginfo . alloc_dbginfo -> Linear . instruction_desc val relax_intop_checkbound : unit -> Linear . instruction_desc val relax_intop_imm_checkbound : bound : int -> Linear . instruction_desc val relax_specific_op : Arch . specific_operation -> Linear . instruction_desc end
let debug_breakpoints = ref false
let breakpoint_number = ref 0
let breakpoints = ref ( [ ] : ( breakpoint_id * code_event ) list )
let positions = ref ( [ ] : ( pc * int ref ) list )
let current_version = ref 0
let max_version = ref 0
let copy_breakpoints ( ) = ! current_checkpoint . c_breakpoints <- ! positions ; ! current_checkpoint . c_breakpoint_version <- ! current_version
let new_version ( ) = incr max_version ; current_version := ! max_version
let breakpoints_count ( ) = List . length ! breakpoints
let rec breakpoints_at_pc pc = begin match Symbols . event_at_pc pc with | { ev_frag = frag ; ev_ev = { ev_repr = Event_child { contents = pos } } } -> breakpoints_at_pc { frag ; pos } | _ -> [ ] | exception Not_found -> [ ] end @ List . map fst ( List . filter ( function ( _ , { ev_frag = frag ; ev_ev = { ev_pos = pos } } ) -> { frag ; pos } = pc ) ! breakpoints )
let breakpoint_at_pc pc = breakpoints_at_pc pc <> [ ]
let print_pc out { frag ; pos } = fprintf out " % d :% d " frag pos
let remove_breakpoints pcs = if ! debug_breakpoints then printf " Removing breakpoints . . . \ n " ; %! List . iter ( function ( pc , _ ) -> if ! debug_breakpoints then printf " % a \ n " %! print_pc pc ; reset_instr pc ; Symbols . set_event_at_pc pc ) pcs
let set_breakpoints pcs = if ! debug_breakpoints then printf " Setting breakpoints . . . \ n " ; %! List . iter ( function ( pc , _ ) -> if ! debug_breakpoints then printf " % a \ n " %! print_pc pc ; set_breakpoint pc ) pcs
let update_breakpoints ( ) = if ! debug_breakpoints then begin prerr_string " Updating breakpoints . . . " ; prerr_int ! current_checkpoint . c_breakpoint_version ; prerr_string " " ; prerr_int ! current_version ; prerr_endline " " end ; if ! current_checkpoint . c_breakpoint_version <> ! current_version then Exec . protect ( function ( ) -> remove_breakpoints ! current_checkpoint . c_breakpoints ; set_breakpoints ! positions ; copy_breakpoints ( ) )
let execute_without_breakpoints f = Misc . protect_refs [ Misc . R ( Debugger_config . break_on_load , false ) ; Misc . R ( current_version , 0 ) ; Misc . R ( positions , [ ] ) ; Misc . R ( breakpoints , [ ] ) ; Misc . R ( breakpoint_number , 0 ) ] f
let insert_position pos = try incr ( List . assoc pos ! positions ) with Not_found -> positions := ( pos , ref 1 ) :: ! positions ; new_version ( )
let remove_position pos = let count = List . assoc pos ! positions in decr count ; if ! count = 0 then begin positions := List . remove_assoc pos ! positions ; new_version ( ) end
let rec new_breakpoint event = match event with { ev_frag = frag ; ev_ev { = ev_repr = Event_child pos } } -> new_breakpoint ( Symbols . any_event_at_pc { frag ; pos ( =! pos ) } ) | { ev_frag = frag ; ev_ev { = ev_pos = pos } } -> let pc = { frag ; pos } in Exec . protect ( function ( ) -> incr breakpoint_number ; insert_position pc ; breakpoints := ( ! breakpoint_number , event ) :: ! breakpoints ) ; if ! Parameters . breakpoint then printf " Breakpoint % d at % a : % s \ n " %! ! breakpoint_number print_pc pc ( Pos . get_desc event )
let remove_breakpoint number = try let ev = List . assoc number ! breakpoints in let pc = { frag = ev . ev_frag ; pos = ev . ev_ev . ev_pos } in Exec . protect ( function ( ) -> breakpoints := List . remove_assoc number ! breakpoints ; remove_position pc ; if ! Parameters . breakpoint then printf " Removed breakpoint % d at % a : % s \ n " %! number print_pc pc ( Pos . get_desc ev ) ) with Not_found -> prerr_endline ( " No breakpoint number " ^ ( Int . to_string number ) ^ " . " ) ; raise Not_found
let remove_all_breakpoints ( ) = List . iter ( function ( number , _ ) -> remove_breakpoint number ) ! breakpoints
let temporary_breakpoint_position = ref ( None : pc option )
let exec_with_temporary_breakpoint pc funct = let previous_version = ! current_version in let remove ( ) = temporary_breakpoint_position := None ; current_version := previous_version ; let count = List . assoc pc ! positions in decr count ; if ! count = 0 then begin positions := List . remove_assoc pc ! positions ; reset_instr pc ; Symbols . set_event_at_pc pc end in Exec . protect ( function ( ) -> insert_position pc ) ; temporary_breakpoint_position := Some pc ; Fun . protect ~ finally ( : fun ( ) -> Exec . protect remove ) funct
module Ev = struct type ' a type ' = Jstr . t module Type = struct type void type ' a t = ' a type ' external create : Jstr . t -> ' a t = " % identity " external name : ' a t -> Jstr . t = " % identity " external void : Jstr . t -> ' a t = " % identity " end type void = Type . void type ' type init = Jv . t let init ? bubbles ? cancelable ? composed ( ) = let o = Jv . obj [ ] || in Jv . Bool . set_if_some o " bubbles " bubbles ; Jv . Bool . set_if_some o " cancelable " cancelable ; Jv . Bool . set_if_some o " composed " composed ; o type target = Jv . t external target_to_jv : target -> ' a = " % identity " external target_of_jv : ' a -> target = " % identity " type ' a t = Jv . t type ' a event = ' a t external to_jv : ' a t -> Jv . t = " % identity " external of_jv : Jv . t -> ' a t = " % identity " let event = Jv . get Jv . global " Event " let create ( ? init = Jv . obj [ ] ) || t = Jv . new ' event Jv . [ | of_jstr t ; init ] | external as_type : ' a t -> ' a = " % identity " let type ' e = Jv . Jstr . get e " type " let target e = Jv . get e " target " let current_target e = Jv . get e " currentTarget " let composed_path e = Jv . to_list target_of_jv ( Jv . call e " composedPath " [ ] ) || let event_phase e = match Jv . Int . get e " eventPhase " with | 1 -> ` Capturing | 2 -> ` At_target | 3 -> ` Bubbling | _ -> ` None let bubbles e = Jv . Bool . get e " bubbles " let stop_propagation e = ignore @@ Jv . call e " stopPropagation " [ ] || let stop_immediate_propagation e = ignore @@ Jv . call e " stopImmediatePropagation " [ ] || let cancelable e = Jv . Bool . get e " cancelable " let prevent_default e = ignore @@ Jv . call e " preventDefault " [ ] || let default_prevented e = Jv . Bool . get e " defaultPrevented " let composed e = Jv . Bool . get e " composed " let is_trusted e = Jv . Bool . get e " isTrusted " let timestamp_ms e = Jv . Float . get e " timeStamp " let dispatch e t = Jv . to_bool @@ Jv . call t " dispatchEvent " [ | e ] | type listen_opts = Jv . t let listen_opts ? capture ? once ? passive ( ) = let o = Jv . obj [ ] || in Jv . Bool . set_if_some o " capture " capture ; Jv . Bool . set_if_some o " once " once ; Jv . Bool . set_if_some o " passive " passive ; o let listen ( ? opts = Jv . obj [ ] ) || type ' f t = ignore @@ Jv . call t " addEventListener " [ | Jv . of_jstr type ' ; Jv . repr f ; opts ] | let unlisten ( ? opts = Jv . obj [ ] ) || type ' f t = ignore @@ Jv . call t " removeEventListener " [ | Jv . of_jstr type ' ; Jv . repr f ; opts ] | let next ? capture type ' t = let fut , set = Fut . create ( ) in let opts = listen_opts ? capture ~ once : true ( ) in listen ~ opts type ' set t ; fut module Data_transfer = struct module Effect = struct type t = Jstr . t let none = Jstr . v " none " let copy = Jstr . v " copy " let copy_link = Jstr . v " copyLink " let copy_move = Jstr . v " copyMove " let link = Jstr . v " link " let link_move = Jstr . v " linkMove " let move = Jstr . v " move " let all = Jstr . v " all " let uninitialized = Jstr . v " uninitialized " end module Item = struct module Kind = struct type t = Jstr . t let file = Jstr . v " file " let string = Jstr . v " string " end type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let kind i = Jv . Jstr . get i " kind " let type ' i = Jv . Jstr . get i " type " let get_file i = Jv . to_option Fun . id ( Jv . call i " getAsFile " [ ] ) || let get_jstr i = let str , set_str = Fut . create ( ) in ignore ( Jv . call i " getAsString " [ | Jv . repr set_str ] ) ; | str end module Item_list = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let length l = Jv . Int . get l " length " let add_jstr l ~ type ' str = Jv . to_option Item . of_jv @@ Jv . call l " add " Jv . [ | of_jstr str ; of_jstr type ' ] | let add_file t file = Jv . to_option Item . of_jv @@ Jv . call t " add " Jv . [ | file ] | let remove l i = ignore ( Jv . call l " remove " Jv . [ | of_int i ] ) | let clear l = ignore ( Jv . call l " clear " [ ] ) || external item : t -> int -> Item . t = " caml_js_get " let items l = let acc = ref [ ] in for i = length l - 1 downto 0 do acc := item l i :: ! acc done ; ! acc end type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let drop_effect d = Jv . Jstr . get d " dropEffect " let set_drop_effect d e = Jv . Jstr . set d " dropEffect " e let effect_allowed d = Jv . Jstr . get d " effectAllowed " let set_effect_allowed d e = Jv . Jstr . set d " effectAllowed " e let items d = Item_list . of_jv @@ Jv . get d " items " end module Clipboard = struct type t = Jv . t let data c = Jv . find_map Data_transfer . of_jv c " clipboardData " end module Composition = struct type t = Jv . t let data i = Jv . Jstr . get i " data " end module Error = struct type t = Jv . t let message e = Jv . Jstr . get e " message " let filename e = Jv . Jstr . get e " filename " let lineno e = Jv . Int . get e " lineno " let colno e = Jv . Int . get e " colno " let error e = Jv . get e " error " end module Extendable = struct type t = Jv . t let wait_until e fut = ignore @@ Jv . call e " waitUntil " [ | Fut . to_promise ~ ok : Jv . repr fut ] | end module Focus = struct type t = Jv . t let related_target m = Jv . find_map target_of_jv m " relatedTarget " end module Hash_change = struct type t = Jv . t let old_url e = Jv . Jstr . get e " oldURL " let new_url e = Jv . Jstr . get e " newURL " end module Input = struct type t = Jv . t let data i = Jv . Jstr . get i " data " let data_transfer i = Jv . find i " dataTransfer " let input_type i = Jv . Jstr . get i " inputType " let is_composing i = Jv . Bool . get i " isComposing " end module Keyboard = struct module Location = struct type t = int let standard = 0x00 let left = 0x01 let right = 0x02 let numpad = 0x03 end type t = Jv . t let key k = Jv . Jstr . get k " key " let code k = Jv . Jstr . get k " code " let location k = Jv . Int . get k " location " let repeat k = Jv . Bool . get k " repeat " let is_composing k = Jv . Bool . get k " isComposing " let alt_key k = Jv . Bool . get k " altKey " let ctrl_key k = Jv . Bool . get k " ctrlKey " let shift_key k = Jv . Bool . get k " shiftKey " let meta_key k = Jv . Bool . get k " metaKey " let get_modifier_state k key = Jv . to_bool @@ Jv . call k " getModifierState " Jv . [ | of_jstr key ] | end module Mouse = struct type t = Jv . t let related_target m = Jv . find_map target_of_jv m " relatedTarget " let offset_x m = Jv . Float . get m " offsetX " let offset_y m = Jv . Float . get m " offsetY " let client_x m = Jv . Float . get m " clientX " let client_y m = Jv . Float . get m " clientY " let page_x m = Jv . Float . get m " pageX " let page_y m = Jv . Float . get m " pageY " let screen_x m = Jv . Float . get m " screenX " let screen_y m = Jv . Float . get m " screenY " let movement_x m = Jv . Float . get m " movementX " let movement_y m = Jv . Float . get m " movementY " let button m = Jv . Int . get m " button " let buttons m = Jv . Int . get m " buttons " let alt_key m = Jv . Bool . get m " altKey " let ctrl_key m = Jv . Bool . get m " ctrlKey " let shift_key m = Jv . Bool . get m " shiftKey " let meta_key m = Jv . Bool . get m " metaKey " let get_modifier_state m key = Jv . to_bool @@ Jv . call m " getModifierState " Jv . [ | of_jstr key ] | end module Drag = struct type t = Jv . t external as_mouse : t -> Mouse . t = " % identity " let data_transfer d = Jv . find_map Fun . id d " dataTransfer " end module Pointer = struct type ' a event = ' a t type t = Jv . t external as_mouse : t -> Mouse . t = " % identity " let id p = Jv . Int . get p " pointerId " let width p = Jv . Float . get p " width " let height p = Jv . Float . get p " height " let pressure p = Jv . Float . get p " pressure " let tangential_pressure p = Jv . Float . get p " tangentialPressure " let tilt_x p = Jv . Int . get p " tiltX " let tilt_y p = Jv . Int . get p " tiltY " let twist p = Jv . Int . get p " twist " let altitude_angle p = Jv . Float . get p " altitudeAngle " let azimuth_angle p = Jv . Float . get p " azimuthAngle " let type ' p = Jv . Jstr . get p " pointerType " let is_primary p = Jv . Bool . get p " isPrimary " let get_coalesced_events p = Jv . to_list Fun . id ( Jv . call p " getCoalescedEvents " [ ] ) || let get_predicted_events p = Jv . to_list Fun . id ( Jv . call p " getPredictedEvents " [ ] ) || end module Wheel = struct module Delta_mode = struct type t = int let pixel = 0x00 let line = 0x01 let page = 0x02 end type t = Jv . t external as_mouse : t -> Mouse . t = " % identity " let delta_x w = Jv . Float . get w " deltaX " let delta_y w = Jv . Float . get w " deltaY " let delta_z w = Jv . Float . get w " deltaZ " let delta_mode w = Jv . Int . get w " deltaMode " end let abort = Type . void ( Jstr . v " abort " ) let activate = Type . create ( Jstr . v " activate " ) let auxclick = Type . create ( Jstr . v " dblclick " ) let beforeinput = Type . create ( Jstr . v " beforeinput " ) let beforeunload = Type . create ( Jstr . v " beforeunload " ) let blur = Type . create ( Jstr . v " blur " ) let canplay = Type . void ( Jstr . v " canplay " ) let canplaythrough = Type . void ( Jstr . v " canplaythrough " ) let change = Type . void ( Jstr . v " change " ) let click = Type . create ( Jstr . v " click " ) let clipboardchange = Type . create ( Jstr . v " clipboardchange " ) let close = Type . void ( Jstr . v " close " ) let compositionend = Type . create ( Jstr . v " compositionend " ) let compositionstart = Type . create ( Jstr . v " compositionstart " ) let compositionudpate = Type . create ( Jstr . v " compositionupdate " ) let controllerchange = Type . create ( Jstr . v " controllerchange " ) let copy = Type . create ( Jstr . v " copy " ) let cut = Type . create ( Jstr . v " cut " ) let dblclick = Type . create ( Jstr . v " dblclick " ) let dom_content_loaded = Type . void ( Jstr . v " DOMContentLoaded " ) let drag = Type . create ( Jstr . v " drag " ) let dragend = Type . create ( Jstr . v " dragend " ) let dragenter = Type . create ( Jstr . v " dragenter " ) let dragexit = Type . create ( Jstr . v " dragexit " ) let dragleave = Type . create ( Jstr . v " dragleave " ) let dragover = Type . create ( Jstr . v " dragover " ) let dragstart = Type . create ( Jstr . v " dragstart " ) let drop = Type . create ( Jstr . v " drop " ) let durationchange = Type . void ( Jstr . v " durationchange " ) let emptied = Type . void ( Jstr . v " emptied " ) let ended = Type . void ( Jstr . v " ended " ) let error = Type . create ( Jstr . v " error " ) let focus = Type . create ( Jstr . v " focus " ) let focusin = Type . create ( Jstr . v " focusin " ) let focusout = Type . create ( Jstr . v " focusout " ) let fullscreenchange = Type . create ( Jstr . v " fullscreenchange " ) let fullscreenerror = Type . create ( Jstr . v " fullscreenerror " ) let gotpointercapture = Type . create ( Jstr . v " gotpointercapture " ) let hashchange = Type . create ( Jstr . v " hashchange " ) let input = Type . create ( Jstr . v " input " ) let install = Type . create ( Jstr . v " install " ) let keydown = Type . create ( Jstr . v " keydown " ) let keyup = Type . create ( Jstr . v " keyup " ) let languagechange = Type . void ( Jstr . v " languagechange " ) let load = Type . void ( Jstr . v " load " ) let loadeddata = Type . void ( Jstr . v " loadeddata " ) let loadedmetadata = Type . void ( Jstr . v " loadedmetadata " ) let loadstart = Type . void ( Jstr . v " loadstart " ) let lostpointercapture = Type . create ( Jstr . v " lostpointercapture " ) let mousedown = Type . create ( Jstr . v " mousedown " ) let mouseenter = Type . create ( Jstr . v " mouseenter " ) let mouseleave = Type . create ( Jstr . v " mouseleave " ) let mousemove = Type . create ( Jstr . v " mousemove " ) let mouseout = Type . create ( Jstr . v " mouseout " ) let mouseover = Type . create ( Jstr . v " mouseover " ) let mouseup = Type . create ( Jstr . v " mouseup " ) let open ' = Type . void ( Jstr . v " open " ) let paste = Type . create ( Jstr . v " paste " ) let pause = Type . void ( Jstr . v " pause " ) let play = Type . void ( Jstr . v " play " ) let playing = Type . void ( Jstr . v " playing " ) let pointercancel = Type . create ( Jstr . v " pointercancel " ) let pointerdown = Type . create ( Jstr . v " pointerdown " ) let pointerenter = Type . create ( Jstr . v " pointerenter " ) let pointerleave = Type . create ( Jstr . v " pointerleave " ) let pointerlockchange = Type . create ( Jstr . v " pointerlockchange " ) let pointerlockerror = Type . create ( Jstr . v " pointerlockerror " ) let pointermove = Type . create ( Jstr . v " pointermove " ) let pointerout = Type . create ( Jstr . v " pointerout " ) let pointerover = Type . create ( Jstr . v " pointerover " ) let pointerrawupdate = Type . create ( Jstr . v " pointerrawupdate " ) let pointerup = Type . create ( Jstr . v " pointerup " ) let progress = Type . void ( Jstr . v " progress " ) let ratechange = Type . void ( Jstr . v " ratechange " ) let reset = Type . void ( Jstr . v " reset " ) let resize = Type . void ( Jstr . v " resize " ) let scroll = Type . create ( Jstr . v " scroll " ) let seeked = Type . void ( Jstr . v " seeked " ) let seeking = Type . void ( Jstr . v " seeking " ) let select = Type . void ( Jstr . v " select " ) let stalled = Type . void ( Jstr . v " stalled " ) let statechange = Type . void ( Jstr . v " statechange " ) let suspend = Type . void ( Jstr . v " suspend " ) let timeupdate = Type . void ( Jstr . v " timeupdate " ) let unload = Type . void ( Jstr . v " unload " ) let updatefound = Type . void ( Jstr . v " updatefound " ) let visibilitychange = Type . void ( Jstr . v " visibilitychange " ) let volumechange = Type . void ( Jstr . v " volumechange " ) let waiting = Type . void ( Jstr . v " waiting " ) let wheel = Type . create ( Jstr . v " wheel " ) end
module Tarray = struct module Buffer = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let array_buffer = Jv . get Jv . global " ArrayBuffer " let create n = Jv . new ' array_buffer Jv . [ | of_int n ] | let byte_length a = Jv . Int . get a " byteLength " let slice ( ? start = 0 ) ? stop a = let stop = match stop with None -> byte_length a | Some stop -> stop in Jv . call a " slice " Jv . [ | of_int start ; of_int stop ] | end let buffer o = Buffer . of_jv @@ Jv . get o " buffer " let byte_offset o = Jv . Int . get o " byteOffset " let byte_length o = Jv . Int . get o " byteLength " module Data_view = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let dataview = Jv . get Jv . global " DataView " let of_buffer ( ? byte_offset = 0 ) ? byte_length b = let byte_length = match byte_length with | None -> Buffer . byte_length b | Some l -> l in Jv . new ' dataview Jv . [ | Buffer . to_jv b ; of_int byte_offset ; of_int byte_length ] | let buffer = buffer let byte_offset = byte_offset let byte_length = byte_length let get_int8 b i = Jv . to_int @@ Jv . call b " getInt8 " Jv . [ | of_int i ] | let get_int16_be b i = Jv . to_int @@ Jv . call b " getInt16 " Jv . [ | of_int i ] | let get_int16_le b i = Jv . to_int @@ Jv . call b " getInt16 " Jv . [ | of_int i ; Jv . true ' ] | let get_int32_be b i = Obj . magic @@ Jv . call b " getInt32 " Jv . [ | of_int i ] | let get_int32_le b i = Obj . magic @@ Jv . call b " getInt32 " Jv . [ | of_int i ; Jv . true ' ] | let get_uint8 b i = Jv . to_int @@ Jv . call b " getUint8 " Jv . [ | of_int i ] | let get_uint16_be b i = Jv . to_int @@ Jv . call b " getUint16 " Jv . [ | of_int i ] | let get_uint16_le b i = Jv . to_int @@ Jv . call b " getUint16 " Jv . [ | of_int i ; Jv . true ' ] | let get_uint32_be b i = Obj . magic @@ Jv . call b " getUint32 " Jv . [ | of_int i ] | let get_uint32_le b i = Obj . magic @@ Jv . call b " getUint32 " Jv . [ | of_int i ; Jv . true ' ] | let get_float32_be b i = Jv . to_float @@ Jv . call b " getFloat32 " Jv . [ | of_int i ] | let get_float32_le b i = Jv . to_float @@ Jv . call b " getFloat32 " Jv . [ | of_int i ; Jv . true ' ] | let get_float64_be b i = Jv . to_float @@ Jv . call b " getFloat64 " Jv . [ | of_int i ] | let get_float64_le b i = Jv . to_float @@ Jv . call b " getFloat64 " Jv . [ | of_int i ; Jv . true ' ] | let set_int8 b i v = ignore @@ Jv . call b " setInt8 " Jv . [ | of_int i ; of_int v ] | let set_int16_be b i v = ignore @@ Jv . call b " setInt16 " Jv . [ | of_int i ; of_int v ] | let set_int16_le b i v = ignore @@ Jv . call b " setInt16 " Jv . [ | of_int i ; of_int v ; Jv . true ' ] | let set_int32_be b i v = ignore @@ Jv . call b " setInt32 " Jv . [ | of_int i ; Obj . magic v ] | let set_int32_le b i v = ignore @@ Jv . call b " setInt32 " Jv . [ | of_int i ; Obj . magic v ; Jv . true ' ] | let set_uint8 b i v = ignore @@ Jv . call b " setUint8 " Jv . [ | of_int i ; of_int v ] | let set_uint16_be b i v = ignore @@ Jv . call b " setUint16 " Jv . [ | of_int i ; of_int v ] | let set_uint16_le b i v = ignore @@ Jv . call b " setUint16 " Jv . [ | of_int i ; of_int v ; Jv . true ' ] | let set_uint32_be b i v = ignore @@ Jv . call b " setUint32 " Jv . [ | of_int i ; Obj . magic v ] | let set_uint32_le b i v = ignore @@ Jv . call b " setUint32 " Jv . [ | of_int i ; Obj . magic v ; Jv . true ' ] | let set_float32_be b i v = ignore @@ Jv . call b " setFloat32 " Jv . [ | of_int i ; of_float v ] | let set_float32_le b i v = ignore @@ Jv . call b " setFloat32 " Jv . [ | of_int i ; of_float v ; Jv . true ' ] | let set_float64_be b i v = ignore @@ Jv . call b " setFloat64 " Jv . [ | of_int i ; of_float v ] | let set_float64_le b i v = ignore @@ Jv . call b " setFloat64 " Jv . [ | of_int i ; of_float v ; Jv . true ' ] | end type ( ' a , ' b ) type ' = | Int8 : ( int , Bigarray . int8_signed_elt ) type ' | Int16 : ( int , Bigarray . int16_signed_elt ) type ' | Int32 : ( int32 , Bigarray . int32_elt ) type ' | Uint8 : ( int , Bigarray . int8_unsigned_elt ) type ' | Uint8_clamped : ( int , Bigarray . int8_unsigned_elt ) type ' | Uint16 : ( int , Bigarray . int16_unsigned_elt ) type ' | Uint32 : ( int32 , Bigarray . int32_elt ) type ' | Float32 : ( float , Bigarray . float32_elt ) type ' | Float64 : ( float , Bigarray . float64_elt ) type ' let type_size_in_bytes : type a b . ( a , b ) type ' -> int = function | Int8 | Uint8 | Uint8_clamped -> 1 | Int16 | Uint16 -> 2 | Int32 | Uint32 | Float32 -> 4 | Float64 -> 8 type ( ' a , ' b ) t = Jv . t external to_jv : ( ' a , ' b ) t -> Jv . t = " % identity " external of_jv : Jv . t -> ( ' a , ' b ) t = " % identity " let cons_of_type : type a b . ( a , b ) type ' -> Jv . t = function | Int8 -> Jv . get Jv . global " Int8Array " | Int16 -> Jv . get Jv . global " Int16Array " | Int32 -> Jv . get Jv . global " Int32Array " | Uint8 -> Jv . get Jv . global " Uint8Array " | Uint8_clamped -> Jv . get Jv . global " Uint8ClampedArray " | Uint16 -> Jv . get Jv . global " Uint16Array " | Uint32 -> Jv . get Jv . global " Uint32Array " | Float32 -> Jv . get Jv . global " Float32Array " | Float64 -> Jv . get Jv . global " Float64Array " let create t n = Jv . new ' ( cons_of_type t ) Jv . [ | of_int n ] | let of_buffer t ( ? byte_offset = 0 ) ? length b = let args = match length with | None -> Jv . [ | b ; of_int byte_offset ] | | Some l -> Jv . [ | b ; of_int byte_offset ; of_int l ] | in Jv . new ' ( cons_of_type t ) args let length a = Jv . Int . get a " length " let type ' : type a b . ( a , b ) t -> ( a , b ) type ' = fun a -> let m = Obj . magic in match Jstr . to_string ( Jv . Jstr . get ( Jv . get a " constructor " ) " name " ) with | " Int8Array " -> m Int8 | " Int16Array " -> m Int16 | " Int32Array " -> m Int32 | " Uint8Array " -> m Uint8 | " Uint8ClampedArray " -> m Uint8_clamped | " Uint16Array " -> m Uint16 | " Uint32Array " -> m Uint32 | " Float32Array " -> m Float32 | " Float64Array " -> m Float64 | s -> let t = Jstr . of_string s in Jv . throw ( Jstr . append ( Jstr . v " Unknown typed array : " ) t ) external get : ( ' a , ' b ) t -> int -> ' a = " caml_js_get " external set : ( ' a , ' b ) t -> int -> ' a -> unit = " caml_js_set " let set_tarray a ~ dst b = ignore @@ Jv . call a " set " Jv . [ | b ; of_int dst ] | let fill ( ? start = 0 ) ? stop v a = let stop = match stop with None -> length a | Some stop -> stop in ignore @@ Jv . call a " fill " Jv . [ | Jv . repr v ; of_int start ; of_int stop ] | let copy_within ( ? start = 0 ) ? stop ~ dst a = let stop = match stop with None -> length a | Some stop -> stop in ignore @@ Jv . call a " copyWithin " Jv . [ | of_int dst ; of_int start ; of_int stop ] | let slice ( ? start = 0 ) ? stop a = let stop = match stop with None -> byte_length a | Some stop -> stop in Jv . call a " slice " Jv . [ | of_int start ; of_int stop ] | let sub ( ? start = 0 ) ? stop a = let stop = match stop with None -> byte_length a | Some stop -> stop in Jv . call a " subArray " Jv . [ | of_int start ; of_int stop ] | let find sat a = let sat v i = Jv . of_bool ( sat i v ) in Jv . to_option Obj . magic ( Jv . call a " find " Jv . [ | repr sat ] ) | let find_index sat a = let sat v i = Jv . of_bool ( sat i v ) in let i = Jv . to_int ( Jv . call a " findIndex " Jv . [ | repr sat ] ) | in if i = - 1 then None else Some i let for_all sat a = let sat v i = Jv . of_bool ( sat i v ) in Jv . to_bool @@ Jv . call a " every " Jv . [ | repr sat ] | let exists sat a = let sat v i = Jv . of_bool ( sat i v ) in Jv . to_bool @@ Jv . call a " every " Jv . [ | repr sat ] | let filter sat a = let sat v i = Jv . of_bool ( sat i v ) in Jv . call a " filter " Jv . [ | repr sat ] | let iter f a = let f v i = f i v in ignore @@ Jv . call a " forEach " Jv . [ | repr f ] | let map f a = Jv . call a " map " Jv . [ | repr f ] | let fold_left f acc a = Obj . magic @@ Jv . call a " reduce " [ | Jv . repr f ; Jv . repr acc ] | let fold_right f a acc = let f acc v = f v acc in Obj . magic @@ Jv . call a " reduceRight " [ | Jv . repr f ; Jv . repr acc ] | let reverse a = Jv . call a " reverse " Jv . [ ] || type int8 = ( int , Bigarray . int8_signed_elt ) t type int16 = ( int , Bigarray . int16_signed_elt ) t type int32 = ( int32 , Bigarray . int32_elt ) t type uint8 = ( int , Bigarray . int8_unsigned_elt ) t type uint8_clamped = ( int , Bigarray . int8_unsigned_elt ) t type uint16 = ( int , Bigarray . int16_unsigned_elt ) t type uint32 = ( int32 , Bigarray . int32_elt ) t type float32 = ( float , Bigarray . float32_elt ) t type float64 = ( float , Bigarray . float64_elt ) t let of_tarray t a = Jv . new ' ( cons_of_type t ) [ | a ] | let of_int_array t a = Jv . new ' ( cons_of_type t ) Jv . [ | of_array Jv . of_int a ] | let of_float_array t a = Jv . new ' ( cons_of_type t ) Jv . [ | of_array of_float a ] | let to_int_jstr ( ? sep = Jstr . sp ) b = Jv . to_jstr @@ Jv . call b " join " Jv . [ | of_jstr sep ] | let to_hex_jstr ( ? sep = Jstr . empty ) a = let hex = Jstr . v " 0123456789abcdef " in let d = Data_view . of_buffer ( buffer a ) in let s = ref Jstr . empty in for i = 0 to Data_view . byte_length d - 1 do let b = Data_view . get_uint8 d i in let sep = if i = 0 then Jstr . empty else sep in s := Jstr . ( ! s + sep + get_jstr hex ( b lsr 4 ) + get_jstr hex ( b land 0xF ) ) done ; ! s let uint8_of_buffer b = of_buffer Uint8 b external to_string : uint8 -> string = " caml_string_of_array " let of_jstr s = let enc = Jv . new ' ( Jv . get Jv . global " TextEncoder " ) [ ] || in Jv . call enc " encode " [ | Jv . of_jstr s ] | let to_jstr a = let args = [ | Jv . of_string " utf - 8 " ; Jv . obj [ | " fatal " , Jv . true ' ] ] || in let dec = Jv . new ' ( Jv . get Jv . global " TextDecoder " ) args in match Jv . call dec " decode " [ | a ] | with | exception Jv . Error e -> Error e | s -> Ok ( Jv . to_jstr s ) let of_binary_jstr s = let code s i = let c = Jv . to_int @@ Jv . call ( Jv . of_jstr s ) " charCodeAt " [ | Jv . of_int i ] | in if c <= 255 then c else Jv . throw Jstr . ( of_int i + v " : char code " + of_int c + v " exceeds 255 " ) in try let b = Buffer . create ( Jstr . length s ) in let d = Data_view . of_buffer b in for i = 0 to Jstr . length s - 1 do Data_view . set_int8 d i ( code s i ) done ; Ok ( of_buffer Int8 b ) with | Jv . Error e -> Error e let to_binary_jstr a = let chr b = Jv . to_jstr @@ Jv . call ( Jv . get Jv . global " String " ) " fromCharCode " [ | Jv . of_int b ] | in let d = Data_view . of_buffer ( buffer a ) in let s = ref Jstr . empty in for i = 0 to Data_view . byte_length d - 1 do let b = Data_view . get_uint8 d i in s := Jstr . ( ! s + chr b ) ; done ; ! s let type_to_bigarray_kind : type a b . ( a , b ) type ' -> ( a , b ) Bigarray . kind = function | Int8 -> Bigarray . int8_signed | Int16 -> Bigarray . int16_signed | Int32 -> Bigarray . int32 | Uint8 -> Bigarray . int8_unsigned | Uint8_clamped -> Bigarray . int8_unsigned | Uint16 -> Bigarray . int16_unsigned | Uint32 -> Bigarray . int32 | Float32 -> Bigarray . float32 | Float64 -> Bigarray . float64 let type_of_bigarray_kind : type a b . ( a , b ) Bigarray . kind -> ( a , b ) type ' option = function | Bigarray . Int8_signed -> Some Int8 | Bigarray . Int16_signed -> Some Int16 | Bigarray . Int32 -> Some Int32 | Bigarray . Int8_unsigned -> Some Uint8 | Bigarray . Int16_unsigned -> Some Uint16 | Bigarray . Float32 -> Some Float32 | Bigarray . Float64 -> Some Float64 | _ -> None external bigarray_kind : ( ' a , ' b ) t -> ( ' a , ' b ) Bigarray . kind = " caml_ba_kind_of_typed_array " external of_bigarray1 : ( ' a , ' b , Bigarray . c_layout ) Bigarray . Array1 . t -> ( ' a , ' b ) t = " caml_ba_to_typed_array " external to_bigarray1 : ( ' a , ' b ) t -> ( ' a , ' b , Bigarray . c_layout ) Bigarray . Array1 . t = " caml_ba_from_typed_array " external of_bigarray : ( ' a , ' b , Bigarray . c_layout ) Bigarray . Genarray . t -> ( ' a , ' b ) t = " caml_ba_to_typed_array " end
module Blob = struct module Ending_type = struct type t = Jstr . t let transparent = Jstr . v " transparent " let native = Jstr . v " native " end type init = Jv . t let init ? type ' ? endings ( ) = let o = Jv . obj [ ] || in Jv . Jstr . set_if_some o " type " type ' ; Jv . Jstr . set_if_some o " endings " endings ; o type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let blob = Jv . get Jv . global " Blob " let of_jstr ( ? init = Jv . undefined ) s = let a = Jv . Jarray . create 1 in Jv . Jarray . set a 0 ( Jv . of_jstr s ) ; Jv . new ' blob [ | a ; init ] | let of_jarray ( ? init = Jv . undefined ) a = Jv . new ' blob [ | a ; init ] | let of_array_buffer ( ? init = Jv . undefined ) b = Jv . new ' blob [ | Jv . of_jv_array [ | Tarray . Buffer . to_jv b ] ; | init ] | let byte_length b = Jv . Int . get b " size " let type ' b = Jv . Jstr . get b " type " let slice ( ? start = 0 ) ? stop ( ? type ' = Jstr . empty ) b = let stop = match stop with None -> byte_length b | Some stop -> stop in Jv . call b " slice " Jv . [ | of_int start ; of_int stop ; of_jstr type ' ] | let array_buffer b = Fut . of_promise ~ ok : Tarray . Buffer . of_jv ( Jv . call b " arrayBuffer " [ ] ) || let stream b = Jv . get b " stream " let text b = Fut . of_promise ~ ok : Jv . to_jstr ( Jv . call b " text " [ ] ) || let data_uri b = let reader = Jv . new ' ( Jv . get Jv . global " FileReader " ) [ ] || in let fut , set_fut = Fut . create ( ) in let ok _e = set_fut ( Ok ( Jv . Jstr . get reader " result " ) ) in let error _e = set_fut ( Error ( Jv . to_error ( Jv . get reader " error " ) ) ) in let t = Ev . target_of_jv reader in Ev . listen ~ opts ( : Ev . listen_opts ~ once : true ( ) ) Ev . load ok t ; Ev . listen ~ opts ( : Ev . listen_opts ~ once : true ( ) ) Ev . error error t ; ignore ( Jv . call reader " readAsDataURL " [ | b ] ) ; | fut end
module File = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) type init = Jv . t let init ? blob_init ? last_modified_ms ( ) = let o = match blob_init with None -> Jv . obj [ ] || | Some b -> Jv . repr b in Jv . Int . set_if_some o " lastModified " last_modified_ms ; o let file = Jv . get Jv . global " File " let of_blob ( ? init = Jv . obj [ ] ) || name b = Jv . new ' file [ | Blob . to_jv b ; Jv . of_jstr name ; init ] | let name f = Jv . Jstr . get f " name " let last_modified_ms f = Jv . Int . get f " lastModified " external as_blob : t -> Blob . t = " % identity " end
module Base64 = struct type data = Jstr . t let data_utf_8_of_jstr s = Tarray . to_binary_jstr ( Tarray . of_jstr s ) let data_utf_8_to_jstr d = match Tarray . of_binary_jstr d with | Error _ as e -> e | Ok t -> Tarray . to_jstr t let data_of_binary_jstr = Fun . id let data_to_binary_jstr = Fun . id let encode bs = match Jv . apply ( Jv . get Jv . global " btoa " ) Jv . [ | of_jstr bs ] | with | exception Jv . Error e -> Error e | v -> Ok ( Jv . to_jstr v ) let decode s = match Jv . apply ( Jv . get Jv . global " atob " ) Jv . [ | of_jstr s ] | with | exception Jv . Error e -> Error e | v -> Ok ( Jv . to_jstr v ) end
module Json = struct type t = Jv . t let json = Jv . get Jv . global " JSON " let encode v = Jv . to_jstr ( Jv . call json " stringify " [ | v ] ) | let decode s = match Jv . call json " parse " [ | Jv . of_jstr s ] | with | exception Jv . Error e -> Error e | v -> Ok v end
module Uri = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let encode = Jv . get Jv . global " encodeURI " let decode = Jv . get Jv . global " decodeURI " let url = Jv . get Jv . global " URL " let v ? base s = match base with | None -> Jv . new ' url [ | Jv . of_jstr s ] | | Some b -> Jv . new ' url [ | Jv . of_jstr s ; Jv . of_jstr b ] | let with_uri ? scheme ? host ? port ? path ? query ? fragment u = let u = Jv . new ' url [ | u ] | in let pct_enc v = Jv . apply encode [ | Jv . of_jstr v ] | in try Jv . set_if_some u " protocol " ( Option . map pct_enc scheme ) ; Jv . set_if_some u " hostname " ( Option . map pct_enc host ) ; begin match port with | None -> ( ) | Some p -> Jv . Jstr . set_if_some u " port " ( Option . map Jstr . of_int p ) end ; Jv . set_if_some u " pathname " ( Option . map pct_enc path ) ; Jv . set_if_some u " search " ( Option . map pct_enc query ) ; Jv . set_if_some u " hash " ( Option . map pct_enc fragment ) ; Ok u with Jv . Error e -> Error e let pct_dec v = Jv . to_jstr @@ Jv . apply decode [ | v ] | let scheme u = let p = pct_dec ( Jv . get u " protocol " ) in if Jstr . length p <> 0 then Jstr . slice p ~ stop ( :- 1 ) else p let host u = pct_dec ( Jv . get u " hostname " ) let port u = let p = Jv . Jstr . get u " port " in if Jstr . is_empty p then None else Jstr . to_int p let query u = let q = pct_dec ( Jv . get u " search " ) in if Jstr . is_empty q then q else Jstr . slice q ~ start : 1 let path u = pct_dec ( Jv . get u " pathname " ) let fragment u = let f = Jv . to_jstr @@ Jv . apply decode [ | Jv . get u " hash " ] | in if Jstr . is_empty f then f else Jstr . slice f ~ start : 1 module Params = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let usp = Jv . get Jv . global " URLSearchParams " let is_empty p = Jv . It . result_done ( Jv . It . next ( Jv . call p " entries " [ ] ) ) || let mem k p = Jv . to_bool ( Jv . call p " has " [ | Jv . of_jstr k ] ) | let find k p = Jv . to_option Jv . to_jstr ( Jv . call p " get " [ | Jv . of_jstr k ] ) | let find_all k p = Jv . to_jstr_list ( Jv . call p " getAll " [ | Jv . of_jstr k ] ) | let fold f p acc = let key = Jv . to_jstr in let value = Jv . to_jstr in Jv . It . fold_bindings ~ key ~ value f ( Jv . call p " entries " [ ] ) || acc let of_jstr s = Jv . new ' usp [ | Jv . of_jstr s ] | let to_jstr p = Jv . to_jstr ( Jv . call p " toString " [ ] ) || let of_assoc l = let p = of_jstr Jstr . empty in let app p ( k , v ) = ignore ( Jv . call p " append " Jv . [ | of_jstr k ; of_jstr v ] ) | in List . iter ( app p ) l ; p let to_assoc p = List . rev ( fold ( fun k v acc -> ( k , v ) :: acc ) p [ ] ) let of_obj o = Jv . new ' usp [ | o ] | end let code f s = match Jv . apply f [ | Jv . of_jstr s ] | with | exception Jv . Error e -> Error e | v -> Ok ( Jv . to_jstr v ) let encode_component = Jv . get Jv . global " encodeURIComponent " let decode_component = Jv . get Jv . global " decodeURIComponent " let encode s = code encode s let decode s = code decode s let encode_component s = code encode_component s let decode_component s = code decode_component s let to_jstr u = Jv . to_jstr ( Jv . call u " toString " [ ] ) || let of_jstr ? base s = match v ? base s with | exception Jv . Error e -> Error e | v -> Ok v end
module At = struct type name = Jstr . t type t = name * Jstr . t let v n v = ( n , v ) let true ' n = ( n , Jstr . empty ) let int n i = ( n , Jstr . of_int i ) let add_if b at l = if b then at :: l else l let add_if_some name o l = match o with None -> l | Some a -> ( name , a ) :: l let to_pair = Fun . id module Name = struct let accesskey = Jstr . v " accesskey " let autofocus = Jstr . v " autofocus " let charset = Jstr . v " charset " let checked = Jstr . v " checked " let class ' = Jstr . v " class " let content = Jstr . v " content " let contenteditable = Jstr . v " contenteditable " let cols = Jstr . v " cols " let defer = Jstr . v " defer " let disabled = Jstr . v " disabled " let dir = Jstr . v " dir " let draggable = Jstr . v " draggable " let for ' = Jstr . v " for " let height = Jstr . v " height " let hidden = Jstr . v " hidden " let href = Jstr . v " href " let id = Jstr . v " id " let lang = Jstr . v " lang " let media = Jstr . v " media " let name = Jstr . v " name " let placeholder = Jstr . v " placeholder " let rel = Jstr . v " rel " let required = Jstr . v " required " let rows = Jstr . v " rows " let src = Jstr . v " src " let spellcheck = Jstr . v " spellcheck " let tabindex = Jstr . v " tabindex " let title = Jstr . v " title " let type ' = Jstr . v " type " let value = Jstr . v " value " let width = Jstr . v " width " let wrap = Jstr . v " wrap " end type ' a cons = ' a -> t let accesskey s = v Name . accesskey s let autofocus = true ' Name . autofocus let charset = v Name . charset let checked = true ' Name . checked let class ' s = v Name . class ' s let cols i = int Name . cols i let content s = v Name . content s let contenteditable s = true ' Name . contenteditable let defer = true ' Name . defer let disabled = true ' Name . disabled let dir s = v Name . dir s let draggable s = true ' Name . draggable let for ' s = v Name . for ' s let height i = int Name . height i let hidden = true ' Name . hidden let href s = v Name . href s let id s = v Name . id s let lang s = v Name . lang s let media s = v Name . media s let name s = v Name . name s let placeholder s = v Name . placeholder s let rel s = v Name . rel s let required = true ' Name . required let rows i = int Name . rows i let src s = v Name . src s let spellcheck = v Name . spellcheck let tabindex i = int Name . tabindex i let title s = v Name . title s let type ' s = v Name . type ' s let value s = v Name . value s let width i = int Name . width i let wrap s = v Name . value s end
module El = struct type document = Jv . t type window = Jv . t type tag_name = Jstr . t type el = Jv . t type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let global_document = Jv . get Jv . global " document " let document e = Jv . get e " ownerDocument " let global_root = Jv . get global_document " documentElement " let el_list_of_node_list nl = let acc = ref [ ] in let len = Jv . Int . get nl " length " in for i = len - 1 downto 0 do acc := Jv . Jarray . get nl i :: ! acc done ; ! acc let append_child e n = ignore ( Jv . call e " appendChild " [ | n ] ) | let set_at e ( a , v ) = match Jstr . equal a At . Name . class ' with | false -> ignore ( Jv . call e " setAttribute " Jv . [ | of_jstr a ; of_jstr v ] ) | | true when Jstr . is_empty v -> ( ) | true -> ignore ( Jv . call ( Jv . get e " classList " ) " add " [ | Jv . of_jstr v ] ) | let v ( ? d = global_document ) ( ? at = [ ] ) name cs = let e = Jv . call d " createElement " [ | Jv . of_jstr name ] | in List . iter ( set_at e ) at ; List . iter ( append_child e ) cs ; e let txt ( ? d = global_document ) s = Jv . call d " createTextNode " [ | Jv . of_jstr s ] | let txt ' ( ? d = global_document ) s = Jv . call d " createTextNode " [ | Jv . of_string s ] | let sp ( ? d = global_document ) ( ) = txt ( Jstr . v " " ) let nbsp ( ? d = global_document ) ( ) = txt ( Jstr . v " \ u { 00A0 } " ) let is_txt e = Jv . Int . get e " nodeType " = 3 let is_el e = Jv . Int . get e " nodeType " = 1 let tag_name e = Jstr . lowercased @@ Jv . Jstr . get e " nodeName " let has_tag_name n e = Jstr . equal n ( tag_name e ) let txt_text txt = match is_txt txt with | true -> Jv . Jstr . get txt " nodeValue " | false -> Jstr . empty external as_target : t -> Ev . target = " % identity " let find_by_class ( ? root = global_root ) c = el_list_of_node_list @@ Jv . call root " getElementsByClassName " [ | Jv . of_jstr c ] | let find_by_tag_name ( ? root = global_root ) n = el_list_of_node_list @@ Jv . call root " getElementsByTagName " [ | Jv . of_jstr n ] | let find_first_by_selector ( ? root = global_root ) sel = Jv . to_option of_jv @@ Jv . call root " querySelector " [ | Jv . of_jstr sel ] | let fold_find_by_selector ( ? root = global_root ) f sel acc = let nl = Jv . call root " querySelectorAll " [ | Jv . of_jstr sel ] | in let acc = ref acc in for i = 0 to ( Jv . Int . get nl " length " ) - 1 do acc := f ( of_jv ( Jv . Jarray . get nl i ) ) ! acc done ; ! acc let parent e = match Jv . find e " parentNode " with | Some e when is_el e -> Some e | _ -> None let delete_children e = while not ( Jv . is_null ( Jv . get e " firstChild " ) ) do ignore @@ Jv . call e " removeChild " [ | Jv . get e " firstChild " ] ; | done let children ( ? only_els = false ) e = match only_els with | true -> el_list_of_node_list ( Jv . get e " children " ) | false -> el_list_of_node_list ( Jv . get e " childNodes " ) let set_children e l = delete_children e ; List . iter ( append_child e ) l let append_child e c = ignore @@ Jv . call e " appendChild " [ | c ] | let prepend_children e l = ignore @@ Jv . call e " prepend " ( Array . of_list l ) let append_children e l = ignore @@ Jv . call e " append " ( Array . of_list l ) let previous_sibling e = Jv . find e " previousElementSibling " let next_sibling e = Jv . find e " nextElementSibling " let insert_siblings loc e l = ignore @@ match loc with | ` Before -> Jv . call e " before " ( Array . of_list l ) | ` After -> Jv . call e " after " ( Array . of_list l ) | ` Replace -> Jv . call e " replaceWith " ( Array . of_list l ) let remove e = ignore @@ Jv . call e " remove " [ | e ] | let at a e = Jv . to_option Jv . to_jstr ( Jv . call e " getAttribute " [ | Jv . of_jstr a ] ) | let set_at a v e = match v with | None -> ignore ( Jv . call e " removeAttribute " Jv . [ | of_jstr a ] ) | | Some v -> ignore ( Jv . call e " setAttribute " Jv . [ | of_jstr a ; of_jstr v ] ) | module Prop = struct type ' a t = { n : Jstr . t ; jv_to : Jv . t -> ' a ; jv_of : ' a -> Jv . t ; } let jv_to_bool b = if Jv . is_undefined b then false else Jv . to_bool b let jv_to_int i = if Jv . is_undefined i then 0 else Jv . to_int i let jv_to_float f = if Jv . is_undefined f then 0 . else Jv . to_float f let jv_to_jstr s = if Jv . is_undefined s then Jstr . empty else Jv . to_jstr s let bool n = { n ; jv_to = jv_to_bool ; jv_of = Jv . of_bool } let int n = { n ; jv_to = jv_to_int ; jv_of = Jv . of_int } let float n = { n ; jv_to = jv_to_float ; jv_of = Jv . of_float } let jstr n = { n ; jv_to = jv_to_jstr ; jv_of = Jv . of_jstr } let checked = bool ( Jstr . v " checked " ) let height = int ( Jstr . v " height " ) let id = jstr ( Jstr . v " id " ) let name = jstr ( Jstr . v " name " ) let title = jstr ( Jstr . v " title " ) let value = jstr ( Jstr . v " value " ) let width = int ( Jstr . v " width " ) end let prop p e = p . Prop . jv_to @@ Jv . get ' e p . Prop . n let set_prop p v e = ignore @@ Jv . set ' e p . Prop . n ( p . Prop . jv_of v ) let class ' c e = Jv . to_bool ( Jv . call ( Jv . get e " classList " ) " contains " [ | Jv . of_jstr c ] ) | let set_class c b e = match b with | true -> ignore ( Jv . call ( Jv . get e " classList " ) " add " [ | Jv . of_jstr c ] ) | | false -> ignore ( Jv . call ( Jv . get e " classList " ) " remove " [ | Jv . of_jstr c ] ) | module Style = struct type prop = Jstr . t let background_color = Jstr . v " background - color " let bottom = Jstr . v " bottom " let color = Jstr . v " color " let cursor = Jstr . v " cursor " let display = Jstr . v " display " let height = Jstr . v " height " let left = Jstr . v " left " let position = Jstr . v " position " let right = Jstr . v " right " let top = Jstr . v " top " let visibility = Jstr . v " visibility " let width = Jstr . v " width " let z_index = Jstr . v " z - index " end let computed_style ( ? w = Jv . get Jv . global " window " ) p e = let style = Jv . call w " getComputedStyle " [ | e ] | in let v = Jv . get ' style p in if Jv . is_none v then Jstr . empty else Jv . to_jstr v let inline_style p e = let style = Jv . get e " style " in if Jv . is_none style then Jstr . empty else let v = Jv . get ' style p in if Jv . is_none v then Jstr . empty else Jv . to_jstr v let set_inline_style ( ? important = false ) p v e = let priority = if important then Jstr . v " important " else Jstr . empty in let style = Jv . get e " style " in if Jv . is_none style then ( ) else ( ignore @@ Jv . call style " setProperty " Jv . [ | of_jstr p ; of_jstr v ; of_jstr priority ] ) | let remove_inline_style p e = let style = Jv . get e " style " in if Jv . is_none style then ( ) else ( ignore @@ Jv . call style " removeProperty " Jv . [ | of_jstr p ] ) | let inner_x e = Jv . Float . get e " clientLeft " let inner_y e = Jv . Float . get e " clientTop " let inner_w e = Jv . Float . get e " clientWidth " let inner_h e = Jv . Float . get e " clientHeight " let bound_x e = Jv . Float . get ( Jv . call e " getBoundingClientRect " [ ] ) || " x " let bound_y e = Jv . Float . get ( Jv . call e " getBoundingClientRect " [ ] ) || " y " let bound_w e = Jv . Float . get ( Jv . call e " getBoundingClientRect " [ ] ) || " width " let bound_h e = Jv . Float . get ( Jv . call e " getBoundingClientRect " [ ] ) || " height " let scroll_x e = Jv . Float . get e " scrollLeft " let scroll_y e = Jv . Float . get e " scrollTop " let scroll_w e = Jv . Float . get e " scrollWidth " let scroll_h e = Jv . Float . get e " scrollHeight " let scroll_into_view ( ? align_v = ` Start ) e = let align = match align_v with ` Start -> false | ` End -> true in ignore @@ Jv . call e " scrollIntoView " [ | Jv . of_bool align ] | let has_focus e = match Jv . to_option Fun . id ( Jv . get ( document e ) " activeElement " ) with | None -> false | Some e ' -> e == e ' let set_has_focus b e = ignore ( if b then Jv . call e " focus " [ ] || else Jv . call e " blur " [ ] ) || let is_locking_pointer e = match Jv . to_option Fun . id ( Jv . get ( document e ) " pointerLockElement " ) with | None -> false | Some e ' -> e == e ' let request_pointer_lock e = let fut , set = Fut . create ( ) in let d = ( Obj . magic document e : Ev . target ) in let opts = Ev . listen_opts ~ once : true ( ) in let rec unlisten ( ) = Ev . unlisten ~ opts Ev . pointerlockchange locked d ; Ev . unlisten ~ opts Ev . pointerlockerror error d ; and locked _ev = set ( Ok ( ) ) ; unlisten ( ) and error _ev = let err = Jv . Error . v ( Jstr . v " Could not lock pointer " ) in set ( Error err ) ; unlisten ( ) in Ev . listen ~ opts Ev . pointerlockchange locked d ; Ev . listen ~ opts Ev . pointerlockerror error d ; ignore @@ Jv . call e " requestPointerLock " [ ] ; || fut let click e = ignore ( Jv . call e " click " [ ] ) || let select_text e = ignore ( Jv . call e " select " [ ] ) || module Navigation_ui = struct type t = Jstr . t let auto = Jstr . v " auto " let hide = Jstr . v " hide " let show = Jstr . v " show " end type fullscreen_opts = Jv . t let fullscreen_opts ? navigation_ui ( ) = let o = Jv . obj [ ] || in Jv . Jstr . set_if_some o " navigationUI " navigation_ui ; o let request_fullscreen ( ? opts = Jv . obj [ ] ) || e = Fut . of_promise ~ ok : ignore @@ Jv . call e " requestFullscreen " [ | opts ] | module Input = struct let files e = match Jv . find e " files " with | None -> [ ] | Some files -> Jv . to_list File . of_jv files end module Name = struct let a = Jstr . v " a " let abbr = Jstr . v " abbr " let address = Jstr . v " address " let area = Jstr . v " area " let article = Jstr . v " article " let aside = Jstr . v " aside " let audio = Jstr . v " audio " let b = Jstr . v " b " let base = Jstr . v " base " let bdi = Jstr . v " bdi " let bdo = Jstr . v " bdo " let blockquote = Jstr . v " blockquote " let body = Jstr . v " body " let br = Jstr . v " br " let button = Jstr . v " button " let canvas = Jstr . v " canvas " let caption = Jstr . v " caption " let cite = Jstr . v " cite " let code = Jstr . v " code " let col = Jstr . v " col " let colgroup = Jstr . v " colgroup " let command = Jstr . v " command " let datalist = Jstr . v " datalist " let dd = Jstr . v " dd " let del = Jstr . v " del " let details = Jstr . v " details " let dfn = Jstr . v " dfn " let div = Jstr . v " div " let dl = Jstr . v " dl " let dt = Jstr . v " dt " let em = Jstr . v " em " let embed = Jstr . v " embed " let fieldset = Jstr . v " fieldset " let figcaption = Jstr . v " figcaption " let figure = Jstr . v " figure " let footer = Jstr . v " footer " let form = Jstr . v " form " let h1 = Jstr . v " h1 " let h2 = Jstr . v " h2 " let h3 = Jstr . v " h3 " let h4 = Jstr . v " h4 " let h5 = Jstr . v " h5 " let h6 = Jstr . v " h6 " let head = Jstr . v " head " let header = Jstr . v " header " let hgroup = Jstr . v " hgroup " let hr = Jstr . v " hr " let html = Jstr . v " html " let i = Jstr . v " i " let iframe = Jstr . v " iframe " let img = Jstr . v " img " let input = Jstr . v " input " let ins = Jstr . v " ins " let kbd = Jstr . v " kbd " let keygen = Jstr . v " keygen " let label = Jstr . v " label " let legend = Jstr . v " legend " let li = Jstr . v " li " let link = Jstr . v " link " let map = Jstr . v " map " let mark = Jstr . v " mark " let menu = Jstr . v " menu " let meta = Jstr . v " meta " let meter = Jstr . v " meter " let nav = Jstr . v " nav " let noscript = Jstr . v " noscript " let object ' = Jstr . v " object " let ol = Jstr . v " ol " let optgroup = Jstr . v " optgroup " let option = Jstr . v " option " let output = Jstr . v " output " let p = Jstr . v " p " let param = Jstr . v " param " let pre = Jstr . v " pre " let progress = Jstr . v " progress " let q = Jstr . v " q " let rp = Jstr . v " rp " let rt = Jstr . v " rt " let ruby = Jstr . v " ruby " let s = Jstr . v " s " let samp = Jstr . v " samp " let script = Jstr . v " script " let section = Jstr . v " section " let select = Jstr . v " select " let small = Jstr . v " small " let source = Jstr . v " source " let span = Jstr . v " span " let strong = Jstr . v " strong " let style = Jstr . v " style " let sub = Jstr . v " sub " let summary = Jstr . v " summary " let sup = Jstr . v " sup " let table = Jstr . v " table " let tbody = Jstr . v " tbody " let td = Jstr . v " td " let textarea = Jstr . v " textarea " let tfoot = Jstr . v " tfoot " let th = Jstr . v " th " let thead = Jstr . v " thead " let time = Jstr . v " time " let title = Jstr . v " title " let tr = Jstr . v " tr " let track = Jstr . v " track " let u = Jstr . v " u " let ul = Jstr . v " ul " let var = Jstr . v " var " let video = Jstr . v " video " let wbr = Jstr . v " wbr " end type cons = ? d : document -> ? at : At . t list -> t list -> t type void_cons = ? d : document -> ? at : At . t list -> unit -> t let cons name ? d ? at cs = v ? d ? at name cs let void_cons name ? d ? at ( ) = v ? d ? at name [ ] let a = cons Name . a let abbr = cons Name . abbr let address = cons Name . address let area = void_cons Name . area let article = cons Name . article let aside = cons Name . aside let audio = cons Name . audio let b = cons Name . b let base = void_cons Name . base let bdi = cons Name . bdi let bdo = cons Name . bdo let blockquote = cons Name . blockquote let body = cons Name . body let br = void_cons Name . br let button = cons Name . button let canvas = cons Name . canvas let caption = cons Name . caption let cite = cons Name . cite let code = cons Name . code let col = void_cons Name . col let colgroup = cons Name . colgroup let command = cons Name . command let datalist = cons Name . datalist let dd = cons Name . dd let del = cons Name . del let details = cons Name . details let dfn = cons Name . dfn let div = cons Name . div let dl = cons Name . dl let dt = cons Name . dt let em = cons Name . em let embed = void_cons Name . embed let fieldset = cons Name . fieldset let figcaption = cons Name . figcaption let figure = cons Name . figure let footer = cons Name . footer let form = cons Name . form let h1 = cons Name . h1 let h2 = cons Name . h2 let h3 = cons Name . h3 let h4 = cons Name . h4 let h5 = cons Name . h5 let h6 = cons Name . h6 let head = cons Name . head let header = cons Name . header let hgroup = cons Name . hgroup let hr = void_cons Name . hr let html = cons Name . html let i = cons Name . i let iframe = cons Name . iframe let img = void_cons Name . img let input = void_cons Name . input let ins = cons Name . ins let kbd = cons Name . kbd let keygen = cons Name . keygen let label = cons Name . label let legend = cons Name . legend let li = cons Name . li let link = void_cons Name . link let map = cons Name . map let mark = cons Name . mark let menu = cons Name . menu let meta = void_cons Name . meta let meter = cons Name . meter let nav = cons Name . nav let noscript = cons Name . noscript let object ' = cons Name . object ' let ol = cons Name . ol let optgroup = cons Name . optgroup let option = cons Name . option let output = cons Name . output let p = cons Name . p let param = void_cons Name . param let pre = cons Name . pre let progress = cons Name . progress let q = cons Name . q let rp = cons Name . rp let rt = cons Name . rt let ruby = cons Name . ruby let s = cons Name . s let samp = cons Name . samp let script = cons Name . script let section = cons Name . section let select = cons Name . select let small = cons Name . small let source = void_cons Name . source let span = cons Name . span let strong = cons Name . strong let style = cons Name . style let sub = cons Name . sub let summary = cons Name . summary let sup = cons Name . sup let table = cons Name . table let tbody = cons Name . tbody let td = cons Name . td let textarea = cons Name . textarea let tfoot = cons Name . tfoot let th = cons Name . th let thead = cons Name . thead let time = cons Name . time let title = cons Name . title let tr = cons Name . tr let track = void_cons Name . track let u = cons Name . u let ul = cons Name . ul let var = cons Name . var let video = cons Name . video let wbr = void_cons Name . wbr end
module Document = struct type t = El . document include ( Jv . Id : Jv . CONV with type t := t ) let as_target d = d let root d = El . of_jv ( Jv . get d " documentElement " ) let body d = let b = Jv . get d " body " in if Jv . is_some b then El . of_jv b else let err = " Document body is null . Try to defer your script execution . " in Jv . throw ( Jstr . v err ) let head d = El . of_jv ( Jv . get d " head " ) let active_el d = Jv . to_option El . of_jv ( Jv . get d " activeElement " ) let find_el_by_id d id = Jv . to_option El . of_jv ( Jv . call d " getElementById " [ | Jv . of_jstr id ] ) | let find_els_by_name d n = El . el_list_of_node_list ( Jv . call d " getElementsByName " [ | Jv . of_jstr n ] ) | let referrer d = Jv . Jstr . get d " referrer " let title d = Jv . Jstr . get d " title " let set_title d t = Jv . Jstr . set d " title " t module Visibility_state = struct type t = Jstr . t let hidden = Jstr . v " hidden " let visible = Jstr . v " visible " end let visibility_state d = Jv . Jstr . get d " visibilityState " let pointer_lock_element d = Jv . to_option El . of_jv @@ Jv . get d " pointerLockElement " let exit_pointer_lock d = let fut = Ev . next Ev . pointerlockchange ( as_target d ) in ignore @@ Jv . call d " exitPointerLock " [ ] ; || fut let fullscreen_available d = Jv . Bool . get d " fullscreenEnabled " let fullscreen_element d = Jv . to_option El . of_jv @@ Jv . get d " fullscreenElement " let exit_fullscreen d = Fut . of_promise ~ ok : ignore @@ Jv . call d " exitFullscreen " [ ] || end
module Abort = struct module Signal = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) external as_target : t -> Ev . target = " % identity " let aborted s = Jv . Bool . get s " aborted " let abort = Ev . Type . void ( Jstr . v " abort " ) end type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let controller ( ) = Jv . new ' ( Jv . get Jv . global " AbortController " ) [ ] || let signal c = Signal . of_jv ( Jv . get c " signal " ) let abort c = ignore @@ Jv . call c " abort " [ ] || end
module Console = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let call c meth args = ignore ( Jv . call c meth args ) let c = ref ( Jv . get Jv . global " console " ) let get ( ) = ! c let set n = c := n let clear ( ) = call ! c " clear " [ ] || type msg = [ ] : msg | ( :: ) : ' a * msg -> msg type ' a msgr = ' a -> msg let msg v = [ v ] let str v = let v = Jv . repr v in if Jv . is_null v then Jstr . v " null " else if Jv . is_undefined v then Jstr . v " undefined " else Jv . to_jstr @@ Jv . call v " toString " [ ] || let msg_to_jv_array msg = let rec loop a i = function | [ ] -> a | v :: vs -> Jv . Jarray . set a i ( Jv . repr v ) ; loop a ( i + 1 ) vs in Jv . to_jv_array @@ loop ( Jv . Jarray . create 0 ) 0 msg type log = msg -> unit let log msg = call ! c " log " ( msg_to_jv_array msg ) let trace msg = call ! c " trace " ( msg_to_jv_array msg ) let error msg = call ! c " error " ( msg_to_jv_array msg ) let warn msg = call ! c " warn " ( msg_to_jv_array msg ) let info msg = call ! c " info " ( msg_to_jv_array msg ) let debug msg = call ! c " debug " ( msg_to_jv_array msg ) let assert ' b msg = call ! c " assert " ( msg_to_jv_array ( Jv . of_bool b :: msg ) ) let dir o = call ! c " dir " [ | Jv . repr o ] | let table ? cols v = let msg = match cols with | None -> [ | Jv . repr v ] | | Some l -> [ | Jv . repr v ; Jv . of_jstr_list l ] | in call ! c " table " msg let group_end ( ) = call ! c " groupEnd " [ ] || let group ( ? closed = false ) msg = match closed with | false -> call ! c " group " ( msg_to_jv_array msg ) | true -> call ! c " groupCollapsed " ( msg_to_jv_array msg ) let count label = call ! c " count " [ | Jv . of_jstr label ] | let count_reset label = call ! c " countReset " [ | Jv . of_jstr label ] | let time label = call ! c " time " [ | Jv . of_jstr label ] | let time_log label msg = call ! c " timeLog " ( msg_to_jv_array ( label :: msg ) ) let time_end label = call ! c " timeEnd " [ | Jv . of_jstr label ] | let profile label = call ! c " profile " [ | Jv . repr label ] | let profile_end label = call ! c " profileEnd " [ | Jv . repr label ] | let time_stamp label = call ! c " timeStamp " [ | Jv . of_jstr label ] | let log_result ( ? ok = fun v -> [ v ] ) ? error ( : err = fun e -> [ str e ] ) r = ( match r with Ok v -> log ( ok v ) | Error e -> error ( err e ) ) ; r let log_if_error ( ? l = error ) ( ? error_msg = fun e -> [ str e ] ) ~ use = function | Ok v -> v | Error e -> l ( error_msg e ) ; use let log_if_error ' ? l ? error_msg ~ use r = Ok ( log_if_error ? l ? error_msg ~ use r ) end
module Window = struct type t = El . window include ( Jv . Id : Jv . CONV with type t := t ) let as_target w = Ev . target_of_jv w let closed w = Jv . Bool . get w " closed " let scroll_x w = Jv . Float . get w " scrollX " let scroll_y w = Jv . Float . get w " scrollY " let device_pixel_ratio w = Jv . Float . get w " devicePixelRatio " let matches_media w s = let o = Jv . call w " matchMedia " [ | Jv . of_jstr s ] | in Jv . Bool . get o " matches " let prefers_dark_color_scheme w = matches_media w ( Jstr . v " ( prefers - color - scheme : dark ) " ) let open ' ( ? features = Jstr . empty ) ( ? name = Jstr . empty ) w u = Jv . to_option of_jv @@ Jv . call w " open " [ | Jv . of_jstr u ; Jv . of_jstr name ; Jv . of_jstr features ] | let close w = ignore ( Jv . call w " close " [ ] ) || let print w = ignore ( Jv . call w " print " [ ] ) || let reload w = ignore ( Jv . call ( Jv . get w " location " ) " reload " [ ] ) || let location w = Jv . new ' Uri . url [ | Jv . get w " location " ] | let set_location w u = Jv . set w " location " ( Uri . to_jv u ) module History = struct module Scroll_restoration = struct type t = Jstr . t let auto = Jstr . v " auto " let manual = Jstr . v " manual " end type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let length h = Jv . Int . get h " length " let scroll_restoration h = Jv . Jstr . get h " scrollRestoration " let set_scroll_restoration h r = Jv . Jstr . set h " scrollRestoration " r let back h = ignore @@ Jv . call h " back " [ ] || let forward h = ignore @@ Jv . call h " forward " [ ] || let go h d = ignore @@ Jv . call h " go " Jv . [ | of_int d ] | type state = Jv . t let state h = Jv . get h " state " let push_state ( ? state = Jv . null ) ( ? title = Jstr . empty ) ( ? uri = Jv . null ) h = ignore @@ Jv . call h " pushState " [ | state ; Jv . of_jstr title ; uri ] | let replace_state ( ? state = Jv . null ) ( ? title = Jstr . empty ) ( ? uri = Jv . null ) h = ignore @@ Jv . call h " replaceState " [ | state ; Jv . of_jstr title ; uri ] | module Ev = struct module Popstate = struct type t = Jv . t let state e = Jv . get e " state " end let popstate = Ev . Type . create ( Jstr . v " popstate " ) end end let history w = History . of_jv @@ Jv . get w " history " end
module Navigator = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let languages n = match Jv . find n " languages " with | Some a -> Jv . to_jstr_list a | None -> match Jv . Jstr . find n " language " with | Some v -> [ v ] | None -> [ ] let max_touch_points n = let t = Jv . get n " maxTouchPoints " in if Jv . is_none t then 0 else Jv . to_int t let online n = Jv . Bool . get n " onLine " end
module Performance = struct module Entry = struct module Type = struct type t = Jstr . t let frame = Jstr . v " frame " let navigation = Jstr . v " navigation " let resource = Jstr . v " resource " let mark = Jstr . v " mark " let measure = Jstr . v " measure " let paint = Jstr . v " paint " let longtask = Jstr . v " longtask " end type t = Jv . t type entry = t include ( Jv . Id : Jv . CONV with type t := t ) let name e = Jv . Jstr . get e " name " let type ' e = Jv . Jstr . get e " entryType " let start_time e = Jv . Float . get e " startTime " let end_time e = Jv . Float . get e " endTime " let duration e = Jv . Float . get e " duration " let to_json e = Jv . call e " toJSON " [ ] || module Resource_timing = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let as_entry = Fun . id let initiator_type e = Jv . Jstr . get e " initiatorType " let next_hop_protocol e = Jv . Jstr . get e " nextHopProtocol " let worker_start e = Jv . Float . get e " workerStart " let redirect_start e = Jv . Float . get e " redirectStart " let redirect_end e = Jv . Float . get e " redirectEnd " let fetch_start e = Jv . Float . get e " fetchStart " let domain_lookup_start e = Jv . Float . get e " domainLookupStart " let domain_lookup_end e = Jv . Float . get e " domainLookupEnd " let connect_start e = Jv . Float . get e " connectStart " let connect_end e = Jv . Float . get e " connectEnd " let secure_connection_start e = Jv . Float . get e " secureConnectionStart " let request_start e = Jv . Float . get e " requestStart " let response_start e = Jv . Float . get e " responseStart " let response_end e = Jv . Float . get e " responseEnd " let transfer_size e = Jv . Int . get e " transferSize " let encoded_body_size e = Jv . Int . get e " encodedBodySize " let decoded_body_size e = Jv . Int . get e " decodedBodySize " end module Navigation_timing = struct module Type = struct type t = Jstr . t let navigate = Jstr . v " navigate " let reload = Jstr . v " reload " let back_forward = Jstr . v " back_forward " let prerender = Jstr . v " prerender " end type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let as_resource_timing = Fun . id let as_entry = Fun . id let unload_event_start e = Jv . Float . get e " unloadEventStart " let unload_event_end e = Jv . Float . get e " unloadEventEnd " let dom_interactive e = Jv . Float . get e " domInteractive " let dom_content_loaded_event_start e = Jv . Float . get e " domContentLoadedEventStart " let dom_content_loaded_event_end e = Jv . Float . get e " domContentLoadedEventEnd " let dom_complete e = Jv . Float . get e " domComplete " let load_event_start e = Jv . Float . get e " loadEventStart " let load_event_end e = Jv . Float . get e " loadEventEnd " let type ' e = Jv . Jstr . get e " type ' " let redirect_count e = Jv . Int . get e " redirectCount " end let as_resource_timing = Fun . id let as_navigation_timing = Fun . id end type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let time_origin_ms p = Jv . Float . get p " timeOrigin " let clear_marks p n = let args = match n with None -> [ ] || | Some n -> Jv . [ | of_jstr n ] | in ignore @@ Jv . call p " clearMarks " args let clear_measures p n = let args = match n with None -> [ ] || | Some n -> Jv . [ | of_jstr n ] | in ignore @@ Jv . call p " clearMeasures " args let clear_resource_timings p = ignore @@ Jv . call p " clearResourceTimings " [ ] || let get_entries ? type ' ? name p = match name , type ' with | None , None -> Jv . to_list Entry . of_jv @@ Jv . call p " getEntries " [ ] || | None , Some t -> Jv . to_list Entry . of_jv @@ Jv . call p " getEntriesByType " Jv . [ | of_jstr t ] | | Some n , None -> Jv . to_list Entry . of_jv @@ Jv . call p " getEntriesByName " Jv . [ | of_jstr n ] | | Some n , Some t -> Jv . to_list Entry . of_jv @@ Jv . call p " getEntriesByName " Jv . [ | of_jstr n ; of_jstr t ] | let mark p n = ignore @@ Jv . call p " mark " Jv . [ | of_jstr n ] | let measure ? start ? stop p n = match start , stop with | None , None -> ignore @@ Jv . call p " measure " [ ] || | Some s , None -> ignore @@ Jv . call p " measure " Jv . [ | of_jstr s ] | | Some s , Some e -> ignore @@ Jv . call p " measure " Jv . [ | of_jstr s ; of_jstr e ] | | None , Some e -> ignore @@ Jv . call p " measure " Jv . [ | undefined ; of_jstr e ] | let now_ms p = Jv . to_float @@ Jv . call p " now " [ ] || let to_json p = Jv . call p " toJSON " [ ] || end
module G = struct let console = Jv . get Jv . global " console " let document = El . global_document let navigator = Jv . get Jv . global " navigator " let performance = Jv . get Jv . global " performance " let window = Jv . get Jv . global " window " let is_secure_context = Jv . Bool . get Jv . global " isSecureContext " let target = Jv . global type timer_id = int let set_timeout ~ ms f = Jv . to_int @@ Jv . call Jv . global " setTimeout " [ | Jv . repr f ; Jv . of_int ms ] | let set_interval ~ ms f = Jv . to_int @@ Jv . call Jv . global " setInterval " [ | Jv . repr f ; Jv . of_int ms ] | let stop_timer tid = ignore @@ Jv . call Jv . global " clearTimeout " [ | Jv . of_int tid ] | type animation_frame_id = int let request_animation_frame f = Jv . to_int @@ Jv . call Jv . global " requestAnimationFrame " [ | Jv . repr f ] | let cancel_animation_frame fid = ignore @@ Jv . call Jv . global " cancelAnimationFrame " [ | Jv . of_int fid ] | end
module Matrix4 = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let is_2d m = Jv . Bool . get m " is2D " let is_identity m = Jv . Bool . get m " isIdentity " let inverse m = Jv . call m " inverse " [ ] || let multiply m m ' = Jv . call m " multiply " [ | m ' ] | let m11 m = Jv . Float . get m " m11 " let m12 m = Jv . Float . get m " m12 " let m13 m = Jv . Float . get m " m13 " let m14 m = Jv . Float . get m " m14 " let m21 m = Jv . Float . get m " m21 " let m22 m = Jv . Float . get m " m22 " let m23 m = Jv . Float . get m " m23 " let m24 m = Jv . Float . get m " m24 " let m31 m = Jv . Float . get m " m31 " let m32 m = Jv . Float . get m " m32 " let m33 m = Jv . Float . get m " m33 " let m34 m = Jv . Float . get m " m34 " let m41 m = Jv . Float . get m " m41 " let m42 m = Jv . Float . get m " m42 " let m43 m = Jv . Float . get m " m43 " let m44 m = Jv . Float . get m " m44 " let a m = Jv . Float . get m " a " let b m = Jv . Float . get m " b " let c m = Jv . Float . get m " c " let d m = Jv . Float . get m " d " let e m = Jv . Float . get m " e " let f m = Jv . Float . get m " f " let dommatrixro = Jv . get Jv . global " DOMMatrixReadOnly " let to_float32_array m = Tarray . of_jv @@ Jv . call m " toFloat32Array " [ ] || let of_float32_array a = Jv . call dommatrixro " fromFloat32Array " [ | Tarray . to_jv a ] | let to_float64_array m = Tarray . of_jv @@ Jv . call m " toFloat64Array " [ ] || let of_float64_array a = Jv . call dommatrixro " fromFloat64Array " [ | Tarray . to_jv a ] | end
module Vec4 = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let v4 = Jv . get Jv . global " DOMPointReadOnly " let v ~ x ~ y ~ z ~ w = Jv . new ' v4 Jv . [ | of_float x ; of_float y ; of_float z ; of_float w ; ] | let tr m v = Jv . call v " matrixTransform " [ | Matrix4 . to_jv m ] | let to_json v = Jv . call v " toJSON " [ ] || let x v = Jv . Float . get v " x " let y v = Jv . Float . get v " y " let z v = Jv . Float . get v " z " let w v = Jv . Float . get v " w " end
module Canvas = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let create ? d ? at ( ? w = 0 ) ( ? h = 0 ) cs = let c = El . to_jv @@ El . canvas ? d ? at cs in Jv . Int . set c " width " w ; Jv . Int . set c " height " h ; c let of_el e = if El . has_tag_name El . Name . canvas e then ( El . to_jv e ) else let exp = Jstr . v " Expected canvas element but found : " in Jv . throw ( Jstr . append exp ( El . tag_name e ) ) let to_el = El . of_jv let w c = Jv . Int . get c " width " let h c = Jv . Int . get c " height " let set_w c w = Jv . Int . set c " width " w let set_h c h = Jv . Int . set c " height " h let set_size_to_layout_size ( ? hidpi = true ) c = let dpr = if hidpi then Window . device_pixel_ratio G . window else 1 . 0 in let cw = Float . to_int @@ Float . ceil ( dpr . * El . inner_w ( El . of_jv c ) ) in let ch = Float . to_int @@ Float . ceil ( dpr . * El . inner_h ( El . of_jv c ) ) in if w c <> cw || h c <> ch then ( set_w c cw ; set_h c ch ) type image_encode = Jv . t let image_encode ( ? type ' = Jstr . v " image / png " ) ? quality ( ) = let o = Jv . obj [ ] || in Jv . Jstr . set o " type " type ' ; Jv . Float . set_if_some o " quality " quality ; o let enc ? encode c meth arg = let encode = match encode with None -> image_encode ( ) | Some e -> e in let t = Jv . get encode " type " in let q = Jv . find encode " quality " in let args = match arg with | None -> ( match q with None -> [ | t ] | | Some q -> [ | t ; q ] ) | | Some a -> ( match q with None -> [ | a ; t ] | | Some q -> [ | a ; t ; q ] ) | in Jv . call c meth args let to_data_url ? encode c = match enc c " toDataURL " None with | exception Jv . Error e -> Error e | v -> Ok ( Jv . to_jstr v ) let to_blob ? encode c = let fut , set = Fut . create ( ) in let cb blob = set ( Ok ( Jv . to_option Blob . of_jv blob ) ) in match enc c " toBlob " ( Some ( Jv . repr cb ) ) with | exception Jv . Error e -> set ( Error e ) ; fut | _ -> fut let capture_stream ~ hz c = let args = match hz with None -> [ ] || | Some hz -> [ | Jv . of_int hz ] | in Brr_io . Media . Stream . of_jv @@ Jv . call c " captureStrseam " args end
module C2d = struct module Fill_rule = struct type t = Jstr . t let nonzero = Jstr . v " nonzero " let evenodd = Jstr . v " evenodd " end module Image_smoothing_quality = struct type t = Jstr . t let low = Jstr . v " low " let medium = Jstr . v " medium " let high = Jstr . v " high " end module Line_cap = struct type t = Jstr . t let butt = Jstr . v " butt " let round = Jstr . v " round " let square = Jstr . v " square " end module Line_join = struct type t = Jstr . t let round = Jstr . v " round " let bevel = Jstr . v " bevel " let miter = Jstr . v " miter " end module Text_align = struct type t = Jstr . t let start = Jstr . v " start " let end ' = Jstr . v " end " let left = Jstr . v " left " let right = Jstr . v " right " let center = Jstr . v " center " end module Text_baseline = struct type t = Jstr . t let top = Jstr . v " top " let hanging = Jstr . v " hanging " let middle = Jstr . v " middle " let alphabetic = Jstr . v " alphabetic " let ideographic = Jstr . v " ideographic " let bottom = Jstr . v " bottom " end module Text_direction = struct type t = Jstr . t let ltr = Jstr . v " ltr " let rtl = Jstr . v " rtl " let inherit ' = Jstr . v " inherit " end module Composite_op = struct type t = Jstr . t let normal = Jstr . v " normal " let multiply = Jstr . v " multiply " let screen = Jstr . v " screen " let overlay = Jstr . v " overlay " let darken = Jstr . v " darken " let lighten = Jstr . v " lighten " let color_dodge = Jstr . v " color - dodge " let color_burn = Jstr . v " color - burn " let hard_light = Jstr . v " hard - light " let soft_light = Jstr . v " soft - light " let difference = Jstr . v " difference " let exclusion = Jstr . v " exclusion " let hue = Jstr . v " hue " let saturation = Jstr . v " saturation " let color = Jstr . v " color " let luminosity = Jstr . v " luminosity " let clear = Jstr . v " clear " let copy = Jstr . v " copy " let source_over = Jstr . v " source - over " let destination_over = Jstr . v " destination - over " let source_in = Jstr . v " source - in " let destination_in = Jstr . v " destination - in " let source_out = Jstr . v " source - out " let destination_out = Jstr . v " destination - out " let source_atop = Jstr . v " source - atop " let destination_atop = Jstr . v " destination - atop " let xor = Jstr . v " xor " let lighter = Jstr . v " lighter " let plus_darker = Jstr . v " plus - darker " let plus_lighter = Jstr . v " plus - lighter " end module Repeat = struct type t = Jstr . t let xy = Jstr . v " repeat " let x = Jstr . v " repeat - x " let y = Jstr . v " repeat - y " let no = Jstr . v " no - repeat " end module Path = struct type t = Jv . t let path = Jv . get Jv . global " Path2D " let create ( ) = Jv . new ' path [ ] || let of_svg svg = Jv . new ' path [ | Jv . of_jstr svg ] | let of_path p = Jv . new ' path [ | p ] | let add ? tr p p ' = ignore @@ Jv . call p " addPath " ( match tr with None -> [ | p ' ] | | Some t -> [ | p ' ; Matrix4 . to_jv t ] ) | let close p = ignore @@ Jv . call p " closePath " [ ] || let move_to p ~ x ~ y = ignore @@ Jv . call p " moveTo " Jv . [ | of_float x ; of_float y ] | let line_to p ~ x ~ y = ignore @@ Jv . call p " lineTo " Jv . [ | of_float x ; of_float y ] | let qcurve_to p ~ cx ~ cy ~ x ~ y = ignore @@ Jv . call p " quadraticCurveTo " Jv . [ | of_float cx ; of_float cy ; of_float x ; of_float y ] | let ccurve_to p ~ cx ~ cy ~ cx ' ~ cy ' ~ x ~ y = ignore @@ Jv . call p " bezierCurveTo " Jv . [ | of_float cx ; of_float cy ; of_float cx ' ; of_float cy ' ; of_float x ; of_float y ] | let arc_to p ~ cx ~ cy ~ cx ' ~ cy ' ~ r = ignore @@ Jv . call p " arcTo " Jv . [ | of_float cx ; of_float cy ; of_float cx ' ; of_float cy ' ; of_float r ] | let arc ( ? anticlockwise = false ) p ~ cx ~ cy ~ r ~ start ~ stop = ignore @@ Jv . call p " arc " Jv . [ | of_float cx ; of_float cy ; of_float r ; of_float start ; of_float stop ; of_bool anticlockwise ] | let rect p ~ x ~ y ~ w ~ h = ignore @@ Jv . call p " rect " Jv . [ | of_float x ; of_float y ; of_float w ; of_float h ] | let ellipse ( ? anticlockwise = false ) p ~ cx ~ cy ~ rx ~ ry ~ rot ~ start ~ stop = ignore @@ Jv . call p " ellipse " Jv . [ | of_float cx ; of_float cy ; of_float rx ; of_float ry ; of_float rot ; of_float start ; of_float stop ; of_bool anticlockwise ] | include ( Jv . Id : Jv . CONV with type t := t ) end type image_src = Jv . t let image_src_of_el = El . to_jv let image_src_of_jv = Fun . id type attrs = Jv . t let attrs ( ? alpha = true ) ( ? desynchronized = false ) ( ) = let o = Jv . obj [ ] || in Jv . Bool . set o " alpha " alpha ; Jv . Bool . set o " desynchronized " desynchronized ; o let attrs_alpha o = Jv . Bool . get o " alpha " let attrs_desynchronized o = Jv . Bool . get o " desynchronized " type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let create ( ? attrs = Jv . undefined ) cnv = Jv . call cnv " getContext " Jv . [ | of_string " 2d " ; attrs ] | let canvas c = Jv . find_map Canvas . of_jv c " canvas " let attrs c = Jv . call c " getContextAttributes " [ ] || let save c = ignore @@ Jv . call c " save " [ ] || let restore c = ignore @@ Jv . call c " restore " [ ] || let image_smoothing_enabled c = Jv . Bool . get c " imageSmoothingEnabled " let set_image_smoothing_enabled c b = Jv . Bool . set c " imageSmoothingEnabled " b let image_smoothing_quality c = Jv . Jstr . get c " imageSmoothingQuality " let set_image_smoothing_quality c v = Jv . Jstr . set c " imageSmoothingQuality " v let global_alpha c = Jv . Float . get c " globalAlpha " let set_global_alpha c a = Jv . Float . set c " globalAlpha " a let global_composite_op c = Jv . Jstr . get c " globalCompositeOperation " let set_global_composite_op c o = Jv . Jstr . set c " globalCompositeOperation " o let filter c = Jv . Jstr . get c " filter " let set_filter c f = Jv . Jstr . set c " filter " f let get_transform c = Matrix4 . of_jv @@ Jv . call c " getTransform " [ ] || let set_transform c m = ignore @@ Jv . call c " setTransform " [ | Matrix4 . to_jv m ] | let reset_transform c = ignore @@ Jv . call c " resetTransform " [ ] || let transform c m = ignore @@ Jv . call c " resetTransform " Jv . [ | of_float ( Matrix4 . a m ) ; of_float ( Matrix4 . b m ) ; of_float ( Matrix4 . c m ) ; of_float ( Matrix4 . d m ) ; of_float ( Matrix4 . e m ) ; of_float ( Matrix4 . f m ) ] | let translate c ~ x ~ y = ignore @@ Jv . call c " translate " Jv . [ | of_float x ; of_float y ] | let rotate c r = ignore @@ Jv . call c " rotate " Jv . [ | of_float r ] | let scale c ~ sx ~ sy = ignore @@ Jv . call c " scale " Jv . [ | of_float sx ; of_float sy ] | type style = Jv . t let set_stroke_style c s = Jv . set c " strokeStyle " s let set_fill_style c s = Jv . set c " fillStyle " s let color = Jv . of_jstr type gradient = Jv . t let gradient_style = Fun . id let make_stops g stops = let add_stop g ( off , c ) = ignore @@ Jv . call g " addColorStop " Jv . [ | of_float off ; of_jstr c ] | in List . iter ( add_stop g ) stops let linear_gradient c ~ x0 ~ y0 ~ x1 ~ y1 ~ stops = let g = Jv . call c " createLinearGradient " Jv . [ | of_float x0 ; of_float y0 ; of_float x1 ; of_float y1 ] | in make_stops g stops ; g let radial_gradient c ~ x0 ~ y0 ~ r0 ~ x1 ~ y1 ~ r1 ~ stops = let g = Jv . call c " createRadialGradient " Jv . [ | of_float x0 ; of_float y0 ; of_float r0 ; of_float x1 ; of_float y1 ; of_float r1 ; ] | in make_stops g stops ; g type pattern = Jv . t let pattern c img r ~ tr = let p = Jv . call c " createPattern " [ | img ; Jv . of_jstr r ] | in match tr with | None -> p | Some t -> ignore @@ Jv . call p " setTransform " [ | Matrix4 . to_jv t ] ; | p let pattern_style = Fun . id let line_width c = Jv . Float . get c " lineWidth " let set_line_width c w = Jv . Float . set c " lineWidth " w let line_cap c = Jv . Jstr . get c " lineCap " let set_line_cap c cap = Jv . Jstr . set c " lineCap " cap let line_join c = Jv . Jstr . get c " lineJoin " let set_line_join c join = Jv . Jstr . set c " lineJoin " join let miter_limit c = Jv . Float . get c " miterLimit " let set_miter_limit c l = Jv . Float . set c " miterLimit " l let line_dash c = Jv . to_list Jv . to_float @@ Jv . call c " getLineDash " [ ] || let set_line_dash c ds = ignore @@ Jv . call c " setLineDash " [ | Jv . of_list Jv . of_float ds ] | let line_dash_offset c = Jv . Float . get c " lineDashOffset " let set_line_dash_offset c o = Jv . Float . set c " lineDashOffset " o let shadow_blur c = Jv . Float . get c " shadowBlur " let set_shadow_blur c b = Jv . Float . set c " shadowBlur " b let shadow_offset_x c = Jv . Float . get c " shadowOffsetX " let set_shadow_offset_x c o = Jv . Float . set c " shadowOffsetX " o let shadow_offset_y c = Jv . Float . get c " shadowOffsetY " let set_shadow_offset_y c o = Jv . Float . set c " shadowOffsetY " o let shadow_color c = Jv . Jstr . get c " shadowColor " let set_shadow_color c col = Jv . Jstr . set c " shadowColor " col let font c = Jv . Jstr . get c " font " let set_font c f = Jv . Jstr . set c " font " f let text_align c = Jv . Jstr . get c " textAlign " let set_text_align c a = Jv . Jstr . set c " textAlign " a let text_baseline c = Jv . Jstr . get c " textBaseline " let set_text_baseline c b = Jv . Jstr . set c " textBaseline " b let text_direction c = Jv . Jstr . get c " direction " let set_text_direction c d = Jv . Jstr . set c " direction " d let clear_rect c ~ x ~ y ~ w ~ h = ignore @@ Jv . call c " clearRect " Jv . [ | of_float x ; of_float y ; of_float w ; of_float h ] | let fill_rect c ~ x ~ y ~ w ~ h = ignore @@ Jv . call c " fillRect " Jv . [ | of_float x ; of_float y ; of_float w ; of_float h ] | let stroke_rect c ~ x ~ y ~ w ~ h = ignore @@ Jv . call c " strokeRect " Jv . [ | of_float x ; of_float y ; of_float w ; of_float h ] | let fill ( ? fill_rule = Fill_rule . nonzero ) c p = ignore @@ Jv . call c " fill " [ | p ; Jv . of_jstr fill_rule ] | let stroke c p = ignore @@ Jv . call c " stroke " [ | p ] | let clip ( ? fill_rule = Fill_rule . nonzero ) c p = ignore @@ Jv . call c " clip " [ | p ; Jv . of_jstr fill_rule ] | let draw_focus_if_needed c p e = ignore @@ Jv . call c " drawFocusIfNeeded " [ | p ; El . to_jv e ] | let scroll_path_into_view c p = ignore @@ Jv . call c " scrollPathIntoView " [ | p ] | let is_point_in_fill ( ? fill_rule = Fill_rule . nonzero ) c p ~ x ~ y = Jv . to_bool @@ Jv . call c " isPointInPath " Jv . [ | p ; of_float x ; of_float y ; of_jstr fill_rule ] | let is_point_in_stroke c p ~ x ~ y = Jv . to_bool @@ Jv . call c " isPointInStroke " Jv . [ | p ; of_float x ; of_float y ; ] | let call_text c meth ? max_width txt ~ x ~ y = let args = match max_width with | None -> Jv . [ | of_jstr txt ; of_float x ; of_float y ] | | Some m -> Jv . [ | of_jstr txt ; of_float x ; of_float y ; of_float m ] | in ignore @@ Jv . call c meth args let fill_text ? max_width c txt ~ x ~ y = call_text c " fillText " ? max_width txt ~ x ~ y let stroke_text ? max_width c txt ~ x ~ y = call_text c " strokeText " ? max_width txt ~ x ~ y module Text_metrics = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let width m = Jv . Float . get m " width " let actual_bounding_box_left m = Jv . Float . get m " actualBoundingBoxLeft " let actual_bounding_box_right m = Jv . Float . get m " actualBoundingBoxRight " let font_bounding_box_ascent m = Jv . Float . get m " fontBoundingBoxAscent " let font_bounding_box_descent m = Jv . Float . get m " fontBoundingBoxDescent " let actual_bounding_box_ascent m = Jv . Float . get m " actualBoundingBoxAscent " let actual_bounding_box_descent m = Jv . Float . get m " actualBoundingBoxDescent " let em_height_ascent m = Jv . Float . get m " emHeightAscent " let em_height_descent m = Jv . Float . get m " emHeightDescent " let hanging_baseline m = Jv . Float . get m " hangingBaseline " let alphabetic_baseline m = Jv . Float . get m " alphabeticBaseline " let ideographic_baseline m = Jv . Float . get m " ideographicBaseline " end let measure_text c txt = Text_metrics . of_jv @@ Jv . call c " measureText " [ | Jv . of_jstr txt ] | let draw_image c i ~ x ~ y = ignore @@ Jv . call c " drawImage " Jv . [ | i ; of_float x ; of_float y ] | let draw_image_in_rect c i ~ x ~ y ~ w ~ h = ignore @@ Jv . call c " drawImage " Jv . [ | i ; of_float x ; of_float y ; of_float w ; of_float h ] | let draw_sub_image_in_rect c i ~ sx ~ sy ~ sw ~ sh ~ x ~ y ~ w ~ h = ignore @@ Jv . call c " drawImage " Jv . [ | i ; of_float sx ; of_float sy ; of_float sw ; of_float sh ; of_float x ; of_float y ; of_float w ; of_float h ] | module Image_data = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let image_data = Jv . get Jv . global " ImageData " let create ? data ~ w ~ h ( ) = let args = match data with | None -> Jv . [ | of_int w ; of_int h ] | | Some data -> Jv . [ | Tarray . to_jv data ; of_int w ; of_int h ] | in Jv . new ' image_data args let w d = Jv . Int . get d " width " let h d = Jv . Int . get d " height " let data d = Tarray . of_jv @@ Jv . get d " data " end let create_image_data c ~ w ~ h = Image_data . of_jv @@ Jv . call c " createImageData " Jv . [ | of_int w ; of_int h ] | let get_image_data c ~ x ~ y ~ w ~ h = Image_data . of_jv @@ Jv . call c " getImageData " Jv . [ | of_int x ; of_int y ; of_int w ; of_int h ] | let put_image_data c d ~ x ~ y = ignore @@ Jv . call c " putImageData " Jv . [ | Image_data . to_jv d ; of_int x ; of_int y ] | let put_sub_image_data c d ~ sx ~ sy ~ sw ~ sh ~ x ~ y = ignore @@ Jv . call c " putImageData " Jv . [ | Image_data . to_jv d ; of_int x ; of_int y ; of_int sx ; of_int sy ; of_int sw ; of_int sh ] | end
module Gl = struct module Attrs = struct module Power_preference = struct type t = Jstr . t let default = Jstr . v " default " let high_performance = Jstr . v " high - performance " let low_power = Jstr . v " low - power " end type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let v ? alpha ? depth ? stencil ? antialias ? premultiplied_alpha ? preserve_drawing_buffer ? power_preference ? fail_if_major_performance_caveat ? desynchronized ( ) = let o = Jv . obj [ ] || in Jv . Bool . set_if_some o " alpha " alpha ; Jv . Bool . set_if_some o " depth " depth ; Jv . Bool . set_if_some o " stencil " stencil ; Jv . Bool . set_if_some o " antialias " antialias ; Jv . Bool . set_if_some o " premultipliedApha " premultiplied_alpha ; Jv . Bool . set_if_some o " preserveDrawingBuffer " preserve_drawing_buffer ; Jv . Jstr . set_if_some o " powerPreference " power_preference ; Jv . Bool . set_if_some o " failIfMajorPerformanceCaveat " fail_if_major_performance_caveat ; Jv . Bool . set_if_some o " desynchronized " desynchronized ; o let alpha a = Jv . Bool . get a " alpha " let depth a = Jv . Bool . get a " depth " let stencil a = Jv . Bool . get a " stencil " let antialias a = Jv . Bool . get a " antialias " let premultiplied_alpha a = Jv . Bool . get a " premultipliedApha " let preserve_drawing_buffer a = Jv . Bool . get a " preserveDrawingBuffer " let fail_if_major_performance_caveat a = Jv . Bool . get a " failIfMajorPerformanceCaveat " let power_preference a = Jv . Jstr . get a " powerPreference " let desynchronized a = Jv . Bool . get a " desynchronized " end type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let create ( ? attrs = Jv . undefined ) ( ? v1 = false ) cnv = let webgl = Jv . of_string ( if v1 then " webgl " else " webgl2 " ) in Jv . to_option Fun . id @@ Jv . call ( Canvas . to_jv cnv ) " getContext " Jv . [ | webgl ; attrs ] | let canvas c = Jv . find_map Canvas . of_jv c " canvas " let attrs c = Jv . call c " getContextAttributes " [ ] || let drawing_buffer_width c = Jv . Int . get c " drawingBufferWidth " let drawing_buffer_height c = Jv . Int . get c " drawingBufferHeight " let is_context_lost c = Jv . Bool . get c " isContextLost " let get_supported_extensions c = Jv . to_jstr_list @@ Jv . call c " getSupportedExtensions " [ ] || let get_extension c ext = Jv . call c " getExtension " Jv . [ | of_jstr ext ] | type enum = int type buffer = Jv . t type framebuffer = Jv . t type program = Jv . t type query = Jv . t type renderbuffer = Jv . t type sampler = Jv . t type shader = Jv . t type sync = Jv . t type texture = Jv . t type transform_feedback = Jv . t type uniform_location = Jv . t type vertex_array_object = Jv . t module Active_info = struct type t = Jv . t let size i = Jv . Int . get i " size " let type ' i = Jv . Int . get i " type " let name i = Jv . Jstr . get i " name " end module Shader_precision_format = struct type t = Jv . t let range_min f = Jv . Int . get f " rangeMin " let range_max f = Jv . Int . get f " rangeMax " let precision f = Jv . Int . get f " precision " end module Tex_image_source = struct type t = Jv . t let of_image_data = C2d . Image_data . to_jv let of_img_el = Brr . El . to_jv let of_canvas_el = Canvas . to_jv let of_video_el = Brr_io . Media . El . to_jv let of_offscreen_canvas = Fun . id end let active_texture c texture = ignore @@ Jv . call c " activeTexture " Jv . [ | of_int texture ] | let attach_shader c program shader = ignore @@ Jv . call c " attachShader " Jv . [ | program ; shader ] | let begin_query c target query = ignore @@ Jv . call c " beginQuery " Jv . [ | of_int target ; query ] | let begin_transform_feedback c primitiveMode = ignore @@ Jv . call c " beginTransformFeedback " Jv . [ | of_int primitiveMode ] | let bind_attrib_location c program index name = ignore @@ Jv . call c " bindAttribLocation " Jv . [ | program ; of_int index ; of_jstr name ] | let bind_buffer c target buffer = ignore @@ Jv . call c " bindBuffer " Jv . [ | of_int target ; of_option ~ none : null Fun . id buffer ] | let bind_buffer_base c target index buffer = ignore @@ Jv . call c " bindBufferBase " Jv . [ | of_int target ; of_int index ; buffer ] | let bind_buffer_range c target index buffer offset size = ignore @@ Jv . call c " bindBufferRange " Jv . [ | of_int target ; of_int index ; buffer ; of_int offset ; of_int size ] | let bind_framebuffer c target framebuffer = ignore @@ Jv . call c " bindFramebuffer " Jv . [ | of_int target ; of_option ~ none : null Fun . id framebuffer ] | let bind_renderbuffer c target renderbuffer = ignore @@ Jv . call c " bindRenderbuffer " Jv . [ | of_int target ; of_option ~ none : null Fun . id renderbuffer ] | let bind_sampler c unit sampler = ignore @@ Jv . call c " bindSampler " Jv . [ | of_int unit ; of_option ~ none : null Fun . id sampler ] | let bind_texture c target texture = ignore @@ Jv . call c " bindTexture " Jv . [ | of_int target ; of_option ~ none : null Fun . id texture ] | let bind_transform_feedback c target tf = ignore @@ Jv . call c " bindTransformFeedback " Jv . [ | of_int target ; of_option ~ none : null Fun . id tf ] | let bind_vertex_array c array = ignore @@ Jv . call c " bindVertexArray " Jv . [ | of_option ~ none : null Fun . id array ] | let blend_color c red green blue alpha = ignore @@ Jv . call c " blendColor " Jv . [ | of_float red ; of_float green ; of_float blue ; of_float alpha ] | let blend_equation c mode = ignore @@ Jv . call c " blendEquation " Jv . [ | of_int mode ] | let blend_equation_separate c modeRGB modeAlpha = ignore @@ Jv . call c " blendEquationSeparate " Jv . [ | of_int modeRGB ; of_int modeAlpha ] | let blend_func c sfactor dfactor = ignore @@ Jv . call c " blendFunc " Jv . [ | of_int sfactor ; of_int dfactor ] | let blend_func_separate c srcRGB dstRGB srcAlpha dstAlpha = ignore @@ Jv . call c " blendFuncSeparate " Jv . [ | of_int srcRGB ; of_int dstRGB ; of_int srcAlpha ; of_int dstAlpha ] | let blit_framebuffer c srcX0 srcY0 srcX1 srcY1 dstX0 dstY0 dstX1 dstY1 mask filter = ignore @@ Jv . call c " blitFramebuffer " Jv . [ | of_int srcX0 ; of_int srcY0 ; of_int srcX1 ; of_int srcY1 ; of_int dstX0 ; of_int dstY0 ; of_int dstX1 ; of_int dstY1 ; of_int mask ; of_int filter ] | let buffer_data c target srcData usage = ignore @@ Jv . call c " bufferData " Jv . [ | of_int target ; Tarray . to_jv srcData ; of_int usage ] | let buffer_data_size c target size usage = ignore @@ Jv . call c " bufferData " Jv . [ | of_int target ; of_int size ; of_int usage ] | let buffer_sub_data c target dstByteOffset srcData = ignore @@ Jv . call c " bufferSubData " Jv . [ | of_int target ; of_int dstByteOffset ; Tarray . to_jv srcData ] | let check_framebuffer_status c target = Jv . to_int @@ Jv . call c " checkFramebufferStatus " Jv . [ | of_int target ] | let clear c mask = ignore @@ Jv . call c " clear " Jv . [ | of_int mask ] | let clear_bufferfi c buffer drawbuffer depth stencil = ignore @@ Jv . call c " clearBufferfi " Jv . [ | of_int buffer ; of_int drawbuffer ; of_float depth ; of_int stencil ] | let clear_bufferfv c buffer drawbuffer values = ignore @@ Jv . call c " clearBufferfv " Jv . [ | of_int buffer ; of_int drawbuffer ; Tarray . to_jv values ] | let clear_bufferiv c buffer drawbuffer values = ignore @@ Jv . call c " clearBufferiv " Jv . [ | of_int buffer ; of_int drawbuffer ; Tarray . to_jv values ] | let clear_bufferuiv c buffer drawbuffer values = ignore @@ Jv . call c " clearBufferuiv " Jv . [ | of_int buffer ; of_int drawbuffer ; Tarray . to_jv values ] | let clear_color c red green blue alpha = ignore @@ Jv . call c " clearColor " Jv . [ | of_float red ; of_float green ; of_float blue ; of_float alpha ] | let clear_depth c depth = ignore @@ Jv . call c " clearDepth " Jv . [ | of_float depth ] | let clear_stencil c s = ignore @@ Jv . call c " clearStencil " Jv . [ | of_int s ] | let client_wait_sync c sync flags timeout = Jv . to_int @@ Jv . call c " clientWaitSync " Jv . [ | sync ; of_int flags ; of_int timeout ] | let color_mask c red green blue alpha = ignore @@ Jv . call c " colorMask " Jv . [ | Jv . of_bool red ; Jv . of_bool green ; Jv . of_bool blue ; Jv . of_bool alpha ] | let compile_shader c shader = ignore @@ Jv . call c " compileShader " Jv . [ | shader ] | let compressed_tex_image2d c target level internalformat width height border srcData = ignore @@ Jv . call c " compressedTexImage2D " Jv . [ | of_int target ; of_int level ; of_int internalformat ; of_int width ; of_int height ; of_int border ; Tarray . to_jv srcData ] | let compressed_tex_image2d_size c target level internalformat width height border imageSize offset = ignore @@ Jv . call c " compressedTexImage2D " Jv . [ | of_int target ; of_int level ; of_int internalformat ; of_int width ; of_int height ; of_int border ; of_int imageSize ; of_int offset ] | let compressed_tex_image3d c target level internalformat width height depth border srcData = ignore @@ Jv . call c " compressedTexImage3D " Jv . [ | of_int target ; of_int level ; of_int internalformat ; of_int width ; of_int height ; of_int depth ; of_int border ; Tarray . to_jv srcData ] | let compressed_tex_image3d_size c target level internalformat width height depth border imageSize offset = ignore @@ Jv . call c " compressedTexImage3D " Jv . [ | of_int target ; of_int level ; of_int internalformat ; of_int width ; of_int height ; of_int depth ; of_int border ; of_int imageSize ; of_int offset ] | let compressed_tex_sub_image2d c target level xoffset yoffset width height format srcData = ignore @@ Jv . call c " compressedTexSubImage2D " Jv . [ | of_int target ; of_int level ; of_int xoffset ; of_int yoffset ; of_int width ; of_int height ; of_int format ; Tarray . to_jv srcData ] | let compressed_tex_sub_image2d_size c target level xoffset yoffset width height format imageSize offset = ignore @@ Jv . call c " compressedTexSubImage2D " Jv . [ | of_int target ; of_int level ; of_int xoffset ; of_int yoffset ; of_int width ; of_int height ; of_int format ; of_int imageSize ; of_int offset ] | let compressed_tex_sub_image3d c target level xoffset yoffset zoffset width height depth format srcData = ignore @@ Jv . call c " compressedTexSubImage3D " Jv . [ | of_int target ; of_int level ; of_int xoffset ; of_int yoffset ; of_int zoffset ; of_int width ; of_int height ; of_int depth ; of_int format ; Tarray . to_jv srcData ] | let compressed_tex_sub_image3d_size c target level xoffset yoffset zoffset width height depth format imageSize offset = ignore @@ Jv . call c " compressedTexSubImage3D " Jv . [ | of_int target ; of_int level ; of_int xoffset ; of_int yoffset ; of_int zoffset ; of_int width ; of_int height ; of_int depth ; of_int format ; of_int imageSize ; of_int offset ] | let copy_buffer_sub_data c readTarget writeTarget readOffset writeOffset size = ignore @@ Jv . call c " copyBufferSubData " Jv . [ | of_int readTarget ; of_int writeTarget ; of_int readOffset ; of_int writeOffset ; of_int size ] | let copy_tex_image2d c target level internalformat x y width height border = ignore @@ Jv . call c " copyTexImage2D " Jv . [ | of_int target ; of_int level ; of_int internalformat ; of_int x ; of_int y ; of_int width ; of_int height ; of_int border ] | let copy_tex_sub_image2d c target level xoffset yoffset x y width height = ignore @@ Jv . call c " copyTexSubImage2D " Jv . [ | of_int target ; of_int level ; of_int xoffset ; of_int yoffset ; of_int x ; of_int y ; of_int width ; of_int height ] | let copy_tex_sub_image3d c target level xoffset yoffset zoffset x y width height = ignore @@ Jv . call c " copyTexSubImage3D " Jv . [ | of_int target ; of_int level ; of_int xoffset ; of_int yoffset ; of_int zoffset ; of_int x ; of_int y ; of_int width ; of_int height ] | let create_buffer c = Jv . call c " createBuffer " Jv . [ ] || let create_framebuffer c = Jv . call c " createFramebuffer " Jv . [ ] || let create_program c = Jv . call c " createProgram " Jv . [ ] || let create_query c = Jv . call c " createQuery " Jv . [ ] || let create_renderbuffer c = Jv . call c " createRenderbuffer " Jv . [ ] || let create_sampler c = Jv . call c " createSampler " Jv . [ ] || let create_shader c type ' = Jv . call c " createShader " Jv . [ | of_int type ' ] | let create_texture c = Jv . call c " createTexture " Jv . [ ] || let create_transform_feedback c = Jv . call c " createTransformFeedback " Jv . [ ] || let create_vertex_array c = Jv . call c " createVertexArray " Jv . [ ] || let cull_face c mode = ignore @@ Jv . call c " cullFace " Jv . [ | of_int mode ] | let delete_buffer c buffer = ignore @@ Jv . call c " deleteBuffer " Jv . [ | buffer ] | let delete_framebuffer c framebuffer = ignore @@ Jv . call c " deleteFramebuffer " Jv . [ | framebuffer ] | let delete_program c program = ignore @@ Jv . call c " deleteProgram " Jv . [ | program ] | let delete_query c query = ignore @@ Jv . call c " deleteQuery " Jv . [ | query ] | let delete_renderbuffer c renderbuffer = ignore @@ Jv . call c " deleteRenderbuffer " Jv . [ | renderbuffer ] | let delete_sampler c sampler = ignore @@ Jv . call c " deleteSampler " Jv . [ | sampler ] | let delete_shader c shader = ignore @@ Jv . call c " deleteShader " Jv . [ | shader ] | let delete_sync c sync = ignore @@ Jv . call c " deleteSync " Jv . [ | sync ] | let delete_texture c texture = ignore @@ Jv . call c " deleteTexture " Jv . [ | texture ] | let delete_transform_feedback c tf = ignore @@ Jv . call c " deleteTransformFeedback " Jv . [ | tf ] | let delete_vertex_array c vertexArray = ignore @@ Jv . call c " deleteVertexArray " Jv . [ | vertexArray ] | let depth_func c func = ignore @@ Jv . call c " depthFunc " Jv . [ | of_int func ] | let depth_mask c flag = ignore @@ Jv . call c " depthMask " Jv . [ | Jv . of_bool flag ] | let depth_range c zNear zFar = ignore @@ Jv . call c " depthRange " Jv . [ | of_float zNear ; of_float zFar ] | let detach_shader c program shader = ignore @@ Jv . call c " detachShader " Jv . [ | program ; shader ] | let disable c cap = ignore @@ Jv . call c " disable " Jv . [ | of_int cap ] | let disable_vertex_attrib_array c index = ignore @@ Jv . call c " disableVertexAttribArray " Jv . [ | of_int index ] | let draw_arrays c mode first count = ignore @@ Jv . call c " drawArrays " Jv . [ | of_int mode ; of_int first ; of_int count ] | let draw_arrays_instanced c mode first count instanceCount = ignore @@ Jv . call c " drawArraysInstanced " Jv . [ | of_int mode ; of_int first ; of_int count ; of_int instanceCount ] | let draw_buffers c buffers = ignore @@ Jv . call c " drawBuffers " Jv . [ | of_list of_int buffers ] | let draw_elements c mode count type ' offset = ignore @@ Jv . call c " drawElements " Jv . [ | of_int mode ; of_int count ; of_int type ' ; of_int offset ] | let draw_elements_instanced c mode count type ' offset instanceCount = ignore @@ Jv . call c " drawElementsInstanced " Jv . [ | of_int mode ; of_int count ; of_int type ' ; of_int offset ; of_int instanceCount ] | let draw_range_elements c mode start end ' count type ' offset = ignore @@ Jv . call c " drawRangeElements " Jv . [ | of_int mode ; of_int start ; of_int end ' ; of_int count ; of_int type ' ; of_int offset ] | let enable c cap = ignore @@ Jv . call c " enable " Jv . [ | of_int cap ] | let enable_vertex_attrib_array c index = ignore @@ Jv . call c " enableVertexAttribArray " Jv . [ | of_int index ] | let end_query c target = ignore @@ Jv . call c " endQuery " Jv . [ | of_int target ] | let end_transform_feedback c = ignore @@ Jv . call c " endTransformFeedback " Jv . [ ] || let fence_sync c condition flags = Jv . call c " fenceSync " Jv . [ | of_int condition ; of_int flags ] | let finish c = ignore @@ Jv . call c " finish " Jv . [ ] || let flush c = ignore @@ Jv . call c " flush " Jv . [ ] || let framebuffer_renderbuffer c target attachment renderbuffertarget renderbuffer = ignore @@ Jv . call c " framebufferRenderbuffer " Jv . [ | of_int target ; of_int attachment ; of_int renderbuffertarget ; renderbuffer ] | let framebuffer_texture2d c target attachment textarget texture level = ignore @@ Jv . call c " framebufferTexture2D " Jv . [ | of_int target ; of_int attachment ; of_int textarget ; texture ; of_int level ] | let framebuffer_texture_layer c target attachment texture level layer = ignore @@ Jv . call c " framebufferTextureLayer " Jv . [ | of_int target ; of_int attachment ; texture ; of_int level ; of_int layer ] | let front_face c mode = ignore @@ Jv . call c " frontFace " Jv . [ | of_int mode ] | let generate_mipmap c target = ignore @@ Jv . call c " generateMipmap " Jv . [ | of_int target ] | let get_active_attrib c program index = Jv . call c " getActiveAttrib " Jv . [ | program ; of_int index ] | let get_active_uniform c program index = Jv . call c " getActiveUniform " Jv . [ | program ; of_int index ] | let get_active_uniform_block_name c program uniformBlockIndex = Jv . to_jstr @@ Jv . call c " getActiveUniformBlockName " Jv . [ | program ; of_int uniformBlockIndex ] | let get_active_uniform_block_parameter c program uniformBlockIndex pname = Jv . call c " getActiveUniformBlockParameter " Jv . [ | program ; of_int uniformBlockIndex ; of_int pname ] | let get_active_uniforms c program uniformIndices pname = Jv . call c " getActiveUniforms " Jv . [ | program ; of_list of_int uniformIndices ; of_int pname ] | let get_attached_shaders c program = Jv . to_jv_list @@ Jv . call c " getAttachedShaders " Jv . [ | program ] | let get_attrib_location c program name = Jv . to_int @@ Jv . call c " getAttribLocation " Jv . [ | program ; of_jstr name ] | let get_buffer_parameter c target pname = Jv . call c " getBufferParameter " Jv . [ | of_int target ; of_int pname ] | let get_buffer_sub_data c target srcByteOffset dstBuffer = ignore @@ Jv . call c " getBufferSubData " Jv . [ | of_int target ; of_int srcByteOffset ; Tarray . to_jv dstBuffer ] | let get_error c = Jv . to_int @@ Jv . call c " getError " Jv . [ ] || let get_frag_data_location c program name = Jv . to_int @@ Jv . call c " getFragDataLocation " Jv . [ | program ; of_jstr name ] | let get_framebuffer_attachment_parameter c target attachment pname = Jv . call c " getFramebufferAttachmentParameter " Jv . [ | of_int target ; of_int attachment ; of_int pname ] | let get_indexed_parameter c target index = Jv . call c " getIndexedParameter " Jv . [ | of_int target ; of_int index ] | let get_internalformat_parameter c target internalformat pname = Jv . call c " getInternalformatParameter " Jv . [ | of_int target ; of_int internalformat ; of_int pname ] | let get_parameter c pname = Jv . call c " getParameter " Jv . [ | of_int pname ] | let get_program_info_log c program = Jv . to_jstr @@ Jv . call c " getProgramInfoLog " Jv . [ | program ] | let get_program_parameter c program pname = Jv . call c " getProgramParameter " Jv . [ | program ; of_int pname ] | let get_query c target pname = Jv . call c " getQuery " Jv . [ | of_int target ; of_int pname ] | let get_query_parameter c query pname = Jv . call c " getQueryParameter " Jv . [ | query ; of_int pname ] | let get_renderbuffer_parameter c target pname = Jv . call c " getRenderbufferParameter " Jv . [ | of_int target ; of_int pname ] | let get_sampler_parameter c sampler pname = Jv . call c " getSamplerParameter " Jv . [ | sampler ; of_int pname ] | let get_shader_info_log c shader = Jv . to_jstr @@ Jv . call c " getShaderInfoLog " Jv . [ | shader ] | let get_shader_parameter c shader pname = Jv . call c " getShaderParameter " Jv . [ | shader ; of_int pname ] | let get_shader_precision_format c shadertype precisiontype = Jv . call c " getShaderPrecisionFormat " Jv . [ | of_int shadertype ; of_int precisiontype ] | let get_shader_source c shader = Jv . to_jstr @@ Jv . call c " getShaderSource " Jv . [ | shader ] | let get_sync_parameter c sync pname = Jv . call c " getSyncParameter " Jv . [ | sync ; of_int pname ] | let get_tex_parameter c target pname = Jv . call c " getTexParameter " Jv . [ | of_int target ; of_int pname ] | let get_transform_feedback_varying c program index = Jv . call c " getTransformFeedbackVarying " Jv . [ | program ; of_int index ] | let get_uniform c program location = Jv . call c " getUniform " Jv . [ | program ; location ] | let get_uniform_block_index c program uniformBlockName = Jv . to_int @@ Jv . call c " getUniformBlockIndex " Jv . [ | program ; of_jstr uniformBlockName ] | let get_uniform_indices c program uniformNames = Jv . to_list Jv . to_int @@ Jv . call c " getUniformIndices " Jv . [ | program ; of_jstr_list uniformNames ] | let get_uniform_location c program name = Jv . call c " getUniformLocation " Jv . [ | program ; of_jstr name ] | let get_vertex_attrib c index pname = Jv . call c " getVertexAttrib " Jv . [ | of_int index ; of_int pname ] | let get_vertex_attrib_offset c index pname = Jv . to_int @@ Jv . call c " getVertexAttribOffset " Jv . [ | of_int index ; of_int pname ] | let hint c target mode = ignore @@ Jv . call c " hint " Jv . [ | of_int target ; of_int mode ] | let invalidate_framebuffer c target attachments = ignore @@ Jv . call c " invalidateFramebuffer " Jv . [ | of_int target ; of_list of_int attachments ] | let invalidate_sub_framebuffer c target attachments x y width height = ignore @@ Jv . call c " invalidateSubFramebuffer " Jv . [ | of_int target ; of_list of_int attachments ; of_int x ; of_int y ; of_int width ; of_int height ] | let is_buffer c buffer = Jv . to_bool @@ Jv . call c " isBuffer " Jv . [ | buffer ] | let is_enabled c cap = Jv . to_bool @@ Jv . call c " isEnabled " Jv . [ | of_int cap ] | let is_framebuffer c framebuffer = Jv . to_bool @@ Jv . call c " isFramebuffer " Jv . [ | framebuffer ] | let is_program c program = Jv . to_bool @@ Jv . call c " isProgram " Jv . [ | program ] | let is_query c query = Jv . to_bool @@ Jv . call c " isQuery " Jv . [ | query ] | let is_renderbuffer c renderbuffer = Jv . to_bool @@ Jv . call c " isRenderbuffer " Jv . [ | renderbuffer ] | let is_sampler c sampler = Jv . to_bool @@ Jv . call c " isSampler " Jv . [ | sampler ] | let is_shader c shader = Jv . to_bool @@ Jv . call c " isShader " Jv . [ | shader ] | let is_texture c texture = Jv . to_bool @@ Jv . call c " isTexture " Jv . [ | texture ] | let is_transform_feedback c tf = Jv . to_bool @@ Jv . call c " isTransformFeedback " Jv . [ | tf ] | let is_vertex_array c vertexArray = Jv . to_bool @@ Jv . call c " isVertexArray " Jv . [ | vertexArray ] | let line_width c width = ignore @@ Jv . call c " lineWidth " Jv . [ | of_float width ] | let link_program c program = ignore @@ Jv . call c " linkProgram " Jv . [ | program ] | let pause_transform_feedback c = ignore @@ Jv . call c " pauseTransformFeedback " Jv . [ ] || let pixel_storei c pname param = ignore @@ Jv . call c " pixelStorei " Jv . [ | of_int pname ; of_int param ] | let polygon_offset c factor units = ignore @@ Jv . call c " polygonOffset " Jv . [ | of_float factor ; of_float units ] | let read_buffer c src = ignore @@ Jv . call c " readBuffer " Jv . [ | of_int src ] | let read_pixels_to_pixel_pack c x y width height format type ' offset = ignore @@ Jv . call c " readPixels " Jv . [ | of_int x ; of_int y ; of_int width ; of_int height ; of_int format ; of_int type ' ; of_int offset ] | let read_pixels c x y width height format type ' dstData = ignore @@ Jv . call c " readPixels " Jv . [ | of_int x ; of_int y ; of_int width ; of_int height ; of_int format ; of_int type ' ; Tarray . to_jv dstData ] | let renderbuffer_storage c target internalformat width height = ignore @@ Jv . call c " renderbufferStorage " Jv . [ | of_int target ; of_int internalformat ; of_int width ; of_int height ] | let renderbuffer_storage_multisample c target samples internalformat width height = ignore @@ Jv . call c " renderbufferStorageMultisample " Jv . [ | of_int target ; of_int samples ; of_int internalformat ; of_int width ; of_int height ] | let resume_transform_feedback c = ignore @@ Jv . call c " resumeTransformFeedback " Jv . [ ] || let sample_coverage c value invert = ignore @@ Jv . call c " sampleCoverage " Jv . [ | of_float value ; Jv . of_bool invert ] | let sampler_parameterf c sampler pname param = ignore @@ Jv . call c " samplerParameterf " Jv . [ | sampler ; of_int pname ; of_float param ] | let sampler_parameteri c sampler pname param = ignore @@ Jv . call c " samplerParameteri " Jv . [ | sampler ; of_int pname ; of_int param ] | let scissor c x y width height = ignore @@ Jv . call c " scissor " Jv . [ | of_int x ; of_int y ; of_int width ; of_int height ] | let shader_source c shader source = ignore @@ Jv . call c " shaderSource " Jv . [ | shader ; of_jstr source ] | let stencil_func c func ref mask = ignore @@ Jv . call c " stencilFunc " Jv . [ | of_int func ; of_int ref ; of_int mask ] | let stencil_func_separate c face func ref mask = ignore @@ Jv . call c " stencilFuncSeparate " Jv . [ | of_int face ; of_int func ; of_int ref ; of_int mask ] | let stencil_mask c mask = ignore @@ Jv . call c " stencilMask " Jv . [ | of_int mask ] | let stencil_mask_separate c face mask = ignore @@ Jv . call c " stencilMaskSeparate " Jv . [ | of_int face ; of_int mask ] | let stencil_op c fail zfail zpass = ignore @@ Jv . call c " stencilOp " Jv . [ | of_int fail ; of_int zfail ; of_int zpass ] | let stencil_op_separate c face fail zfail zpass = ignore @@ Jv . call c " stencilOpSeparate " Jv . [ | of_int face ; of_int fail ; of_int zfail ; of_int zpass ] | let tex_image2d c target level internalformat width height border format type ' srcData srcOffset = ignore @@ Jv . call c " texImage2D " Jv . [ | of_int target ; of_int level ; of_int internalformat ; of_int width ; of_int height ; of_int border ; of_int format ; of_int type ' ; Tarray . to_jv srcData ; of_int srcOffset ] | let tex_image2d_of_source c target level internalformat width height border format type ' source = ignore @@ Jv . call c " texImage2D " Jv . [ | of_int target ; of_int level ; of_int internalformat ; of_int width ; of_int height ; of_int border ; of_int format ; of_int type ' ; source ] | let tex_image2d_of_pixel_unpack c target level internalformat width height border format type ' pboOffset = ignore @@ Jv . call c " texImage2D " Jv . [ | of_int target ; of_int level ; of_int internalformat ; of_int width ; of_int height ; of_int border ; of_int format ; of_int type ' ; of_int pboOffset ] | let tex_image3d c target level internalformat width height depth border format type ' srcData srcOffset = ignore @@ Jv . call c " texImage3D " Jv . [ | of_int target ; of_int level ; of_int internalformat ; of_int width ; of_int height ; of_int depth ; of_int border ; of_int format ; of_int type ' ; Tarray . to_jv srcData ; of_int srcOffset ] | let tex_image3d_of_source c target level internalformat width height depth border format type ' source = ignore @@ Jv . call c " texImage3D " Jv . [ | of_int target ; of_int level ; of_int internalformat ; of_int width ; of_int height ; of_int depth ; of_int border ; of_int format ; of_int type ' ; source ] | let tex_image3d_of_pixel_unpack c target level internalformat width height depth border format type ' pboOffset = ignore @@ Jv . call c " texImage3D " Jv . [ | of_int target ; of_int level ; of_int internalformat ; of_int width ; of_int height ; of_int depth ; of_int border ; of_int format ; of_int type ' ; of_int pboOffset ] | let tex_parameterf c target pname param = ignore @@ Jv . call c " texParameterf " Jv . [ | of_int target ; of_int pname ; of_float param ] | let tex_parameteri c target pname param = ignore @@ Jv . call c " texParameteri " Jv . [ | of_int target ; of_int pname ; of_int param ] | let tex_storage2d c target levels internalformat width height = ignore @@ Jv . call c " texStorage2D " Jv . [ | of_int target ; of_int levels ; of_int internalformat ; of_int width ; of_int height ] | let tex_storage3d c target levels internalformat width height depth = ignore @@ Jv . call c " texStorage3D " Jv . [ | of_int target ; of_int levels ; of_int internalformat ; of_int width ; of_int height ; of_int depth ] | let tex_sub_image2d c target level xoffset yoffset width height format type ' srcData srcOffset = ignore @@ Jv . call c " texSubImage2D " Jv . [ | of_int target ; of_int level ; of_int xoffset ; of_int yoffset ; of_int width ; of_int height ; of_int format ; of_int type ' ; Tarray . to_jv srcData ; of_int srcOffset ] | let tex_sub_image2d_of_source c target level xoffset yoffset width height format type ' source = ignore @@ Jv . call c " texSubImage2D " Jv . [ | of_int target ; of_int level ; of_int xoffset ; of_int yoffset ; of_int width ; of_int height ; of_int format ; of_int type ' ; source ] | let tex_sub_image2d_of_pixel_unpack c target level xoffset yoffset width height format type ' pboOffset = ignore @@ Jv . call c " texSubImage2D " Jv . [ | of_int target ; of_int level ; of_int xoffset ; of_int yoffset ; of_int width ; of_int height ; of_int format ; of_int type ' ; of_int pboOffset ] | let tex_sub_image3d c target level xoffset yoffset zoffset width height depth format type ' srcData = ignore @@ Jv . call c " texSubImage3D " Jv . [ | of_int target ; of_int level ; of_int xoffset ; of_int yoffset ; of_int zoffset ; of_int width ; of_int height ; of_int depth ; of_int format ; of_int type ' ; Tarray . to_jv srcData ] | let tex_sub_image3d_of_source c target level xoffset yoffset zoffset width height depth format type ' source = ignore @@ Jv . call c " texSubImage3D " Jv . [ | of_int target ; of_int level ; of_int xoffset ; of_int yoffset ; of_int zoffset ; of_int width ; of_int height ; of_int depth ; of_int format ; of_int type ' ; source ] | let tex_sub_image3d_of_pixel_unpack c target level xoffset yoffset zoffset width height depth format type ' pboOffset = ignore @@ Jv . call c " texSubImage3D " Jv . [ | of_int target ; of_int level ; of_int xoffset ; of_int yoffset ; of_int zoffset ; of_int width ; of_int height ; of_int depth ; of_int format ; of_int type ' ; of_int pboOffset ] | let transform_feedback_varyings c program varyings bufferMode = ignore @@ Jv . call c " transformFeedbackVaryings " Jv . [ | program ; of_jstr_list varyings ; of_int bufferMode ] | let uniform1f c location x = ignore @@ Jv . call c " uniform1f " Jv . [ | location ; of_float x ] | let uniform1fv c location data = ignore @@ Jv . call c " uniform1fv " Jv . [ | location ; Tarray . to_jv data ] | let uniform1i c location x = ignore @@ Jv . call c " uniform1i " Jv . [ | location ; of_int x ] | let uniform1iv c location data = ignore @@ Jv . call c " uniform1iv " Jv . [ | location ; Tarray . to_jv data ] | let uniform1ui c location v0 = ignore @@ Jv . call c " uniform1ui " Jv . [ | location ; of_int v0 ] | let uniform1uiv c location data = ignore @@ Jv . call c " uniform1uiv " Jv . [ | location ; Tarray . to_jv data ] | let uniform2f c location x y = ignore @@ Jv . call c " uniform2f " Jv . [ | location ; of_float x ; of_float y ] | let uniform2fv c location data = ignore @@ Jv . call c " uniform2fv " Jv . [ | location ; Tarray . to_jv data ] | let uniform2i c location x y = ignore @@ Jv . call c " uniform2i " Jv . [ | location ; of_int x ; of_int y ] | let uniform2iv c location data = ignore @@ Jv . call c " uniform2iv " Jv . [ | location ; Tarray . to_jv data ] | let uniform2ui c location v0 v1 = ignore @@ Jv . call c " uniform2ui " Jv . [ | location ; of_int v0 ; of_int v1 ] | let uniform2uiv c location data = ignore @@ Jv . call c " uniform2uiv " Jv . [ | location ; Tarray . to_jv data ] | let uniform3f c location x y z = ignore @@ Jv . call c " uniform3f " Jv . [ | location ; of_float x ; of_float y ; of_float z ] | let uniform3fv c location data = ignore @@ Jv . call c " uniform3fv " Jv . [ | location ; Tarray . to_jv data ] | let uniform3i c location x y z = ignore @@ Jv . call c " uniform3i " Jv . [ | location ; of_int x ; of_int y ; of_int z ] | let uniform3iv c location data = ignore @@ Jv . call c " uniform3iv " Jv . [ | location ; Tarray . to_jv data ] | let uniform3ui c location v0 v1 v2 = ignore @@ Jv . call c " uniform3ui " Jv . [ | location ; of_int v0 ; of_int v1 ; of_int v2 ] | let uniform3uiv c location data = ignore @@ Jv . call c " uniform3uiv " Jv . [ | location ; Tarray . to_jv data ] | let uniform4f c location x y z w = ignore @@ Jv . call c " uniform4f " Jv . [ | location ; of_float x ; of_float y ; of_float z ; of_float w ] | let uniform4fv c location data = ignore @@ Jv . call c " uniform4fv " Jv . [ | location ; Tarray . to_jv data ] | let uniform4i c location x y z w = ignore @@ Jv . call c " uniform4i " Jv . [ | location ; of_int x ; of_int y ; of_int z ; of_int w ] | let uniform4iv c location data = ignore @@ Jv . call c " uniform4iv " Jv . [ | location ; Tarray . to_jv data ] | let uniform4ui c location v0 v1 v2 v3 = ignore @@ Jv . call c " uniform4ui " Jv . [ | location ; of_int v0 ; of_int v1 ; of_int v2 ; of_int v3 ] | let uniform4uiv c location data = ignore @@ Jv . call c " uniform4uiv " Jv . [ | location ; Tarray . to_jv data ] | let uniform_block_binding c program uniformBlockIndex uniformBlockBinding = ignore @@ Jv . call c " uniformBlockBinding " Jv . [ | program ; of_int uniformBlockIndex ; of_int uniformBlockBinding ] | let uniform_matrix2fv c location transpose data = ignore @@ Jv . call c " uniformMatrix2fv " Jv . [ | location ; Jv . of_bool transpose ; Tarray . to_jv data ] | let uniform_matrix2x3fv c location transpose data = ignore @@ Jv . call c " uniformMatrix2x3fv " Jv . [ | location ; Jv . of_bool transpose ; Tarray . to_jv data ] | let uniform_matrix2x4fv c location transpose data = ignore @@ Jv . call c " uniformMatrix2x4fv " Jv . [ | location ; Jv . of_bool transpose ; Tarray . to_jv data ] | let uniform_matrix3fv c location transpose data = ignore @@ Jv . call c " uniformMatrix3fv " Jv . [ | location ; Jv . of_bool transpose ; Tarray . to_jv data ] | let uniform_matrix3x2fv c location transpose data = ignore @@ Jv . call c " uniformMatrix3x2fv " Jv . [ | location ; Jv . of_bool transpose ; Tarray . to_jv data ] | let uniform_matrix3x4fv c location transpose data = ignore @@ Jv . call c " uniformMatrix3x4fv " Jv . [ | location ; Jv . of_bool transpose ; Tarray . to_jv data ] | let uniform_matrix4fv c location transpose data = ignore @@ Jv . call c " uniformMatrix4fv " Jv . [ | location ; Jv . of_bool transpose ; Tarray . to_jv data ] | let uniform_matrix4x2fv c location transpose data = ignore @@ Jv . call c " uniformMatrix4x2fv " Jv . [ | location ; Jv . of_bool transpose ; Tarray . to_jv data ] | let uniform_matrix4x3fv c location transpose data = ignore @@ Jv . call c " uniformMatrix4x3fv " Jv . [ | location ; Jv . of_bool transpose ; Tarray . to_jv data ] | let use_program c program = ignore @@ Jv . call c " useProgram " Jv . [ | program ] | let validate_program c program = ignore @@ Jv . call c " validateProgram " Jv . [ | program ] | let vertex_attrib1f c index x = ignore @@ Jv . call c " vertexAttrib1f " Jv . [ | of_int index ; of_float x ] | let vertex_attrib1fv c index values = ignore @@ Jv . call c " vertexAttrib1fv " Jv . [ | of_int index ; Tarray . to_jv values ] | let vertex_attrib2f c index x y = ignore @@ Jv . call c " vertexAttrib2f " Jv . [ | of_int index ; of_float x ; of_float y ] | let vertex_attrib2fv c index values = ignore @@ Jv . call c " vertexAttrib2fv " Jv . [ | of_int index ; Tarray . to_jv values ] | let vertex_attrib3f c index x y z = ignore @@ Jv . call c " vertexAttrib3f " Jv . [ | of_int index ; of_float x ; of_float y ; of_float z ] | let vertex_attrib3fv c index values = ignore @@ Jv . call c " vertexAttrib3fv " Jv . [ | of_int index ; Tarray . to_jv values ] | let vertex_attrib4f c index x y z w = ignore @@ Jv . call c " vertexAttrib4f " Jv . [ | of_int index ; of_float x ; of_float y ; of_float z ; of_float w ] | let vertex_attrib4fv c index values = ignore @@ Jv . call c " vertexAttrib4fv " Jv . [ | of_int index ; Tarray . to_jv values ] | let vertex_attrib_divisor c index divisor = ignore @@ Jv . call c " vertexAttribDivisor " Jv . [ | of_int index ; of_int divisor ] | let vertex_attrib_i4i c index x y z w = ignore @@ Jv . call c " vertexAttribI4i " Jv . [ | of_int index ; of_int x ; of_int y ; of_int z ; of_int w ] | let vertex_attrib_i4iv c index values = ignore @@ Jv . call c " vertexAttribI4iv " Jv . [ | of_int index ; Tarray . to_jv values ] | let vertex_attrib_i4ui c index x y z w = ignore @@ Jv . call c " vertexAttribI4ui " Jv . [ | of_int index ; of_int x ; of_int y ; of_int z ; of_int w ] | let vertex_attrib_i4uiv c index values = ignore @@ Jv . call c " vertexAttribI4uiv " Jv . [ | of_int index ; Tarray . to_jv values ] | let vertex_attrib_ipointer c index size type ' stride offset = ignore @@ Jv . call c " vertexAttribIPointer " Jv . [ | of_int index ; of_int size ; of_int type ' ; of_int stride ; of_int offset ] | let vertex_attrib_pointer c index size type ' normalized stride offset = ignore @@ Jv . call c " vertexAttribPointer " Jv . [ | of_int index ; of_int size ; of_int type ' ; Jv . of_bool normalized ; of_int stride ; of_int offset ] | let viewport c x y width height = ignore @@ Jv . call c " viewport " Jv . [ | of_int x ; of_int y ; of_int width ; of_int height ] | let wait_sync c sync flags timeout = ignore @@ Jv . call c " waitSync " Jv . [ | sync ; of_int flags ; of_int timeout ] | let gl1ctx = Jv . get Jv . global " WebGLRenderingContext " let depth_buffer_bit = Jv . Int . get gl1ctx " DEPTH_BUFFER_BIT " let stencil_buffer_bit = Jv . Int . get gl1ctx " STENCIL_BUFFER_BIT " let color_buffer_bit = Jv . Int . get gl1ctx " COLOR_BUFFER_BIT " let points = Jv . Int . get gl1ctx " POINTS " let lines = Jv . Int . get gl1ctx " LINES " let line_loop = Jv . Int . get gl1ctx " LINE_LOOP " let line_strip = Jv . Int . get gl1ctx " LINE_STRIP " let triangles = Jv . Int . get gl1ctx " TRIANGLES " let triangle_strip = Jv . Int . get gl1ctx " TRIANGLE_STRIP " let triangle_fan = Jv . Int . get gl1ctx " TRIANGLE_FAN " let zero = Jv . Int . get gl1ctx " ZERO " let one = Jv . Int . get gl1ctx " ONE " let src_color = Jv . Int . get gl1ctx " SRC_COLOR " let one_minus_src_color = Jv . Int . get gl1ctx " ONE_MINUS_SRC_COLOR " let src_alpha = Jv . Int . get gl1ctx " SRC_ALPHA " let one_minus_src_alpha = Jv . Int . get gl1ctx " ONE_MINUS_SRC_ALPHA " let dst_alpha = Jv . Int . get gl1ctx " DST_ALPHA " let one_minus_dst_alpha = Jv . Int . get gl1ctx " ONE_MINUS_DST_ALPHA " let dst_color = Jv . Int . get gl1ctx " DST_COLOR " let one_minus_dst_color = Jv . Int . get gl1ctx " ONE_MINUS_DST_COLOR " let src_alpha_saturate = Jv . Int . get gl1ctx " SRC_ALPHA_SATURATE " let func_add = Jv . Int . get gl1ctx " FUNC_ADD " let blend_equation ' = Jv . Int . get gl1ctx " BLEND_EQUATION " let blend_equation_rgb = Jv . Int . get gl1ctx " BLEND_EQUATION_RGB " let blend_equation_alpha = Jv . Int . get gl1ctx " BLEND_EQUATION_ALPHA " let func_subtract = Jv . Int . get gl1ctx " FUNC_SUBTRACT " let func_reverse_subtract = Jv . Int . get gl1ctx " FUNC_REVERSE_SUBTRACT " let blend_dst_rgb = Jv . Int . get gl1ctx " BLEND_DST_RGB " let blend_src_rgb = Jv . Int . get gl1ctx " BLEND_SRC_RGB " let blend_dst_alpha = Jv . Int . get gl1ctx " BLEND_DST_ALPHA " let blend_src_alpha = Jv . Int . get gl1ctx " BLEND_SRC_ALPHA " let constant_color = Jv . Int . get gl1ctx " CONSTANT_COLOR " let one_minus_constant_color = Jv . Int . get gl1ctx " ONE_MINUS_CONSTANT_COLOR " let constant_alpha = Jv . Int . get gl1ctx " CONSTANT_ALPHA " let one_minus_constant_alpha = Jv . Int . get gl1ctx " ONE_MINUS_CONSTANT_ALPHA " let blend_color ' = Jv . Int . get gl1ctx " BLEND_COLOR " let array_buffer = Jv . Int . get gl1ctx " ARRAY_BUFFER " let element_array_buffer = Jv . Int . get gl1ctx " ELEMENT_ARRAY_BUFFER " let array_buffer_binding = Jv . Int . get gl1ctx " ARRAY_BUFFER_BINDING " let element_array_buffer_binding = Jv . Int . get gl1ctx " ELEMENT_ARRAY_BUFFER_BINDING " let stream_draw = Jv . Int . get gl1ctx " STREAM_DRAW " let static_draw = Jv . Int . get gl1ctx " STATIC_DRAW " let dynamic_draw = Jv . Int . get gl1ctx " DYNAMIC_DRAW " let buffer_size = Jv . Int . get gl1ctx " BUFFER_SIZE " let buffer_usage = Jv . Int . get gl1ctx " BUFFER_USAGE " let current_vertex_attrib = Jv . Int . get gl1ctx " CURRENT_VERTEX_ATTRIB " let front = Jv . Int . get gl1ctx " FRONT " let back = Jv . Int . get gl1ctx " BACK " let front_and_back = Jv . Int . get gl1ctx " FRONT_AND_BACK " let cull_face ' = Jv . Int . get gl1ctx " CULL_FACE " let blend = Jv . Int . get gl1ctx " BLEND " let dither = Jv . Int . get gl1ctx " DITHER " let stencil_test = Jv . Int . get gl1ctx " STENCIL_TEST " let depth_test = Jv . Int . get gl1ctx " DEPTH_TEST " let scissor_test = Jv . Int . get gl1ctx " SCISSOR_TEST " let polygon_offset_fill = Jv . Int . get gl1ctx " POLYGON_OFFSET_FILL " let sample_alpha_to_coverage = Jv . Int . get gl1ctx " SAMPLE_ALPHA_TO_COVERAGE " let sample_coverage ' = Jv . Int . get gl1ctx " SAMPLE_COVERAGE " let no_error = Jv . Int . get gl1ctx " NO_ERROR " let invalid_enum = Jv . Int . get gl1ctx " INVALID_ENUM " let invalid_value = Jv . Int . get gl1ctx " INVALID_VALUE " let invalid_operation = Jv . Int . get gl1ctx " INVALID_OPERATION " let out_of_memory = Jv . Int . get gl1ctx " OUT_OF_MEMORY " let cw = Jv . Int . get gl1ctx " CW " let ccw = Jv . Int . get gl1ctx " CCW " let line_width ' = Jv . Int . get gl1ctx " LINE_WIDTH " let aliased_point_size_range = Jv . Int . get gl1ctx " ALIASED_POINT_SIZE_RANGE " let aliased_line_width_range = Jv . Int . get gl1ctx " ALIASED_LINE_WIDTH_RANGE " let cull_face_mode = Jv . Int . get gl1ctx " CULL_FACE_MODE " let front_face ' = Jv . Int . get gl1ctx " FRONT_FACE " let depth_range = Jv . Int . get gl1ctx " DEPTH_RANGE " let depth_writemask = Jv . Int . get gl1ctx " DEPTH_WRITEMASK " let depth_clear_value = Jv . Int . get gl1ctx " DEPTH_CLEAR_VALUE " let depth_func ' = Jv . Int . get gl1ctx " DEPTH_FUNC " let stencil_clear_value = Jv . Int . get gl1ctx " STENCIL_CLEAR_VALUE " let stencil_func ' = Jv . Int . get gl1ctx " STENCIL_FUNC " let stencil_fail = Jv . Int . get gl1ctx " STENCIL_FAIL " let stencil_pass_depth_fail = Jv . Int . get gl1ctx " STENCIL_PASS_DEPTH_FAIL " let stencil_pass_depth_pass = Jv . Int . get gl1ctx " STENCIL_PASS_DEPTH_PASS " let stencil_ref = Jv . Int . get gl1ctx " STENCIL_REF " let stencil_value_mask = Jv . Int . get gl1ctx " STENCIL_VALUE_MASK " let stencil_writemask = Jv . Int . get gl1ctx " STENCIL_WRITEMASK " let stencil_back_func = Jv . Int . get gl1ctx " STENCIL_BACK_FUNC " let stencil_back_fail = Jv . Int . get gl1ctx " STENCIL_BACK_FAIL " let stencil_back_pass_depth_fail = Jv . Int . get gl1ctx " STENCIL_BACK_PASS_DEPTH_FAIL " let stencil_back_pass_depth_pass = Jv . Int . get gl1ctx " STENCIL_BACK_PASS_DEPTH_PASS " let stencil_back_ref = Jv . Int . get gl1ctx " STENCIL_BACK_REF " let stencil_back_value_mask = Jv . Int . get gl1ctx " STENCIL_BACK_VALUE_MASK " let stencil_back_writemask = Jv . Int . get gl1ctx " STENCIL_BACK_WRITEMASK " let viewport ' = Jv . Int . get gl1ctx " VIEWPORT " let scissor_box = Jv . Int . get gl1ctx " SCISSOR_BOX " let color_clear_value = Jv . Int . get gl1ctx " COLOR_CLEAR_VALUE " let color_writemask = Jv . Int . get gl1ctx " COLOR_WRITEMASK " let unpack_alignment = Jv . Int . get gl1ctx " UNPACK_ALIGNMENT " let pack_alignment = Jv . Int . get gl1ctx " PACK_ALIGNMENT " let max_texture_size = Jv . Int . get gl1ctx " MAX_TEXTURE_SIZE " let max_viewport_dims = Jv . Int . get gl1ctx " MAX_VIEWPORT_DIMS " let subpixel_bits = Jv . Int . get gl1ctx " SUBPIXEL_BITS " let red_bits = Jv . Int . get gl1ctx " RED_BITS " let green_bits = Jv . Int . get gl1ctx " GREEN_BITS " let blue_bits = Jv . Int . get gl1ctx " BLUE_BITS " let alpha_bits = Jv . Int . get gl1ctx " ALPHA_BITS " let depth_bits = Jv . Int . get gl1ctx " DEPTH_BITS " let stencil_bits = Jv . Int . get gl1ctx " STENCIL_BITS " let polygon_offset_units = Jv . Int . get gl1ctx " POLYGON_OFFSET_UNITS " let polygon_offset_factor = Jv . Int . get gl1ctx " POLYGON_OFFSET_FACTOR " let texture_binding_2d = Jv . Int . get gl1ctx " TEXTURE_BINDING_2D " let sample_buffers = Jv . Int . get gl1ctx " SAMPLE_BUFFERS " let samples = Jv . Int . get gl1ctx " SAMPLES " let sample_coverage_value = Jv . Int . get gl1ctx " SAMPLE_COVERAGE_VALUE " let sample_coverage_invert = Jv . Int . get gl1ctx " SAMPLE_COVERAGE_INVERT " let compressed_texture_formats = Jv . Int . get gl1ctx " COMPRESSED_TEXTURE_FORMATS " let dont_care = Jv . Int . get gl1ctx " DONT_CARE " let fastest = Jv . Int . get gl1ctx " FASTEST " let nicest = Jv . Int . get gl1ctx " NICEST " let generate_mipmap_hint = Jv . Int . get gl1ctx " GENERATE_MIPMAP_HINT " let byte = Jv . Int . get gl1ctx " BYTE " let unsigned_byte = Jv . Int . get gl1ctx " UNSIGNED_BYTE " let short = Jv . Int . get gl1ctx " SHORT " let unsigned_short = Jv . Int . get gl1ctx " UNSIGNED_SHORT " let int = Jv . Int . get gl1ctx " INT " let unsigned_int = Jv . Int . get gl1ctx " UNSIGNED_INT " let float = Jv . Int . get gl1ctx " FLOAT " let depth_component = Jv . Int . get gl1ctx " DEPTH_COMPONENT " let alpha = Jv . Int . get gl1ctx " ALPHA " let rgb = Jv . Int . get gl1ctx " RGB " let rgba = Jv . Int . get gl1ctx " RGBA " let luminance = Jv . Int . get gl1ctx " LUMINANCE " let luminance_alpha = Jv . Int . get gl1ctx " LUMINANCE_ALPHA " let unsigned_short_4_4_4_4 = Jv . Int . get gl1ctx " UNSIGNED_SHORT_4_4_4_4 " let unsigned_short_5_5_5_1 = Jv . Int . get gl1ctx " UNSIGNED_SHORT_5_5_5_1 " let unsigned_short_5_6_5 = Jv . Int . get gl1ctx " UNSIGNED_SHORT_5_6_5 " let fragment_shader = Jv . Int . get gl1ctx " FRAGMENT_SHADER " let vertex_shader = Jv . Int . get gl1ctx " VERTEX_SHADER " let max_vertex_attribs = Jv . Int . get gl1ctx " MAX_VERTEX_ATTRIBS " let max_vertex_uniform_vectors = Jv . Int . get gl1ctx " MAX_VERTEX_UNIFORM_VECTORS " let max_varying_vectors = Jv . Int . get gl1ctx " MAX_VARYING_VECTORS " let max_combined_texture_image_units = Jv . Int . get gl1ctx " MAX_COMBINED_TEXTURE_IMAGE_UNITS " let max_vertex_texture_image_units = Jv . Int . get gl1ctx " MAX_VERTEX_TEXTURE_IMAGE_UNITS " let max_texture_image_units = Jv . Int . get gl1ctx " MAX_TEXTURE_IMAGE_UNITS " let max_fragment_uniform_vectors = Jv . Int . get gl1ctx " MAX_FRAGMENT_UNIFORM_VECTORS " let shader_type = Jv . Int . get gl1ctx " SHADER_TYPE " let delete_status = Jv . Int . get gl1ctx " DELETE_STATUS " let link_status = Jv . Int . get gl1ctx " LINK_STATUS " let validate_status = Jv . Int . get gl1ctx " VALIDATE_STATUS " let attached_shaders = Jv . Int . get gl1ctx " ATTACHED_SHADERS " let active_uniforms = Jv . Int . get gl1ctx " ACTIVE_UNIFORMS " let active_attributes = Jv . Int . get gl1ctx " ACTIVE_ATTRIBUTES " let shading_language_version = Jv . Int . get gl1ctx " SHADING_LANGUAGE_VERSION " let current_program = Jv . Int . get gl1ctx " CURRENT_PROGRAM " let never = Jv . Int . get gl1ctx " NEVER " let less = Jv . Int . get gl1ctx " LESS " let equal = Jv . Int . get gl1ctx " EQUAL " let lequal = Jv . Int . get gl1ctx " LEQUAL " let greater = Jv . Int . get gl1ctx " GREATER " let notequal = Jv . Int . get gl1ctx " NOTEQUAL " let gequal = Jv . Int . get gl1ctx " GEQUAL " let always = Jv . Int . get gl1ctx " ALWAYS " let keep = Jv . Int . get gl1ctx " KEEP " let replace = Jv . Int . get gl1ctx " REPLACE " let incr = Jv . Int . get gl1ctx " INCR " let decr = Jv . Int . get gl1ctx " DECR " let invert = Jv . Int . get gl1ctx " INVERT " let incr_wrap = Jv . Int . get gl1ctx " INCR_WRAP " let decr_wrap = Jv . Int . get gl1ctx " DECR_WRAP " let vendor = Jv . Int . get gl1ctx " VENDOR " let renderer = Jv . Int . get gl1ctx " RENDERER " let version = Jv . Int . get gl1ctx " VERSION " let nearest = Jv . Int . get gl1ctx " NEAREST " let linear = Jv . Int . get gl1ctx " LINEAR " let nearest_mipmap_nearest = Jv . Int . get gl1ctx " NEAREST_MIPMAP_NEAREST " let linear_mipmap_nearest = Jv . Int . get gl1ctx " LINEAR_MIPMAP_NEAREST " let nearest_mipmap_linear = Jv . Int . get gl1ctx " NEAREST_MIPMAP_LINEAR " let linear_mipmap_linear = Jv . Int . get gl1ctx " LINEAR_MIPMAP_LINEAR " let texture_mag_filter = Jv . Int . get gl1ctx " TEXTURE_MAG_FILTER " let texture_min_filter = Jv . Int . get gl1ctx " TEXTURE_MIN_FILTER " let texture_wrap_s = Jv . Int . get gl1ctx " TEXTURE_WRAP_S " let texture_wrap_t = Jv . Int . get gl1ctx " TEXTURE_WRAP_T " let texture_2d = Jv . Int . get gl1ctx " TEXTURE_2D " let texture = Jv . Int . get gl1ctx " TEXTURE " let texture_cube_map = Jv . Int . get gl1ctx " TEXTURE_CUBE_MAP " let texture_binding_cube_map = Jv . Int . get gl1ctx " TEXTURE_BINDING_CUBE_MAP " let texture_cube_map_positive_x = Jv . Int . get gl1ctx " TEXTURE_CUBE_MAP_POSITIVE_X " let texture_cube_map_negative_x = Jv . Int . get gl1ctx " TEXTURE_CUBE_MAP_NEGATIVE_X " let texture_cube_map_positive_y = Jv . Int . get gl1ctx " TEXTURE_CUBE_MAP_POSITIVE_Y " let texture_cube_map_negative_y = Jv . Int . get gl1ctx " TEXTURE_CUBE_MAP_NEGATIVE_Y " let texture_cube_map_positive_z = Jv . Int . get gl1ctx " TEXTURE_CUBE_MAP_POSITIVE_Z " let texture_cube_map_negative_z = Jv . Int . get gl1ctx " TEXTURE_CUBE_MAP_NEGATIVE_Z " let max_cube_map_texture_size = Jv . Int . get gl1ctx " MAX_CUBE_MAP_TEXTURE_SIZE " let texture0 = Jv . Int . get gl1ctx " TEXTURE0 " let texture1 = Jv . Int . get gl1ctx " TEXTURE1 " let texture2 = Jv . Int . get gl1ctx " TEXTURE2 " let texture3 = Jv . Int . get gl1ctx " TEXTURE3 " let texture4 = Jv . Int . get gl1ctx " TEXTURE4 " let texture5 = Jv . Int . get gl1ctx " TEXTURE5 " let texture6 = Jv . Int . get gl1ctx " TEXTURE6 " let texture7 = Jv . Int . get gl1ctx " TEXTURE7 " let texture8 = Jv . Int . get gl1ctx " TEXTURE8 " let texture9 = Jv . Int . get gl1ctx " TEXTURE9 " let texture10 = Jv . Int . get gl1ctx " TEXTURE10 " let texture11 = Jv . Int . get gl1ctx " TEXTURE11 " let texture12 = Jv . Int . get gl1ctx " TEXTURE12 " let texture13 = Jv . Int . get gl1ctx " TEXTURE13 " let texture14 = Jv . Int . get gl1ctx " TEXTURE14 " let texture15 = Jv . Int . get gl1ctx " TEXTURE15 " let texture16 = Jv . Int . get gl1ctx " TEXTURE16 " let texture17 = Jv . Int . get gl1ctx " TEXTURE17 " let texture18 = Jv . Int . get gl1ctx " TEXTURE18 " let texture19 = Jv . Int . get gl1ctx " TEXTURE19 " let texture20 = Jv . Int . get gl1ctx " TEXTURE20 " let texture21 = Jv . Int . get gl1ctx " TEXTURE21 " let texture22 = Jv . Int . get gl1ctx " TEXTURE22 " let texture23 = Jv . Int . get gl1ctx " TEXTURE23 " let texture24 = Jv . Int . get gl1ctx " TEXTURE24 " let texture25 = Jv . Int . get gl1ctx " TEXTURE25 " let texture26 = Jv . Int . get gl1ctx " TEXTURE26 " let texture27 = Jv . Int . get gl1ctx " TEXTURE27 " let texture28 = Jv . Int . get gl1ctx " TEXTURE28 " let texture29 = Jv . Int . get gl1ctx " TEXTURE29 " let texture30 = Jv . Int . get gl1ctx " TEXTURE30 " let texture31 = Jv . Int . get gl1ctx " TEXTURE31 " let active_texture ' = Jv . Int . get gl1ctx " ACTIVE_TEXTURE " let repeat = Jv . Int . get gl1ctx " REPEAT " let clamp_to_edge = Jv . Int . get gl1ctx " CLAMP_TO_EDGE " let mirrored_repeat = Jv . Int . get gl1ctx " MIRRORED_REPEAT " let float_vec2 = Jv . Int . get gl1ctx " FLOAT_VEC2 " let float_vec3 = Jv . Int . get gl1ctx " FLOAT_VEC3 " let float_vec4 = Jv . Int . get gl1ctx " FLOAT_VEC4 " let int_vec2 = Jv . Int . get gl1ctx " INT_VEC2 " let int_vec3 = Jv . Int . get gl1ctx " INT_VEC3 " let int_vec4 = Jv . Int . get gl1ctx " INT_VEC4 " let bool = Jv . Int . get gl1ctx " BOOL " let bool_vec2 = Jv . Int . get gl1ctx " BOOL_VEC2 " let bool_vec3 = Jv . Int . get gl1ctx " BOOL_VEC3 " let bool_vec4 = Jv . Int . get gl1ctx " BOOL_VEC4 " let float_mat2 = Jv . Int . get gl1ctx " FLOAT_MAT2 " let float_mat3 = Jv . Int . get gl1ctx " FLOAT_MAT3 " let float_mat4 = Jv . Int . get gl1ctx " FLOAT_MAT4 " let sampler_2d = Jv . Int . get gl1ctx " SAMPLER_2D " let sampler_cube = Jv . Int . get gl1ctx " SAMPLER_CUBE " let vertex_attrib_array_enabled = Jv . Int . get gl1ctx " VERTEX_ATTRIB_ARRAY_ENABLED " let vertex_attrib_array_size = Jv . Int . get gl1ctx " VERTEX_ATTRIB_ARRAY_SIZE " let vertex_attrib_array_stride = Jv . Int . get gl1ctx " VERTEX_ATTRIB_ARRAY_STRIDE " let vertex_attrib_array_type = Jv . Int . get gl1ctx " VERTEX_ATTRIB_ARRAY_TYPE " let vertex_attrib_array_normalized = Jv . Int . get gl1ctx " VERTEX_ATTRIB_ARRAY_NORMALIZED " let vertex_attrib_array_pointer = Jv . Int . get gl1ctx " VERTEX_ATTRIB_ARRAY_POINTER " let vertex_attrib_array_buffer_binding = Jv . Int . get gl1ctx " VERTEX_ATTRIB_ARRAY_BUFFER_BINDING " let implementation_color_read_type = Jv . Int . get gl1ctx " IMPLEMENTATION_COLOR_READ_TYPE " let implementation_color_read_format = Jv . Int . get gl1ctx " IMPLEMENTATION_COLOR_READ_FORMAT " let compile_status = Jv . Int . get gl1ctx " COMPILE_STATUS " let low_float = Jv . Int . get gl1ctx " LOW_FLOAT " let medium_float = Jv . Int . get gl1ctx " MEDIUM_FLOAT " let high_float = Jv . Int . get gl1ctx " HIGH_FLOAT " let low_int = Jv . Int . get gl1ctx " LOW_INT " let medium_int = Jv . Int . get gl1ctx " MEDIUM_INT " let high_int = Jv . Int . get gl1ctx " HIGH_INT " let framebuffer = Jv . Int . get gl1ctx " FRAMEBUFFER " let renderbuffer = Jv . Int . get gl1ctx " RENDERBUFFER " let rgba4 = Jv . Int . get gl1ctx " RGBA4 " let rgb5_a1 = Jv . Int . get gl1ctx " RGB5_A1 " let rgb565 = Jv . Int . get gl1ctx " RGB565 " let depth_component16 = Jv . Int . get gl1ctx " DEPTH_COMPONENT16 " let stencil_index8 = Jv . Int . get gl1ctx " STENCIL_INDEX8 " let depth_stencil = Jv . Int . get gl1ctx " DEPTH_STENCIL " let renderbuffer_width = Jv . Int . get gl1ctx " RENDERBUFFER_WIDTH " let renderbuffer_height = Jv . Int . get gl1ctx " RENDERBUFFER_HEIGHT " let renderbuffer_internal_format = Jv . Int . get gl1ctx " RENDERBUFFER_INTERNAL_FORMAT " let renderbuffer_red_size = Jv . Int . get gl1ctx " RENDERBUFFER_RED_SIZE " let renderbuffer_green_size = Jv . Int . get gl1ctx " RENDERBUFFER_GREEN_SIZE " let renderbuffer_blue_size = Jv . Int . get gl1ctx " RENDERBUFFER_BLUE_SIZE " let renderbuffer_alpha_size = Jv . Int . get gl1ctx " RENDERBUFFER_ALPHA_SIZE " let renderbuffer_depth_size = Jv . Int . get gl1ctx " RENDERBUFFER_DEPTH_SIZE " let renderbuffer_stencil_size = Jv . Int . get gl1ctx " RENDERBUFFER_STENCIL_SIZE " let framebuffer_attachment_object_type = Jv . Int . get gl1ctx " FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE " let framebuffer_attachment_object_name = Jv . Int . get gl1ctx " FRAMEBUFFER_ATTACHMENT_OBJECT_NAME " let framebuffer_attachment_texture_level = Jv . Int . get gl1ctx " FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL " let framebuffer_attachment_texture_cube_map_face = Jv . Int . get gl1ctx " FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE " let color_attachment0 = Jv . Int . get gl1ctx " COLOR_ATTACHMENT0 " let depth_attachment = Jv . Int . get gl1ctx " DEPTH_ATTACHMENT " let stencil_attachment = Jv . Int . get gl1ctx " STENCIL_ATTACHMENT " let depth_stencil_attachment = Jv . Int . get gl1ctx " DEPTH_STENCIL_ATTACHMENT " let none = Jv . Int . get gl1ctx " NONE " let framebuffer_complete = Jv . Int . get gl1ctx " FRAMEBUFFER_COMPLETE " let framebuffer_incomplete_attachment = Jv . Int . get gl1ctx " FRAMEBUFFER_INCOMPLETE_ATTACHMENT " let framebuffer_incomplete_missing_attachment = Jv . Int . get gl1ctx " FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT " let framebuffer_incomplete_dimensions = Jv . Int . get gl1ctx " FRAMEBUFFER_INCOMPLETE_DIMENSIONS " let framebuffer_unsupported = Jv . Int . get gl1ctx " FRAMEBUFFER_UNSUPPORTED " let framebuffer_binding = Jv . Int . get gl1ctx " FRAMEBUFFER_BINDING " let renderbuffer_binding = Jv . Int . get gl1ctx " RENDERBUFFER_BINDING " let max_renderbuffer_size = Jv . Int . get gl1ctx " MAX_RENDERBUFFER_SIZE " let invalid_framebuffer_operation = Jv . Int . get gl1ctx " INVALID_FRAMEBUFFER_OPERATION " let unpack_flip_y_webgl = Jv . Int . get gl1ctx " UNPACK_FLIP_Y_WEBGL " let unpack_premultiply_alpha_webgl = Jv . Int . get gl1ctx " UNPACK_PREMULTIPLY_ALPHA_WEBGL " let context_lost_webgl = Jv . Int . get gl1ctx " CONTEXT_LOST_WEBGL " let unpack_colorspace_conversion_webgl = Jv . Int . get gl1ctx " UNPACK_COLORSPACE_CONVERSION_WEBGL " let browser_default_webgl = Jv . Int . get gl1ctx " BROWSER_DEFAULT_WEBGL " let gl2ctx = Jv . get Jv . global " WebGL2RenderingContext " let get_int = if Jv . is_none gl2ctx then ( fun _ _ -> 0 ) else Jv . Int . get let read_buffer ' = get_int gl2ctx " READ_BUFFER " let unpack_row_length = get_int gl2ctx " UNPACK_ROW_LENGTH " let unpack_skip_rows = get_int gl2ctx " UNPACK_SKIP_ROWS " let unpack_skip_pixels = get_int gl2ctx " UNPACK_SKIP_PIXELS " let pack_row_length = get_int gl2ctx " PACK_ROW_LENGTH " let pack_skip_rows = get_int gl2ctx " PACK_SKIP_ROWS " let pack_skip_pixels = get_int gl2ctx " PACK_SKIP_PIXELS " let color = get_int gl2ctx " COLOR " let depth = get_int gl2ctx " DEPTH " let stencil = get_int gl2ctx " STENCIL " let red = get_int gl2ctx " RED " let rgb8 = get_int gl2ctx " RGB8 " let rgba8 = get_int gl2ctx " RGBA8 " let rgb10_a2 = get_int gl2ctx " RGB10_A2 " let texture_binding_3d = get_int gl2ctx " TEXTURE_BINDING_3D " let unpack_skip_images = get_int gl2ctx " UNPACK_SKIP_IMAGES " let unpack_image_height = get_int gl2ctx " UNPACK_IMAGE_HEIGHT " let texture_3d = get_int gl2ctx " TEXTURE_3D " let texture_wrap_r = get_int gl2ctx " TEXTURE_WRAP_R " let max_3d_texture_size = get_int gl2ctx " MAX_3D_TEXTURE_SIZE " let unsigned_int_2_10_10_10_rev = get_int gl2ctx " UNSIGNED_INT_2_10_10_10_REV " let max_elements_vertices = get_int gl2ctx " MAX_ELEMENTS_VERTICES " let max_elements_indices = get_int gl2ctx " MAX_ELEMENTS_INDICES " let texture_min_lod = get_int gl2ctx " TEXTURE_MIN_LOD " let texture_max_lod = get_int gl2ctx " TEXTURE_MAX_LOD " let texture_base_level = get_int gl2ctx " TEXTURE_BASE_LEVEL " let texture_max_level = get_int gl2ctx " TEXTURE_MAX_LEVEL " let min = get_int gl2ctx " MIN " let max = get_int gl2ctx " MAX " let depth_component24 = get_int gl2ctx " DEPTH_COMPONENT24 " let max_texture_lod_bias = get_int gl2ctx " MAX_TEXTURE_LOD_BIAS " let texture_compare_mode = get_int gl2ctx " TEXTURE_COMPARE_MODE " let texture_compare_func = get_int gl2ctx " TEXTURE_COMPARE_FUNC " let current_query = get_int gl2ctx " CURRENT_QUERY " let query_result = get_int gl2ctx " QUERY_RESULT " let query_result_available = get_int gl2ctx " QUERY_RESULT_AVAILABLE " let stream_read = get_int gl2ctx " STREAM_READ " let stream_copy = get_int gl2ctx " STREAM_COPY " let static_read = get_int gl2ctx " STATIC_READ " let static_copy = get_int gl2ctx " STATIC_COPY " let dynamic_read = get_int gl2ctx " DYNAMIC_READ " let dynamic_copy = get_int gl2ctx " DYNAMIC_COPY " let max_draw_buffers = get_int gl2ctx " MAX_DRAW_BUFFERS " let draw_buffer0 = get_int gl2ctx " DRAW_BUFFER0 " let draw_buffer1 = get_int gl2ctx " DRAW_BUFFER1 " let draw_buffer2 = get_int gl2ctx " DRAW_BUFFER2 " let draw_buffer3 = get_int gl2ctx " DRAW_BUFFER3 " let draw_buffer4 = get_int gl2ctx " DRAW_BUFFER4 " let draw_buffer5 = get_int gl2ctx " DRAW_BUFFER5 " let draw_buffer6 = get_int gl2ctx " DRAW_BUFFER6 " let draw_buffer7 = get_int gl2ctx " DRAW_BUFFER7 " let draw_buffer8 = get_int gl2ctx " DRAW_BUFFER8 " let draw_buffer9 = get_int gl2ctx " DRAW_BUFFER9 " let draw_buffer10 = get_int gl2ctx " DRAW_BUFFER10 " let draw_buffer11 = get_int gl2ctx " DRAW_BUFFER11 " let draw_buffer12 = get_int gl2ctx " DRAW_BUFFER12 " let draw_buffer13 = get_int gl2ctx " DRAW_BUFFER13 " let draw_buffer14 = get_int gl2ctx " DRAW_BUFFER14 " let draw_buffer15 = get_int gl2ctx " DRAW_BUFFER15 " let max_fragment_uniform_components = get_int gl2ctx " MAX_FRAGMENT_UNIFORM_COMPONENTS " let max_vertex_uniform_components = get_int gl2ctx " MAX_VERTEX_UNIFORM_COMPONENTS " let sampler_3d = get_int gl2ctx " SAMPLER_3D " let sampler_2d_shadow = get_int gl2ctx " SAMPLER_2D_SHADOW " let fragment_shader_derivative_hint = get_int gl2ctx " FRAGMENT_SHADER_DERIVATIVE_HINT " let pixel_pack_buffer = get_int gl2ctx " PIXEL_PACK_BUFFER " let pixel_unpack_buffer = get_int gl2ctx " PIXEL_UNPACK_BUFFER " let pixel_pack_buffer_binding = get_int gl2ctx " PIXEL_PACK_BUFFER_BINDING " let pixel_unpack_buffer_binding = get_int gl2ctx " PIXEL_UNPACK_BUFFER_BINDING " let float_mat2x3 = get_int gl2ctx " FLOAT_MAT2x3 " let float_mat2x4 = get_int gl2ctx " FLOAT_MAT2x4 " let float_mat3x2 = get_int gl2ctx " FLOAT_MAT3x2 " let float_mat3x4 = get_int gl2ctx " FLOAT_MAT3x4 " let float_mat4x2 = get_int gl2ctx " FLOAT_MAT4x2 " let float_mat4x3 = get_int gl2ctx " FLOAT_MAT4x3 " let srgb = get_int gl2ctx " SRGB " let srgb8 = get_int gl2ctx " SRGB8 " let srgb8_alpha8 = get_int gl2ctx " SRGB8_ALPHA8 " let compare_ref_to_texture = get_int gl2ctx " COMPARE_REF_TO_TEXTURE " let rgba32f = get_int gl2ctx " RGBA32F " let rgb32f = get_int gl2ctx " RGB32F " let rgba16f = get_int gl2ctx " RGBA16F " let rgb16f = get_int gl2ctx " RGB16F " let vertex_attrib_array_integer = get_int gl2ctx " VERTEX_ATTRIB_ARRAY_INTEGER " let max_array_texture_layers = get_int gl2ctx " MAX_ARRAY_TEXTURE_LAYERS " let min_program_texel_offset = get_int gl2ctx " MIN_PROGRAM_TEXEL_OFFSET " let max_program_texel_offset = get_int gl2ctx " MAX_PROGRAM_TEXEL_OFFSET " let max_varying_components = get_int gl2ctx " MAX_VARYING_COMPONENTS " let texture_2d_array = get_int gl2ctx " TEXTURE_2D_ARRAY " let texture_binding_2d_array = get_int gl2ctx " TEXTURE_BINDING_2D_ARRAY " let r11f_g11f_b10f = get_int gl2ctx " R11F_G11F_B10F " let unsigned_int_10f_11f_11f_rev = get_int gl2ctx " UNSIGNED_INT_10F_11F_11F_REV " let rgb9_e5 = get_int gl2ctx " RGB9_E5 " let unsigned_int_5_9_9_9_rev = get_int gl2ctx " UNSIGNED_INT_5_9_9_9_REV " let transform_feedback_buffer_mode = get_int gl2ctx " TRANSFORM_FEEDBACK_BUFFER_MODE " let max_transform_feedback_separate_components = get_int gl2ctx " MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS " let transform_feedback_varyings ' = get_int gl2ctx " TRANSFORM_FEEDBACK_VARYINGS " let transform_feedback_buffer_start = get_int gl2ctx " TRANSFORM_FEEDBACK_BUFFER_START " let transform_feedback_buffer_size = get_int gl2ctx " TRANSFORM_FEEDBACK_BUFFER_SIZE " let transform_feedback_primitives_written = get_int gl2ctx " TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN " let rasterizer_discard = get_int gl2ctx " RASTERIZER_DISCARD " let max_transform_feedback_interleaved_components = get_int gl2ctx " MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS " let max_transform_feedback_separate_attribs = get_int gl2ctx " MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS " let interleaved_attribs = get_int gl2ctx " INTERLEAVED_ATTRIBS " let separate_attribs = get_int gl2ctx " SEPARATE_ATTRIBS " let transform_feedback_buffer = get_int gl2ctx " TRANSFORM_FEEDBACK_BUFFER " let transform_feedback_buffer_binding = get_int gl2ctx " TRANSFORM_FEEDBACK_BUFFER_BINDING " let rgba32ui = get_int gl2ctx " RGBA32UI " let rgb32ui = get_int gl2ctx " RGB32UI " let rgba16ui = get_int gl2ctx " RGBA16UI " let rgb16ui = get_int gl2ctx " RGB16UI " let rgba8ui = get_int gl2ctx " RGBA8UI " let rgb8ui = get_int gl2ctx " RGB8UI " let rgba32i = get_int gl2ctx " RGBA32I " let rgb32i = get_int gl2ctx " RGB32I " let rgba16i = get_int gl2ctx " RGBA16I " let rgb16i = get_int gl2ctx " RGB16I " let rgba8i = get_int gl2ctx " RGBA8I " let rgb8i = get_int gl2ctx " RGB8I " let red_integer = get_int gl2ctx " RED_INTEGER " let rgb_integer = get_int gl2ctx " RGB_INTEGER " let rgba_integer = get_int gl2ctx " RGBA_INTEGER " let sampler_2d_array = get_int gl2ctx " SAMPLER_2D_ARRAY " let sampler_2d_array_shadow = get_int gl2ctx " SAMPLER_2D_ARRAY_SHADOW " let sampler_cube_shadow = get_int gl2ctx " SAMPLER_CUBE_SHADOW " let unsigned_int_vec2 = get_int gl2ctx " UNSIGNED_INT_VEC2 " let unsigned_int_vec3 = get_int gl2ctx " UNSIGNED_INT_VEC3 " let unsigned_int_vec4 = get_int gl2ctx " UNSIGNED_INT_VEC4 " let int_sampler_2d = get_int gl2ctx " INT_SAMPLER_2D " let int_sampler_3d = get_int gl2ctx " INT_SAMPLER_3D " let int_sampler_cube = get_int gl2ctx " INT_SAMPLER_CUBE " let int_sampler_2d_array = get_int gl2ctx " INT_SAMPLER_2D_ARRAY " let unsigned_int_sampler_2d = get_int gl2ctx " UNSIGNED_INT_SAMPLER_2D " let unsigned_int_sampler_3d = get_int gl2ctx " UNSIGNED_INT_SAMPLER_3D " let unsigned_int_sampler_cube = get_int gl2ctx " UNSIGNED_INT_SAMPLER_CUBE " let unsigned_int_sampler_2d_array = get_int gl2ctx " UNSIGNED_INT_SAMPLER_2D_ARRAY " let depth_component32f = get_int gl2ctx " DEPTH_COMPONENT32F " let depth32f_stencil8 = get_int gl2ctx " DEPTH32F_STENCIL8 " let float_32_unsigned_int_24_8_rev = get_int gl2ctx " FLOAT_32_UNSIGNED_INT_24_8_REV " let framebuffer_attachment_color_encoding = get_int gl2ctx " FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING " let framebuffer_attachment_component_type = get_int gl2ctx " FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE " let framebuffer_attachment_red_size = get_int gl2ctx " FRAMEBUFFER_ATTACHMENT_RED_SIZE " let framebuffer_attachment_green_size = get_int gl2ctx " FRAMEBUFFER_ATTACHMENT_GREEN_SIZE " let framebuffer_attachment_blue_size = get_int gl2ctx " FRAMEBUFFER_ATTACHMENT_BLUE_SIZE " let framebuffer_attachment_alpha_size = get_int gl2ctx " FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE " let framebuffer_attachment_depth_size = get_int gl2ctx " FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE " let framebuffer_attachment_stencil_size = get_int gl2ctx " FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE " let framebuffer_default = get_int gl2ctx " FRAMEBUFFER_DEFAULT " let unsigned_int_24_8 = get_int gl2ctx " UNSIGNED_INT_24_8 " let depth24_stencil8 = get_int gl2ctx " DEPTH24_STENCIL8 " let unsigned_normalized = get_int gl2ctx " UNSIGNED_NORMALIZED " let draw_framebuffer_binding = get_int gl2ctx " DRAW_FRAMEBUFFER_BINDING " let read_framebuffer = get_int gl2ctx " READ_FRAMEBUFFER " let draw_framebuffer = get_int gl2ctx " DRAW_FRAMEBUFFER " let read_framebuffer_binding = get_int gl2ctx " READ_FRAMEBUFFER_BINDING " let renderbuffer_samples = get_int gl2ctx " RENDERBUFFER_SAMPLES " let framebuffer_attachment_texture_layer = get_int gl2ctx " FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER " let max_color_attachments = get_int gl2ctx " MAX_COLOR_ATTACHMENTS " let color_attachment1 = get_int gl2ctx " COLOR_ATTACHMENT1 " let color_attachment2 = get_int gl2ctx " COLOR_ATTACHMENT2 " let color_attachment3 = get_int gl2ctx " COLOR_ATTACHMENT3 " let color_attachment4 = get_int gl2ctx " COLOR_ATTACHMENT4 " let color_attachment5 = get_int gl2ctx " COLOR_ATTACHMENT5 " let color_attachment6 = get_int gl2ctx " COLOR_ATTACHMENT6 " let color_attachment7 = get_int gl2ctx " COLOR_ATTACHMENT7 " let color_attachment8 = get_int gl2ctx " COLOR_ATTACHMENT8 " let color_attachment9 = get_int gl2ctx " COLOR_ATTACHMENT9 " let color_attachment10 = get_int gl2ctx " COLOR_ATTACHMENT10 " let color_attachment11 = get_int gl2ctx " COLOR_ATTACHMENT11 " let color_attachment12 = get_int gl2ctx " COLOR_ATTACHMENT12 " let color_attachment13 = get_int gl2ctx " COLOR_ATTACHMENT13 " let color_attachment14 = get_int gl2ctx " COLOR_ATTACHMENT14 " let color_attachment15 = get_int gl2ctx " COLOR_ATTACHMENT15 " let framebuffer_incomplete_multisample = get_int gl2ctx " FRAMEBUFFER_INCOMPLETE_MULTISAMPLE " let max_samples = get_int gl2ctx " MAX_SAMPLES " let half_float = get_int gl2ctx " HALF_FLOAT " let rg = get_int gl2ctx " RG " let rg_integer = get_int gl2ctx " RG_INTEGER " let r8 = get_int gl2ctx " R8 " let rg8 = get_int gl2ctx " RG8 " let r16f = get_int gl2ctx " R16F " let r32f = get_int gl2ctx " R32F " let rg16f = get_int gl2ctx " RG16F " let rg32f = get_int gl2ctx " RG32F " let r8i = get_int gl2ctx " R8I " let r8ui = get_int gl2ctx " R8UI " let r16i = get_int gl2ctx " R16I " let r16ui = get_int gl2ctx " R16UI " let r32i = get_int gl2ctx " R32I " let r32ui = get_int gl2ctx " R32UI " let rg8i = get_int gl2ctx " RG8I " let rg8ui = get_int gl2ctx " RG8UI " let rg16i = get_int gl2ctx " RG16I " let rg16ui = get_int gl2ctx " RG16UI " let rg32i = get_int gl2ctx " RG32I " let rg32ui = get_int gl2ctx " RG32UI " let vertex_array_binding = get_int gl2ctx " VERTEX_ARRAY_BINDING " let r8_snorm = get_int gl2ctx " R8_SNORM " let rg8_snorm = get_int gl2ctx " RG8_SNORM " let rgb8_snorm = get_int gl2ctx " RGB8_SNORM " let rgba8_snorm = get_int gl2ctx " RGBA8_SNORM " let signed_normalized = get_int gl2ctx " SIGNED_NORMALIZED " let copy_read_buffer = get_int gl2ctx " COPY_READ_BUFFER " let copy_write_buffer = get_int gl2ctx " COPY_WRITE_BUFFER " let copy_read_buffer_binding = get_int gl2ctx " COPY_READ_BUFFER_BINDING " let copy_write_buffer_binding = get_int gl2ctx " COPY_WRITE_BUFFER_BINDING " let uniform_buffer = get_int gl2ctx " UNIFORM_BUFFER " let uniform_buffer_binding = get_int gl2ctx " UNIFORM_BUFFER_BINDING " let uniform_buffer_start = get_int gl2ctx " UNIFORM_BUFFER_START " let uniform_buffer_size = get_int gl2ctx " UNIFORM_BUFFER_SIZE " let max_vertex_uniform_blocks = get_int gl2ctx " MAX_VERTEX_UNIFORM_BLOCKS " let max_fragment_uniform_blocks = get_int gl2ctx " MAX_FRAGMENT_UNIFORM_BLOCKS " let max_combined_uniform_blocks = get_int gl2ctx " MAX_COMBINED_UNIFORM_BLOCKS " let max_uniform_buffer_bindings = get_int gl2ctx " MAX_UNIFORM_BUFFER_BINDINGS " let max_uniform_block_size = get_int gl2ctx " MAX_UNIFORM_BLOCK_SIZE " let max_combined_vertex_uniform_components = get_int gl2ctx " MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS " let max_combined_fragment_uniform_components = get_int gl2ctx " MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS " let uniform_buffer_offset_alignment = get_int gl2ctx " UNIFORM_BUFFER_OFFSET_ALIGNMENT " let active_uniform_blocks = get_int gl2ctx " ACTIVE_UNIFORM_BLOCKS " let uniform_type = get_int gl2ctx " UNIFORM_TYPE " let uniform_size = get_int gl2ctx " UNIFORM_SIZE " let uniform_block_index = get_int gl2ctx " UNIFORM_BLOCK_INDEX " let uniform_offset = get_int gl2ctx " UNIFORM_OFFSET " let uniform_array_stride = get_int gl2ctx " UNIFORM_ARRAY_STRIDE " let uniform_matrix_stride = get_int gl2ctx " UNIFORM_MATRIX_STRIDE " let uniform_is_row_major = get_int gl2ctx " UNIFORM_IS_ROW_MAJOR " let uniform_block_binding ' = get_int gl2ctx " UNIFORM_BLOCK_BINDING " let uniform_block_data_size = get_int gl2ctx " UNIFORM_BLOCK_DATA_SIZE " let uniform_block_active_uniforms = get_int gl2ctx " UNIFORM_BLOCK_ACTIVE_UNIFORMS " let uniform_block_active_uniform_indices = get_int gl2ctx " UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES " let uniform_block_referenced_by_vertex_shader = get_int gl2ctx " UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER " let uniform_block_referenced_by_fragment_shader = get_int gl2ctx " UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER " let invalid_index = get_int gl2ctx " INVALID_INDEX " let max_vertex_output_components = get_int gl2ctx " MAX_VERTEX_OUTPUT_COMPONENTS " let max_fragment_input_components = get_int gl2ctx " MAX_FRAGMENT_INPUT_COMPONENTS " let max_server_wait_timeout = get_int gl2ctx " MAX_SERVER_WAIT_TIMEOUT " let object_type = get_int gl2ctx " OBJECT_TYPE " let sync_condition = get_int gl2ctx " SYNC_CONDITION " let sync_status = get_int gl2ctx " SYNC_STATUS " let sync_flags = get_int gl2ctx " SYNC_FLAGS " let sync_fence = get_int gl2ctx " SYNC_FENCE " let sync_gpu_commands_complete = get_int gl2ctx " SYNC_GPU_COMMANDS_COMPLETE " let unsignaled = get_int gl2ctx " UNSIGNALED " let signaled = get_int gl2ctx " SIGNALED " let already_signaled = get_int gl2ctx " ALREADY_SIGNALED " let timeout_expired = get_int gl2ctx " TIMEOUT_EXPIRED " let condition_satisfied = get_int gl2ctx " CONDITION_SATISFIED " let wait_failed = get_int gl2ctx " WAIT_FAILED " let sync_flush_commands_bit = get_int gl2ctx " SYNC_FLUSH_COMMANDS_BIT " let vertex_attrib_array_divisor = get_int gl2ctx " VERTEX_ATTRIB_ARRAY_DIVISOR " let any_samples_passed = get_int gl2ctx " ANY_SAMPLES_PASSED " let any_samples_passed_conservative = get_int gl2ctx " ANY_SAMPLES_PASSED_CONSERVATIVE " let sampler_binding = get_int gl2ctx " SAMPLER_BINDING " let rgb10_a2ui = get_int gl2ctx " RGB10_A2UI " let int_2_10_10_10_rev = get_int gl2ctx " INT_2_10_10_10_REV " let transform_feedback = get_int gl2ctx " TRANSFORM_FEEDBACK " let transform_feedback_paused = get_int gl2ctx " TRANSFORM_FEEDBACK_PAUSED " let transform_feedback_active = get_int gl2ctx " TRANSFORM_FEEDBACK_ACTIVE " let transform_feedback_binding = get_int gl2ctx " TRANSFORM_FEEDBACK_BINDING " let texture_immutable_format = get_int gl2ctx " TEXTURE_IMMUTABLE_FORMAT " let max_element_index = get_int gl2ctx " MAX_ELEMENT_INDEX " let texture_immutable_levels = get_int gl2ctx " TEXTURE_IMMUTABLE_LEVELS " let timeout_ignored = get_int gl2ctx " TIMEOUT_IGNORED " let max_client_wait_timeout_webgl = get_int gl2ctx " MAX_CLIENT_WAIT_TIMEOUT_WEBGL " end
module Clipboard = struct module Item = struct module Presentation_style = struct type t = Jstr . t let unspecified = Jstr . v " unspecified " let inline = Jstr . v " inline " let attachment = Jstr . v " attachement " end type opts = Jv . t let opts ? presentation_style ( ) = let o = Jv . obj [ ] || in Jv . Jstr . set_if_some o " presentationStyle " presentation_style ; o type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let item = Jv . get Jv . global " ClipboardItem " let create ? opts vs = let o = Jv . obj [ ] || in let add_v ( t , b ) = Jv . set ' o t ( Blob . to_jv b ) in List . iter add_v vs ; Jv . new ' item [ | o ] | let presentation_style i = Jv . Jstr . get i " presentationStyle " let last_modified_ms i = Jv . Int . get i " lastModified " let delayed i = Jv . Bool . get i " delayed " let types i = Jv . to_jstr_list @@ Jv . get i " types " let get_type i t = Fut . of_promise ~ ok : Blob . of_jv @@ Jv . call i " getType " [ | i ; Jv . of_jstr t ] | end type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let of_navigator n = Jv . get ( Navigator . to_jv n ) " clipboard " let as_target = Ev . target_of_jv let read c = let ok = Jv . to_list Item . of_jv in Fut . of_promise ~ ok @@ Jv . call c " read " [ ] || let read_text c = Fut . of_promise ~ ok : Jv . to_jstr @@ Jv . call c " readText " [ ] || let write c data = let args = [ | Jv . of_list Item . to_jv data ] | in Fut . of_promise ~ ok : ignore @@ Jv . call c " write " args let write_text c data = Fut . of_promise ~ ok : ignore @@ Jv . call c " writeText " [ | Jv . of_jstr data ] | end
module Form = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let of_el e = if El . has_tag_name El . Name . form e then El . to_jv e else let exp = Jstr . v " Expected form element but found : " in Jv . throw ( Jstr . append exp ( El . tag_name e ) ) let to_el e = El . of_jv e let name f = Jv . Jstr . get f " name " let method ' f = Jv . Jstr . get f " method " let target f = Jv . Jstr . get f " target " let action f = Jv . Jstr . get f " action " let enctype f = Jv . Jstr . get f " enctype " let accept_charset f = Jv . Jstr . get f " acceptCharset " let autocomplete f = Jv . Jstr . get f " autocomplete " let no_validate f = Jv . Bool . get f " noValidate " let check_validity f = Jv . to_bool @@ Jv . call f " checkValidity " [ ] || let report_validity f = Jv . to_bool @@ Jv . call f " reportValidity " [ ] || let request_submit f el = let args = match el with None -> [ ] || | Some e -> [ | El . to_jv e ] | in ignore @@ Jv . call f " requestSubmit " args let reset f = ignore @@ Jv . call f " reset " [ ] || let submit f = ignore @@ Jv . call f " submit " [ ] || module Data = struct type form = t type entry_value = [ ` String of Jstr . t | ` File of File . t ] type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let formdata = Jv . get Jv . global " FormData " let create ( ) = Jv . new ' formdata [ ] || let of_form f = Jv . new ' formdata [ | f ] | let is_empty d = Jv . It . result_done ( Jv . It . next ( Jv . call d " entries " [ ] ) ) || let mem d k = Jv . to_bool @@ Jv . call d " has " Jv . [ | of_jstr k ] | let has_file_entry d = let rec loop it = let r = Jv . It . next it in if Jv . It . result_done r then false else let v = Jv . Jarray . get ( Jv . It . get_result_value r ) 1 in if Jv . instanceof v ~ cons ( : Jv . get Jv . global " File " ) then true else loop it in loop ( Jv . call d " entries " [ ] ) || let entry_value v = match Jv . instanceof v ~ cons ( : Jv . get Jv . global " File " ) with | true -> ` File ( File . of_jv v ) | false -> ` String ( Jv . to_jstr v ) let find d k = Jv . to_option entry_value @@ Jv . call d " get " [ | Jv . of_jstr k ] | let find_all d k = Jv . to_list entry_value @@ Jv . call d " getAll " [ | Jv . of_jstr k ] | let fold f d acc = let key = Jv . to_jstr in let value = entry_value in Jv . It . fold_bindings ~ key ~ value f ( Jv . call d " entries " [ ] ) || acc let set d k v = ignore @@ Jv . call d " set " Jv . [ | of_jstr k ; of_jstr v ] | let set_blob ? filename : fn d k b = let fn = match fn with None -> Jv . undefined | Some f -> Jv . of_jstr f in ignore @@ Jv . call d " set " Jv . [ | of_jstr k ; Blob . to_jv b ; fn ] | let append d k v = ignore @@ Jv . call d " append " Jv . [ | of_jstr k ; of_jstr v ] | let append_blob ? filename : fn d k b = let fn = match fn with None -> Jv . undefined | Some f -> Jv . of_jstr f in ignore @@ Jv . call d " append " Jv . [ | of_jstr k ; Blob . to_jv b ; fn ] | let delete d k = ignore @@ Jv . call d " delete " Jv . [ | of_jstr k ] | let of_assoc l = let d = create ( ) in let app d ( k , v ) = let v , fn = match v with | ` String s -> Jv . of_jstr s , Jv . undefined | ` File f -> File . to_jv f , Jv . of_jstr ( File . name f ) in ignore ( Jv . call d " append " Jv . [ | of_jstr k ; v ; fn ] ) | in List . iter ( app d ) l ; d let to_assoc p = List . rev ( fold ( fun k v acc -> ( k , v ) :: acc ) p [ ] ) let of_uri_params p = let add k v d = append d k v ; d in Uri . Params . fold add p ( create ( ) ) let to_uri_params p = let usp = Jv . get Jv . global " URLSearchParams " in Uri . Params . of_jv ( Jv . new ' usp [ | p ] ) | end module Ev = struct module Data = struct type t = Jv . t let form_data e = Data . of_jv @@ Jv . get e " formData " end let formdata = Ev . Type . create ( Jstr . v " formdata " ) module Submit = struct type t = Jv . t let submitter e = Jv . to_option El . of_jv @@ Jv . get e " submitter " end let submit = Ev . Type . create ( Jstr . v " submit " ) end end
module Fetch = struct module Body = struct type init = Jv . t let of_jstr = Jv . of_jstr let of_uri_params = Uri . Params . to_jv let of_form_data = Form . Data . to_jv let of_blob = Blob . to_jv let of_array_buffer = Tarray . Buffer . to_jv type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let body_used r = Jv . Bool . get r " bodyUsed " let body r = Jv . to_option Fun . id ( Jv . get r " body " ) let array_buffer r = Fut . of_promise ~ ok : Tarray . Buffer . of_jv ( Jv . call r " arrayBuffer " [ ] ) || let blob r = Fut . of_promise ~ ok : Blob . of_jv ( Jv . call r " blob " [ ] ) || let form_data r = Fut . of_promise ~ ok : Form . Data . of_jv ( Jv . call r " formData " [ ] ) || let json r = Fut . of_promise ~ ok : Fun . id ( Jv . call r " json " [ ] ) || let text r = Fut . of_promise ~ ok : Jv . to_jstr ( Jv . call r " text " [ ] ) || end module Headers = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let headers = Jv . get Jv . global " Headers " let mem h hs = Jv . to_bool ( Jv . call hs " has " [ | Jv . of_jstr h ] ) | let find h hs = Jv . to_option Jv . to_jstr ( Jv . call hs " get " [ | Jv . of_jstr h ] ) | let fold f p acc = let key = Jv . to_jstr in let value = Jv . to_jstr in Jv . It . fold_bindings ~ key ~ value f ( Jv . call p " entries " [ ] ) || acc let of_obj o = Jv . new ' headers [ | o ] | let of_assoc ? init l = let args = match init with None -> [ ] || | Some h -> [ | h ] | in let hs = Jv . new ' headers args in let add hs ( k , v ) = ignore ( Jv . call hs " append " Jv . [ | of_jstr k ; of_jstr v ] ) | in List . iter ( add hs ) l ; hs let to_assoc p = List . rev ( fold ( fun k v acc -> ( k , v ) :: acc ) p [ ] ) end module Request = struct module Cache = struct type t = Jstr . t let default = Jstr . v " default " let force_cache = Jstr . v " force - cache " let no_cache = Jstr . v " no - cache " let no_store = Jstr . v " no - store " let only_if_cached = Jstr . v " only - if - cached " let reload = Jstr . v " reload " end module Credentials = struct type t = Jstr . t let include ' = Jstr . v " include " let omit = Jstr . v " omit " let same_origin = Jstr . v " same - origin " end module Destination = struct type t = Jstr . t let audio = Jstr . v " audio " let audioworklet = Jstr . v " audioworklet " let document = Jstr . v " document " let embed = Jstr . v " embed " let font = Jstr . v " font " let frame = Jstr . v " frame " let iframe = Jstr . v " iframe " let image = Jstr . v " image " let manifest = Jstr . v " manifest " let object ' = Jstr . v " object ' " let paintworklet = Jstr . v " paintworklet " let report = Jstr . v " report " let script = Jstr . v " script " let sharedworker = Jstr . v " sharedworker " let style = Jstr . v " style " let track = Jstr . v " track " let video = Jstr . v " video " let worker = Jstr . v " worker " let xslt = Jstr . v " xslt " end module Mode = struct type t = Jstr . t let cors = Jstr . v " cors " let navigate = Jstr . v " navigate " let no_cors = Jstr . v " no - cors " let same_origin = Jstr . v " same - origin " end module Redirect = struct type t = Jstr . t let error = Jstr . v " error " let follow = Jstr . v " follow " let manual = Jstr . v " manual " end type init = Jv . t let init ? body ? cache ? credentials ? headers ? integrity ? keepalive ? method ' ? mode ? redirect ? referrer ? referrer_policy ? signal ( ) = let o = Jv . obj [ ] || in Jv . set o " body " ( Jv . of_option ~ none : Jv . undefined Fun . id body ) ; Jv . Jstr . set_if_some o " cache " cache ; Jv . Jstr . set_if_some o " credentials " credentials ; Jv . set_if_some o " headers " ( Option . map Headers . to_jv headers ) ; Jv . Jstr . set_if_some o " integrity " integrity ; Jv . Bool . set_if_some o " keepalive " keepalive ; Jv . Jstr . set_if_some o " method " method ' ; Jv . Jstr . set_if_some o " mode " mode ; Jv . Jstr . set_if_some o " redirect " redirect ; Jv . Jstr . set_if_some o " referrer " referrer ; Jv . Jstr . set_if_some o " referrerPolicy " referrer_policy ; Jv . set o " signal " ( Jv . of_option ~ none : Jv . undefined Abort . Signal . to_jv signal ) ; o type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let request = Jv . get Jv . global " Request " let v ( ? init = Jv . obj [ ] ) || url = Jv . new ' request [ | Jv . of_jstr url ; init ] | let of_request ? init r = match init with | None -> Jv . call r " clone " [ ] || | Some init -> Jv . new ' request [ | r ; init ] | external as_body : t -> Body . t = " % identity " let cache r = Jv . Jstr . get r " cache " let credentials r = Jv . Jstr . get r " credentials " let destination r = Jv . Jstr . get r " destination " let headers r = Headers . of_jv ( Jv . get r " headers " ) let integrity r = Jv . Jstr . get r " integrity " let is_history_navigation r = Jv . Bool . get r " isHistoryNavigation " let is_reload_navigation r = Jv . Bool . get r " isReloadNavigation " let keepalive r = Jv . Bool . get r " keepalive " let method ' r = Jv . Jstr . get r " method ' " let mode r = Jv . Jstr . get r " mode " let redirect r = Jv . Jstr . get r " redirect " let referrer r = Jv . Jstr . get r " referrer " let referrer_policy r = Jv . Jstr . get r " referrerPolicy " let signal r = Jv . to_option Abort . Signal . of_jv ( Jv . get r " signal " ) let url r = Jv . Jstr . get r " url " end module Response = struct module Type = struct type t = Jstr . t let basic = Jstr . v " basic " let cors = Jstr . v " cors " let default = Jstr . v " default " let error = Jstr . v " error " let opaque = Jstr . v " opaque " let opaqueredirect = Jstr . v " opaqueredirect " end type init = Jv . t let init ? headers ? status ? status_text ( ) = let o = Jv . obj [ ] || in Jv . set_if_some o " headers " ( Option . map Headers . to_jv headers ) ; Jv . Int . set_if_some o " status " status ; Jv . Jstr . set_if_some o " statusText " status_text ; o type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let response = Jv . get Jv . global " Response " let v ( ? init = Jv . obj [ ] ) || ? body ( ) = let body = Jv . of_option ~ none : Jv . null Fun . id body in Jv . new ' response [ | body ; init ] | let of_response r = Jv . call r " clone " [ ] || let error ( ) = Jv . call response " error " [ ] || let redirect ? status url = let args = match status with | None -> [ | Jv . of_jstr url ] | | Some status -> [ | Jv . of_jstr url ; Jv . of_int status ] | in Jv . call response " redirect " args external as_body : t -> Body . t = " % identity " let headers r = Headers . of_jv ( Jv . get r " headers " ) let ok r = Jv . Bool . get r " ok " let redirected r = Jv . Bool . get r " redirected " let status r = Jv . Int . get r " status " let status_text r = Jv . Jstr . get r " statusText " let url r = Jv . Jstr . get r " url " end module Cache = struct type query_opts = Jv . t let query_opts ? ignore_search ? ignore_method ? ignore_vary ? cache_name ( ) = let o = Jv . obj [ ] || in Jv . Bool . set_if_some o " ignoreSearch " ignore_search ; Jv . Bool . set_if_some o " ignoreMethod " ignore_method ; Jv . Bool . set_if_some o " ignoreVary " ignore_vary ; Jv . Jstr . set_if_some o " cacheName " cache_name ; o type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let match ' ( ? query_opts = Jv . undefined ) c req = let ok = Jv . to_option Response . of_jv in let args = [ | Request . to_jv req ; query_opts ] | in Fut . of_promise ~ ok @@ Jv . call c " match " args let match_all ( ? query_opts = Jv . undefined ) c req = let ok = Jv . to_list Response . of_jv in let args = [ | Request . to_jv req ; query_opts ] | in Fut . of_promise ~ ok @@ Jv . call c " matchAll " args let add c req = Fut . of_promise ~ ok : ignore @@ Jv . call c " add " [ | Request . to_jv req ] | let add_all c reqs = let args = [ | Jv . of_list Request . to_jv reqs ] | in Fut . of_promise ~ ok : ignore @@ Jv . call c " addAll " args let put c req resp = let args = [ | Request . to_jv req ; Response . to_jv resp ] | in Fut . of_promise ~ ok : ignore @@ Jv . call c " put " args let delete ( ? query_opts = Jv . undefined ) c req = let args = [ | Request . to_jv req ; query_opts ] | in Fut . of_promise ~ ok : Jv . to_bool @@ Jv . call c " delete " args let keys ( ? query_opts = Jv . undefined ) ( ? req = Jv . undefined ) c = let args = [ | req ; query_opts ] | in Fut . of_promise ~ ok ( : Jv . to_list Request . of_jv ) @@ Jv . call c " keys " args module Storage = struct type cache = t type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let match ' ( ? query_opts = Jv . undefined ) s req = let ok = Jv . to_option Response . of_jv in let args = [ | Request . to_jv req ; query_opts ] | in Fut . of_promise ~ ok @@ Jv . call s " match " args let has s n = Fut . of_promise ~ ok : Jv . to_bool @@ Jv . call s " has " Jv . [ | of_jstr n ] | let open ' s n = Fut . of_promise ~ ok : Fun . id @@ Jv . call s " open " Jv . [ | of_jstr n ] | let delete s n = Fut . of_promise ~ ok : Jv . to_bool @@ Jv . call s " delete " Jv . [ | of_jstr n ] | let keys s = Fut . of_promise ~ ok : Jv . to_jstr_list @@ Jv . call s " keys " Jv . [ ] || end end module Ev = struct type t = Jv . t let fetch = Ev . Type . create ( Jstr . v " fetch " ) let as_extendable = Obj . magic let request e = Request . of_jv @@ Jv . get e " request " let preload_response e = let ok = Jv . to_option Response . of_jv in Fut . of_promise ~ ok @@ Jv . get e " preloadReponse " let client_id e = Jv . Jstr . get e " clientId " let resulting_client_id e = Jv . Jstr . get e " resultingClientId " let replaces_client_id e = Jv . Jstr . get e " replacesClientId " let handled e = Fut . of_promise ~ ok : ignore @@ Jv . get e " handled " let respond_with e fut = let args = [ | Fut . to_promise ~ ok : Response . to_jv fut ] | in ignore @@ Jv . call e " respondWith " args end let fetch = Jv . get Jv . global " fetch " let url ( ? init = Jv . obj [ ] ) || url = Fut . of_promise ~ ok : Response . of_jv @@ Jv . apply fetch [ | Jv . of_jstr url ; init ] | let request r = Fut . of_promise ~ ok : Response . of_jv @@ Jv . apply fetch [ | Request . to_jv r ] | let caches = Jv . get Jv . global " caches " end
module Geolocation = struct module Error = struct type code = int let permission_denied = 1 let position_unavailable = 2 let timeout = 3 type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let code e = Jv . Int . get e " code " let message e = Jv . Jstr . get e " message " end module Pos = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let coords p = Jv . get p " coords " let latitude p = Jv . Float . get ( coords p ) " latitude " let longitude p = Jv . Float . get ( coords p ) " longitude " let altitude p = Jv . Float . find ( coords p ) " altitude " let accuracy p = Jv . Float . get ( coords p ) " accuracy " let altitude_accuracy p = Jv . Float . find ( coords p ) " altitudeAccuracy " let heading p = Jv . Float . find ( coords p ) " heading " let speed p = Jv . Float . find ( coords p ) " speed " let timestamp_ms p = Jv . Float . get p " timestamp " end type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let of_navigator n = Jv . get ( Navigator . to_jv n ) " geolocation " type opts = Jv . t let opts ? high_accuracy ? timeout_ms ? maximum_age_ms ( ) = let o = Jv . obj [ ] || in Jv . Bool . set_if_some o " enableHighAccuracy " high_accuracy ; Jv . Int . set_if_some o " timeout " timeout_ms ; Jv . Int . set_if_some o " maximumAge " maximum_age_ms ; o let get ? opts l = let fut , set_fut = Fut . create ( ) in let pos p = set_fut ( Ok p ) and error e = set_fut ( Error e ) in let opts = Jv . of_option ~ none : Jv . undefined Fun . id opts in let args = Jv . [ | repr pos ; repr error ; opts ] | in ignore @@ Jv . call l " getCurrentPosition " args ; fut type watch_id = int let watch ? opts l f = let pos p = f ( Ok p ) and error e = f ( Error e ) in let opts = Jv . of_option ~ none : Jv . undefined Fun . id opts in Jv . to_int @@ Jv . call l " watchPosition " Jv . [ | repr pos ; repr error ; opts ] | let unwatch l id = ignore @@ Jv . call l " clearWatch " [ | Jv . of_int id ] | end
module Media = struct module Prop = struct module Bool = struct module Constraint = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let v ? exact ? ideal ( ) = let o = Jv . obj [ ] || in Jv . Bool . set_if_some o " exact " exact ; Jv . Bool . set_if_some o " ideal " ideal ; o end end module Int = struct module Range = struct type t = Jv . t let v ? min ? max ( ) = let o = Jv . obj [ ] || in Jv . Int . set_if_some o " min " min ; Jv . Int . set_if_some o " max " max ; o let min r = Jv . Int . find r " min " let max r = Jv . Int . find r " max " include ( Jv . Id : Jv . CONV with type t := t ) end module Constraint = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let v ? min ? max ? exact ? ideal ( ) = let o = Jv . obj [ ] || in Jv . Int . set_if_some o " min " min ; Jv . Int . set_if_some o " max " max ; Jv . Int . set_if_some o " exact " exact ; Jv . Int . set_if_some o " ideal " ideal ; o end end module Float = struct module Range = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let v ? min ? max ( ) = let o = Jv . obj [ ] || in Jv . Float . set_if_some o " min " min ; Jv . Float . set_if_some o " max " max ; o let min r = Jv . Float . find r " min " let max r = Jv . Float . find r " max " end module Constraint = struct type t = Jv . t let v ? min ? max ? exact ? ideal ( ) = let o = Jv . obj [ ] || in Jv . Float . set_if_some o " min " min ; Jv . Float . set_if_some o " max " max ; Jv . Float . set_if_some o " exact " exact ; Jv . Float . set_if_some o " ideal " ideal ; o include ( Jv . Id : Jv . CONV with type t := t ) end end module Jstr = struct type t = Jstr . t module Constraint = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let v ? exact ? ideal ( ) = let o = Jv . obj [ ] || in Jv . set_if_some o " exact " ( Option . map Jv . of_jstr_list exact ) ; Jv . set_if_some o " ideal " ( Option . map Jv . of_jstr_list ideal ) ; o end end type ' a conv = ( ' a -> Jv . t ) * ( Jv . t -> ' a ) type ( ' a , ' b , ' c ) t = { name : Jstr . t ; value_to_jv : ' a -> Jv . t ; value_of_jv : Jv . t -> ' a ; cap_to_jv : ' b -> Jv . t ; cap_of_jv : Jv . t -> ' b ; constr_to_jv : ' c -> Jv . t ; constr_of_jv : Jv . t -> ' c } let v name ( value_to_jv , value_of_jv ) ( cap_to_jv , cap_of_jv ) ( constr_to_jv , constr_of_jv ) = { name ; value_to_jv ; value_of_jv ; cap_to_jv ; cap_of_jv ; constr_to_jv ; constr_of_jv ; } let name p = p . name let value_to_jv p = p . value_to_jv let value_of_jv p = p . value_of_jv let cap_to_jv p = p . cap_to_jv let cap_of_jv p = p . cap_of_jv let constr_to_jv p = p . constr_to_jv let constr_of_jv p = p . constr_of_jv type bool_t = ( bool , bool list , Bool . Constraint . t ) t let bool name = let value_conv = Jv . ( of_bool , Jv . to_bool ) in let cap_conv = Jv . ( of_list of_bool , to_list to_bool ) in let constr_conv = Bool . Constraint . ( to_jv , of_jv ) in v name value_conv cap_conv constr_conv type int_t = ( int , Int . Range . t , Int . Constraint . t ) t let int name = let value_conv = Jv . ( of_int , to_int ) in let cap_conv = Int . Range . ( to_jv , of_jv ) in let constr_conv = Int . Constraint . ( to_jv , of_jv ) in v name value_conv cap_conv constr_conv type float_t = ( float , Float . Range . t , Float . Constraint . t ) t let float name = let value_conv = Jv . ( of_float , to_float ) in let cap_conv = Float . Range . ( to_jv , of_jv ) in let constr_conv = Float . Constraint . ( to_jv , of_jv ) in v name value_conv cap_conv constr_conv type jstr_t = ( Jstr . t , Jstr . t , Jstr . Constraint . t ) t let jstr name = let value_conv = Jv . ( of_jstr , to_jstr ) in let cap_conv = value_conv in let constr_conv = Jstr . Constraint . ( to_jv , of_jv ) in v name value_conv cap_conv constr_conv type jstr_enum_t = ( Jstr . t , Jstr . t list , Jstr . Constraint . t ) t let jstr_enum name = let value_conv = Jv . ( of_jstr , to_jstr ) in let cap_conv = Jv . ( of_jstr_list , to_jstr_list ) in let constr_conv = Jstr . Constraint . ( to_jv , of_jv ) in v name value_conv cap_conv constr_conv end module Supported_constraints = struct type t = Jv . t let mem p cs = let mem = Jv . get ' cs ( Prop . name p ) in if Jv . is_none mem then false else Jv . to_bool mem let names cs = Jv . to_jstr_list @@ Jv . call ( Jv . get Jv . global " Object " ) " keys " [ | cs ] | include ( Jv . Id : Jv . CONV with type t := t ) end module Constraints = struct type t = Jv . t let empty ( ) = Jv . obj [ ] || let find p c = Jv . find_map ' ( Prop . constr_of_jv p ) c ( Prop . name p ) let set p v c = Jv . set ' c ( Prop . name p ) ( Prop . constr_to_jv p v ) let delete p c = Jv . delete ' c ( Prop . name p ) include ( Jv . Id : Jv . CONV with type t := t ) end module Capabilities = struct type t = Jv . t let find p s = Jv . find_map ' ( Prop . cap_of_jv p ) s ( Prop . name p ) let set p v s = Jv . set ' s ( Prop . name p ) ( Prop . cap_to_jv p v ) let delete p s = Jv . delete ' s ( Prop . name p ) include ( Jv . Id : Jv . CONV with type t := t ) end module Settings = struct type t = Jv . t let get p s = Prop . value_of_jv p @@ Jv . get ' s ( Prop . name p ) let find p s = Jv . find_map ' ( Prop . value_of_jv p ) s ( Prop . name p ) include ( Jv . Id : Jv . CONV with type t := t ) end module Track = struct module Prop = struct let aspect_ratio = Prop . float ( Jstr . v " aspectRatio " ) let auto_gain_control = Prop . bool ( Jstr . v " autoGainControl " ) let channel_count = Prop . int ( Jstr . v " channelCount " ) let cursor = Prop . jstr_enum ( Jstr . v " cursor " ) let device_id = Prop . jstr ( Jstr . v " deviceId " ) let display_surface = Prop . jstr_enum ( Jstr . v " displaySurface " ) let echo_cancellation = Prop . bool ( Jstr . v " echoCancellation " ) let facing_mode = Prop . jstr_enum ( Jstr . v " facingMode " ) let frame_rate = Prop . float ( Jstr . v " frameRate " ) let group_id = Prop . jstr ( Jstr . v " groupId " ) let height = Prop . int ( Jstr . v " height " ) let latency = Prop . float ( Jstr . v " latency " ) let logical_surface = Prop . bool ( Jstr . v " logicalSurface " ) let noise_suppresion = Prop . bool ( Jstr . v " noiseSuppresion " ) let resize_mode = Prop . jstr_enum ( Jstr . v " resizeMode " ) let sample_rate = Prop . int ( Jstr . v " sampleRate " ) let sample_size = Prop . int ( Jstr . v " sampleSize " ) let width = Prop . int ( Jstr . v " width " ) end module State = struct type t = Jstr . t let live = Jstr . v " live " let ended = Jstr . v " ended " end module Kind = struct type t = Jstr . t let audio = Jstr . v " audio " let video = Jstr . v " video " end type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) external as_target : t -> Ev . target = " % identity " let id t = Jv . Jstr . get t " id " let isolated t = Jv . Bool . get t " isolated " let kind t = Jv . Jstr . get t " kind " let label t = Jv . Jstr . get t " label " let muted t = Jv . Bool . get t " muted " let ready_state t = Jv . Jstr . get t " readyState " let enabled t = Jv . Bool . get t " enabled " let set_enabled t b = Jv . Bool . set t " enabled " b let get_capabilities t = Capabilities . of_jv @@ Jv . call t " getCapabilities " [ ] || let get_constraints t = Constraints . of_jv @@ Jv . call t " getConstraints " [ ] || let apply_constraints t c = let a = match c with None -> [ ] || | Some c -> [ | Constraints . to_jv c ] | in Fut . of_promise ~ ok ( : Fun . const ( ) ) @@ Jv . call t " applyConstraints " a let get_settings t = Settings . of_jv @@ Jv . call t " getSettings " [ ] || let stop t = ignore @@ Jv . call t " stop " [ ] || let clone t = Jv . call t " clone " [ ] || module Ev = struct let ended = Ev . Type . void ( Jstr . v " ended " ) let isolationchange = Ev . Type . void ( Jstr . v " isolationchange " ) let mute = Ev . Type . void ( Jstr . v " mute " ) let unmute = Ev . Type . void ( Jstr . v " unmute " ) type track = t type t = Jv . t let track p = Jv . get p " track " end end module Stream = struct module Constraints = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) type track = [ ` No | ` Yes of Constraints . t option ] let v ( ? audio = ` No ) ( ? video = ` No ) ( ) = let o = Jv . obj [ ] || in let set_track o n = function | ` No -> Jv . Bool . set o n false | ` Yes None -> Jv . Bool . set o n true | ` Yes ( Some c ) -> Jv . set o n ( Constraints . to_jv c ) in set_track o " audio " audio ; set_track o " video " video ; o let av ( ) = v ~ audio ( ` : Yes None ) ~ video ( ` : Yes None ) ( ) end type t = Jv . t let stream = Jv . get Jv . global " MediaStream " let create ( ) = Jv . new ' stream [ ] || let of_stream s = Jv . new ' stream [ | s ] | let of_tracks ts = Jv . new ' stream [ | Jv . of_list Track . to_jv ts ] | external as_target : t -> Ev . target = " % identity " let id s = Jv . Jstr . get s " id " let active s = Jv . Bool . get s " active " let get_audio_tracks s = Jv . to_list Track . of_jv @@ Jv . call s " getAudioTracks " [ ] || let get_video_tracks s = Jv . to_list Track . of_jv @@ Jv . call s " getVideoTracks " [ ] || let get_tracks s = Jv . to_list Track . of_jv @@ Jv . call s " getTracks " [ ] || let get_track_by_id s id = Jv . to_option Track . of_jv @@ Jv . call s " getTrackById " [ | Jv . of_jstr id ] | let add_track s t = ignore @@ Jv . call s " addTrack " [ | Track . to_jv t ] | let remove_track s t = ignore @@ Jv . call s " removeTrack " [ | Track . to_jv t ] | let clone s = Jv . call s " clone " [ ] || module Ev = struct let addtrack = Ev . Type . create ( Jstr . v " addtrack " ) let removetrack = Ev . Type . create ( Jstr . v " removetrack " ) end include ( Jv . Id : Jv . CONV with type t := t ) end module Recorder = struct module Bitrate_mode = struct type t = Jstr . t let cbr = Jstr . v " cbr " let vbr = Jstr . v " vbr " end module Recording_state = struct type t = Jstr . t let inactive = Jstr . v " inactive " let recording = Jstr . v " recording " let paused = Jstr . v " paused " end type init = Jv . t let init ? type ' ? audio_bps ? video_bps ? bps ? audio_bitrate_mode ( ) = let o = Jv . obj [ ] || in Jv . Jstr . set_if_some o " mimeType " type ' ; Jv . Int . set_if_some o " audioBitsPerSecond " audio_bps ; Jv . Int . set_if_some o " videoBitsPerSecond " video_bps ; Jv . Int . set_if_some o " bitsPerSecond " bps ; Jv . Jstr . set_if_some o " audioBitrateMode " audio_bitrate_mode ; o let recorder = Jv . get Jv . global " MediaRecorder " let is_type_supported t = Jv . to_bool @@ Jv . call recorder " isTypeSupported " [ | Jv . of_jstr t ] | type t = Jv . t let create ( ? init = Jv . obj [ ] ) || s = Jv . new ' recorder [ | Stream . to_jv s ; init ] | let stream r = Stream . of_jv ( Jv . get r " stream " ) let type ' r = Jv . Jstr . get r " mimeType " let state r = Jv . Jstr . get r " state " let video_bps r = Jv . Int . get r " videoBitsPerSecond " let audio_bps r = Jv . Int . get r " audioBitsPerSecond " let audio_bitrate_mode r = Jv . Jstr . get r " audioBitrateMode " let start r ~ timeslice_ms : ts = let args = match ts with None -> [ ] || | Some ms -> Jv . [ | of_int ms ] | in match Jv . call r " start " args with | exception Jv . Error e -> Error e | _ -> Ok ( ) let stop r = ignore @@ Jv . call r " stop " [ ] || let pause r = ignore @@ Jv . call r " pause " [ ] || let resume r = ignore @@ Jv . call r " resume " [ ] || let request_data r = ignore @@ Jv . call r " requestData " [ ] || module Ev = struct module Blob = struct type t = Jv . t let data e = Blob . of_jv @@ Jv . get e " data " let timecode e = Jv . Float . get e " timecode " end module Error = struct type t = Jv . t let error e = Jv . to_error @@ Jv . get e " error " end let start = Ev . Type . void ( Jstr . v " start " ) let stop = Ev . Type . void ( Jstr . v " stop " ) let dataavailable = Ev . Type . create ( Jstr . v " dataavailable " ) let pause = Ev . Type . void ( Jstr . v " pause " ) let resume = Ev . Type . void ( Jstr . v " resume " ) let error = Ev . Type . create ( Jstr . v " error " ) end end module Device = struct module Kind = struct type t = Jstr . t let audioinput = Jstr . v " audioinput " let audiooutput = Jstr . v " audiooutput " let videoinput = Jstr . v " videoinput " end module Info = struct type t = Jv . t let device_id d = Jv . Jstr . get d " deviceId " let kind d = Jv . Jstr . get d " kind " let label d = Jv . Jstr . get d " label " let group_id d = Jv . Jstr . get d " groupId " let to_json d = Jv . call d " toJSON " [ ] || include ( Jv . Id : Jv . CONV with type t := t ) end end module Devices = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) external as_target : t -> Ev . target = " % identity " let of_navigator n = Jv . get ( Navigator . to_jv n ) " mediaDevices " let enumerate m = let ok = Jv . to_list Device . Info . of_jv in Fut . of_promise ~ ok @@ Jv . call m " enumerateDevices " [ ] || let get_supported_constraints m = Supported_constraints . of_jv @@ Jv . call m " getSupportedConstraints " [ ] || let get_user_media m c = let ok = Stream . of_jv in Fut . of_promise ~ ok @@ Jv . call m " getUserMedia " [ | c ] | let get_display_media m c = let ok = Stream . of_jv in Fut . of_promise ~ ok @@ Jv . call m " getDisplayMedia " [ | c ] | module Ev = struct let devicechange = Ev . Type . void ( Jstr . v " devicechange " ) end end module El = struct module Error = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) type code = int let aborted = 1 let network = 2 let decode = 3 let src_not_supported = 4 let code e = Jv . Int . get e " code " let message e = Jv . Jstr . get e " message " end module Can_play = struct type t = Jstr . t let maybe = Jstr . v " maybe " let probably = Jstr . v " probably " end module Have = struct type t = int let nothing = 0 let metadata = 1 let current_data = 2 let future_data = 3 let enought_data = 4 end module Network = struct type t = int let empty = 0 let idle = 1 let loading = 2 let no_source = 3 end module Cors = struct type t = Jstr . t let anonymous = Jstr . v " anonymous " let use_credentials = Jstr . v " use - credentials " end module Provider = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let of_media_stream = Fun . id let of_blob = Blob . to_jv let of_media_source = Fun . id end module Audio_track = struct module List = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) end type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) end module Video_track = struct module List = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) end type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) end module Text_track = struct module Kind = struct type t = Jstr . t end module List = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) end type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) end module Time_ranges = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let length r = Jv . Int . get r " length " let start r i = Jv . to_float @@ Jv . call r " start " Jv . [ | of_int i ] | let end ' r i = Jv . to_float @@ Jv . call r " end " Jv . [ | of_int i ] | end type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let of_el e = if El . has_tag_name El . Name . video e then ( El . to_jv e ) else if El . has_tag_name El . Name . audio e then ( El . to_jv e ) else let exp = Jstr . v " Expected audio or video element but found : " in Jv . throw ( Jstr . append exp ( El . tag_name e ) ) let to_el = El . of_jv let error m = Jv . to_option Error . of_jv ( Jv . get m " error " ) let src m = Jv . Jstr . get m " src " let set_src m s = Jv . Jstr . set m " src " s let src_object m = Jv . to_option Provider . of_jv ( Jv . get m " srcObject " ) let set_src_object m o = Jv . set m " srcObject " ( Jv . of_option ~ none : Jv . null Provider . to_jv o ) let current_src m = Jv . Jstr . get m " currentSrc " let cross_origin m = Jv . Jstr . get m " crossOrigin " let set_cross_origin m c = Jv . Jstr . set m " crossOrigin " c let network_state m = Jv . Int . get m " networkState " let preload m = Jv . Jstr . get m " preload " let set_preload m p = Jv . Jstr . set m " preload " p let buffered m = Time_ranges . of_jv @@ Jv . get m " buffered " let load m = ignore @@ Jv . call m " load " [ ] || let can_play_type m t = Jv . to_jstr @@ Jv . call m " canPlayType " Jv . [ | of_jstr t ] | let ready_state m = Jv . Int . get m " readyState " let seeking m = Jv . Bool . get m " seeking " let current_time_s m = Jv . Float . get m " currentTime " let set_current_time_s m t = Jv . Float . set m " currentTime " t let fast_seek_s m t = ignore @@ Jv . call m " fastSeek " Jv . [ | of_float t ] | let duration_s m = Jv . Float . get m " duration " let paused m = Jv . Bool . get m " paused " let default_playback_rate m = Jv . Float . get m " defaultPlaybackRate " let set_default_playback_rate m r = Jv . Float . set m " defaultPlaybackRate " r let playback_rate m = Jv . Float . get m " playbackRate " let set_playback_rate m r = Jv . Float . set m " playbackRate " r let played m = Time_ranges . of_jv @@ Jv . get m " played " let seekable m = Time_ranges . of_jv @@ Jv . get m " seekable " let ended m = Jv . Bool . get m " ended " let autoplay m = Jv . Bool . get m " autoplay " let set_auto_play m b = Jv . Bool . set m " autoplay " b let loop m = Jv . Bool . get m " loop " let set_loop m b = Jv . Bool . set m " loop " b let play m = Fut . of_promise ~ ok : ignore ( Jv . call m " play " [ ] ) || let pause m = ignore ( Jv . call m " pause " [ ] ) || let controls m = Jv . Bool . get m " controls " let set_controls m b = Jv . Bool . set m " controls " b let volume m = Jv . Float . get m " volume " let set_volume m f = Jv . Float . set m " volume " f let muted m = Jv . Bool . get m " muted " let set_muted m b = Jv . Bool . set m " muted " b let default_muted m = Jv . Bool . get m " defaultMuted " let set_default_muted m b = Jv . Bool . set m " defaultMuted " b let audio_track_list m = Audio_track . List . of_jv @@ Jv . get m " audioTracks " let video_track_list m = Video_track . List . of_jv @@ Jv . get m " videoTracks " let text_track_list m = Text_track . List . of_jv @@ Jv . get m " textTracks " let capture_stream m = Stream . of_jv @@ Jv . call m " captureStream " [ ] || end end
module Message = struct type transfer = Jv . t let transfer = Jv . repr type opts = Jv . t let opts ? target_origin ? transfer ( ) = let o = Jv . obj [ ] || in Jv . Jstr . set_if_some o " targetOrigin " target_origin ; Jv . set_if_some o " transfer " ( Option . map Jv . of_jv_list transfer ) ; o module Port = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) external as_target : t -> Ev . target = " % identity " let start p = ignore @@ Jv . call p " start " [ ] || let close p = ignore @@ Jv . call p " close " [ ] || let post ( ? opts = Jv . undefined ) p v = ignore @@ Jv . call p " postMessage " [ | Jv . repr v ; opts ] | end module Channel = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let channel = Jv . get Jv . global " MessageChannel " let create ( ) = Jv . new ' channel [ ] || let port1 c = Port . of_jv @@ Jv . get c " port1 " let port2 c = Port . of_jv @@ Jv . get c " port2 " end module Broadcast_channel = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) external as_target : t -> Ev . target = " % identity " let broadcast = Jv . get Jv . global " BroadcastChannel " let create n = Jv . new ' broadcast [ | Jv . of_jstr n ] | let name b = Jv . Jstr . get b " name " let close b = ignore @@ Jv . call b " close " [ ] || let post b v = ignore @@ Jv . call b " postMessage " [ | Jv . repr v ] | end let window_post ( ? opts = Jv . undefined ) w v = ignore @@ Jv . call ( Window . to_jv w ) " postMessage " [ | Jv . repr v ; opts ] | module Ev = struct type t = Jv . t let message = Brr . Ev . Type . create ( Jstr . v " message " ) let messageerror = Brr . Ev . Type . create ( Jstr . v " messageerror " ) let as_extendable = Obj . magic let data e = Obj . magic @@ Jv . get e " data " let origin e = Jv . Jstr . get e " origin " let last_event_id e = Jv . Jstr . get e " lastEventId " let source e = Jv . to_option Fun . id ( Jv . get e " source " ) let ports e = Jv . to_list Port . of_jv ( Jv . get e " ports " ) end end
module Notification = struct module Permission = struct type t = Jstr . t let default = Jstr . v " default " let denied = Jstr . v " denied " let granted = Jstr . v " granted " end let notification = Jv . get Jv . global " Notification " let permission ( ) = Jv . Jstr . get notification " permission " let request_permission ( ) = Fut . of_promise ~ ok : Jv . to_jstr @@ Jv . call notification " requestPermission " [ ] || module Direction = struct type t = Jstr . t let auto = Jstr . v " auto " let ltr = Jstr . v " ltr " let rtl = Jstr . v " rtl " end module Action = struct let max ( ) = Jv . Int . get notification " maxActions " type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let v ? icon ~ action ~ title ( ) = let o = Jv . obj [ ] || in Jv . Jstr . set o " action " action ; Jv . Jstr . set o " title " title ; Jv . Jstr . set_if_some o " icon " icon ; o let action a = Jv . Jstr . get a " action " let title a = Jv . Jstr . get a " title " let icon a = Jv . Jstr . find a " icon " end type action = Jv . t type opts = Jv . t let opts ? dir ? lang ? body ? tag ? image ? icon ? badge ? timestamp_ms ? renotify ? silent ? require_interaction ? data ( ? actions = [ ] ) ( ) = let o = Jv . obj [ ] || in Jv . Jstr . set_if_some o " dir " dir ; Jv . Jstr . set_if_some o " lang " lang ; Jv . Jstr . set_if_some o " body " body ; Jv . Jstr . set_if_some o " image " image ; Jv . Jstr . set_if_some o " icon " icon ; Jv . Jstr . set_if_some o " badge " badge ; Jv . Int . set_if_some o " timestamp " timestamp_ms ; Jv . Bool . set_if_some o " renotify " renotify ; Jv . Bool . set_if_some o " silent " silent ; Jv . Bool . set_if_some o " requireInteraction " require_interaction ; Jv . set_if_some o " data " ( Option . map Jv . repr data ) ; Jv . set o " actions " ( Jv . of_list Fun . id actions ) ; o type t = Jv . t type notification = t include ( Jv . Id : Jv . CONV with type t := t ) let create ( ? opts = Jv . undefined ) title = Jv . new ' notification [ | Jv . of_jstr title ; opts ] | let close n = ignore @@ Jv . call n " close " [ ] || external as_target : t -> Ev . target = " % identity " let actions n = Jv . to_list Fun . id ( Jv . get n " actions " ) let badge n = Jv . Jstr . get n " badge " let body n = Jv . Jstr . get n " body " let data n = Obj . magic @@ Jv . get n " data " let dir n = Jv . Jstr . get n " dir " let lang n = Jv . Jstr . get n " lang " let tag n = Jv . Jstr . get n " tag " let icon n = Jv . Jstr . get n " icon " let image n = Jv . Jstr . get n " image " let url n = Jv . Jstr . get n " url " let renotify n = Jv . Bool . get n " renotify " let require_interaction n = Jv . Bool . get n " requireInteraction " let silent n = Jv . Bool . get n " silent " let timestamp_ms n = Jv . Int . get n " timestamp " let title n = Jv . Jstr . get n " title " module Ev = struct type t = Jv . t let notificationclick = Ev . Type . create ( Jstr . v " notificationclick " ) let notificationclose = Ev . Type . create ( Jstr . v " notificationclose " ) let as_extendable = Obj . magic let notification e = of_jv @@ Jv . get e " notification " let action e = Jv . Jstr . get e " action " end end
module Storage = struct type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) let local w = Jv . get ( Window . to_jv w ) " localStorage " let session w = Jv . get ( Window . to_jv w ) " sessionStorage " let length s = Jv . Int . get s " length " let key s i = Jv . to_option Jv . to_jstr @@ Jv . call s " key " Jv . [ | of_int i ] | let get_item s k = Jv . to_option Jv . to_jstr @@ Jv . call s " getItem " Jv . [ | of_jstr k ] | let set_item s k v = match Jv . to_jstr @@ Jv . call s " setItem " Jv . [ | of_jstr k ; of_jstr v ] | with | exception Jv . Error e -> Error e | _ -> Ok ( ) let remove_item s k = ignore @@ Jv . call s " removeItem " Jv . [ | of_jstr k ] | let clear s = ignore @@ Jv . call s " clear " [ ] || module Ev = struct type storage_area = t type t = Jv . t let storage = Ev . Type . create ( Jstr . v " storage " ) let key e = Jv . Jstr . find e " key " let old_value e = Jv . Jstr . find e " oldValue " let new_value e = Jv . Jstr . find e " newValue " let url e = Jv . Jstr . get e " url " let storage_area e = Jv . find e " storageArea " end end
module Websocket = struct module Binary_type = struct type t = Jstr . t let blob = Jstr . v " blob " let arraybuffer = Jstr . v " arraybuffer " end module Ready_state = struct type t = int let connecting = 0 let open ' = 1 let closing = 2 let closed = 3 end type t = Jv . t include ( Jv . Id : Jv . CONV with type t := t ) external as_target : t -> Ev . target = " % identity " let websocket = Jv . get Jv . global " WebSocket " let create ? protocols url = let protocols = match protocols with | None -> Jv . undefined | Some ps -> Jv . of_jstr_list ps in Jv . new ' websocket Jv . [ | of_jstr url ; protocols ] | let binary_type s = Jv . Jstr . get s " binaryType " let set_binary_type s t = Jv . Jstr . set s " binaryType " t let close ? code ? reason : r s = let code = match code with None -> Jv . undefined | Some c -> Jv . of_int c in let reason = match r with None -> Jv . undefined | Some s -> Jv . of_jstr s in ignore @@ Jv . call s " close " [ | code ; reason ] | let url s = Jv . Jstr . get s " url " let ready_state s = Jv . Int . get s " readyState " let buffered_amount s = Jv . Int . get s " bufferedAmount " let extensions s = Jv . Jstr . get s " extensions " let protocol s = Jv . Jstr . get s " protocol " let send_string s d = ignore @@ Jv . call s " send " [ | Jv . of_jstr d ] | let send_blob s d = ignore @@ Jv . call s " send " [ | Blob . to_jv d ] | let send_tarray s d = ignore @@ Jv . call s " send " [ | Tarray . to_jv d ] | let send_array_buffer s d = ignore @@ Jv . call s " send " [ | Tarray . Buffer . to_jv d ] | module Ev = struct module Close = struct type t = Jv . t let was_clean e = Jv . Bool . get e " wasClean " let code e = Jv . Int . get e " code " let reason e = Jv . Jstr . get e " reason " end let close = Ev . Type . create ( Jstr . v " close " ) end end
module Futr = struct let to_event f = let e , send_e = E . create ( ) in let send_e v = ignore ( G . set_timeout ~ ms : 0 @@ fun ( ) -> send_e v ) in Fut . await f send_e ; e let of_event e = let fut , set_fut = Fut . create ( ) in let logr = ref None in let set_fut v = ignore @@ G . set_timeout ~ ms : 0 @@ fun ( ) -> match ! logr with | None -> assert false | Some logr -> Logr . destroy logr ; set_fut v in match E . log ~ now : true e set_fut with | None -> None | Some _ as s -> logr := s ; Some fut end
module Consoler = struct let tick _ = Console . [ Jstr . v " tick " ] let log_value ( ? l = Console . debug ) ( ? v = fun v -> Console . [ v ] ) id x = l Console . ( Jstr . ( v id + v " " ) : :: ( v x ) ) ; x module E = struct let log ( ? obs = false ) ? l ? v id e = match obs with | false -> E . map ( log_value ? l ? v id ) e | true -> Logr . may_hold ( E . log e ( fun ev -> ignore @@ log_value ? l ? v id ev ) ) ; e end module S = struct let log ( ? obs = false ) ? l ? v id s = match obs with | false -> S . map ~ eq ( : S . eq s ) ( log_value ? l ? v id ) s | true -> Logr . hold ( S . log s ( fun sv -> ignore @@ log_value ? l ? v id sv ) ) ; s end end
module Evr = struct let instruct ( ? propagate = true ) ( ? default = true ) e = ( if default then ( ) else Ev . prevent_default e ) ; if propagate then ( ) else Ev . stop_propagation e let endless_listen ( ? capture = false ) ? propagate ? default t type ' f = let opts = match capture with | false -> None | true -> Some ( Ev . listen_opts ~ capture ( ) ) in let f ev = instruct ? propagate ? default ev ; f ev in Ev . listen ? opts type ' f t let on_target ( ? capture = false ) ? propagate ? default type ' f t = let opts = match capture with | false -> None | true -> Some ( Ev . listen_opts ~ capture ( ) ) in let e , send_e = E . create ( ) in let f ev = instruct ? propagate ? default ev ; send_e ( f ev ) in Ev . listen ? opts type ' f t ; e let on_targets ( ? capture = false ) ? propagate ? default type ' f ts = let opts = match capture with | false -> None | true -> Some ( Ev . listen_opts ~ capture ( ) ) in let e , send_e = E . create ( ) in let f ev = instruct ? propagate ? default ev ; send_e ( f ( Ev . target ev ) ev ) in List . iter ( Ev . listen ? opts type ' f ) ts ; e let on_el ? capture ? propagate ? default type ' f el = on_target ? capture ? propagate ? default type ' f ( El . as_target el ) let on_els ( ? capture = false ) ? propagate ? default type ' f els = let opts = match capture with | false -> None | true -> Some ( Ev . listen_opts ~ capture ( ) ) in let e , send_e = E . create ( ) in let f ev = instruct ? propagate ? default ev ; send_e ( f ( Obj . magic ( Ev . target ev ) : El . t ) ev ) in List . iter ( fun el -> Ev . listen ? opts type ' f ( El . as_target el ) ) els ; e let unit e = ( ) let stamp v e = v let listen ( ? capture = false ) ? propagate ? default t type ' f = let opts = match capture with | false -> None | true -> Some ( Ev . listen_opts ~ capture ( ) ) in let f ev = instruct ? propagate ? default ev ; f ev in Ev . listen ? opts type ' f t ; fun ( ) -> Ev . unlisten ? opts type ' f t end
module Elr = struct let xxx_funs xxx e : ( unit -> unit ) list = Obj . magic @@ Jv . get e xxx let add_xxx_fun xxx f e = let fs = Jv . get e xxx in let fs = if Jv . is_undefined fs then [ f ] else ( f :: Obj . magic fs ) in Jv . set e xxx ( Jv . repr fs ) let add_add_fun = add_xxx_fun " brr_add " let add_rem_fun = add_xxx_fun " brr_rem " let add_funs = xxx_funs " brr_add " let rem_funs = xxx_funs " brr_rem " let invoke_funs xxx node = let star = Jv . of_string " " * in let descendents n = Jv . call ( El . to_jv n ) " querySelectorAll " [ | star ] | in if not ( El . is_el node ) then ( ) else let invoke_node_funs n = let funs = xxx_funs xxx n in List . iter ( fun f -> f ( ) ) funs ; Jv . set n xxx ( Jv . repr [ ] ) in let ns = descendents node in for i = 0 to ( Jv . Int . get ns " length " ) - 1 do let n = Jv . call ns " item " [ | Jv . of_int i ] | in invoke_node_funs n done ; invoke_node_funs ( El . to_jv node ) let ( ) = let obs records _obs = let in_html_dom n = Jv . call ( El . to_jv n ) " getRootNode " [ ] || == Document . to_jv @@ G . document in for i = 0 to ( Jv . Int . get records " length " ) - 1 do let r = Jv . Jarray . get records i in let adds = Jv . get r " addedNodes " in for i = 0 to ( Jv . Int . get adds " length " ) - 1 do let n = El . of_jv @@ Jv . call adds " item " [ | Jv . of_int i ] | in if in_html_dom n then invoke_funs " brr_add " n done ; let rems = Jv . get r " removedNodes " in for i = 0 to ( Jv . Int . get rems " length " ) - 1 do let n = El . of_jv @@ Jv . call rems " item " [ | Jv . of_int i ] | in if not ( in_html_dom n ) then invoke_funs " brr_rem " n done done in let mutation_observer = Jv . get Jv . global " MutationObserver " in let obs = Jv . new ' mutation_observer [ | Jv . repr obs ] | in let opts = Jv . obj [ | " childList " , Jv . true ' ; " subtree " , Jv . true ' ] | in let root = El . to_jv @@ Document . root G . document in ignore @@ Jv . call obs " observe " [ | root ; opts ] | let add_logr e l = add_rem_fun ( fun ( ) -> Logr . destroy l ) ( El . to_jv e ) let may_add_logr e = function None -> ( ) | Some l -> add_logr e l let set_children e ~ on = may_add_logr e ( E . log on ( El . set_children e ) ) let def_children e cs = add_logr e ( S . log cs ( El . set_children e ) ) let set_at a ~ on e = may_add_logr e ( E . log on ( fun v -> El . set_at a v e ) ) let def_at a vs e = add_logr e ( S . log vs ( fun v -> El . set_at a v e ) ) let set_class c ~ on e = may_add_logr e ( E . log on ( fun v -> El . set_class c v e ) ) let def_class c bs e = add_logr e ( S . log bs ( fun v -> El . set_class c v e ) ) let set_prop p ~ on e = may_add_logr e ( E . log on ( fun v -> El . set_prop p v e ) ) let def_prop p vs e = add_logr e ( S . log vs ( fun v -> El . set_prop p v e ) ) let set_inline_style ? important p ~ on e = may_add_logr e ( E . log on ( fun v -> El . set_inline_style ? important p v e ) ) let def_inline_style ? important p vs e = add_logr e ( S . log vs ( fun v -> El . set_inline_style ? important p v e ) ) let set_has_focus ~ on e = may_add_logr e ( E . log on ( fun v -> El . set_has_focus v e ) ) let def_has_focus b e = add_logr e ( S . log b ( fun v -> El . set_has_focus v e ) ) let on_add f e = add_add_fun f ( El . to_jv e ) let on_rem f e = add_rem_fun f ( El . to_jv e ) let call f ~ on e = may_add_logr e ( E . log on ( fun v -> f v e ) ) let hold_logr e l = add_logr e l let may_hold_logr e l = may_add_logr e l end
module Key = struct type code = int type t = [ ` Alt of [ ` Left | ` Right ] | ` Arrow of [ ` Up | ` Down | ` Left | ` Right ] | ` Ascii of Char . t | ` Backspace | ` Ctrl of [ ` Left | ` Right ] | ` End | ` Enter | ` Escape | ` Func of int | ` Home | ` Insert | ` Key of code | ` Meta of [ ` Left | ` Right ] | ` Page of [ ` Up | ` Down ] | ` Return | ` Shift of [ ` Left | ` Right ] | ` Spacebar | ` Tab ] let of_keycode kc = match kc with | c when 48 <= c && c <= 57 -> ` Ascii ( Char . chr c ) | c when 65 <= c && c <= 90 -> ` Ascii ( Char . chr ( c + 32 ) ) | c when 96 <= c && c <= 105 -> ` Ascii ( Char . chr ( c - 96 + 48 ) ) | c when 112 <= c && c <= 135 -> ` Func ( c - 111 ) | 8 -> ` Backspace | 9 -> ` Tab | 13 -> ` Return | 16 -> ` Shift ` Left | 17 -> ` Ctrl ` Left | 18 -> ` Alt ` Left | 27 -> ` Escape | 32 -> ` Spacebar | 33 -> ` Page ` Up | 34 -> ` Page ` Down | 35 -> ` End | 36 -> ` Home | 37 -> ` Arrow ` Left | 38 -> ` Arrow ` Up | 39 -> ` Arrow ` Right | 40 -> ` Arrow ` Down | 45 -> ` Enter | 91 | 224 -> ` Meta ` Left | 93 -> ` Meta ` Right | c -> ` Key c let of_ev e = of_keycode ( Jv . Int . get ( Ev . to_jv e ) " keyCode " ) let equal k0 k1 = k0 = k1 let compare k0 k1 = compare k0 k1 let dir_to_jstr = function | ` Left -> Jstr . v " left " | ` Right -> Jstr . v " right " | ` Up -> Jstr . v " up " | ` Down -> Jstr . v " down " let to_jstr = function | ` Alt dir -> Jstr . ( v " alt_ " + dir_to_jstr dir ) | ` Arrow dir -> Jstr . ( v " arrow_ " + dir_to_jstr dir ) | ` Ascii c -> Jstr . ( v " key_ " + of_char c ) | ` Backspace -> Jstr . v " backspace " | ` Ctrl dir -> Jstr . ( v " ctrl_ " + dir_to_jstr dir ) | ` End -> Jstr . v " end " | ` Enter -> Jstr . v " enter " | ` Escape -> Jstr . v " escape " | ` Func n -> Jstr . ( v " F " + of_int n ) | ` Home -> Jstr . v " home " | ` Insert -> Jstr . v " insert " | ` Key c -> Jstr . ( v " key_ " + of_int c ) | ` Meta dir -> Jstr . ( v " meta_ " + dir_to_jstr dir ) | ` Page dir -> Jstr . ( v " page_ " + dir_to_jstr dir ) | ` Return -> Jstr . v " return " | ` Shift dir -> Jstr . ( v " shift_ " + dir_to_jstr dir ) | ` Spacebar -> Jstr . v " spacebar " | ` Tab -> Jstr . v " tab " type events = { any_down : t event ; send_any_down : t E . send ; any_up : t event ; send_any_up : t E . send ; mutable down_count : int ; any_holds : bool signal ; set_any_holds : bool S . set ; down_event : ( t , unit event * unit E . send ) Hashtbl . t ; up_event : ( t , unit event * unit E . send ) Hashtbl . t ; holds : ( t , bool signal * bool S . set ) Hashtbl . t ; alt : bool signal ; ctrl : bool signal ; meta : bool signal ; shift : bool signal ; } let def_event event k = try fst ( Hashtbl . find event k ) with | Not_found -> let d = E . create ( ) in Hashtbl . add event k d ; fst d let send_event ? step event k = try snd ( Hashtbl . find event k ) ? step ( ) with | Not_found -> ( ) let def_holds holds k = try fst ( Hashtbl . find holds k ) with | Not_found -> let d = S . create false in Hashtbl . add holds k d ; fst d let set_holds ? step holds k v = try snd ( Hashtbl . find holds k ) ? step v with | Not_found -> ( ) let add_modifiers holds = let lalt = S . create false in let ralt = S . create false in let alt = S . Bool . ( fst lalt || fst ralt ) in let lctrl = S . create false in let rctrl = S . create false in let ctrl = S . Bool . ( fst lctrl || fst rctrl ) in let lmeta = S . create false in let rmeta = S . create false in let meta = S . Bool . ( fst lmeta || fst rmeta ) in let lshift = S . create false in let rshift = S . create false in let shift = S . Bool . ( fst lshift || fst rshift ) in Hashtbl . add holds ( ` Alt ` Left ) lalt ; Hashtbl . add holds ( ` Alt ` Right ) ralt ; Hashtbl . add holds ( ` Ctrl ` Left ) lctrl ; Hashtbl . add holds ( ` Ctrl ` Right ) rctrl ; Hashtbl . add holds ( ` Meta ` Left ) lmeta ; Hashtbl . add holds ( ` Meta ` Right ) rmeta ; Hashtbl . add holds ( ` Shift ` Left ) lshift ; Hashtbl . add holds ( ` Shift ` Right ) rshift ; alt , ctrl , meta , shift let handle_down evs ~ step k = evs . down_count <- evs . down_count + 1 ; evs . send_any_down ~ step k ; evs . set_any_holds ~ step true ; send_event ~ step evs . down_event k ; set_holds ~ step evs . holds k true ; ( ) let handle_up evs ~ step k = evs . down_count <- evs . down_count - 1 ; evs . send_any_up ~ step k ; if evs . down_count <= 0 then ( evs . down_count <- 0 ; evs . set_any_holds ~ step false ) ; send_event ~ step evs . up_event k ; set_holds ~ step evs . holds k false ; ( ) let down_cb evs e = if Ev . ( Keyboard . repeat ( as_type e ) ) then ( ) else let step = Step . create ( ) in handle_down evs ~ step ( of_ev e ) ; Step . execute step let up_cb evs e = let step = Step . create ( ) in handle_up evs ~ step ( of_ev e ) ; Step . execute step let on_target ? capture ? propagate ? default t = let hsize = 47 in let any_down , send_any_down = E . create ( ) in let any_up , send_any_up = E . create ( ) in let any_holds , set_any_holds = S . create false in let down_event = Hashtbl . create hsize in let up_event = Hashtbl . create hsize in let holds = Hashtbl . create hsize in let alt , ctrl , meta , shift = add_modifiers holds in let evs = { any_down ; send_any_down ; any_up ; send_any_up ; down_count = 0 ; any_holds ; set_any_holds ; down_event ; up_event ; holds ; alt ; ctrl ; meta ; shift } in Evr . endless_listen ? capture ? propagate ? default t Ev . keydown ( down_cb evs ) ; Evr . endless_listen ? capture ? propagate ? default t Ev . keyup ( up_cb evs ) ; evs let on_el ? capture ? propagate ? default t = on_target ? capture ? propagate ? default ( El . as_target t ) let any_down evs = evs . any_down let any_up evs = evs . any_up let any_holds evs = evs . any_holds let down evs k = def_event evs . down_event k let up evs k = def_event evs . up_event k let holds evs k = def_holds evs . holds k let alt evs = evs . alt let ctrl evs = evs . ctrl let meta evs = evs . meta let shift evs = evs . shift end
module Mouse = struct let warn_but ( ) = Console . ( warn [ Jstr . v " unexpected e . which " ] ) let pt x y = ( x , y ) type ' a events = { t : Ev . target ; normalize : bool ; pt : float -> float -> ' a ; mutable last_pos : float * float ; mutable unlisten : ( unit -> unit ) list ; pos : ' a signal ; set_pos : ' a S . set ; dpos : ' a event ; send_dpos : ' a E . send ; mem : bool signal ; set_mem : bool S . set ; left : bool signal ; set_left : bool S . set ; left_down : ' a event ; send_left_down : ' a E . send ; left_up : ' a event ; send_left_up : ' a E . send ; mid : bool signal ; set_mid : bool S . set ; mid_down : ' a event ; send_mid_down : ' a E . send ; mid_up : ' a event ; send_mid_up : ' a E . send ; right : bool signal ; set_right : bool S . set ; right_down : ' a event ; send_right_down : ' a E . send ; right_up : ' a event ; send_right_up : ' a E . send ; } let destroy evs = List . iter ( fun f -> f ( ) ) evs . unlisten let event_mouse_pos pt evs e = let t = ( Obj . magic evs . t : El . t ) in let x = ( Ev . Mouse . client_x e ) . - El . bound_x t in let y = ( Ev . Mouse . client_y e ) . - El . bound_y t in if not evs . normalize then pt x y else let nx = x . / ( El . bound_w t ) in let ny = 1 . . - ( y . / ( El . bound_h t ) ) in pt nx ny let set_mouse_pos ~ step evs e = let x , y as l = event_mouse_pos pt evs e in let epos = evs . pt x y in let dx = x . - fst evs . last_pos in let dy = y . - snd evs . last_pos in evs . send_dpos ~ step ( evs . pt dx dy ) ; evs . set_pos ~ step epos ; evs . last_pos <- l ; epos let move_cb evs e = let step = Step . create ( ) in let _ = set_mouse_pos ~ step evs ( Ev . as_type e ) in Step . execute step let mem_cb mem evs e = let step = Step . create ( ) in let _ = set_mouse_pos ~ step evs ( Ev . as_type e ) in evs . set_mem ~ step mem ; Step . execute step let down_cb evs e = let step = Step . create ( ) in let epos = set_mouse_pos ~ step evs ( Ev . as_type e ) in let set , send_down = match Ev . Mouse . button ( Ev . as_type e ) with | 0 -> evs . set_left , evs . send_left_down | 1 -> evs . set_mid , evs . send_mid_down | 2 -> evs . set_right , evs . send_right_down | _ -> warn_but ( ) ; evs . set_left , evs . send_left_down in set ~ step true ; send_down ~ step epos ; Step . execute step let up_cb evs e = let step = Step . create ( ) in let epos = set_mouse_pos ~ step evs ( Ev . as_type e ) in let set , send_up = match Ev . Mouse . button ( Ev . as_type e ) with | 0 -> evs . set_left , evs . send_left_up | 1 -> evs . set_mid , evs . send_mid_up | 2 -> evs . set_right , evs . send_right_up | _ -> warn_but ( ) ; evs . set_left , evs . send_left_up in set ~ step false ; send_up ~ step epos ; Step . execute step let doc_up_cb evs e = if not ( S . rough_value evs . mem ) && ( S . rough_value evs . left || S . rough_value evs . mid || S . rough_value evs . right ) then up_cb evs e else ( ) let on_target ? capture ? propagate ? default ( ? normalize = true ) pt t = let pos , set_pos = S . create ( pt 0 . 0 . ) in let dpos , send_dpos = E . create ( ) in let mem , set_mem = S . create false in let left , set_left = S . create false in let left_down , send_left_down = E . create ( ) in let left_up , send_left_up = E . create ( ) in let mid , set_mid = S . create false in let mid_down , send_mid_down = E . create ( ) in let mid_up , send_mid_up = E . create ( ) in let right , set_right = S . create false in let right_down , send_right_down = E . create ( ) in let right_up , send_right_up = E . create ( ) in let evs = { t ; normalize ; pt ; last_pos = ( 0 . , 0 . ) ; unlisten = [ ] ; pos ; set_pos ; dpos ; send_dpos ; mem ; set_mem ; left ; set_left ; left_down ; send_left_down ; left_up ; send_left_up ; mid ; set_mid ; mid_down ; send_mid_down ; mid_up ; send_mid_up ; right ; set_right ; right_down ; send_right_down ; right_up ; send_right_up } in let l = Evr . listen in let unlisten = [ l ? capture ? propagate ? default evs . t Ev . mousedown ( down_cb evs ) ; l ? capture ? propagate ? default evs . t Ev . mouseup ( up_cb evs ) ; l ? capture ? propagate ? default evs . t Ev . mousemove ( move_cb evs ) ; l ? capture ? propagate ? default evs . t Ev . mouseenter ( mem_cb true evs ) ; l ? capture ? propagate ? default evs . t Ev . mouseleave ( mem_cb false evs ) ; l ? capture ? propagate ? default ( Document . as_target G . document ) Ev . mouseup ( doc_up_cb evs ) ] in evs . unlisten <- unlisten ; evs let on_el ? capture ? propagate ? default ? normalize pt e = let t = El . as_target e in let evs = on_target ? capture ? propagate ? default ? normalize pt t in Elr . on_rem ( fun ( ) -> destroy evs ) e ; evs let pos evs = evs . pos let dpos evs = evs . dpos let mem evs = evs . mem let left evs = evs . left let left_down evs = evs . left_down let left_up evs = evs . left_up let mid evs = evs . mid let mid_down evs = evs . mid_down let mid_up evs = evs . mid_up let right evs = evs . right let right_down evs = evs . right_down let right_up evs = evs . right_up module Cursor = struct type t = Jstr . t let url ( ? x = 0 ) ( ? y = 0 ) url = match x = 0 && y = 0 with | true -> Jstr . ( v " url ( " + url + v " ) " ) | false -> Jstr . ( v " url ( " + url + v " ) " + of_int x + sp + of_int y ) let auto = Jstr . v " auto " let default = Jstr . v " default " let none = Jstr . v " none " let context_menu = Jstr . v " context - menu " let help = Jstr . v " help " let pointer = Jstr . v " pointer " let progress = Jstr . v " progress " let wait = Jstr . v " wait " let cell = Jstr . v " cell " let crosshair = Jstr . v " crosshair " let text = Jstr . v " text " let vertical_text = Jstr . v " vertical - text " let alias = Jstr . v " alias " let copy = Jstr . v " copy " let move = Jstr . v " move " let no_drop = Jstr . v " no - drop " let not_allowed = Jstr . v " not - allowed " let grab = Jstr . v " grab " let grabbing = Jstr . v " grabbing " let e_resize = Jstr . v " e - resize " let n_resize = Jstr . v " n - resize " let ne_resize = Jstr . v " ne - resize " let nw_resize = Jstr . v " nw - resize " let s_resize = Jstr . v " s - resize " let se_resize = Jstr . v " se - resize " let sw_resize = Jstr . v " sw - resize " let w_resize = Jstr . v " w - resize " let ew_resize = Jstr . v " ew - resize " let ns_resize = Jstr . v " ns - resize " let nesw_resize = Jstr . v " nesw - resize " let nwse_resize = Jstr . v " nwse - resize " let col_resize = Jstr . v " col - resize " let row_resize = Jstr . v " row - resize " let all_scroll = Jstr . v " all - scroll " let zoom_in = Jstr . v " zoom - in " let zoom_out = Jstr . v " zoom - out " end end
module Windowr = struct let in_fullscreen ( ) = Option . is_some ( Document . fullscreen_element G . document ) let is_fullscreen = let is_fullscreen , set_fullscreen = S . create ( in_fullscreen ( ) ) in let change _e = set_fullscreen ( in_fullscreen ( ) ) in Ev . listen Ev . fullscreenchange change ( Document . as_target G . document ) ; is_fullscreen let quit = let quit , send_quit = E . create ( ) in let send_quit _e = send_quit ( ) in Ev . listen Ev . unload send_quit ( Document . as_target G . document ) ; quit end
module Time = struct type span = float let tick_now ( ) = Performance . now_ms G . performance . / 1000 . let start = tick_now ( ) let elapsed ( ) = tick_now ( ) . - start type counter = span let counter ( ) = tick_now ( ) let counter_value c = tick_now ( ) . - c let tick span = let e , send_e = E . create ( ) in let c = counter ( ) in let action ( ) = send_e ( counter_value c ) in let ms = truncate @@ span . * 1000 . in ignore ( G . set_timeout action ~ ms ) ; e let delay span f = ignore ( G . set_timeout f ~ ms ( : truncate @@ span . * 1000 . ) ) let to_jstr u s = match u with | ` S -> Jstr . ( of_float s + v " s " ) | ` Ms -> Jstr . ( of_float ( s . * 1e3 ) + v " ms " ) | ` Mus -> Jstr . ( of_float ( s . * 1e6 ) + v " μs " ) end
module Human = struct let noticed = 0 . 1 let interrupted = 1 . let left = 10 . let rec feel_action feel set_feel ( ) = let new_feel , delay = match S . value feel with | ` Interacting -> ` Interrupted , left . - interrupted | ` Interrupted -> ` Left , 0 . | ` Left -> assert false in set_feel new_feel ; if delay = 0 . then ( ) else let action = feel_action feel set_feel in let ms = truncate @@ delay . * 1000 . in ignore ( G . set_timeout ~ ms action ) ; ( ) let feel ( ) = let feel , set_feel = S . create ` Interacting in let action = feel_action feel set_feel in let ms = truncate @@ interrupted . * 1000 . in ignore ( G . set_timeout ~ ms action ) ; feel let touch_target_size = 9 . let touch_target_size_min = 7 . let touch_target_pad = 2 . let average_finger_width = 11 . end
module Ui = struct let ui_active = Jstr . v " ui - active " let ui_button = Jstr . v " ui - button " let ui_button_selector = Jstr . v " ui - button - selector " let ui_dir_align_center = Jstr . v " ui - dir - align - center " let ui_dir_align_distribute = Jstr . v " ui - dir - align - distribute " let ui_dir_align_end = Jstr . v " ui - dir - align - end " let ui_dir_align_justify = Jstr . v " ui - dir - align - justify " let ui_dir_align_start = Jstr . v " ui - dir - align - start " let ui_dir_align_stretch = Jstr . v " ui - dir - align - stretch " let ui_dir_h = Jstr . v " ui - dir - h " let ui_dir_v = Jstr . v " ui - dir - v " let ui_disabled = Jstr . v " ui - disabled " let ui_editing = Jstr . v " ui - editing " let ui_file_selector = Jstr . v " ui - file - selector " let ui_group = Jstr . v " ui - group " let ui_label = Jstr . v " ui - label " let ui_menu_selector = Jstr . v " ui - menu - selector " let ui_selected = Jstr . v " ui - selected " let ui_slider_selector = Jstr . v " ui - slider - selector " let ui_str_editor = Jstr . v " ui - str - editor " let ui_xdir_align_center = Jstr . v " ui - xdir - align - center " let ui_xdir_align_distribute = Jstr . v " ui - xdir - align - distribute " let ui_xdir_align_end = Jstr . v " ui - xdir - align - end " let ui_xdir_align_justify = Jstr . v " ui - xdir - align - justify " let ui_xdir_align_start = Jstr . v " ui - xdir - align - start " let ui_xdir_align_stretch = Jstr . v " ui - xdir - align - stretch " let disabled ~ enabled = let is_disabled enabled = if enabled then None else Some Jstr . empty in S . map is_disabled enabled let el_def_tip ~ tip el = match tip with | None -> ( ) | Some tip -> Elr . def_at At . Name . title ( S . Option . some tip ) el module Group = struct type dir = [ ` H | ` V ] type align = [ ` Start | ` End | ` Center | ` Justify | ` Distribute | ` Stretch ] let dir_cls = [ ` H , ui_dir_h ; ` V , ui_dir_v ; ] let align_cls = [ ` Start , ui_dir_align_start ; ` End , ui_dir_align_end ; ` Center , ui_dir_align_center ; ` Justify , ui_dir_align_justify ; ` Distribute , ui_dir_align_distribute ; ` Stretch , ui_dir_align_stretch ; ] let xalign_cls = [ ` Start , ui_xdir_align_start ; ` End , ui_xdir_align_end ; ` Center , ui_xdir_align_center ; ` Justify , ui_xdir_align_justify ; ` Distribute , ui_xdir_align_distribute ; ` Stretch , ui_xdir_align_stretch ; ] let set_class classes el v = El . set_class ( List . assoc v classes ) true el type ' a t = { el : El . t ; enabled : bool signal ; action : ' a event ; dir : dir ; dir_align : align ; xdir_align : align ; } let v ? class ' : cl ( ? enabled = S . Bool . true ' ) ( ? action = E . never ) ( ? xdir_align = ` Start ) ( ? dir_align = ` Start ) ~ dir cs = let at = At . ( add_if_some Name . class ' cl [ class ' ui_group ] ) in let el = El . div ~ at [ ] in let ( ) = Elr . def_children el cs and ( ) = Elr . def_class ui_disabled ( S . Bool . not enabled ) el and ( ) = set_class dir_cls el dir and ( ) = set_class align_cls el dir_align and ( ) = set_class xalign_cls el xdir_align in { el ; enabled ; action ; dir ; dir_align ; xdir_align } let dir g = g . dir let dir_align g = g . dir_align let xdir_align g = g . xdir_align let action g = g . action let enabled g = g . enabled let el g = g . el let with_action action g = { g with action } let hide_action g = with_action E . never g end module Label = struct type t = { el : El . t ; enabled : bool signal } let v ? class ' : cl ( ? enabled = S . Bool . true ' ) ? tip cs = let at = At . ( add_if_some Name . class ' cl [ class ' ui_label ] ) in let el = El . div ~ at [ ] in let ( ) = Elr . def_children el cs and ( ) = el_def_tip ~ tip el and ( ) = Elr . def_class ui_disabled ( S . Bool . not enabled ) el in { el ; enabled } let el l = l . el let enabled l = l . enabled end module Button = struct type ' a t = { el : El . t ; action : ' a event ; active : bool signal ; enabled : bool signal ; } let button_str = Jstr . v " button " let at_base cl = At . ( add_if_some Name . class ' cl [ type ' button_str ; class ' ui_button ] ) let v ? class ' : cl ( ? active = S . Bool . false ' ) ( ? enabled = S . Bool . true ' ) ? tip cs v = let el = El . button ~ at ( : at_base cl ) [ ] in let action = Evr . on_el Ev . click ( Evr . stamp v ) el in let ( ) = Elr . def_children el cs and ( ) = el_def_tip ~ tip el and ( ) = Elr . def_at At . Name . disabled ( disabled ~ enabled ) el and ( ) = Elr . def_class ui_disabled ( S . Bool . not enabled ) el and ( ) = Elr . def_class ui_active active el in { el ; action ; active ; enabled } let action b = b . action let enabled b = b . enabled let active b = b . active let el b = b . el let file_str = Jstr . v " file " let accept_str = Jstr . v " accept " let multiple_str = Jstr . v " multiple " let _file_selector ~ multiple get ? class ' : cl ( ? active = S . Bool . false ' ) ( ? enabled = S . Bool . true ' ) ? tip ( ? exts = [ ] ) cs = let input = let at = match exts with | [ ] -> [ ] | exts -> [ At . v accept_str ( Jstr . v ( String . concat " , " exts ) ) ] in let at = At . add_if multiple ( At . v multiple_str Jstr . empty ) @@ at in let at = At . type ' file_str :: at in El . input ~ at ( ) in let el = El . button ~ at : At . ( class ' ui_file_selector :: at_base cl ) [ ] in let ( ) = El . set_inline_style El . Style . display ( Jstr . v " none " ) input and ( ) = let forward e = El . set_prop El . Prop . value Jstr . empty input ; El . click input in Ev . listen Ev . click forward ( El . as_target el ) and ( ) = Elr . def_children el ( S . map ~ eq ( ) :== ( fun cs -> cs @ [ input ] ) cs ) and ( ) = el_def_tip ~ tip el and ( ) = Elr . def_at At . Name . disabled ( disabled ~ enabled ) el and ( ) = Elr . def_class ui_disabled ( S . Bool . not enabled ) el and ( ) = Elr . def_class ui_active active el and action = Evr . on_el Ev . change ( get input ) input in { el ; enabled ; action ; active } let file_selector = _file_selector ~ multiple : false ( fun i _ -> List . hd ( El . Input . files i ) ) let files_selector = _file_selector ~ multiple : true ( fun i _ -> El . Input . files i ) end module Jstr_editor = struct let text_str = Jstr . v " text " type t = { el : El . t ; enabled : bool signal ; editing : bool signal ; action : Jstr . t event } let att_size = Jstr . v " size " let v ? class ' : cl ( ? enabled = S . Bool . true ' ) ? on ( : edit = E . never ) ? length str = let span = El . span [ ] in let editor = El . input ~ at : At . [ type ' text_str ] ( ) in let div = let at = At . ( add_if_some Name . class ' cl [ class ' ui_str_editor ] ) in El . div ~ at [ span ; editor ] in let edit = E . select [ E . stamp edit ( ) ; Evr . on_el Ev . click Evr . unit div ] in let edit = S . sample_filter enabled ~ on : edit @@ fun enabled _ -> if enabled then Some ( ) else None in let keys = Evr . on_el Ev . keydown Key . of_ev editor in let escape_key = E . stamp ( E . filter ( Key . equal ` Escape ) keys ) false in let return_key = E . stamp ( E . filter ( Key . equal ` Return ) keys ) true in let start_focus = Evr . on_el Ev . focus ( Evr . stamp true ) editor in let stop_focus = Evr . on_el Ev . blur ( Evr . stamp false ) editor in let focus = S . hold ( El . has_focus editor ) @@ E . select [ start_focus ; stop_focus ] in let valid = S . hold true @@ E . select [ start_focus ; escape_key ] in let start = E . stamp edit true in let key_stop = E . stamp ( E . select [ escape_key ; return_key ] ) false in let stop = E . stamp ( E . select [ key_stop ; stop_focus ] ) false in let editing = S . hold false ( E . select [ start ; stop ] ) in let action = S . sample_filter valid ~ on : stop_focus @@ fun valid _ -> if valid then Some ( El . prop El . Prop . value editor ) else None in let ( ) = Elr . def_children span ( S . map ( fun s -> [ El . txt s ] ) str ) and ( ) = Elr . call ( fun _ e -> El . select_text e ) ~ on : start editor and ( ) = Elr . set_prop El . Prop . value ~ on ( : S . snapshot str ~ on : edit ) editor and ( ) = Elr . def_has_focus focus editor and ( ) = Elr . def_at At . Name . disabled ( disabled ~ enabled ) editor and ( ) = Elr . def_class ui_disabled ( S . Bool . not enabled ) div and ( ) = Elr . def_class ui_editing editing div and ( ) = match length with | None -> ( ) | Some l -> let size = S . map ( fun l -> Some ( Jstr . of_int l ) ) l in Elr . def_at att_size size editor in { el = div ; enabled ; editing ; action } let action e = e . action let enabled e = e . enabled let editing e = e . editing let el e = e . el end module Value_selector = struct module Menu = struct type ' a t = { el : El . t ; enabled : bool signal ; action : ' a event } let v ? class ' : cl ( ? enabled = S . Bool . true ' ) label choices sel = let select = let at = At . [ class ' ui_menu_selector ; class ' ui_button ] in let at = At . ( add_if_some Name . class ' cl at ) in El . select ~ at [ ] in let sel_idx_change = let extract_value e _ = Jstr . to_int @@ El . prop El . Prop . value e in E . Option . on_some @@ Evr . ( on_el Ev . change ( extract_value select ) select ) in let sel_index = let find_sel_index eq selected choices = let rec loop i selected = function | c :: _ when eq c selected -> Jstr . of_int i | _ :: cs -> loop ( i + 1 ) selected cs | [ ] -> Jstr . empty in loop 0 selected choices in S . l2 ( find_sel_index ( S . eq sel ) ) sel choices in let action = S . sample choices ~ on : sel_idx_change List . nth in let opt i v = El . option ~ at : At . [ value ( Jstr . of_int i ) ] [ El . txt ( label v ) ] in let opts = S . map ( List . mapi opt ) choices in let set_children opts sel_index = El . set_children select opts ; El . set_prop El . Prop . value sel_index select in let set_children = Logr . ( const set_children $ S . obs opts $ S . obs sel_index ) in let ( ) = Elr . hold_logr select ( Logr . create set_children ) and ( ) = Elr . def_at At . Name . disabled ( disabled ~ enabled ) select and ( ) = Elr . def_class ui_disabled ( S . Bool . not enabled ) select and ( ) = Elr . def_prop El . Prop . value sel_index select in { el = select ; enabled ; action } let action e = e . action let enabled e = e . enabled let el e = e . el end module Button = struct type ' a t = ' a Group . t let v ? class ' ( ? enabled = S . Bool . true ' ) ? button_class ? button_tip ? xdir_align ? dir_align ~ dir label choices sel = let but v = let class ' = match button_class with | Some f -> Some ( f v ) | None -> None in let tip = match button_tip with Some f -> Some ( f v ) | None -> None in let label = label v in Button . v ? class ' ? tip ~ enabled label v in let buts = S . map ~ eq ( : == ) ( List . map but ) choices in let els = S . map ~ eq ( : == ) ( List . map Button . el ) buts in let action = let select buts = E . select ( List . map Button . action buts ) in E . swap @@ S . map ~ eq ( : == ) select buts in let sel_obs = let find_sel_but eq sel choices buts = match sel with | None -> let deselect b = El . set_class ui_selected false ( Button . el b ) in List . iter deselect buts | Some sel -> let rec loop sel choices buts = match choices , buts with | c :: cs , b :: bs when eq ( Some c ) ( Some sel ) -> El . set_class ui_selected true ( Button . el b ) ; loop sel cs bs | _ :: cs , b :: bs -> El . set_class ui_selected false ( Button . el b ) ; loop sel cs bs | [ ] , [ ] -> ( ) | _ , _ -> assert false in loop sel choices buts in Logr . ( const ( find_sel_but ( S . eq sel ) ) $ S . obs sel $ S . obs choices $ S . obs buts ) in let g = Group . v ? class ' ~ action ? xdir_align ? dir_align ~ dir els in let ( ) = El . set_class ui_button_selector true ( Group . el g ) in let ( ) = Elr . hold_logr ( Group . el g ) ( Logr . create sel_obs ) in g end end module Float_selector = struct type t = { el : El . t ; enabled : bool signal ; action : float event ; } let range_str = Jstr . v " range " let min_str = Jstr . v " min " let max_str = Jstr . v " max " let step_str = Jstr . v " step " let v ? class ' ( ? enabled = S . Bool . true ' ) ( ? min = S . const 0 . ) ( ? max = S . const 1 . ) ( ? step = S . const None ) v = let v = S . map ( fun v -> Jstr . of_float v ) v in let at = At . [ type ' range_str ; class ' ui_slider_selector ; tabindex ( - 1 ) ] in let el = El . input ~ at ( ) in let extract_value e _ = match El . prop El . Prop . value e with | s when Jstr . is_empty s -> None | s -> Some ( float_of_string ( Jstr . to_string s ) ) in let action = E . Option . on_some @@ Evr . on_el Ev . input ( extract_value el ) el in let min_att = S . map ( fun v -> Some ( Jstr . of_float v ) ) min in let max_att = S . map ( fun v -> Some ( Jstr . of_float v ) ) max in let step_att = step |> S . map @@ function | None -> Some ( Jstr . v " any " ) | Some f -> Some ( Jstr . v @@ string_of_float f ) in let ( ) = Elr . def_at min_str min_att el and ( ) = Elr . def_at max_str max_att el and ( ) = Elr . def_at step_str step_att el and ( ) = Elr . def_at At . Name . disabled ( disabled ~ enabled ) el and ( ) = Elr . def_class ui_disabled ( S . Bool . not enabled ) el and ( ) = Elr . def_prop El . Prop . value v el and ( ) = let unset_focus _ = El . set_has_focus false el in Ev . listen Ev . focus unset_focus ( El . as_target el ) in { el ; action ; enabled } let action r = r . action let enabled r = r . enabled let el r = r . el end end
let json = Jv . get Jv . global " JSON " = " caml_int64_create_lo_mi_hi "