text stringlengths 12 786k |
|---|
let integer = digits => int_of_string |
let number = digits => num_of_string |
let add = token " " + >> return ( fun x y -> AddExp ( x , y ) ) |
let sub = token " " - >> return ( fun x y -> SubExp ( x , y ) ) |
let mul = token " " * >> return ( fun x y -> MulExp ( x , y ) ) |
let div = token " " / >> return ( fun x y -> DivExp ( x , y ) ) |
let pos = token " " + >> return ( fun x -> PosExp ( x ) ) |
let neg = token " " - >> return ( fun x -> NegExp ( x ) ) |
let rec expr input = ( chainl1 term ( add <|> sub ) ) input |
let func_1 = expr => fun x -> [ | x ] | |
let func_n = kwd " function " >> kwd " of " >> integer >>= fun argc -> token " " : >> comma_list expr >>= fun argv -> let args = Array . of_list argv in if argc + 1 <> Array . length args then mzero else return args |
let func = func_1 <|> func_n |
let decl = ident >>= fun name -> kwd " is " >> func >>= fun func -> token " . " >> return ( Decl ( name , func ) ) |
let pair = expr >>= fun rhs -> kwd " to " >> ident => fun lhs -> ( lhs , rhs ) |
let assign_impl = kwd " assign " >> sep_by1 pair ( kwd " and " ) << token " " ! |
let assign = assign_impl => fun x -> Assign ( x ) |
let loop = kwd " do " >> braces expr >>= fun times -> assign_impl >>= fun body -> return ( Loop ( times , body ) ) |
let queries = sep_by1 call ( kwd " and " ) |
let ask = kwd " what " >> kwd " is " >> queries << token " " ? => fun q -> Ask ( q ) |
let program = many ( decl <|> assign <|> loop <|> ask ) |
let parser = parse program |
let rec evlis env l = List . iter ( function | Decl ( name , func ) -> eval_decl env name func | Assign pairs -> eval_assign env pairs | Loop ( times , body ) -> eval_loop env times body | Ask queries -> eval_ask env queries ) l let value = eval_func env func in Hashtbl . replace env name ... |
let rec run src = match parser src with | None -> raise Syntax_error | Some ast -> let env = make_env ( ) in evlis env ast channel |> LazyStream . of_channel |> run str |> LazyStream . of_string |> run |
let ( ) = run_of_channel stdin |
let hash_seed = let seed = Random . bits ( ) in if seed mod 2 = 0 then seed + 1 else seed |
let hash2 a b = let a = Hashtbl . hash a in let b = Hashtbl . hash b in let r = ( a * hash_seed ) + b in r lxor ( r lsr 17 ) |
module Const_data = struct type t = | Naked_immediate of Targetint_31_63 . t | Tagged_immediate of Targetint_31_63 . t | Naked_float of Numeric_types . Float_by_bit_pattern . t | Naked_int32 of Int32 . t | Naked_int64 of Int64 . t | Naked_nativeint of Targetint_32_64 . t let flags = const_flags i... |
module Variable_data = struct type t = { compilation_unit : Compilation_unit . t ; previous_compilation_units : Compilation_unit . t list ; name : string ; name_stamp : int ; user_visible : bool } let flags = var_flags let [ @ ocamlformat " disable " ] print ppf { compilation_unit ; ... |
module Symbol_data = struct type t = { compilation_unit : Compilation_unit . t ; linkage_name : Linkage_name . t } let flags = symbol_flags let [ @ ocamlformat " disable " ] print ppf { compilation_unit ; linkage_name ; } = Format . fprintf ppf " [ @< hov 1 ( >\ [ @< hov 1... |
module Code_id_data = struct type t = { compilation_unit : Compilation_unit . t ; name : string ; linkage_name : Linkage_name . t } let flags = code_id_flags let [ @ ocamlformat " disable " ] print ppf { compilation_unit ; name ; linkage_name ; } = Format . fprintf ppf " [ @... |
module Const = struct type t = Id . t type exported = Const_data . t module Table = Table_by_int_id . Make ( Const_data ) let grand_table_of_constants = ref ( Table . create ( ) ) let initialise ( ) = grand_table_of_constants := Table . create ( ) let find_data t = Table . find ... |
module Variable = struct type t = Id . t type exported = Variable_data . t module Table = Table_by_int_id . Make ( Variable_data ) let grand_table_of_variables = ref ( Table . create ( ) ) let initialise ( ) = grand_table_of_variables := Table . create ( ) let find_data t = Table .... |
module Symbol = struct type t = Id . t type exported = Symbol_data . t module Table = Table_by_int_id . Make ( Symbol_data ) let grand_table_of_symbols = ref ( Table . create ( ) ) let initialise ( ) = grand_table_of_symbols := Table . create ( ) let find_data t = Table . find !... |
module Name = struct type t = Id . t let var v = v let symbol s = s let [ @ inline always ] pattern_match t ~ var ~ symbol = let flags = Id . flags t in if flags = var_flags then var t else if flags = symbol_flags then symbol t else assert false module T0 = struct let compare = Id . compare let e... |
module Rec_info_expr = Rec_info_expr0 . Make ( Variable ) |
module Coercion = Coercion0 . Make ( Rec_info_expr ) |
module Simple_data = struct type t = { simple : Id . t ; coercion : Coercion . t } let flags = simple_flags let [ @ ocamlformat " disable " ] print ppf { simple = _ ; coercion ; } = Format . fprintf ppf " [ @< hov 1 >\ [ @< hov 1 ( > coercion @ % a ) ] @\ ] " ... |
module Simple = struct type t = Id . t type exported = Simple_data . t module Table = Table_by_int_id . Make ( Simple_data ) let grand_table_of_simples = ref ( Table . create ( ) ) let initialise ( ) = grand_table_of_simples := Table . create ( ) let find_data t = Table . find !... |
module Code_id = struct type t = Id . t type exported = Code_id_data . t module Table = Table_by_int_id . Make ( Code_id_data ) let grand_table_of_code_ids = ref ( Table . create ( ) ) let initialise ( ) = grand_table_of_code_ids := Table . create ( ) let find_data t = Table . fi... |
module Code_id_or_symbol = struct type t = Table_by_int_id . Id . t let create_code_id code_id = code_id let create_symbol symbol = symbol let pattern_match t ~ code_id ~ symbol = let flags = Table_by_int_id . Id . flags t in if flags = Code_id_data . flags then code_id t else if flags = Symbol_data... |
let initialise ( ) = Const . initialise ( ) ; Variable . initialise ( ) ; Symbol . initialise ( ) ; Simple . initialise ( ) ; Code_id . initialise ( ) |
let reset ( ) = initialise ( ) |
let test_signed64 ( type t ) ( ~ create : Int64 . t -> t ) ( module T : Test_lib . T with type t = t ) = Printf . printf " Test % s \ n " %! ( T . name ' ( ) ) ; let values = [ - 1073741823L ; - 2L ; - 1L ; 0L ; 1L ; 2L ; 1073741823L ] in List . ... |
let test_unsigned64 ( type t ) ( ~ create : Int64 . t -> t ) ( module T : Test_lib . T with type t = t ) = Printf . printf " Test % s \ n " %! ( T . name ' ( ) ) ; let values = [ 0L ; 1L ; 2L ; 2147483647L ] in List . iter ~ f ( : fun v -> Test_lib . ... |
let test_signed32 ( type t ) ( ~ create : Int32 . t -> t ) ( module T : Test_lib . T with type t = t ) = Printf . printf " Test % s \ n " %! ( T . name ' ( ) ) ; let values = [ - 1073741823l ; - 2l ; - 1l ; 0l ; 1l ; 2l ; 1073741823l ] in List . ... |
let test_unsigned32 ( type t ) ( ~ create : Int32 . t -> t ) ( module T : Test_lib . T with type t = t ) = Printf . printf " Test % s \ n " %! ( T . name ' ( ) ) ; let values = [ 0l ; 1l ; 2l ; 2147483647l ] in List . iter ~ f ( : fun v -> Test_lib . ... |
let test_signed ( type t ) ( ~ create : int -> t ) ( module T : Test_lib . T with type t = t ) = Printf . printf " Test % s \ n " %! ( T . name ' ( ) ) ; let values = [ - 1073741823 ; - 2 ; - 1 ; 0 ; 1 ; 2 ; 1073741823 ] in List . iter ~ f ( : ... |
let test_unsigned ( type t ) ( ~ create : int -> t ) ( module T : Test_lib . T with type t = t ) = Printf . printf " Test % s \ n " %! ( T . name ' ( ) ) ; let values = [ 0 ; 1 ; 2 ; 2147483647 ; 4294967295 ] in List . iter ~ f ( : fun v -> Test_lib . ... |
type t = | Top | Implication of Variable . Pair . Set . t |
let _print ppf = function | Top -> Format . fprintf ppf " Top " | Implication args -> Format . fprintf ppf " Implication : [ @< hv >% a ] " @ Variable . Pair . Set . print args |
let top relation p = Variable . Pair . Map . add p Top relation |
let implies relation from to_ = match Variable . Pair . Map . find to_ relation with | Top -> relation | Implication set -> Variable . Pair . Map . add to_ ( Implication ( Variable . Pair . Set . add from set ) ) relation | exception Not_found -> Variable . Pair . Map . add to_ ( ... |
let transitive_closure state = let union s1 s2 = match s1 , s2 with | Top , _ | _ , Top -> Top | Implication s1 , Implication s2 -> Implication ( Variable . Pair . Set . union s1 s2 ) in let equal s1 s2 = match s1 , s2 with | Top , Implication _ | Implication _ , Top -> false | T... |
let function_variable_alias ( function_decls : Flambda . function_declarations ) ~ backend = let fun_vars = Variable . Map . keys function_decls . funs in let symbols_to_fun_vars = let module Backend = ( val backend : Backend_intf . S ) in Variable . Set . fold ( fun fun_var symbols_to_fu... |
let analyse_functions ~ backend ~ param_to_param ~ anything_to_param ~ param_to_anywhere ( decls : Flambda . function_declarations ) = let function_variable_alias = function_variable_alias ~ backend decls in let param_indexes_by_fun_vars = Variable . Map . map ( fun ( decl : Flambda . function... |
let invariant_params_in_recursion ( decls : Flambda . function_declarations ) ~ backend = let param_to_param ~ caller ~ caller_arg ~ callee ~ callee_arg relation = implies relation ( caller , caller_arg ) ( callee , callee_arg ) in let anything_to_param ~ callee ~ callee_arg relation = top ... |
let invariant_param_sources decls ~ backend = let param_to_param ~ caller ~ caller_arg ~ callee ~ callee_arg relation = implies relation ( caller , caller_arg ) ( callee , callee_arg ) in let anything_to_param ~ callee : _ ~ callee_arg : _ relation = relation in let param_to_anywhere ~ caller... |
let ( ) = Clflags . all_passes := pass_name :: ! Clflags . all_passes |
let unused_arguments ( decls : Flambda . function_declarations ) ~ backend = let dump = Clflags . dumped_pass pass_name in let param_to_param ~ caller ~ caller_arg ~ callee ~ callee_arg relation = implies relation ( callee , callee_arg ) ( caller , caller_arg ) in let anything_to_param ~ c... |
let debug_io = ref false |
let complete name offset op fd buffer = let open Lwt in let ofs = buffer . Cstruct . off in let len = buffer . Cstruct . len in let buf = buffer . Cstruct . buffer in let rec loop acc fd buf ofs len = op fd buf ofs len >>= fun n -> let len ' = len - n in let acc ' = acc + n in if len ' = 0... |
module Fd = struct open Lwt type fd = { fd : Lwt_unix . file_descr ; filename : string ; lock : Lwt_mutex . t ; } let openfile filename rw = let unix_fd = File . openfile filename rw 0o644 in let fd = Lwt_unix . of_unix_file_descr unix_fd in let lock = Lwt_mutex . create ( ) in return ... |
module IO = struct type ' a t = ' a Lwt . t let ( ) >>= = Lwt . ( ) >>= let return = Lwt . return let fail = Lwt . fail let exists path = return ( try ignore ( Unix . LargeFile . stat path ) ; true with _ -> false ) let y2k = 946684800 . 0 let get_vhd_time time = Int32 ... |
let to_file_descr x = x . Fd . fd |
let slack_io = ref false |
let set_slack_io ( ) = slack_io := true |
let slack_log = ref None |
let set_slack_log f = slack_log := Some ( open_out f ) |
let log msg = begin match ! slack_log with | None -> ( ) | Some oc -> output_string oc msg ; flush oc end |
let close_slack_log ( ) = begin match ! slack_log with | None -> ( ) | Some oc -> close_out oc ; end |
let pretty_json_string s = Yojson . Basic . pretty_to_string ( Yojson . Basic . from_string s ) |
let slack_response msg = let resp = Yojson . Basic . to_string ( ` Assoc [ ( " text " , ` String msg ) ; ( " userinput " , ` Bool false ) ; ( " status " , ` String " active " ) ] ) in begin log ( resp ^ " \ n " ) ; print_endline resp end |
let slack_user_input ( ) = let resp = Yojson . Basic . to_string ( ` Assoc [ ( " text " , ` String " " ) ; ( " userinput " , ` Bool true ) ; ( " status " , ` String " active " ) ] ) in begin log ( resp ^ " \ n " ) ; print_endline resp end |
let slack_done ( ) = let resp = Yojson . Basic . to_string ( ` Assoc [ ( " text " , ` String " " ) ; ( " userinput " , ` Bool false ) ; ( " status " , ` String " done " ) ] ) in begin log ( resp ^ " \ n " ) ; print_endline resp end |
let print_rule_line ( ) = if not ( ! slack_io ) then print_endline " " -------- |
let print_berl_error quoted_string = let error_msg = " Quoted expression ` " ^ quoted_string " ` ^ is not valid BERL " in if not ( ! slack_io ) then print_endline ( " [ WARNING ] " ^ error_msg ) else slack_response error_msg |
let print_rule r = if not ( ! slack_io ) then print_endline ( cnl_print_rule_top r ) else let msg = Printf . sprintf " ` ` ` \ n % s \ n ` ` ` \ n " ( cnl_print_rule_top r ) in slack_response msg |
let print_workspace ws_ids = if not ( ! slack_io ) then begin print_endline " " ; ------------------------- print_endline " Workspaces configuration " ; : print_endline ( pretty_json_string ws_ids ) ; print_endline " " ------------------------- end |
let print_instr nb = if not ( ! slack_io ) then print_endline ( ( string_of_int nb ) ^ " " ) > |
let print_done ( ) = if not ( ! slack_io ) then print_endline " > DONE " else slack_done ( ) |
let print_C msg = if not ( ! slack_io ) then print_endline ( " C : " ^ msg ) else slack_response msg |
let print_output_stdout rule_opt msg = begin match rule_opt with | Some rule -> print_rule_line ( ) ; print_rule rule ; print_rule_line ( ) | None -> ( ) end ; print_C msg |
let get_input_stdin ( ) = if not ( ! slack_io ) then begin print_string " H : " ; flush stdout ; input_line stdin end else begin slack_user_input ( ) ; let text = input_line stdin in log ( " H " : ^ text ^ " \ n " ) ; text end |
let g x = let block = ( 1 , x ) in assert ( is_in_static_data block ) |
let ( ) = ( g [ @ inlined always ] ) 2 |
let block3 = ( Sys . opaque_identity 1 , Sys . opaque_identity 2 ) |
let ( ) = assert ( is_in_static_data block3 ) |
let ( ) = assert ( is_in_static_data ( Sys . opaque_identity 1 , Sys . opaque_identity 2 ) ) |
let h x = let block = ( Sys . opaque_identity 1 , x ) in assert ( is_in_static_data block ) |
let ( ) = ( h [ @ inlined always ] ) ( Sys . opaque_identity 2 ) ) * |
let rec a = 1 :: b |
let ( ) = assert ( is_in_static_data a ) ; assert ( is_in_static_data b ) |
type e = E : ' a -> e |
let rec f1 a = E ( g1 a , l1 ) |
let ( ) = assert ( is_in_static_data f1 ) ; assert ( is_in_static_data g1 ) ; assert ( is_in_static_data l1 ) ; assert ( is_in_static_data l2 ) |
let i ( ) = let rec f1 a = E ( g1 a , l1 ) and g1 a = E ( f1 a , l2 ) and l1 = E ( f1 , l2 ) and l2 = E ( g1 , l1 ) in assert ( is_in_static_data f1 ) ; assert ( is_in_static_data g1 ) ; assert ( is_in_static_data l1 ) ; assert ( is_in_static_data l2 ) |
let ( ) = ( i [ @ inlined never ] ) ( ) |
module type P = module type of Stdlib |
let ( ) = assert ( is_in_static_data ( module Stdlib : P ) ) |
let r = ref 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.