text stringlengths 0 601k |
|---|
let eval_tests = [ (Let ("x", I 1, Primop (Plus, [Var "x"; I 5])), I 6); (Rec("f", Int, I 1 ), I 1); (Apply(eval1, [I 1]), I 1); (Apply(eval2, [I 2; I 1]), I 3); (Apply(eval3, []), I 1); (Apply(eval6, [I 1]), I 0) ] |
let infer_tests = [ (([("x", Int)], Var "x"), Int); (( [("x", Arrow([Int], Int)); ("x", Int)], eval1) , Arrow([Int], Int)); (( [("x", Arrow([Int; Int], Int)); ("x", Int); ("y", Int)], eval2), Arrow([Int; Int], Int)); (( [], eval7), Arrow([], Int)); (( [("x", Arrow([Int], Int)); ("x", Int)], app1), Int); (( [("x", Arrow... |
let rec infer ctx e = match e with | Var x -> begin try lookup x ctx with Not_found -> raise (TypeError (Free_variable x)) end | I _ -> Int | B _ -> Bool | Primop (po, exps) -> let (domain, range) = primopType po in check ctx exps domain range | If (e, e1, e2) -> begin match infer ctx e with | Bool -> let t1 = infer ct... |
let unused_vars_tests = [ (Let ("x", I 1, I 5), ["x"]); (Fn ([("x", Int ); ("y", Int);("b", Int ); ("c", Int)], (Primop (Plus, [I 1; I 2] ))), ["x"; "y"; "b"; "c"]); (Apply(e1, [I 3; I 4]), ["b"; "c"]); ((Rec("f", Int, Primop (Plus, [(Fn ([("x", Int )], (Primop (Minus, [Var "x"; I 1])))); (Apply (Var "f", [ (Primop (Mi... |
let subst_tests : (((exp * name) * exp) * exp) list = [ (((I 1, "x"), Let ("y", I 2, Primop (Plus, [Var "y"; Var "x"]))), Let ("y", I 2, Primop (Plus, [Var "y"; I 1]))); (((I 1, "x"),Rec("facti", Int, Var "x")), (Rec("facti", Int, I 1))); ((( Var "f", "fact"), (Rec ("fact", Int, Primop (Plus, [ (Fn ([("x", Int)] , Prim... |
let eval_tests = [ (Let ("x", I 1, Primop (Plus, [Var "x"; I 5])), I 6); (Rec("f", Int, I 1 ), I 1); (Apply(eval1, [I 1]), I 1); (Apply(eval2, [I 2; I 1]), I 3); (Apply(eval3, []), I 1); (Apply(eval6, [I 1]), I 0) ] |
let infer_tests = [ (([("x", Int)], Var "x"), Int); (( [("x", Arrow([Int], Int)); ("x", Int)], eval1) , Arrow([Int], Int)); (( [("x", Arrow([Int; Int], Int)); ("x", Int); ("y", Int)], eval2), Arrow([Int; Int], Int)); (( [], eval7), Arrow([], Int)); (( [("x", Arrow([Int], Int)); ("x", Int)], app1), Int); (( [("x", Arrow... |
let rec infer ctx e = match e with | Var x -> begin try lookup x ctx with Not_found -> raise (TypeError (Free_variable x)) end | I _ -> Int | B _ -> Bool | Primop (po, exps) -> let (domain, range) = primopType po in check ctx exps domain range | If (e, e1, e2) -> begin match infer ctx e with | Bool -> let t1 = infer ct... |
let rec unused_vars = function | Var _ | I _ | B _ -> [] | If (e, e1, e2) -> unused_vars e @ unused_vars e1 @ unused_vars e2 | Primop (_, args) -> List.fold_left (fun acc exp -> acc @ unused_vars exp) [] args | Let (x, e1, e2) -> let unused = unused_vars e1 @ unused_vars e2 in if List.mem x (free_variables e2) then unu... |
let rec subst ((e', x) as s) exp = match exp with | Var y -> if x = y then e' else Var y | I n -> I n | B b -> B b | Primop (po, args) -> Primop (po, List.map (subst s) args) | If (e, e1, e2) -> If (subst s e, subst s e1, subst s e2) | Let (y, e1, e2) -> let e1' = subst s e1 in if y = x then Let (y, e1', e2) else let (... |
let rec eval exp = match exp with | I _ -> exp | B _ -> exp | Fn _ -> exp | Var x -> raise (Stuck (Free_variable x)) | Primop (po, args) -> let args = List.map eval args in begin match eval_op po args with | None -> raise (Stuck Bad_primop_args) | Some v -> v end | If (e, e1, e2) -> begin match eval e with | B true -> ... |
let rec infer ctx e = match e with | Var x -> begin try lookup x ctx with Not_found -> raise (TypeError (Free_variable x)) end | I _ -> Int | B _ -> Bool | Primop (po, exps) -> let (domain, range) = primopType po in check ctx exps domain range | If (e, e1, e2) -> begin match infer ctx e with | Bool -> let t1 = infer ct... |
let unify : utp -> utp -> utp UTVarMap.t = let rec unify (substitution : utp UTVarMap.t) (t1 : utp) (t2 : utp) : utp UTVarMap.t = match t1, t2 with | UInt, UInt -> substitution | UBool, UBool -> substitution | UTVar a, UTVar a' when a = a' -> substitution | UArrow (t1, t1'), UArrow (t2, t2') -> let typeMatch1 = unify s... |
let rec unused_vars = function | Var _ | I _ | B _ -> [] | If (e, e1, e2) -> unused_vars e @ unused_vars e1 @ unused_vars e2 | Primop (_, args) -> List.fold_left (fun acc exp -> acc @ unused_vars exp) [] args | Let (x, e1, e2) -> let unused = unused_vars e1 @ unused_vars e2 in if List.mem x (free_variables e2) then unu... |
let rec subst ((e', x) as s) exp = match exp with | Var y -> if x = y then e' else Var y | I n -> I n | B b -> B b | Primop (po, args) -> Primop (po, List.map (subst s) args) | If (e, e1, e2) -> If (subst s e, subst s e1, subst s e2) | Let (y, e1, e2) -> let e1' = subst s e1 in if y = x then Let (y, e1', e2) else let (... |
let rec eval exp = match exp with | I _ -> exp | B _ -> exp | Fn _ -> exp | Var x -> raise (Stuck (Free_variable x)) | Primop (po, args) -> let args = List.map eval args in begin match eval_op po args with | None -> raise (Stuck Bad_primop_args) | Some v -> v end | If (e, e1, e2) -> begin match eval e with | B true -> ... |
let rec infer ctx e = match e with | Var x -> begin try lookup x ctx with Not_found -> raise (TypeError (Free_variable x)) end | I _ -> Int | B _ -> Bool | Primop (po, exps) -> let (domain, range) = primopType po in check ctx exps domain range | If (e, e1, e2) -> begin match infer ctx e with | Bool -> let t1 = infer ct... |
let unify : utp -> utp -> utp UTVarMap.t = let rec unify (substitution : utp UTVarMap.t) (t1 : utp) (t2 : utp) : utp UTVarMap.t = match t1, t2 with | UInt, UInt | UBool, UBool -> substitution | UTVar a, UTVar a' when a = a' -> substitution | UArrow (t1, t1'), UArrow (t2, t2') -> raise NotImplemented | UTVar a, _ -> uni... |
let rec unused_vars = function | Var _ | I _ | B _ -> [] | If (e, e1, e2) -> unused_vars e @ unused_vars e1 @ unused_vars e2 | Primop (_, args) -> List.fold_left (fun acc exp -> acc @ unused_vars exp) [] args | Let (x, e1, e2) -> let unused = unused_vars e1 @ unused_vars e2 in if List.mem x (free_variables e2) then unu... |
let rec subst ((e', x) as s) exp = match exp with | Var y -> if x = y then e' else Var y | I n -> I n | B b -> B b | Primop (po, args) -> Primop (po, List.map (subst s) args) | If (e, e1, e2) -> If (subst s e, subst s e1, subst s e2) | Let (y, e1, e2) -> let e1' = subst s e1 in if y = x then Let (y, e1', e2) else let (... |
let rec eval exp = match exp with | I _ -> exp | B _ -> exp | Fn _ -> exp | Var x -> raise (Stuck (Free_variable x)) | Primop (po, args) -> let args = List.map eval args in begin match eval_op po args with | None -> raise (Stuck Bad_primop_args) | Some v -> v end | If (e, e1, e2) -> begin match eval e with | B true -> ... |
let rec infer ctx e = match e with | Var x -> begin try lookup x ctx with Not_found -> raise (TypeError (Free_variable x)) end | I _ -> Int | B _ -> Bool | Primop (po, exps) -> let (domain, range) = primopType po in check ctx exps domain range | If (e, e1, e2) -> begin match infer ctx e with | Bool -> let t1 = infer ct... |
let unify : utp -> utp -> utp UTVarMap.t = let rec unify (substitution : utp UTVarMap.t) (t1 : utp) (t2 : utp) : utp UTVarMap.t = match t1, t2 with | UInt, UInt | UBool, UBool -> substitution | UTVar a, UTVar a' when a = a' -> substitution | UArrow (t1, t1'), UArrow (t2, t2') -> raise NotImplemented | UTVar a, _ -> uni... |
let rec unused_vars = function | Var _ | I _ | B _ -> [] | If (e, e1, e2) -> unused_vars e @ unused_vars e1 @ unused_vars e2 | Primop (_, args) -> List.fold_left (fun acc exp -> acc @ unused_vars exp) [] args | Let (x, e1, e2) -> let unused = unused_vars e1 @ unused_vars e2 in if List.mem x (free_variables e2) then unu... |
let rec subst ((e', x) as s) exp = match exp with | Var y -> if x = y then e' else Var y | I n -> I n | B b -> B b | Primop (po, args) -> Primop (po, List.map (subst s) args) | If (e, e1, e2) -> If (subst s e, subst s e1, subst s e2) | Let (y, e1, e2) -> let e1' = subst s e1 in if y = x then Let (y, e1', e2) else let (... |
let rec eval exp = match exp with | I _ -> exp | B _ -> exp | Fn _ -> exp | Var x -> raise (Stuck (Free_variable x)) | Primop (po, args) -> let args = List.map eval args in begin match eval_op po args with | None -> raise (Stuck Bad_primop_args) | Some v -> v end | If (e, e1, e2) -> begin match eval e with | B true -> ... |
let rec infer ctx e = match e with | Var x -> begin try lookup x ctx with Not_found -> raise (TypeError (Free_variable x)) end | I _ -> Int | B _ -> Bool | Primop (po, exps) -> let (domain, range) = primopType po in check ctx exps domain range | If (e, e1, e2) -> begin match infer ctx e with | Bool -> let t1 = infer ct... |
let unify : utp -> utp -> utp UTVarMap.t = let rec unify (substitution : utp UTVarMap.t) (t1 : utp) (t2 : utp) : utp UTVarMap.t = match t1, t2 with | UInt, UInt | UBool, UBool -> substitution | UTVar a, UTVar a' when a = a' -> substitution | UArrow (t1, t1'), UArrow (t2, t2') -> raise NotImplemented | UTVar a, _ -> uni... |
module Key = struct type t = { tag : Dwarf_tag . t ; has_children : Child_determination . t ; attribute_specs : Dwarf_attributes . Attribute_specification . Sealed . Set . t } include Identifiable . Make ( struct type nonrec t = t let compare { tag = tag1 ; has_children = has_children1 ; attribute_specs = attribute_spe... |
type t = Abbreviations_table_entry . t Key . Map . t |
let create ( ) = Key . Map . empty |
let add t entry = let tag = Abbreviations_table_entry . tag entry in let has_children = Abbreviations_table_entry . has_children entry in let attribute_specs = Abbreviations_table_entry . attribute_specs entry in let key : Key . t = { tag ; has_children ; attribute_specs } in Key . Map . add key entry t |
let find t ~ tag ~ has_children ~ attribute_specs = let key : Key . t = { tag ; has_children ; attribute_specs } in match Key . Map . find key t with | exception Not_found -> None | entry -> Some ( Abbreviations_table_entry . abbreviation_code entry ) |
let size t = let ( + ) = Dwarf_int . add in Dwarf_value . size ( Dwarf_value . uleb128 Uint64 . zero ) + Key . Map . fold ( fun _key entry size -> size + Abbreviations_table_entry . size entry ) t ( Dwarf_int . zero ( ) ) |
let emit ~ asm_directives t = let module Asm_directives = ( val asm_directives : Asm_directives . S ) in Key . Map . iter ( fun _key entry -> Asm_directives . new_line ( ) ; Abbreviations_table_entry . emit ~ asm_directives entry ) t ; Dwarf_value . emit ~ asm_directives ( Dwarf_value . uleb128 ~ comment " : End of abb... |
type t = { abbreviation_code : Abbreviation_code . t ; tag : Dwarf_tag . t ; has_children : Child_determination . t ; attribute_specs : Dwarf_attributes . Attribute_specification . Sealed . Set . t } |
let create ~ abbreviation_code ~ tag ~ has_children ~ attribute_specs = { abbreviation_code ; tag ; has_children ; attribute_specs } |
let size t = let ( + ) = Dwarf_int . add in Abbreviation_code . size t . abbreviation_code + Dwarf_tag . size t . tag + Child_determination . size t . has_children + AS . Set . fold ( fun attr_spec size -> Dwarf_int . add size ( AS . size attr_spec ) ) t . attribute_specs ( Dwarf_int . zero ( ) ) + Dwarf_value . size (... |
let emit ~ asm_directives t = Abbreviation_code . emit ~ asm_directives t . abbreviation_code ; Dwarf_tag . emit ~ asm_directives t . tag ; Child_determination . emit ~ asm_directives t . has_children ; AS . Set . iter ( fun spec -> AS . emit ~ asm_directives spec ) t . attribute_specs ; Dwarf_value . emit ~ asm_direct... |
let tag t = t . tag |
let has_children t = t . has_children |
let attribute_specs t = t . attribute_specs |
let abbreviation_code t = t . abbreviation_code |
let rec ack ( x , y ) = if x = 0 then y + 1 else if y = 0 then ack ( x - 1 , 1 ) else ack ( x - 1 , ack ( x , y - 1 ) ) |
let rec ack_cps ( x , y , cnt ) = if x = 0 then cnt ( y + 1 ) else if y = 0 then ack_cps ( x - 1 , 1 , cnt ) else ack_cps ( x , y - 1 , fun a -> ack_cps ( x - 1 , a , cnt ) ) |
let ack_2 ( x , y ) = ack_cps ( x , y , fun x -> x ) |
let rec ack_cps_dfc ( x , y , cnt ) = if x = 0 then apply_cnt ( cnt , y + 1 ) else if y = 0 then ack_cps_dfc ( x - 1 , 1 , cnt ) else ack_cps_dfc ( x , y - 1 , x :: cnt ) | ( [ ] , x ) -> x | ( x :: cnt , a ) -> ack_cps_dfc ( x - 1 , a , cnt ) |
let ack_3 ( x , y ) = ack_cps_dfc ( x , y , [ ] ) |
type state = ACK of int * int * ( int list ) | APP of ( int list ) * int |
let rec string_of_int_list_aux = function | [ ] -> " " | [ t ] -> ( string_of_int t ) | t :: rest -> ( string_of_int t ) ^ " , " ^ ( string_of_int_list_aux rest ) |
let string_of_int_list l = " [ " ^ ( string_of_int_list_aux l ) ^ " ] " |
let print_state n = function | APP ( cnt , m ) -> print_string ( ( string_of_int n ) ^ " " | ACK ( x , y , cnt ) -> print_string ( ( string_of_int n ) ^ " " |
let step = function | ACK ( 0 , y , cnt ) -> APP ( cnt , y + 1 ) | ACK ( x , 0 , cnt ) -> ACK ( x - 1 , 1 , cnt ) | ACK ( x , y , cnt ) -> ACK ( x , y - 1 , x :: cnt ) | APP ( x :: cnt , a ) -> ACK ( x - 1 , a , cnt ) | s -> s |
let rec driver n state = let _ = print_state n state in match state with | APP ( [ ] , v ) -> v | s -> driver ( n + 1 ) ( step s ) |
let ack_4 ( x , y ) = driver 0 ( ACK ( x , y , [ ] ) ) |
type code = out_channel -> Environments . t -> Result . t * Environments . t |
type t = { name : string ; body : code ; mutable hook : code option } |
let name a = a . name |
let action_name = Variables . make ( " action_name " , " Name of the current action " ) |
let make n c = { name = n ; body = c ; hook = None } |
let update action code = { action with body = code } |
let compare a1 a2 = String . compare a1 . name a2 . name |
let ( actions : ( string , t ) Hashtbl . t ) = Hashtbl . create 10 |
let register action = Hashtbl . add actions action . name action |
let get_registered_actions ( ) = let f _name action acc = action :: acc in let unsorted_actions = Hashtbl . fold f actions [ ] in List . sort compare unsorted_actions |
let lookup name = try Some ( Hashtbl . find actions name ) with Not_found -> None |
let set_hook name hook = let action = ( Hashtbl . find actions name ) in action . hook <- Some hook |
let clear_hook name = let action = ( Hashtbl . find actions name ) in action . hook <- None |
let clear_all_hooks ( ) = let f _name action = action . hook <- None in Hashtbl . iter f actions |
let run log env action = let code = match action . hook with | None -> action . body | Some code -> code in let env = Environments . add action_name action . name env in code log env |
module ActionSet = Set . Make ( struct type nonrec t = t let compare = compare end ) |
let _ = Variables . register_variable action_name |
let skip_with_reason reason = let code _log env = let result = Result . skip_with_reason reason in ( result , env ) in Actions . make " skip " code |
let pass_or_skip test pass_reason skip_reason _log env = let open Result in let result = if test then pass_with_reason pass_reason else skip_with_reason skip_reason in ( result , env ) |
let mkreason what commandline exitcode = Printf . sprintf " % s : command \ n % s \ nfailed with exit code % d " what commandline exitcode |
let testfile env = match Environments . lookup Builtin_variables . test_file env with | None -> assert false | Some t -> t |
let test_source_directory env = Environments . safe_lookup Builtin_variables . test_source_directory env |
let test_build_directory env = Environments . safe_lookup Builtin_variables . test_build_directory env |
let test_build_directory_prefix env = Environments . safe_lookup Builtin_variables . test_build_directory_prefix env |
let words_of_variable env variable = String . words ( Environments . safe_lookup variable env ) |
let exit_status_of_variable env variable = try int_of_string ( Environments . safe_lookup variable env ) with _ -> 0 |
let files env = words_of_variable env Builtin_variables . files |
let setup_symlinks test_source_directory build_directory files = let symlink filename = let src = Filename . concat test_source_directory filename in let dst = Filename . concat build_directory filename in let ( ) = if Sys . file_exists dst then if Sys . win32 && Sys . is_directory dst then Sys . rmdir dst else Sys . r... |
let setup_build_env add_testfile additional_files ( _log : out_channel ) env = let build_dir = ( test_build_directory env ) in let some_files = additional_files @ ( files env ) in let files = if add_testfile then ( testfile env ) :: some_files else some_files in setup_symlinks ( test_source_directory env ) build_dir fi... |
let setup_simple_build_env add_testfile additional_files log env = let build_env = Environments . add Builtin_variables . test_build_directory ( test_build_directory_prefix env ) env in setup_build_env add_testfile additional_files log build_env |
let run_cmd ( ? environment [ ] ) =|| ( ? stdin_variable = Builtin_variables . stdin ) ( ? stdout_variable = Builtin_variables . stdout ) ( ? stderr_variable = Builtin_variables . stderr ) ( ? append = false ) ( ? timeout = 0 ) log env original_cmd = let log_redirection std filename = if filename " " <> then begin Prin... |
let run ( log_message : string ) ( redirect_output : bool ) ( can_skip : bool ) ( prog_variable : Variables . t ) ( args_variable : Variables . t option ) ( log : out_channel ) ( env : Environments . t ) = match Environments . lookup prog_variable env with | None -> let msg = Printf . sprintf " % s : variable % s is un... |
let run_program = run " Running program " true false Builtin_variables . program ( Some Builtin_variables . arguments ) |
let run_script log env = let response_file = Filename . temp_file " ocamltest " - " . response " in Printf . fprintf log " Script should write its response to % s \ n " %! response_file ; let scriptenv = Environments . add Builtin_variables . ocamltest_response response_file env in let ( result , newenv ) = run " Runni... |
let run_hook hook_name log input_env = Printf . fprintf log " Entering run_hook for hook % s \ n " %! hook_name ; let response_file = Filename . temp_file " ocamltest " - " . response " in Printf . fprintf log " Hook should write its response to % s \ n " %! response_file ; let hookenv = Environments . add Builtin_vari... |
let check_output kind_of_output output_variable reference_variable log env = let to_int = function None -> 0 | Some s -> int_of_string s in let skip_lines = to_int ( Environments . lookup Builtin_variables . skip_header_lines env ) in let skip_bytes = to_int ( Environments . lookup Builtin_variables . skip_header_bytes... |
let main ( ) = let top = opentk ( ) in let en1 = Entry . create top [ TextWidth 6 ; Relief Sunken ] in let lab1 = Label . create top [ Text " plus " ] in let en2 = Entry . create top [ TextWidth 6 ; Relief Sunken ] in let lab2 = Label . create top [ Text " " ] = in let result_display = Label . create top [ ] in let n1 ... |
let _ = Printexc . catch main ( ) ; ; |
let norec = ref false |
let input_file file = let ic = try open_in file with _ -> failwith ( " input_file : " ^ file ) in let b = Buffer . create 1024 in let buf = String . create 1024 and len = ref 0 in while len := input ic buf 0 1024 ; ! len > 0 do Buffer . add_substring b buf 0 ! len done ; close_in ic ; Buffer . contents b |
module SMap = struct include Map . Make ( struct type t = string let compare = compare end ) let rec removes l m = match l with [ ] -> m | k :: l -> let m = try remove k m with Not_found -> m in removes l m end |
let rec labels_of_sty sty = match sty . ptyp_desc with Ptyp_arrow ( lab , _ , rem ) -> lab :: labels_of_sty rem | Ptyp_alias ( rem , _ ) -> labels_of_sty rem | _ -> [ ] |
let rec labels_of_cty cty = match cty . pcty_desc with Pcty_fun ( lab , _ , rem ) -> let ( labs , meths ) = labels_of_cty rem in ( lab :: labs , meths ) | Pcty_signature ( _ , fields ) -> ( [ ] , List . fold_left fields ~ init [ ] : ~ f : begin fun meths -> function Pctf_meth ( s , _ , sty , _ ) -> ( s , labels_of_sty ... |
let rec pattern_vars pat = match pat . ppat_desc with Ppat_var s -> [ s ] | Ppat_alias ( pat , s ) -> s :: pattern_vars pat | Ppat_tuple l | Ppat_array l -> List . concat ( List . map pattern_vars l ) | Ppat_construct ( _ , Some pat , _ ) | Ppat_variant ( _ , Some pat ) | Ppat_constraint ( pat , _ ) -> pattern_vars pat... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.