text stringlengths 0 601k |
|---|
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 |
method m = 23 end ; ; |
let o = new c in ; ; |
module type MapArgument = sig val enter_structure : structure -> structure val leave_structure : structure -> structure end |
module MakeMap : functor ( Iter : MapArgument ) -> sig val map_structure : structure -> structure val map_pattern : pattern -> pattern val map_structure_item : structure_item -> structure_item val map_expression : expression -> expression val map_class_expr : class_expr -> class_expr val map_signature : signature -> si... |
let rec f a n = if n <= 0 then a else f ( 1 :: a ) ( n - 1 ) in |
let l = f [ ] 30000 in ; ; |
let v = Array . make 200000 2 in |
let t = ref 0 in ; ; |
let rec f n = if n <= 0 then [ ] else n :: f ( n - 1 ) in |
let l = f 300 in ; ; |
let rec f n = if n <= 0 then [ ] else n :: f ( n - 1 ) in |
let l = f 300 in ; ; |
let rec f n = if n <= 0 then [ ] else n :: f ( n - 1 ) in |
let l = f 300 in ; ; |
let rec f n = if n <= 0 then [ ] else n :: f ( n - 1 ) in |
let l = f 300 in ; ; |
let rec f n = if n <= 0 then [ ] else n :: f ( n - 1 ) in |
let l = f 300 in ; ; |
let x = Array . make 20 " " in |
let w = weak_create 20 in x . ( i ) <- String . make 20 ' s ' ; weak_set w i ( Some x . ( i ) ) ; done ; match weak_get w i with | None -> raise Not_found | _ -> ( ) done ; if i mod 2 = 0 then x . ( i ) <- " " done ; match weak_get w i with | None when i mod 2 = 0 -> ( ) | Some s when i mod 2 = 1 -> if s . [ 5 ] <> ' s... |
let x = Array . make 20 " " in |
let w = weak_create 20 in x . ( i ) <- String . make 20 ' s ' ; weak_set w i ( Some x . ( i ) ) ; done ; match weak_get w i with | None -> raise Not_found | _ -> ( ) done ; if i mod 2 = 0 then x . ( i ) <- " " done ; match weak_get w i with | None when i mod 2 = 0 -> ( ) | Some s when i mod 2 = 1 -> if s . [ 5 ] <> ' s... |
let rec f n = if n <= 0 then 12 else 1 + f ( n - 1 ) in ; ; |
let rec f n = if n <= 0 then 12 else 1 + f ( n - 1 ) in try ignore ( f 3000000 ) ; raise Not_found ; ; |
type ' a t = { mutable next : int ; mutable data : ' a array } |
let default_size = 32 ; ; |
let create x = { next = 0 ; data = Array . make default_size x } ; ; |
let incr_table table new_size = let t = Array . make new_size table . data . ( 0 ) in Array . blit table . data 0 t 0 ( Array . length table . data ) ; table . data <- t |
let emit table i = let size = Array . length table . data in if table . next >= size then incr_table table ( 2 * size ) ; table . data . ( table . next ) <- i ; table . next <- table . next + 1 ; ; |
let get t i = if 0 <= i && i < t . next then t . data . ( i ) else raise Error |
let trim t = let r = Array . sub t . data 0 t . next in reset t ; r |
let iter t f = let size = t . next and data = t . data in for i = 0 to size - 1 do f data . ( i ) done |
let size t = t . next |
module Run ( T : sig end ) = struct |
let make_engine_table = menhirlib ^ " . TableInterpreter . MakeEngineTable " |
let make_engine = menhirlib ^ " . Engine . Make " |
let make_symbol = menhirlib ^ " . InspectionTableInterpreter . Symbols " |
let make_inspection = menhirlib ^ " . InspectionTableInterpreter . Make " |
let engineTypes = menhirlib ^ " . EngineTypes " |
let field x = engineTypes ^ " . " ^ x |
let fstate = field " state " |
let fsemv = field " semv " |
let fstartp = field " startp " |
let fendp = field " endp " |
let fnext = field " next " |
let fstack = field " stack " |
let fcurrent = field " current " |
let entry = interpreter ^ " . entry " |
let start = interpreter ^ " . start " |
let staticVersion = menhirlib ^ " . StaticVersion " |
let div a b = if a mod b = 0 then a / b else a / b + 1 |
let rec size unboxed = function | EIntConst _ | ETuple [ ] | EData ( _ , [ ] ) -> if unboxed then 0 else 1 | EStringConst s -> 1 + div ( String . length s * 8 ) Sys . word_size | ETuple es | EData ( _ , es ) | EArray es -> 1 + List . length es + List . fold_left ( fun s e -> s + size true e ) 0 es | _ -> assert false |
let size = size false |
let define ( name , expr ) = { valpublic = true ; valpat = PVar name ; valval = expr } |
let define_and_measure ( x , e ) = Error . logC 1 ( fun f -> fprintf f " The % s table occupies roughly % d bytes . \ n " x ( size e * ( Sys . word_size / 8 ) ) ) ; define ( x , e ) |
let reducecellparams prod i _symbol ( next : pattern ) : pattern = let ids = Production . identifiers prod in PRecord [ fstate , ( if i = 0 then PVar state else PWildcard ) ; fsemv , PVar ids . ( i ) ; fstartp , PVar ( Printf . sprintf " _startpos_ % s_ " ids . ( i ) ) ; fendp , PVar ( Printf . sprintf " _endpos_ % s_ ... |
let reducecellcasts prod i symbol casts = let ids = Production . identifiers prod in let id = ids . ( i ) in let t : typ = match semvtype symbol with | [ ] -> tunit | [ t ] -> t | _ -> assert false in ( PVar id , annotate ( EMagic ( EVar id ) ) t ) :: casts |
let endpos_of_top_stack_cell = ERecordAccess ( EVar stack , fendp ) |
let reducebody prod = let nt , rhs = Production . def prod and ids = Production . identifiers prod and length = Production . length prod in let ( _ : int ) , pat , casts = Array . fold_left ( fun ( i , pat , casts ) symbol -> i + 1 , reducecellparams prod i symbol pat , reducecellcasts prod i symbol casts ) ( 0 , PVar ... |
let semantic_action prod = let env = prefix " env " in EFun ( [ PVar env ] , ELet ( [ PVar stack , ERecordAccess ( EVar env , fstack ) ] @ ( if Production . length prod = 0 then [ PVar state , ERecordAccess ( EVar env , fcurrent ) ] else [ ] ) , reducebody prod ) ) |
let start_def = define ( " start " , EIntConst Production . start ) |
let encode_DefRed prod = 1 + Production . p2i prod |
let encode_Reduce prod = ( Production . p2i prod lsl 2 ) lor 1 |
let encode_ShiftDiscard s = ( ( Lr1 . number s ) lsl 2 ) lor 0b10 |
let encode_ShiftNoDiscard s = ( ( Lr1 . number s ) lsl 2 ) lor 0b11 |
let encode_Goto node = 1 + Lr1 . number node |
let hole = assert ( encode_Fail = 0 ) ; assert ( encode_NoGoto = 0 ) ; 0 |
let encode_terminal tok = ( Terminal . t2i tok + 1 ) lsl 1 |
let encode_nonterminal nt = ( ( Nonterminal . n2i nt ) lsl 1 ) lor 1 |
let encode_symbol = function | Symbol . T tok -> encode_terminal tok | Symbol . N nt -> encode_nonterminal nt |
let encode_symbol_option = function | None -> encode_no_symbol | Some symbol -> encode_symbol symbol |
let encode_bool b = if b then 1 else 0 |
let population ( matrix : int array array ) = Array . fold_left ( fun population row -> Array . fold_left ( fun population entry -> if entry = hole then population else population + 1 ) population row ) 0 matrix |
let marshal1 ( table : int array ) = let ( bits : int ) , ( text : string ) = MenhirLib . PackedIntArray . pack table in ETuple [ EIntConst bits ; EStringConst text ] |
let marshal11 ( table : int array ) = let ( bits : int ) , ( text : string ) = MenhirLib . PackedIntArray . pack table in assert ( bits = 1 ) ; EStringConst text |
let marshal1_list ( table : int list ) = marshal1 ( Array . of_list table ) |
let marshal11_list ( table : int list ) = marshal11 ( Array . of_list table ) |
let linearize_and_marshal1 ( table : int array array ) = let data , entry = MenhirLib . LinearizedArray . make table in ETuple [ marshal1 data ; marshal1 entry ] |
let flatten_and_marshal11_list ( table : int list list ) = ETuple [ EIntConst ( Terminal . n - 1 ) ; marshal11_list ( List . flatten table ) ] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.