text stringlengths 0 601k |
|---|
let parse_error code err = let errors = [ ] @ Errors_internal . common in match Errors_internal . of_string err with | Some var -> if ( List . mem var errors ) && ( ( match Errors_internal . to_http_code var with | Some var -> var = code | None -> true ) ) then Some var else None | None -> None |
type inp = t * t |
module VMap = Map . Make ( struct type t = int let compare = compare end ) |
type env = { freshId : var ; writerInps : inp list VMap . t ; outs : t VMap . t ; } |
type ' a recipe = Recipe of ( t -> env -> ( t * env * ' a ) ) |
let delay clr d = reg Signal . Types . ( { r_sync with reg_clear_value = clr ; } ) enable d |
let delayEn clr enable d = reg Signal . Types . ( { r_sync with reg_clear_value = clr ; } ) enable d |
let delayFb clr f = reg_fb Signal . Types . ( { r_sync with reg_clear_value = clr } ) enable ( width clr ) f |
let setReset s r = delayFb gnd ( fun q -> ( s |: q ) &: ( ~: r ) ) |
module Monad = struct let return a = Recipe ( fun start env -> ( start , env , a ) ) let bind ( Recipe m ) f = Recipe ( fun start env -> let ( fin0 , env0 , a ) = m start env in let Recipe ( f ) = f a in let ( fin1 , env1 , b ) = f fin0 env0 in ( fin1 , env1 , b ) ) let ( ) >>= = bind let ( ) >> m f = bind m ( fun _ ->... |
let skip = Recipe ( fun start env -> ( delay gnd start ) -- " skip_fin " , env , ( ) ) |
let rec wait = function | 0 -> return ( ) | n -> skip >> wait ( n - 1 ) |
let gen_par_fin comb_fin fin ' fin = let fin = setReset fin ' fin in if comb_fin then fin ' |: fin else fin |
let par2 ( ? comb_fin = true ) ( Recipe p ) ( Recipe q ) = Recipe ( fun start env -> let ( fin0 , env0 , a ) = p start env in let ( fin1 , env1 , b ) = q start env0 in let fin = wire 1 in let ( ) = fin <== ( gen_par_fin comb_fin fin0 fin &: gen_par_fin comb_fin fin1 fin ) in ( fin , env1 , ( a , b ) ) ) |
let ( ) ||| p q = par2 ~ comb_fin : true p q |
let par ( ? comb_fin = true ) r = Recipe ( fun start env -> let finl , env , al = List . fold_left ( fun ( finl , env , al ) ( Recipe r ) -> let fin , env , a = r start env in ( fin :: finl , env , a :: al ) ) ( [ ] , env , [ ] ) r in let fin = wire 1 -- " par_fin " in let ( ) = fin <== reduce ( ) &: ( List . map ( fun... |
let cond c ( Recipe p ) ( Recipe q ) = Recipe ( fun start env -> let ( fin0 , env0 , _ ) = p ( start &: c ) env in let ( fin1 , env1 , _ ) = q ( start &: ( ~: c ) ) env in ( ( fin0 |: fin1 ) -- " cond_fin " , env1 , ( ) ) ) |
let iter c ( Recipe p ) = Recipe ( fun start env -> let ready = wire 1 -- " iter_ready " in let ( fin , env ' , b ) = p ( ( c &: ready ) -- " iter_start " ) env in let ( ) = ready <== ( start |: fin ) in ( ( ( ~: c ) &: ready ) -- " iter_fin " , env ' , b ) ) |
let forever p = iter vdd p |
let waitWhile a = iter a skip |
let waitUntil a = iter ( ~: a ) skip |
let follow start ( Recipe r ) = let initialEnv = { freshId = 0 ; writerInps = VMap . empty ; outs = VMap . empty ; } in let fin , env , a = r start initialEnv in VMap . iter ( fun v o -> try let inps = VMap . find v env . writerInps in let enable = reduce ( ) |: ( List . map fst inps ) in let value = reduce ( ) |: ( Li... |
let createVar env a = let v = env . freshId in v , { env with freshId = v + 1 ; outs = VMap . add v a env . outs } |
let ofList al = List . fold_left ( fun m ( k , v ) -> VMap . add k v m ) VMap . empty al |
let addInps env al = let merge _ a b = match a , b with | None , None -> None | Some ( a ) , None | None , Some ( a ) -> Some ( a ) | Some ( a ) , Some ( b ) -> Some ( a @ b ) in { env with writerInps = VMap . merge merge ( ofList al ) env . writerInps } |
let newVar ? name n = Recipe ( fun start env -> let out = match name with None -> wire n | Some ( x ) -> ( wire n ) -- x in let v , env ' = createVar env out in ( start , env ' , v ) ) |
let readVar v = Recipe ( fun start env -> ( start , env , VMap . find v env . outs ) ) |
let assign al = Recipe ( fun start env -> let al ' = List . map ( fun ( a , b ) -> a , [ start , b ] ) al in ( delay gnd start , addInps env al ' , ( ) ) ) |
let writeVar v a = assign [ v , a ] |
let modifyVar f v = readVar v >>= fun a -> writeVar v ( f a ) |
let rewriteVar f v w = readVar v >>= fun a -> writeVar w ( f a ) |
module type Same = sig type ' a same val smap : ( var -> t ) -> var same -> t same val szip : var same -> t same -> ( var * t ) list val newVar : unit -> var same recipe val read : var same -> t same recipe val rewrite : ( t same -> t same ) -> var same -> var same -> unit recipe val apply : ( t same -> t same ) -> var... |
module Same ( X : Interface . S ) = struct type ' a same = ' a X . t let smap f t = X . map f t let szip x y = X . ( to_list ( map2 ( fun a b -> a , b ) x y ) ) let read a = Recipe ( fun start env -> ( start , env , smap ( fun a -> VMap . find a env . outs ) a ) ) let rewrite f a b = read a >>= fun x -> assign ( szip b... |
module SVar = Same ( struct type ' a t = ' a let t = " var " , 0 let map f a = f a let map2 f a b = f a b let to_list a = [ a ] end ) |
module SList = Same ( struct type ' a t = ' a list let t = [ ] let map = List . map let map2 = List . map2 let to_list a = a end ) |
module SArray = Same ( struct type ' a t = ' a array let t = [ ] || let map = Array . map let map2 f a b = Array . init ( Array . length a ) ( fun i -> f a . ( i ) b . ( i ) ) let to_list = Array . to_list end ) |
module STuple2 = Same ( struct type ' a t = ' a * ' a let t = ( " a " , 0 ) , ( " b " , 0 ) let map f ( a , b ) = ( f a , f b ) let map2 f ( a , b ) ( c , d ) = ( f a c , f b d ) let to_list ( a , b ) = [ a ; b ] end ) |
module STuple3 = Same ( struct type ' a t = ' a * ' a * ' a let t = ( " a " , 0 ) , ( " b " , 0 ) , ( " c " , 0 ) let map f ( a , b , c ) = ( f a , f b , f c ) let map2 f ' ( a , b , c ) ( d , e , f ) = ( f ' a d , f ' b e , f ' c f ) let to_list ( a , b , c ) = [ a ; b ; c ] end ) |
module Let_syntax = struct type ' a t = ' a recipe let return x = Monad . return let bind e f = Monad . bind e f end |
module Test_mult = struct module I = struct type ' a t = { start : ' a [ @ bits 1 ] ; a : ' a [ @ bits 8 ] ; b : ' a [ @ bits 8 ] ; } [ @@ deriving hardcaml ] end module O = struct type ' a t = { fin : ' a [ @ bits 1 ] ; mult : ' a [ @ bits 8 ] ; } [ @@ deriving hardcaml ] end module State = struct type ' a t = { a : '... |
module Test_sha1 = struct module I = struct type ' a t = { start : ' a [ @ bits 1 ] ; d : ' a [ @ bits 32 ] ; d_valid : ' a [ @ bits 1 ] ; } [ @@ deriving hardcaml ] end module O = struct type ' a t = { fin : ' a [ @ bits 1 ] ; hash : ' a array [ @ length 5 ] [ @ bits 32 ] ; redundant : ' a [ @ bits 1 ] ; } [ @@ derivi... |
let test number result expected = if result = expected then Printf . printf " Test % d passed . \ n " number else Printf . printf " Test % d FAILED . \ n " number ; flush stdout |
module rec A : sig type t = Leaf of int | Node of ASet . t val compare : t -> t -> int end = struct type t = Leaf of int | Node of ASet . t let compare x y = match ( x , y ) with ( Leaf i , Leaf j ) -> Pervasives . compare i j | ( Leaf i , Node t ) -> - 1 | ( Node s , Leaf j ) -> 1 | ( Node s , Node t ) -> ASet . compa... |
let _ = let x = A . Node ( ASet . add ( A . Leaf 3 ) ( ASet . singleton ( A . Leaf 2 ) ) ) in let y = A . Node ( ASet . add ( A . Leaf 1 ) ( ASet . singleton x ) ) in test 10 ( A . compare x x ) 0 ; test 11 ( A . compare x ( A . Leaf 3 ) ) 1 ; test 12 ( A . compare ( A . Leaf 0 ) x ) ( - 1 ) ; test 13 ( A . compare y y... |
module rec Fib : sig val f : int -> int end = struct let f x = if x < 2 then 1 else Fib . f ( x - 1 ) + Fib . f ( x - 2 ) end ; ; |
let _ = test 20 ( Fib . f 10 ) 89 ; ; |
module rec Fib2 : sig val f : int -> int end = struct let rec g x = Fib2 . f ( x - 1 ) + Fib2 . f ( x - 2 ) and f x = if x < 2 then 1 else g x end ; ; |
let _ = test 21 ( Fib2 . f 10 ) 89 ; ; |
let _ = let res = try let module A = struct module rec Bad : sig val f : int -> int end = struct let f = let y = Bad . f 5 in fun x -> x + y end end in false with Undefined_recursive_module _ -> true in test 30 res true ; ; |
module rec After : sig val x : int end = struct let x = Before . x + 1 end : sig val x : int end = struct let x = 3 end ; ; |
let _ = test 40 After . x 4 ; ; |
module rec Strengthen : sig type t val f : t -> t end = struct type t = A | B let _ = ( A : Strengthen . t ) let f x = if true then A else Strengthen . f B end ; ; |
module rec Strengthen2 : sig type t val f : t -> t module M : sig type u end module R : sig type v end end = struct type t = A | B let _ = ( A : Strengthen2 . t ) let f x = if true then A else Strengthen2 . f B module M = struct type u = C let _ = ( C : Strengthen2 . M . u ) end module rec R : sig type v = Strengthen2 ... |
module rec PolyRec : sig type ' a t = Leaf of ' a | Node of ' a list t * ' a list t val depth : ' a t -> int end = struct type ' a t = Leaf of ' a | Node of ' a list t * ' a list t let x = ( PolyRec . Leaf 1 : int t ) let depth = function Leaf x -> 0 | Node ( l , r ) -> 1 + max ( PolyRec . depth l ) ( PolyRec . depth r... |
module rec Expr : sig type t = Var of string | Const of int | Add of t * t | Binding of Binding . t * t val make_let : string -> t -> t -> t val fv : t -> StringSet . t val simpl : t -> t end = struct type t = Var of string | Const of int | Add of t * t | Binding of Binding . t * t let make_let id e1 e2 = Binding ( [ i... |
let _ = let e = Expr . make_let " x " ( Expr . Add ( Expr . Var " y " , Expr . Const 0 ) ) ( Expr . Var " x " ) in let e ' = Expr . make_let " x " ( Expr . Var " y " ) ( Expr . Var " x " ) in test 50 ( StringSet . elements ( Expr . fv e ) ) [ " y " ] ; test 51 ( Expr . simpl e ) e ' ; ; |
module type ORDERED = sig type t val eq : t -> t -> bool val lt : t -> t -> bool val leq : t -> t -> bool end |
module type HEAP = sig module Elem : ORDERED type heap val empty : heap val isEmpty : heap -> bool val insert : Elem . t -> heap -> heap val merge : heap -> heap -> heap val findMin : heap -> Elem . t val deleteMin : heap -> heap end |
module Bootstrap ( MakeH : functor ( Element : ORDERED ) -> HEAP with module Elem = Element ) ( Element : ORDERED ) : HEAP with module Elem = Element = struct module Elem = Element module rec BE : sig type t = E | H of Elem . t * PrimH . heap val eq : t -> t -> bool val lt : t -> t -> bool val leq : t -> t -> bool end ... |
module LeftistHeap ( Element : ORDERED ) : HEAP with module Elem = Element = struct module Elem = Element type heap = E | T of int * Elem . t * heap * heap let rank = function E -> 0 | T ( r , _ , _ , _ ) -> r let make x a b = if rank a >= rank b then T ( rank b + 1 , x , a , b ) else T ( rank a + 1 , x , b , a ) let e... |
module Ints = struct type t = int let eq = ( ) = let lt = ( ) < let leq = ( ) <= end ; ; |
let _ = let h = List . fold_right C . insert [ 6 ; 4 ; 8 ; 7 ; 3 ; 1 ] C . empty in test 60 ( C . findMin h ) 1 ; test 61 ( C . findMin ( C . deleteMin h ) ) 3 ; test 62 ( C . findMin ( C . deleteMin ( C . deleteMin h ) ) ) 4 ; ; |
module rec Class1 : sig class c : object method m : int -> int end end = struct class c = object method m x = if x <= 0 then x else ( new Class2 . d ) # m x end end : sig class d : object method m : int -> int end end = struct class d = object ( self ) inherit Class1 . c as super method m ( x : int ) = super # m 0 end ... |
let _ = test 70 ( ( new Class1 . c ) # m 7 ) 0 ; ; |
let _ = try let module A = struct module rec BadClass1 : sig class c : object method m : int end end = struct class c = object method m = 123 end end and BadClass2 : sig val x : int end = struct let x = ( new BadClass1 . c ) # m end end in test 71 true false with Undefined_recursive_module _ -> test 71 true true ; ; |
module rec Coerce1 : sig val g : int -> int val f : int -> int end = struct module A = ( Coerce1 : sig val f : int -> int end ) let g x = x let f x = if x <= 0 then 1 else A . f ( x - 1 ) * x end ; ; |
let _ = test 80 ( Coerce1 . f 10 ) 3628800 ; ; |
module CoerceF ( S : sig end ) = struct let f1 ( ) = 1 let f2 ( ) = 2 let f3 ( ) = 3 let f4 ( ) = 4 let f5 ( ) = 5 end |
module rec Coerce2 : sig val f1 : unit -> int end = CoerceF ( Coerce3 ) and Coerce3 : sig end = struct end ; ; |
let _ = test 81 ( Coerce2 . f1 ( ) ) 1 ; ; |
module Coerce4 ( A : sig val f : int -> int end ) = struct let x = 0 let at a = A . f a end |
module rec Coerce5 : sig val blabla : int -> int val f : int -> int end = struct let blabla x = 0 let f x = 5 end : sig val at : int -> int end = Coerce4 ( Coerce5 ) |
let _ = test 82 ( Coerce6 . at 100 ) 5 ; ; |
module rec F : sig type t = X of int | Y of int val f : t -> bool end = struct type t = X of int | Y of int let f = function | X _ -> false | _ -> true end ; ; |
let _ = test 100 ( F . f ( F . X 1 ) ) false ; test 101 ( F . f ( F . Y 2 ) ) true |
module G ( S : sig val x : int Lazy . t end ) = struct include S end |
module M1 = struct let x = lazy 3 end |
let _ = Lazy . force M1 . x |
module rec M2 : sig val x : int Lazy . t end = G ( M1 ) |
let _ = test 102 ( Lazy . force M2 . x ) 3 |
module rec M3 : sig val x : int Lazy . t end = G ( M1 ) |
let _ = test 103 ( Lazy . force M3 . x ) 3 |
module rec A : sig type t = Leaf of B . t end = struct type t = Leaf of B . t end and B : sig type t = int end = struct type t = int end [ %% expect { | { ( " A " , module ) -> { ( " t " , type ) -> . < 8 ; > } ; ( " B " , module ) -> { ( " t " , type ) -> . < 10 ; > } ; } |
module rec A : sig type t = Leaf of B . t end } ] | |
module rec A : sig type t = Leaf of B . t end = A type t = int [ %% expect { | { ( " A " , module ) -> { . < 11 > ( " t " , type ) -> A / 307 . < 11 > . " t " [ type ] ; } ; ( " B " , module ) -> { . < 12 > ( " t " , type ) -> B / 308 . < 12 > . " t " [ type ] ; } ; } |
module rec A : sig type t = Leaf of B . t end } ] | module rec A : sig type t = Leaf of string | Node of ASet . t val compare : t -> t -> int end = struct type t = Leaf of string | Node of ASet . t let compare t1 t2 = match ( t1 , t2 ) with | ( Leaf s1 , Leaf s2 ) -> Stdlib . compare s1 s2 | ( Leaf _ , Node _ ) -> 1 | ... |
module rec A : sig type t = Leaf of string | Node of ASet . t val compare : t -> t -> int end } ] | |
module Context = struct type ' a t = | Extension of ' a Extension . Context . t | Floating_attribute of ' a Attribute . Floating . Context . t let paren pp ppf x = Caml . Format . fprintf ppf " ( % a ) " pp x let printer : type a . a t -> Caml . Format . formatter -> a -> unit = let open Extension . Context in let open... |
module Replacement = struct type data = | Values : ' a Context . t * ' a Context_free . Generated_code_hook . single_or_many -> data | Text of string type t = { start : Lexing . position ; stop : Lexing . position ; data : data } let make ~ context ~ start ~ stop ~ repl ( ) = { start ; stop ; data = Values ( context , ... |
module Replacements = struct type t = Replacement . t list let check_and_sort ~ input_filename ~ input_name repls = List . iter repls ~ f ( : fun repl -> if String . ( <> ) repl . start . pos_fname input_name || String . ( <> ) repl . stop . pos_fname input_name then Location . raise_errorf ~ loc ( : Location . in_file... |
let count_newlines s = let n = ref 0 in String . iter s ~ f ( : function ' \ n ' -> n := ! n + 1 | _ -> ( ) ) ; ! n |
type mode = Using_line_directives | Delimiting_generated_blocks |
type target = Output of mode | Corrected |
let skip_blank_eol contents ( pos : Lexing . position ) = let rec loop cnum = if cnum = String . length contents then { pos with pos_cnum = cnum } else match contents . [ cnum ] with | ' ' | ' \ t ' | ' \ r ' -> loop ( cnum + 1 ) | ' \ n ' -> { pos with pos_cnum = cnum + 1 ; pos_lnum = pos . pos_lnum + 1 ; pos_bol = cn... |
let with_output ~ styler ( ~ kind : Kind . t ) fn ~ f = match styler with | None -> with_output fn ~ binary : false ~ f | Some cmd -> let tmp_fn , oc = Caml . Filename . open_temp_file " ppxlib_driver " ( match kind with Impl -> " . ml " | Intf -> " . mli " ) in let cmd = Printf . sprintf " % s % s % s " cmd ( Caml . F... |
let reconcile ? styler ( repls : Replacements . t ) ~ kind ~ contents ~ input_filename ~ output ~ input_name ~ target = let repls = Replacements . check_and_sort ~ input_filename ~ input_name repls in let output_name = match output with None -> " < stdout " > | Some fn -> fn in with_output output ~ styler ~ kind ~ f ( ... |
type failure_kind = | Nothing_to_reconstruct | Context_hash_mismatch of Block_header . t * Context_hash . t * Context_hash . t | Cannot_read_block_hash of Block_hash . t | Cannot_read_block_level of Int32 . t |
let failure_kind_encoding = let open Data_encoding in union [ case ( Tag 0 ) ~ title " : nothing_to_reconstruct " empty ( function Nothing_to_reconstruct -> Some ( ) | _ -> None ) ( fun ( ) -> Nothing_to_reconstruct ) ; case ( Tag 1 ) ~ title " : context_hash_mismatch " ( obj3 ( req " block_header " Block_header . enco... |
let failure_kind_pp ppf = function | Nothing_to_reconstruct -> Format . fprintf ppf " nothing to reconstruct " | Context_hash_mismatch ( h , e , g ) -> Format . fprintf ppf " resulting context hash for block % a ( level % ld ) does not match . \ Context hash expected % a , got % a " Block_hash . pp ( Block_header . has... |
type error += Reconstruction_failure of failure_kind |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.