text
stringlengths
0
601k
let get_code_pointer cls = Obj . field cls 0
let set_code_pointer cls ptr = Obj . set_field cls 0 ptr
let invoke_traced_function codeptr env arg = Meta . invoke_traced_function codeptr env arg
let print_label ppf l = if l <> Asttypes . Nolabel then fprintf ppf " % s " : ( Printtyp . string_of_label l )
let rec instrument_result env name ppf clos_typ = match ( Ctype . repr ( Ctype . expand_head env clos_typ ) ) . desc with | Tarrow ( l , t1 , t2 , _ ) -> let starred_name = match name with | Lident s -> Lident ( s ^ " " ) * | Ldot ( lid , s ) -> Ldot ( lid , s ^ " " ) * | Lapply _ -> fatal_error " Trace . instrument_re...
let instrument_closure env name ppf clos_typ = match ( Ctype . repr ( Ctype . expand_head env clos_typ ) ) . desc with | Tarrow ( l , t1 , t2 , _ ) -> let trace_res = instrument_result env name ppf t2 in ( fun actual_code closure arg -> if not ! may_trace then begin try invoke_traced_function actual_code closure arg wi...
let rec find_traced_closure clos = function | [ ] -> fatal_error " Trace . find_traced_closure " | f :: rem -> if f . closure == clos then f else find_traced_closure clos rem
let print_trace clos arg = let f = find_traced_closure clos ! traced_functions in f . instrumented_fun f . actual_code clos arg
module S = Preface . List . Monoid ( String )
module D = Preface . Traced . Over ( S )
let dependencies_of = function | " preface_make " -> [ " preface_specs " ] | " preface_specs " -> [ " preface_core " ] | " preface_stdlib " -> [ " preface_make " ; " preface_specs " ; " preface_core " ] | " preface " -> [ " preface_stdlib " ] | _ -> [ ] ; ;
let f = Preface . List . Foldable . fold_map ( module S ) dependencies_of
let direct_deps = D . traced f
let deps subject = let open D in trace subject ( direct_deps =>> traces Fun . id ) |> List . sort_uniq String . compare ; ;
let deps_for_make ( ) = let open Alcotest in let expected = [ " preface_core " ; " preface_specs " ] and computed = deps [ " preface_make " ] in check ( list string ) " Should be equal " expected computed ; ;
let deps_for_stdlib ( ) = let open Alcotest in let expected = [ " preface_core " ; " preface_make " ; " preface_specs " ] and computed = deps [ " preface_stdlib " ] in check ( list string ) " Should be equal " expected computed ; ;
let deps_for_specs ( ) = let open Alcotest in let expected = [ " preface_core " ] and computed = deps [ " preface_specs " ] in check ( list string ) " Should be equal " expected computed ; ;
let deps_for_preface ( ) = let open Alcotest in let expected = [ " preface_core " ; " preface_make " ; " preface_specs " ; " preface_stdlib " ] and computed = deps [ " preface " ] in check ( list string ) " Should be equal " expected computed ; ;
let cases = let open Alcotest in [ ( " Dependencies computing using Traced Comonad " , [ test_case " Deps for preface_make " ` Quick deps_for_make ; test_case " Deps for preface_stdlib " ` Quick deps_for_stdlib ; test_case " Deps for preface_specs " ` Quick deps_for_specs ; test_case " Deps for preface_preface " ` Quic...
module type S = Traced_sigs . Trace . S
module type EXTENDED = sig include S val pp : ( Format . formatter -> ' err -> unit ) -> Format . formatter -> ' err trace -> unit val pp_top : ( Format . formatter -> ' err -> unit ) -> Format . formatter -> ' err trace -> unit val fold : ( ' a -> ' error -> ' a ) -> ' a -> ' error trace -> ' a val salvage : ( ' error...
module SingletonR : EXTENDED = struct type ' error trace = ' error let make e = e let cons e _ = e let cons_list e _ = e let conp e _ = e let conp_list e _ = e let pp pp_error fmt e = pp_error fmt e let pp_top pp_error fmt e = pp_error fmt e let fold f acc e = f acc e open Bare_structs . Monad let salvage f e = match f...
module SingletonL : EXTENDED = struct type ' error trace = ' error let make e = e let cons e _ = e let cons_list e _ = e let conp _ e = e let rec conp_list e = function [ ] -> e | e :: es -> conp_list e es let pp pp_error fmt e = pp_error fmt e let pp_top pp_error fmt e = pp_error fmt e let fold f acc e = f acc e open ...
module SingletonND : EXTENDED = struct let prng = Random . State . make_self_init ( ) let either a b = if Random . State . bool prng then a else b let rec any e = function | [ ] -> e | x :: xs -> if Random . State . bool prng then e else any x xs type ' error trace = ' error let make e = e let cons = either let cons_li...
module Flat : EXTENDED = struct type ' error trace = ' error list let make e = [ e ] let cons e t = e :: t let cons_list e es = e :: es let conp el er = el @ er let conp_list e es = Stdlib . List . flatten ( e :: es ) let pp pp_error fmt t = Format . pp_print_list ~ pp_sep : Format . pp_print_cut pp_error fmt t let pp_...
module Full : EXTENDED = struct type ' a tree = | Par of ' a tree list | Seq of ' a * ' a tree | Singl of ' a type ' error trace = ' error tree let make e = Singl e let cons e t = Seq ( e , t ) let cons_list e es = match List . rev es with | [ ] -> Singl e | [ ee ] -> Seq ( e , Singl ee ) | last :: rev_es -> Seq ( e , ...
module Strs = Set . Make ( String )
let tracing = ConfigProfile . profile = " trace "
let current_loc = ref locUnknown
let next_loc = ref locUnknown
let trace_sys = ref Strs . empty
let activated = ref Strs . empty
let active_dep = Hashtbl . create 9
let tracevars = ref ( [ ] : string list )
let tracelocs = ref ( [ ] : int list )
let addsystem sys = trace_sys := Strs . add sys ! trace_sys
let activate ( sys : string ) ( subsys : string list ) : unit = let subs = List . fold_right Strs . add subsys ( Strs . add sys Strs . empty ) in activated := Strs . union ! activated subs ; Hashtbl . add active_dep sys subs
let deactivate ( sys : string ) : unit = activated := Strs . diff ! activated ( try Hashtbl . find active_dep sys with Not_found -> print_endline ( " WTF ? " ^ sys ) ; Strs . empty )
let indent_level = ref 0
let traceIndent ( ) = indent_level := ! indent_level + 2
let traceOutdent ( ) = indent_level := ! indent_level - 2
let mygprintf ( format : ( ' a , unit , doc , ' b ) format4 ) : ' a = let format = string_of_format format in let flen = String . length format in let fget = String . unsafe_get format in let rec literal acc i = let rec skipChars j = if j >= flen || ( match fget j with ' ' % | ' ' @ | ' \ n ' -> true | _ -> false ) the...
let traceTag ( sys : string ) : Pretty . doc = let rec ind ( i : int ) : string = if ( i <= 0 ) then " " else " " ^ ( ind ( i - 1 ) ) in ( text ( ( ind ! indent_level ) ^ " %%% " ^ sys ^ " : " ) )
let printtrace sys d : unit = fprint stderr ~ width : 80 ( ( traceTag sys ) ++ d ) ; flush stderr
let gtrace always f sys var ? loc do_subsys fmt = let cond = ( Strs . mem sys ! activated || always && Strs . mem sys ! trace_sys ) && match var , loc with | Some s , Some l -> ( ! tracevars = [ ] || List . mem s ! tracevars ) && ( ! tracelocs = [ ] || List . mem l . line ! tracelocs ) | Some s , None -> ( ! tracevars ...
let trace sys ? var fmt = gtrace true printtrace sys var ignore fmt
let tracel sys ? var fmt = let loc = ! current_loc in let docloc sys doc = printtrace sys ( dprintf " ( % a ) " @? CilType . Location . pretty loc ++ indent 2 doc ) ; in gtrace true docloc sys var ~ loc ignore fmt
let tracei ( sys : string ) ? var ( ? subsys [ ] ) = fmt = let f sys d = printtrace sys d ; traceIndent ( ) in let g ( ) = activate sys subsys in gtrace true f sys var g fmt
let tracec sys fmt = gtrace false printtrace sys None ignore fmt
let traceu sys fmt = let f sys d = printtrace sys d ; traceOutdent ( ) in let g ( ) = deactivate sys in gtrace true f sys None g fmt
let traceli sys ? var ( ? subsys [ ] ) = fmt = let loc = ! current_loc in let g ( ) = activate sys subsys in let docloc sys doc : unit = printtrace sys ( dprintf " ( % a ) " CilType . Location . pretty loc ++ indent 2 doc ) ; traceIndent ( ) in gtrace true docloc sys var ~ loc g fmt
module OpamPackage = struct include OpamPackage let to_yojson t = ` String ( OpamPackage . to_string t ) let of_yojson = function | ` String str -> ( match OpamPackage . of_string_opt str with | Some x -> Ok x | None -> Error " failed to parse version " ) | _ -> Error " failed to parse version " end
module Track = struct type t = No_context let id = " opam - repo - track " let auto_cancel = true module Key = struct type t = { limit : int option ; repo : Git . Commit . t ; filter : string list } let digest { repo ; filter ; limit } = Git . Commit . hash repo ^ String . concat " ; " filter ^ " ; " ^ ( limit |> Optio...
module TrackCache = Misc . LatchedBuilder ( Track )
type t = package_definition [ @@ deriving yojson ]
let pkg t = t . package
let digest t = t . digest
module Map = OpamStd . Map . Make ( struct type nonrec t = t let compare a b = O . OpamPackage . compare a . package b . package let to_json { package ; digest } = ` A [ OpamPackage . to_json package ; ` String digest ] let of_json _ = None let to_string t = OpamPackage . to_string t . package end )
let v ~ limit ( ~ filter : string list ) ( repo : Git . Commit . t Current . t ) = let open Current . Syntax in Current . component " Track packages - % a " Fmt . ( list string ) filter |> let > repo = repo in TrackCache . get ~ opkey " : track " No_context { filter ; repo ; limit }
type vec = { x : float ; y : float ; z : float }
type quat = { v : vec ; w : float }
let as_tuple v = v . x , v . y , v . z
let vzero = ( 0 . 0 , 0 . 0 , 0 . 0 )
let ( ) -^ a b = { x = a . x . - b . x ; y = a . y . - b . y ; z = a . z . - b . z ; }
let ( ) +^ a b = { x = a . x . + b . x ; y = a . y . + b . y ; z = a . z . + b . z ; }
let ( ) ^^ a b = { x = a . y . * b . z . - a . z . * b . y ; y = a . z . * b . x . - a . x . * b . z ; z = a . x . * b . y . - a . y . * b . x }
let vlength v = sqrt ( v . x . * v . x . + v . y . * v . y . + v . z . * v . z )
let vscale s v = { x = s . * v . x ; y = s . * v . y ; z = s . * v . z }
let vnormal v = vscale ( 1 . 0 . / ( vlength v ) ) v
let ( . ) ^^ a b = a . x . * b . x . + a . y . * b . y . + a . z . * b . z
let tb_project_to_sphere r x y = let d = sqrt ( x . * x . + y . * y ) in let z = if ( d < r . * 0 . 70710678118654752440 ) then sqrt ( r . * r . - d . * d ) else begin let t = r . / 1 . 41421356237309504880 in t . * t . / d end in z ; ;
let axis_to_quat ~ axis ~ phi = let ax = match axis with x , y , z -> { x = x ; y = y ; z = z } in let sax = vscale ( sin ( phi . / 2 . 0 ) ) ( vnormal ax ) in { v = sax ; w ( = cos ( phi . / 2 . 0 ) ) } ; ;
let trackball ~ p1 ~ p2 = match p1 with p1x , p1y -> match p2 with p2x , p2y -> if ( p1 = p2 ) then { v { = x = 0 . 0 ; y = 0 . 0 ; z = 0 . 0 } ; w = 1 . 0 } else begin let pp1 = { x = p1x ; y = p1y ; z ( = tb_project_to_sphere trackballsize p1x p1y ) } in let pp2 = { x = p2x ; y = p2y ; z ( = tb_project_to_sphere trac...
let count = ref 0
let normalized_quat q = let minv = 1 . 0 . / ( sqrt ( ( q . v . ^^ q . v ) . + q . w . * q . w ) ) in { v = vscale minv q . v ; w = q . w . * minv } ; ;
let add_quats ~ q1 ~ q2 = let t1 = vscale q2 . w q1 . v in let t2 = vscale q1 . w q2 . v in let t3 = q2 . v ^^ q1 . v in let q = { v = t1 +^ t2 +^ t3 ; w = q1 . w . * q2 . w . - ( q1 . v . ^^ q2 . v ) } in incr count ; if ( ! count > renormcount ) then begin count := 0 ; normalized_quat q ; end else q ; ;
let unit_quat ( ) = { v { = x = 0 . 0 ; y = 0 . 0 ; z = 0 . 0 } ; w = 1 . 0 }
let build_rotmatrix ~ q = GlMat . of_array [ | [ | 1 . 0 . - 2 . 0 . * ( q . v . y . * q . v . y . + q . v . z . * q . v . z ) ; 2 . 0 . * ( q . v . x . * q . v . y . - q . v . z . * q . w ) ; 2 . 0 . * ( q . v . z . * q . v . x . + q . v . y . * q . w ) ; 0 . 0 ] ; | [ | 2 . 0 . * ( q . v . x . * q . v . y . + q . v ....
module Michelson = struct let prepare_origination_of_id_script ? delegate ( ? push_drops = 0 ) ( ? amount = " 2 " ) state ~ name ~ from ~ protocol_kind ~ parameter ~ init_storage = let id_script parameter = Fmt . str " parameter % s ; \ n \ storage % s ; \ n \ code \ n \ \ { \ n \ \ % s \ n \ \ { CAR ; NIL operation ; ...
module Random = struct let run state ~ protocol ~ nodes ~ clients ~ until_level kind = assert ( Poly . equal kind ` Any ) ; let tbb = protocol . Tezos_protocol . time_between_blocks |> List . hd |> Option . value ~ default : 10 in let info fmt = Fmt . kstr ( fun s -> Console . sayf state Fmt . ( fun ppf ( ) -> pf ppf "...
module Forge = struct let batch_transfer ( ? protocol_kind : Tezos_protocol . Protocol_kind . t = ` Babylon ) ( ? counter = 0 ) ( ? dst = [ ( " tz2KZPgf2rshxNUBXFcTaCemik1LH1v9qz3F " , 1 ) ] ) ~ src ~ fee ~ branch n : Ezjsonm . value = let open Ezjsonm in ignore protocol_kind ; dict [ ( " branch " , ` String branch ) ;...
type ' error trace = ' error Support . Lib . Monad . trace
module type BASE = sig val name : string type ' a elt type ' a_elt t val of_list : int list -> int t val to_list : int t -> int list val pp : Format . formatter -> int t -> unit end
module type ITER_VANILLA = sig type ' a elt type ' a t val iter : ( ' a elt -> unit ) -> ' a t -> unit end
module type ITER_SEQUENTIAL = sig include ITER_VANILLA val iter_e : ( ' a elt -> ( unit , ' trace ) result ) -> ' a t -> ( unit , ' trace ) result val iter_s : ( ' a elt -> unit Lwt . t ) -> ' a t -> unit Lwt . t val iter_es : ( ' a elt -> ( unit , ' trace ) result Lwt . t ) -> ' a t -> ( unit , ' trace ) result Lwt . ...
module type ITER_PARALLEL = sig include ITER_SEQUENTIAL val iter_p : ( ' a elt -> unit Lwt . t ) -> ' a t -> unit Lwt . t val iter_ep : ( ' a elt -> ( unit , ' error trace ) result Lwt . t ) -> ' a t -> ( unit , ' error trace ) result Lwt . t end
module type ITERI_VANILLA = sig type ' a elt type ' a t val iteri : ( int -> ' a elt -> unit ) -> ' a t -> unit end
module type ITERI_SEQUENTIAL = sig include ITERI_VANILLA val iteri_e : ( int -> ' a elt -> ( unit , ' trace ) result ) -> ' a t -> ( unit , ' trace ) result val iteri_s : ( int -> ' a elt -> unit Lwt . t ) -> ' a t -> unit Lwt . t val iteri_es : ( int -> ' a elt -> ( unit , ' trace ) result Lwt . t ) -> ' a t -> ( unit...
module type MAP_VANILLA = sig type ' a t val map : ( ' a -> ' b ) -> ' a t -> ' b t end
module type MAP_SEQUENTIAL = sig include MAP_VANILLA val map_e : ( ' a -> ( ' b , ' trace ) result ) -> ' a t -> ( ' b t , ' trace ) result val map_s : ( ' a -> ' b Lwt . t ) -> ' a t -> ' b t Lwt . t val map_es : ( ' a -> ( ' b , ' trace ) result Lwt . t ) -> ' a t -> ( ' b t , ' trace ) result Lwt . t end
module type MAP_PARALLEL = sig include MAP_SEQUENTIAL val map_p : ( ' a -> ' b Lwt . t ) -> ' a t -> ' b t Lwt . t val map_ep : ( ' a -> ( ' b , ' error trace ) result Lwt . t ) -> ' a t -> ( ' b t , ' error trace ) result Lwt . t end
module type REVMAP_VANILLA = sig type ' a t val rev : ' a t -> ' a t val rev_map : ( ' a -> ' b ) -> ' a t -> ' b t end
module type REVMAP_SEQUENTIAL = sig include REVMAP_VANILLA val rev_map_e : ( ' a -> ( ' b , ' trace ) result ) -> ' a t -> ( ' b t , ' trace ) result val rev_map_s : ( ' a -> ' b Lwt . t ) -> ' a t -> ' b t Lwt . t val rev_map_es : ( ' a -> ( ' b , ' trace ) result Lwt . t ) -> ' a t -> ( ' b t , ' trace ) result Lwt ....
module type REVMAP_PARALLEL = sig include REVMAP_SEQUENTIAL val rev_map_p : ( ' a -> ' b Lwt . t ) -> ' a t -> ' b t Lwt . t val rev_map_ep : ( ' a -> ( ' b , ' error trace ) result Lwt . t ) -> ' a t -> ( ' b t , ' error trace ) result Lwt . t end
module type FOLDLEFT_VANILLA = sig type ' a elt type ' a t val fold_left : ( ' a -> ' b elt -> ' a ) -> ' a -> ' b t -> ' a end
module type FOLDLEFT_SEQUENTIAL = sig include FOLDLEFT_VANILLA val fold_left_e : ( ' a -> ' b elt -> ( ' a , ' trace ) result ) -> ' a -> ' b t -> ( ' a , ' trace ) result val fold_left_s : ( ' a -> ' b elt -> ' a Lwt . t ) -> ' a -> ' b t -> ' a Lwt . t val fold_left_es : ( ' a -> ' b elt -> ( ' a , ' trace ) result L...
module type FOLDLEFTMAP_VANILLA = sig type ' a elt type ' a t val fold_left_map : ( ' a -> ' b elt -> ' a * ' c ) -> ' a -> ' b t -> ' a * ' c list end
module type FOLDLEFTMAP_SEQUENTIAL = sig include FOLDLEFTMAP_VANILLA val fold_left_map_e : ( ' a -> ' b elt -> ( ' a * ' c , ' trace ) result ) -> ' a -> ' b t -> ( ' a * ' c list , ' trace ) result val fold_left_map_s : ( ' a -> ' b elt -> ( ' a * ' c ) Lwt . t ) -> ' a -> ' b t -> ( ' a * ' c list ) Lwt . t val fold_...
module type FOLDRIGHT_VANILLA = sig type ' a t val fold_right : ( ' a -> ' b -> ' b ) -> ' a t -> ' b -> ' b end
module type FOLDRIGHT_SEQUENTIAL = sig include FOLDRIGHT_VANILLA val fold_right_e : ( ' a -> ' b -> ( ' b , ' trace ) result ) -> ' a t -> ' b -> ( ' b , ' trace ) result val fold_right_s : ( ' a -> ' b -> ' b Lwt . t ) -> ' a t -> ' b -> ' b Lwt . t val fold_right_es : ( ' a -> ' b -> ( ' b , ' trace ) result Lwt . t ...