text
stringlengths 12
786k
|
---|
let open_font_index_rw = foreign " TTF_OpenFontIndexRW " ( rw_ops @-> int @-> int @-> int64_as_long @-> returning font_result )
|
let byte_swapped_unicode = foreign " TTF_ByteSwappedUNICODE " ( int @-> returning void )
|
module Style = struct type t = Unsigned . uint32 let i = Unsigned . UInt32 . of_int let ( + ) = Unsigned . UInt32 . logor let test f m = Unsigned . UInt32 . ( compare ( logand f m ) zero <> 0 ) let eq f f ' = Unsigned . UInt32 . ( compare f f ' = 0 ) let normal = i 0 let bold = i 1 let italic = i 2 let underline = i 4 let strikethrough = i 8 end
|
let get_font_style = foreign " TTF_GetFontStyle " ( font @-> returning uint32_t )
|
let set_font_style = foreign " TTF_SetFontStyle " ( font @-> uint32_t @-> returning void )
|
let get_font_outline = foreign " TTF_GetFontOutline " ( font @-> returning int )
|
let set_font_outline = foreign " TTF_SetFontOutline " ( font @-> int @-> returning void )
|
module Hinting = struct type t = Normal | Light | Mono | None let t = let read = function 0 -> Normal | 1 -> Light | 2 -> Mono | 3 -> None | _ -> failwith " Unexpected value " in let write = function Normal -> 0 | Light -> 1 | Mono -> 2 | None -> 3 in view ~ read ~ write int end
|
let get_font_hinting = foreign " TTF_GetFontHinting " ( font @-> returning Hinting . t )
|
let set_font_hinting = foreign " TTF_SetFontHinting " ( font @-> Hinting . t @-> returning void )
|
let font_height = foreign " TTF_FontHeight " ( font @-> returning int )
|
let font_ascent = foreign " TTF_FontAscent " ( font @-> returning int )
|
let font_descent = foreign " TTF_FontDescent " ( font @-> returning int )
|
let font_line_skip = foreign " TTF_FontLineSkip " ( font @-> returning int )
|
let get_font_kerning = foreign " TTF_GetFontKerning " ( font @-> returning bool )
|
let set_font_kerning = foreign " TTF_SetFontKerning " ( font @-> bool @-> returning void )
|
let font_faces = foreign " TTF_FontFaces " ( font @-> returning int64_as_long )
|
let font_face_is_fixed_width = foreign " TTF_FontFaceIsFixedWidth " ( font @-> returning int )
|
let font_face_family_name = foreign " TTF_FontFaceFamilyName " ( font @-> returning string )
|
let font_face_style_name = foreign " TTF_FontFaceStyleName " ( font @-> returning string )
|
let glyph_ucs2 = view ~ read : Unsigned . UInt16 . to_int ~ write : Unsigned . UInt16 . of_int uint16_t
|
let glyph_is_provided = foreign " TTF_GlyphIsProvided " ( font @-> glyph_ucs2 @-> returning bool )
|
module GlyphMetrics = struct type t = { min_x : int ; max_x : int ; min_y : int ; max_y : int ; advance : int } end
|
let glyph_metrics = foreign " TTF_GlyphMetrics " ( font @-> glyph_ucs2 @-> ptr int @-> ptr int @-> ptr int @-> ptr int @-> ptr int @-> returning int )
|
let glyph_metrics f g = let ( min_x , max_x , min_y , max_y , advance ) = ( allocate int 0 , allocate int 0 , allocate int 0 , allocate int 0 , allocate int 0 ) in if 0 = glyph_metrics f g min_x max_x min_y max_y advance then Ok GlyphMetrics . ( { min_x = !@ min_x ; max_x = !@ max_x ; min_y = !@ min_y ; max_y = !@ max_y ; advance = !@ advance } ) else error ( )
|
let size_text = foreign " TTF_SizeText " ( font @-> string @-> ptr int @-> ptr int @-> returning int )
|
let size_text f s = let ( w , h ) = ( allocate int 0 , allocate int 0 ) in if 0 = size_text f s w h then Ok ( !@ w , !@ h ) else error ( )
|
let size_utf8 = foreign " TTF_SizeUTF8 " ( font @-> string @-> ptr int @-> ptr int @-> returning int )
|
let size_utf8 f s = let ( w , h ) = ( allocate int 0 , allocate int 0 ) in if 0 = size_utf8 f s w h then Ok ( !@ w , !@ h ) else error ( )
|
let size_unicode = foreign " TTF_SizeUNICODE " ( font @-> ptr glyph_ucs2 @-> ptr int @-> ptr int @-> returning int )
|
type color = _color structure
|
let color : color typ = structure " SDL_Color "
|
let color_r = field color " r " uint8_t
|
let color_g = field color " g " uint8_t
|
let color_b = field color " b " uint8_t
|
let color_a = field color " a " uint8_t
|
let ( ) = seal color
|
let color = let read v = let ( r , g , b , a ) = Unsigned . UInt8 . ( to_int @@ getf v color_r , to_int @@ getf v color_g , to_int @@ getf v color_b , to_int @@ getf v color_a ) in Sdl . Color . create r g b a in let write v = let c = make color in setf c color_r ( Unsigned . UInt8 . of_int ( Sdl . Color . r v ) ) ; setf c color_g ( Unsigned . UInt8 . of_int ( Sdl . Color . g v ) ) ; setf c color_b ( Unsigned . UInt8 . of_int ( Sdl . Color . b v ) ) ; setf c color_a ( Unsigned . UInt8 . of_int ( Sdl . Color . a v ) ) ; c in view ~ read ~ write color
|
let render_text_solid = foreign " TTF_RenderText_Solid " ( font @-> string @-> color @-> returning surface_result )
|
let render_utf8_solid = foreign " TTF_RenderUTF8_Solid " ( font @-> string @-> color @-> returning surface_result )
|
let render_unicode_solid = foreign " TTF_RenderUNICODE_Solid " ( font @-> ptr glyph_ucs2 @-> color @-> returning surface_result )
|
let render_glyph_solid = foreign " TTF_RenderGlyph_Solid " ( font @-> glyph_ucs2 @-> color @-> returning surface_result )
|
let render_text_shaded = foreign " TTF_RenderText_Shaded " ( font @-> string @-> color @-> color @-> returning surface_result )
|
let render_utf8_shaded = foreign " TTF_RenderUTF8_Shaded " ( font @-> string @-> color @-> color @-> returning surface_result )
|
let render_unicode_shaded = foreign " TTF_RenderUNICODE_Shaded " ( font @-> ptr glyph_ucs2 @-> color @-> color @-> returning surface_result )
|
let render_glyph_shaded = foreign " TTF_RenderGlyph_Shaded " ( font @-> glyph_ucs2 @-> color @-> color @-> returning surface_result )
|
let render_text_blended = foreign " TTF_RenderText_Blended " ( font @-> string @-> color @-> returning surface_result )
|
let render_utf8_blended = foreign " TTF_RenderUTF8_Blended " ( font @-> string @-> color @-> returning surface_result )
|
let render_unicode_blended = foreign " TTF_RenderUNICODE_Blended " ( font @-> ptr glyph_ucs2 @-> color @-> returning surface_result )
|
let render_text_blended_wrapped = foreign " TTF_RenderText_Blended_Wrapped " ( font @-> string @-> color @-> int32_as_uint32_t @-> returning surface_result )
|
let render_utf8_blended_wrapped = foreign " TTF_RenderUTF8_Blended_Wrapped " ( font @-> string @-> color @-> int32_as_uint32_t @-> returning surface_result )
|
let render_unicode_blended_wrapped = foreign " TTF_RenderUNICODE_Blended_Wrapped " ( font @-> ptr glyph_ucs2 @-> color @-> int32_as_uint32_t @-> returning surface_result )
|
let render_glyph_blended = foreign " TTF_RenderGlyph_Blended " ( font @-> glyph_ucs2 @-> color @-> returning surface_result )
|
let close_font = foreign " TTF_CloseFont " ( font @-> returning void )
|
let quit = foreign " TTF_Quit " ( void @-> returning void )
|
let was_init = foreign " TTF_WasInit " ( void @-> returning bool )
|
let get_font_kerning_size = foreign " TTF_GetFontKerningSize " ( font @-> int @-> int @-> returning int ) end
|
let cs = let module M = struct type t = Cstruct . t let pp = Cstruct . hexdump_pp let equal = Cstruct . equal end in ( module M : Alcotest . TESTABLE with type t = M . t )
|
let msg = let module M = struct type t = [ ` Msg of string ] let pp ppf = function ` Msg str -> Fmt . string ppf str let equal _ _ = true end in ( module M : Alcotest . TESTABLE with type t = M . t )
|
let key = match Base64 . decode " GSnQJ + fHuzwj5yKzCOkXdISyGQXBUxMrjEjL4Kr1WIs " = with | Error _ -> assert false | Ok x -> Cstruct . of_string x
|
let key_name = Domain_name . of_string_exn " mykey . bla . example "
|
let tsig ( ? fudge = 300 ) algorithm signed = let fudge = Ptime . Span . of_int_s fudge in let signed = match Ptime . of_float_s signed with | None -> assert false | Some x -> x in match Dns . Tsig . tsig ~ algorithm ~ signed ~ fudge ( ) with | None -> assert false | Some x -> x
|
let example0 ( ) = let buf = of_h { __ | 62 d7 28 00 00 01 00 00 00 02 00 00 07 65 78 61 6d 70 6c 65 03 63 6f 6d 00 00 06 00 01 03 66 6f 6f c0 0c 00 ff 00 ff 00 00 00 00 00 00 03 62 61 72 c0 0c 00 01 00 01 00 00 01 2c 00 04 01 02 03 04 | __ } and now = 1506887417 . and mac = of_h { __ | bf 5d 77 ba 97 ba 7b 95 9e 1b 0d 95 64 a7 5b a6 95 bf 24 15 3b 9d a2 1b bf 6f ae 61 9d 0f 28 a1 | __ } in Alcotest . ( check cs " tsig is the same " mac ( Dns_tsig . compute_tsig key_name ( tsig Dns . Tsig . SHA256 now ) ~ key buf ) )
|
let example1 ( ) = let buf = of_h { __ | 4c 56 28 00 00 01 00 00 00 01 00 00 07 45 78 41 6d 50 6c 45 03 63 6f 6d 00 00 06 00 01 03 66 6f 6f 07 65 78 61 6d 70 6c 65 c0 14 00 ff 00 ff 00 00 00 00 00 00 | __ } and now = 1506887742 . and mac = of_h { __ | 70 67 ae 70 9e fd 22 9e ce d9 65 25 8a db 8c 96 10 95 80 89 a7 ee 4f bb 13 81 e7 38 e3 a0 78 80 | __ } in Alcotest . ( check cs " tsig is the same " mac ( Dns_tsig . compute_tsig key_name ( tsig Dns . Tsig . SHA256 now ) ~ key buf ) )
|
let example2 ( ) = let buf = of_h { __ | 76 8a 28 00 00 01 00 00 00 01 00 00 07 65 78 61 6d 70 6c 65 00 00 06 00 01 03 66 6f 6f c0 0c 00 ff 00 ff 00 00 00 00 00 00 | __ } and now = 1506888104 . and mac = of_h { __ | e7 76 e6 df 4e 73 14 c8 eb ba 4c c7 a5 39 b3 93 a7 df 6d de 47 b6 fa cc 81 c8 47 29 20 77 40 44 | __ } in Alcotest . ( check cs " tsig is the same " mac ( Dns_tsig . compute_tsig key_name ( tsig Dns . Tsig . SHA256 now ) ~ key buf ) )
|
let tsig_tests = [ " example0 " , ` Quick , example0 ; " example1 " , ` Quick , example1 ; " example2 " , ` Quick , example2 ; ]
|
let tests = [ " Tsig example " , tsig_tests ; ]
|
let ( ) = Alcotest . run " DNS name tests " tests
|
let string_of_location loc = let buf = Buffer . create 64 in let fmt = Format . formatter_of_buffer buf in Location . print_loc fmt loc ; Format . pp_print_flush fmt ( ) ; Buffer . contents buf
|
let no_such_variable loc name = let locstr = string_of_location loc in Printf . eprintf " % s \ nNo such variable % s \ n " %! locstr name ; exit 2
|
let no_such_modifiers loc name = let locstr = string_of_location loc in Printf . eprintf " % s \ nNo such modifiers % s \ n " %! locstr name ; exit 2
|
let apply_modifiers env modifiers_name = let name = modifiers_name . node in let modifier = Environments . Include name in try Environments . apply_modifier env modifier with | Environments . Modifiers_name_not_found name -> no_such_modifiers modifiers_name . loc name
|
let rec add_to_env decl loc variable_name value env = match ( Variables . find_variable variable_name , decl ) with | ( None , true ) -> let newvar = Variables . make ( variable_name , " User variable " ) in Variables . register_variable newvar ; add_to_env false loc variable_name value env | ( Some variable , false ) -> Environments . add variable value env | ( None , false ) -> raise ( Variables . No_such_variable variable_name ) | ( Some _ , true ) -> raise ( Variables . Variable_already_registered variable_name )
|
let append_to_env loc variable_name value env = let variable = match Variables . find_variable variable_name with | None -> raise ( Variables . No_such_variable variable_name ) | Some variable -> variable in try Environments . append variable value env with Variables . No_such_variable name -> no_such_variable loc name
|
let interprete_environment_statement env statement = match statement . node with | Assignment ( decl , var , value ) -> add_to_env decl statement . loc var . node value . node env | Append ( var , value ) -> append_to_env statement . loc var . node value . node env | Include modifiers_name -> apply_modifiers env modifiers_name
|
let interprete_environment_statements env l = List . fold_left interprete_environment_statement env l
|
type test_tree = | Node of ( Tsl_ast . environment_statement located list ) * Tests . t * string located list * ( test_tree list )
|
let too_deep testname max_level real_level = Printf . eprintf " Test % s should have depth atmost % d but has depth % d \ n " %! testname max_level real_level ; exit 2
|
let unexpected_environment_statement s = let locstr = string_of_location s . loc in Printf . eprintf " % s \ nUnexpected environment statement \ n " %! locstr ; exit 2
|
let no_such_test_or_action t = let locstr = string_of_location t . loc in Printf . eprintf " % s \ nNo such test or action : % s \ n " %! locstr t . node ; exit 2
|
let test_trees_of_tsl_block tsl_block = let rec env_of_lines = function | [ ] -> ( [ ] , [ ] ) | Environment_statement s :: lines -> let ( env ' , remaining_lines ) = env_of_lines lines in ( s :: env ' , remaining_lines ) | lines -> ( [ ] , lines ) and tree_of_lines depth = function | [ ] -> ( None , [ ] ) | line :: remaining_lines as l -> begin match line with | Environment_statement s -> unexpected_environment_statement s | Test ( test_depth , located_name , env_modifiers ) -> begin let name = located_name . node in if test_depth > depth then too_deep name depth test_depth else if test_depth < depth then ( None , l ) else let ( env , rem ) = env_of_lines remaining_lines in let ( trees , rem ) = trees_of_lines ( depth + 1 ) rem in match Tests . lookup name with | None -> begin match Actions . lookup name with | None -> no_such_test_or_action located_name | Some action -> let test = Tests . test_of_action action in ( Some ( Node ( env , test , env_modifiers , trees ) ) , rem ) end | Some test -> ( Some ( Node ( env , test , env_modifiers , trees ) ) , rem ) end end and trees_of_lines depth lines = let remaining_lines = ref lines in let trees = ref [ ] in let continue = ref true in while ! continue ; do let ( tree , rem ) = tree_of_lines depth ! remaining_lines in remaining_lines := rem ; match tree with | None -> continue := false | Some t -> trees := t :: ! trees done ; ( List . rev ! trees , ! remaining_lines ) in let ( env , rem ) = env_of_lines tsl_block in let ( trees , rem ) = trees_of_lines 1 rem in match rem with | [ ] -> ( env , trees ) | ( Environment_statement s ) :: _ -> unexpected_environment_statement s | _ -> assert false
|
let rec tests_in_tree_aux set = function Node ( _ , test , _ , subtrees ) -> let set ' = List . fold_left tests_in_tree_aux set subtrees in Tests . TestSet . add test set '
|
let tests_in_tree t = tests_in_tree_aux Tests . TestSet . empty t
|
let tests_in_trees subtrees = List . fold_left tests_in_tree_aux Tests . TestSet . empty subtrees
|
let actions_in_test test = let add action_set action = Actions . ActionSet . add action action_set in List . fold_left add Actions . ActionSet . empty test . Tests . test_actions
|
let actions_in_tests tests = let f test action_set = Actions . ActionSet . union ( actions_in_test test ) action_set in Tests . TestSet . fold f tests Actions . ActionSet . empty
|
module T = Transport inherit T . t val mutable chans = None method isOpen = chans != None method opn = try let addr = ( let { Unix . h_addr_list = x } = Unix . gethostbyname host in x . ( 0 ) ) in chans <- Some ( Unix . open_connection ( Unix . ADDR_INET ( addr , port ) ) ) with Unix . Unix_error ( e , fn , _ ) -> raise ( T . E ( T . NOT_OPEN , ( " TSocket : Could not connect to " ^ host " " ( ^:^ string_of_int port ) " ^ because : " ^ fn " " ( ^:^ Unix . error_message e ) ) ) ) | _ -> raise ( T . E ( T . NOT_OPEN , ( " TSocket : Could not connect to " ^ host " " ( ^:^ string_of_int port ) ) ) ) method close = match chans with None -> ( ) | Some ( inc , out ) -> ( Unix . shutdown_connection inc ; close_in inc ; chans <- None ) method read buf off len = match chans with None -> raise ( T . E ( T . NOT_OPEN , " TSocket : Socket not open " ) ) | Some ( i , o ) -> try really_input i buf off len ; len with Unix . Unix_error ( e , fn , _ ) -> raise ( T . E ( T . UNKNOWN , ( " TSocket : Could not read " ( ^ string_of_int len ) " ^ from " ^ host " " ( ^:^ string_of_int port ) " ^ because : " ^ fn " " ( ^:^ Unix . error_message e ) ) ) ) | _ -> raise ( T . E ( T . UNKNOWN , ( " TSocket : Could not read " ( ^ string_of_int len ) " ^ from " ^ host " " ( ^:^ string_of_int port ) ) ) ) method write buf off len = match chans with None -> raise ( T . E ( T . NOT_OPEN , " TSocket : Socket not open " ) ) | Some ( i , o ) -> output o buf off len method write_string buf off len = match chans with None -> raise ( T . E ( T . NOT_OPEN , " TSocket : Socket not open " ) ) | Some ( i , o ) -> output_substring o buf off len method flush = match chans with None -> raise ( T . E ( T . NOT_OPEN , " TSocket : Socket not open " ) ) | Some ( i , o ) -> flush o end
|
type ' a entry = { node : ' a ; mutable pred_count : int ; mutable successors : ' a entry list }
|
type ' a porder = ' a entry list ref
|
let find_entry order node = let rec search_entry = function [ ] -> raise Not_found | x :: l -> if x . node = node then x else search_entry l in try search_entry ! order with Not_found -> let entry = { node = node ; pred_count = 0 ; successors = [ ] } in order := entry ::! order ; entry
|
let create ( ) = ref [ ]
|
let add_relation order ( succ , pred ) = let pred_entry = find_entry order pred and succ_entry = find_entry order succ in succ_entry . pred_count <- succ_entry . pred_count + 1 ; pred_entry . successors <- succ_entry :: pred_entry . successors
|
let add_element order e = ignore ( find_entry order e )
|
let sort order = let q = Queue . create ( ) and result = ref [ ] in List . iter ! order ~ f ( : function { pred_count = n } as node -> if n = 0 then Queue . add node q ) ; begin try while true do let t = Queue . take q in result := t . node :: ! result ; List . iter t . successors ~ f : begin fun s -> let n = s . pred_count - 1 in s . pred_count <- n ; if n = 0 then Queue . add s q end done with Queue . Empty -> List . iter ! order ~ f ( : fun node -> if node . pred_count <> 0 then raise Cyclic ) end ; ! result
|
module Literal = struct type t = | String of string | Int of int | Float of float end
|
module Enum = struct type t = ( string * Literal . t ) list end
|
module type S = sig type ident type field_def = | Single of { optional : bool ; typ : typ } | Pattern of { pat : typ ; typ : typ } and field = field_def Named . t and typ = | Literal of Literal . t | Ident of ident | Sum of typ list | List of typ | Record of field list | Tuple of typ list | App of typ * typ and interface = { extends : ident list ; fields : field list ; params : string list } and decl = | Interface of interface | Type of typ | Enum_anon of Enum . t and t = decl Named . t class map : object method typ : typ -> typ method interface : interface -> interface method field : field -> field method t : t -> t end class [ ' a ] fold : object method field : field -> init ' : a -> ' a method ident : ident -> init ' : a -> ' a method t : t -> init ' : a -> ' a method typ : typ -> init ' : a -> ' a end end
|
module Make ( Ident : sig type t struct type field_def = | Single of { optional : bool ; typ : typ } | Pattern of { pat : typ ; typ : typ } and field = field_def Named . t and typ = | Literal of Literal . t | Ident of Ident . t | Sum of typ list | List of typ | Record of field list | Tuple of typ list | App of typ * typ and interface = { extends : Ident . t list ; fields : field list ; params : string list } and decl = | Interface of interface | Type of typ | Enum_anon of Enum . t and t = decl Named . t class [ ' a ] fold = object ( self ) method t ( t : t ) ~ init = match t . data with | Interface ( i : interface ) -> let init = List . fold_left i . extends ~ init ~ f ( : fun acc e -> self # ident e ~ init : acc ) in List . fold_left ~ init i . fields ~ f ( : fun init f -> self # field f ~ init ) | Type ( t : typ ) -> self # typ t ~ init | Enum_anon _ -> init method ident _ ~ init = init method field ( f : field ) ~ init : ' a = match f . data with | Single { optional = _ ; typ } -> self # typ ~ init typ | Pattern { pat ; typ } -> let init = self # typ ~ init pat in self # typ ~ init typ method typ ( t : typ ) ~ init = match t with | Literal _ -> init | Ident i -> self # ident i ~ init | App ( t1 , t2 ) -> let init = self # typ t1 ~ init in self # typ t2 ~ init | List t -> self # typ t ~ init | Tuple typs | Sum typs -> List . fold_left typs ~ init ~ f ( : fun init f -> self # typ f ~ init ) | Record fs -> List . fold_left fs ~ init ~ f ( : fun init f -> self # field f ~ init ) end class map = object ( self ) method field ( f : field ) = let data = match f . data with | Single s -> let typ = self # typ s . typ in Single { s with typ } | Pattern { pat ; typ } -> let pat = self # typ pat in let typ = self # typ typ in Pattern { pat ; typ } in { f with data } method interface ( i : interface ) = let fields = List . map ~ f : self # field i . fields in { i with fields } method typ ( t : typ ) = match t with | Literal i -> Literal i | Ident i -> Ident i | App ( x , y ) -> let x = self # typ x and y = self # typ y in App ( x , y ) | List t -> List ( self # typ t ) | Tuple ts -> Tuple ( List . map ts ~ f : self # typ ) | Sum ts -> Sum ( List . map ts ~ f : self # typ ) | Record ts -> Record ( List . map ts ~ f : self # field ) method t ( t : t ) = let data = match t . data with | Interface i -> Interface ( self # interface i ) | Type t -> Type ( self # typ t ) | Enum_anon _ -> t . data in { t with data } end end
|
module Unresolved = struct include Make ( String ) let enum ~ name ~ constrs : Enum . t Named . t = { Named . name ; data = constrs } let interface ~ name ~ extends ~ fields ~ params : interface Named . t = { Named . name ; data = { extends ; fields ; params } } let pattern_field ~ name ~ pat ~ typ = { Named . name ; data = Pattern { pat ; typ } } let named_field ( ? optional = false ) typ name = { Named . name ; data = Single { optional ; typ } } end
|
module type Prim_intf = sig type resolved type t = | Null | String | Bool | Number | Any | Object | List | Self | Resolved of resolved val of_string : string -> resolve ( : string -> t ) -> t end
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.