text
stringlengths
0
601k
let fundecl f = ( new scheduler ) # schedule_fundecl f
type action = | Atom of zaction | Fork of zaction * zaction | Yield of zaction | Suspend | Resume of zaction * zaction | Stop
type ' a t = ( ' a -> action ) -> action
type ' a cont = ' a -> action
let ( ) >>= f k = fun c -> f ( fun a -> k a c )
let ( ) >> a b = a >>= ( fun _ -> b )
let return x = fun c -> c x
let atom f = fun c -> Atom ( fun ( ) -> ( let b = f ( ) in c b ) )
let action f = f ( fun ( ) -> Stop )
let fork f = fun c -> Fork ( ( fun ( ) -> action f ) , c )
let stop = fun c -> Stop
let yield = fun c -> Yield c
let suspend f = fun c -> match f c with | None -> Suspend | Some ( v , None ) -> c v | Some ( v , Some l ) -> Resume ( ( fun ( ) -> c v ) , l )
let prepare k v = fun ( ) -> k v
let rec round = function | [ ] -> ( ) | ( x :: xs ) -> match x with | Atom th -> let y = th ( ) in round ( xs @ [ y ] ) | Fork ( a1 , a2 ) -> round ( a1 ( ) :: a2 ( ) :: xs ) | Yield a -> round ( xs @ [ a ( ) ] ) | Suspend -> round xs | Resume ( a1 , a2 ) -> round ( a1 ( ) :: a2 ( ) :: xs ) | Stop -> round xs
let run m = round [ action m ]
let rec iter_p f l = match l with | [ ] -> return ( ) | x :: l -> let tx = f x and tl = iter_p f l in tx >>= fun ( ) -> tl
let map f m = ( ) >>= m ( fun x -> return ( f x ) )
let ( ) >|= t f = map f t
let rec map_p f l = match l with | [ ] -> return [ ] | x :: l -> let tx = f x and tl = map_p f l in tx >>= fun x -> tl >|= fun l -> x :: l
module type S = sig type queue_id = int type thread_id = int type ' a cont val suspend : ( ' a cont -> ' a option ) -> ' a val resume : ' a cont -> ' a -> unit val fork : ( unit -> unit ) -> unit val fork_on : ( unit -> unit ) -> queue_id -> unit val yield : unit -> unit val get_qid : unit -> queue_id val get_tid : uni...
module Make ( S : sig val num_domains : int val is_affine : bool end ) : S = struct type queue_id = int type thread_id = int type ' a cont = ( ' a , unit ) continuation * queue_id effect Suspend : ( ' a cont -> ' a option ) -> ' a effect Resume : ( ' a cont * ' a ) -> unit effect Fork : ( unit -> unit ) -> unit effect ...
let bool_of_string = function | " true " -> true | " false " -> false | x -> Fmt . failwith { | Expected " true " or " false " , but got % S } | x
let int_of_string x v = match int_of_string_opt v with | Some i -> i | None -> Fmt . failwith " Not an integer % S at % a " v Xml . pp x
let int32_of_string x v = match Int32 . of_string_opt v with | Some i -> i | None -> Fmt . failwith " Not an int32 % S at % a " v Xml . pp x
module Description = struct type t = { summary : string ; full : string ; } let parse x = { summary = Xml . take_attr " summary " x ; full = Xml . take_data x ; } end
module Entry = struct type t = { name : string ; value : int32 ; summary : string option ; since : int ; description : Description . t option ; } let parse x = { name = Xml . take_attr " name " x ; value = Xml . take_attr " value " x |> int32_of_string x ; summary = Xml . take_attr_opt " summary " x ; since = Xml . tak...
module Enum = struct type t = { name : string ; since : int ; bitfield : bool ; description : Description . t option ; entries : Entry . t list ; } let parse x = { name = Xml . take_attr " name " x ; since = Xml . take_attr_opt " since " x |> Option . value ~ default " : 1 " |> int_of_string x ; bitfield = Xml . take_a...
module Arg = struct type ty = [ ` Object of string option | ` New_ID of string option | ` Uint | ` Int | ` String | ` Fixed | ` FD | ` Array ] type t = { name : string ; ty : ty ; summary : string option ; allow_null : bool ; enum : string option ; description : Description . t option ; } let parse_type x = function | ...
module Message = struct type t = { name : string ; description : Description . t option ; ty : [ ` Normal | ` Destructor ] ; since : int ; args : Arg . t list ; } let parse_type x = function | Some " destructor " -> ` Destructor | None -> ` Normal | Some v -> Fmt . failwith " Unknown message type % S at % a " v Xml . p...
module Interface = struct type t = { name : string ; version : int ; description : Description . t option ; requests : Message . t list ; events : Message . t list ; enums : Enum . t list ; } let parse x = { name = Xml . take_attr " name " x ; version = Xml . take_attr " version " x |> int_of_string x ; description = X...
module Protocol = struct type t = { name : string ; copyright : string option ; description : Description . t option ; interfaces : Interface . t list ; } let parse x = { name = Xml . take_attr " name " x ; copyright = Xml . take_sole_opt " copyright " x Xml . take_data ; description = Xml . take_sole_opt " description...
let rec print_type_ref ( type_ref : type_ref ) = match type_ref with | Schema . Named n -> n | List t -> " [ " ^ print_type_ref t ^ " ] " | NonNull t -> print_type_ref t ^ " " !
let print_field ( { fm_name ; fm_field_type } : field_meta ) = fm_name ^ " : " ^ ( fm_field_type |> print_type_ref )
let print_input_field ( { am_name ; am_arg_type } : argument_meta ) = am_name ^ " : " ^ ( am_arg_type |> print_type_ref )
let print_object ( { om_fields ; om_name } : object_meta ) = ( om_fields |> List . fold_left ( fun p ( { fm_name } as field : Schema . field_meta ) -> match fm_name <> " __typename " with | true -> p ^ " \ n " ^ print_field field | false -> p ) ( om_name ^ " { " ) ) ^ " \ n } "
let print_input_object ( { iom_input_fields ; iom_name } : input_object_meta ) = ( iom_input_fields |> List . fold_left ( fun p ( input_field : Schema . argument_meta ) -> p ^ " \ n " ^ print_input_field input_field ) ( iom_name ^ " { " ) ) ^ " \ n } "
let print_enum ( { em_name ; em_values } : enum_meta ) = em_name ^ " { \ n " ^ ( em_values |> List . fold_left ( fun p { evm_name ; evm_deprecation_reason } -> p ^ " " ^ evm_name ^ ( match evm_deprecation_reason with | None -> " " | Some _ -> " ( DEPRECATED ) " ) ^ " \ n " ) " " ) ^ " } "
let print_scalar ( { sm_name } : scalar_meta ) = sm_name
let print_type ( name : string ) ( schema : t ) = Schema . lookup_type schema name |> Option . flat_map ( function | Object obj_meta -> Some ( print_object obj_meta ) | Scalar scalar_meta -> Some ( print_scalar scalar_meta ) | InputObject input_obj_meta -> Some ( print_input_object input_obj_meta ) | Enum enum_meta -> ...
let rec print_type_from_ref ( type_ref : type_ref ) ( schema : t ) = match type_ref with | Schema . Named n -> print_type n schema |> Option . get_or_else " N / A " | List t -> " [ " ^ print_type_from_ref t schema ^ " ] " | NonNull t -> print_type_from_ref t schema ^ " " !
let test_query = Test_common . test_query Test_schema . schema ( )
let suite = [ ( " query " , ` Quick , fun ( ) -> let query = " { users { id } } " in test_query query ( ` Assoc [ ( " data " , ` Assoc [ ( " users " , ` List [ ` Assoc [ ( " id " , ` Int 1 ) ] ; ` Assoc [ ( " id " , ` Int 2 ) ] ; ] ) ; ] ) ; ] ) ) ; ( " mutation " , ` Quick , fun ( ) -> let query = " mutation { add_use...
type lisp_object = Fixnum of int | Character of char | String of string | EmptyList | Pair of mutable_pair | Symbol of string | PrimitiveProc of ( lisp_object -> lisp_object ) | CompoundProc of lisp_object * lisp_object * environment | Boolean of bool EmptyEnvironment | Environment of ( lisp_object , lisp_object ) Hash...
let car = function Pair pair -> pair . car | _ -> invalid_arg " Argument is not a Pair " ; ;
let cdr = function Pair pair -> pair . cdr | _ -> invalid_arg " Argument is not a Pair " ; ;
let cadr exp = car ( cdr exp ) ; ;
let cddr exp = cdr ( cdr exp ) ; ;
let caddr exp = car ( cddr exp ) ; ;
let cdddr exp = cdr ( cddr exp ) ; ;
let cadddr exp = car ( cdddr exp ) ; ;
let make_pair a b = Pair { car = a ; cdr = b } ; ;
let symbol_table = Hashtbl . create 20 ; ;
let make_symbol name = try Hashtbl . find symbol_table name with Not_found -> let symbol = Symbol name in begin Hashtbl . add symbol_table name symbol ; symbol end ; ;
let extend_environment vars vals env = let rec frame = Hashtbl . create 5 and aux vars vals = match vars , vals with | EmptyList , EmptyList -> ( ) | Pair vars , Pair vals -> begin Hashtbl . add frame vars . car vals . car ; aux vars . cdr vals . cdr end | _ -> invalid_arg " The arguments must be of type EmptyList or P...
let setup_environment ( ) = extend_environment EmptyList EmptyList EmptyEnvironment ; ;
let add_binding_to_frame var value frame = Hashtbl . add frame var value ; ;
let rec lookup_variable_value var = function EmptyEnvironment -> failwith " Unbound variable " | Environment ( frame , env ) -> try Hashtbl . find frame var with Not_found -> lookup_variable_value var env ; ;
let rec set_variable_value var value = function EmptyEnvironment -> failwith " Unbound variable " | Environment ( frame , env ) -> try ignore ( Hashtbl . find frame var ) ; Hashtbl . add frame var value with Not_found -> set_variable_value var value env ; ;
let input_buffers = Hashtbl . create 11 ; ;
let find_or_create_stack input = try Hashtbl . find input_buffers input with Not_found -> let stack = Stack . create ( ) in begin Hashtbl . add input_buffers input stack ; stack end ; ;
let getc in_channel = let stack = find_or_create_stack in_channel in if Stack . is_empty stack then input_char in_channel else Stack . pop stack ; ;
let ungetc c in_channel = let stack = find_or_create_stack in_channel in Stack . push c stack ; ;
let peek input_channel = let c = getc input_channel in ( ungetc c input_channel ; c ) ; ;
let isspace = function ' ' | ' \ n ' | ' \ r ' | ' \ t ' -> true | _ -> false ; ;
let isdigit = function ' 0 ' . . ' 9 ' -> true | _ -> false ; ;
let rec eat_comment input_channel = match ( getc input_channel ) with | ' \ n ' -> ( ) | _ -> eat_comment input_channel ; ;
let rec eat_whitespace input_channel = try match ( getc input_channel ) with | ' ; ' -> begin eat_comment input_channel ; eat_whitespace input_channel end | c when isspace c -> eat_whitespace input_channel | c -> ungetc c input_channel with End_of_file -> ( ) ; ;
let is_delimiter c = isspace c || c = ' ( ' || c = ' ) ' || c = ' " ' || c = ' ; ' ; ;
let error_char dir c = begin Printf . fprintf stderr dir c ; flush stdout ; raise Exit end ; ;
let eat_expected_string in_channel str = let aux c = if c != ( getc in_channel ) then error_char " Unexpcted character ' % c ' \ n " c in String . iter aux str ; ;
let peek_expected_delimiter in_channel = let c = peek in_channel in if not ( is_delimiter c ) then failwith " Character not followed by delimiter " ; ;
let read_character in_channel = try let aux next rest result alt = if next = ( peek in_channel ) then begin eat_expected_string in_channel rest ; peek_expected_delimiter in_channel ; Character result end else begin peek_expected_delimiter in_channel ; Character alt end in match ( getc in_channel ) with | ' s ' -> aux '...
let read_string in_channel = let rec buf = Buffer . create 80 and aux ( ) = match ( getc in_channel ) with | ' " ' -> String ( Buffer . contents buf ) | ' ' \\ -> begin match ( getc in_channel ) with | ' n ' -> ( Buffer . add_char buf ' \ n ' ; aux ( ) ) | c -> ( Buffer . add_char buf c ; aux ( ) ) end | c -> ( Buffer ...
let read_fixnum in_channel c = let sign = if c = ' ' - then - 1 else ( ungetc c in_channel ; 1 ) and num = ref 0 in try let c = ref ( getc in_channel ) in begin while isdigit ! c do num := ! num * 10 + ( Char . code ! c ) - ( Char . code ' 0 ' ) ; c := getc in_channel done ; num := ! num * sign ; if is_delimiter ! c th...
let is_initial = function ' a ' . . ' z ' | ' A ' . . ' Z ' | ' ' * | ' ' / | ' ' > | ' ' < | ' ' = | ' ' ? | ' ' ! -> true | _ -> false ; ;
let read_symbol in_channel init = let buf = Buffer . create 10 in let c = ref init in begin while is_initial ! c || isdigit ! c || ! c = ' ' + || ! c = ' ' - do Buffer . add_char buf ! c ; c := getc in_channel done ; if is_delimiter ! c then ( ungetc ! c in_channel ; make_symbol ( Buffer . contents buf ) ) else error_c...
let quote_symbol = make_symbol " quote " ; ;
let set_symbol = make_symbol " set " ! ; ;
let define_symbol = make_symbol " define " ; ;
let ok_symbol = make_symbol " ok " ; ;
let if_symbol = make_symbol " if " ; ;
let lambda_symbol = make_symbol " lambda " ; ;
let begin_symbol = make_symbol " begin " ; ;
let cond_symbol = make_symbol " cond " ; ;
let else_symbol = make_symbol " else " ; ;
let let_symbol = make_symbol " let " ; ;
let and_symbol = make_symbol " and " ; ;
let or_symbol = make_symbol " or " ; ;
let the_true = Boolean true ; ;
let the_false = Boolean false ; ;
let rec read_dotted_pair_cdr in_channel = match ( peek in_channel ) with | c when not ( isspace c ) -> failwith " Dot not followed by whitespace " | _ -> begin eat_whitespace in_channel ; let cdr_obj = read in_channel in begin eat_whitespace in_channel ; match ( getc in_channel ) with | ' ) ' -> cdr_obj | _ -> failwith...
let is_self_evaluating = function Pair _ | Symbol _ -> false | _ -> true ; ;
let is_tagged_list exp tag = match exp with | Pair { car ; _ } -> car = tag | _ -> false ; ;
let is_quoted exp = is_tagged_list exp quote_symbol ; ;
let text_of_quotation = cadr ; ;
let is_symbol = function Symbol _ -> true | _ -> false ; ;
let is_variable = is_symbol ; ;
let define_variable var value = function EmptyEnvironment -> invalid_arg " Empty environment " | Environment ( frame , _ ) -> add_binding_to_frame var value frame ; ;
let is_assignment exp = is_tagged_list exp set_symbol ; ;