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 l...
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 = ...
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 . UI...
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...
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 { __...
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...
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 valu...
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_suc...
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_...
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_line...
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 ) ) )...
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 ; ent...
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 . s...
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 lis...
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 |...
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 patter...
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