text
stringlengths
12
786k
let insert_destroyed_at_raise intervals pos = let destroyed = Proc . destroyed_at_raise in if Array . length destroyed > 0 then update_interval_position_by_array intervals destroyed pos Result
let build_intervals fd = let intervals = Array . init ( Reg . num_registers ( ) ) ( fun _ -> { reg = Reg . dummy ; ibegin = 0 ; iend = 0 ; ranges = [ ] ; } ) in let pos = ref 0 in let rec walk_instruction i = incr pos ; update_interval_position_by_instr intervals i ! po...
type t = A | B of int | C of float | D of string | E of char | F of t | G of t * t | H of int * t | I of t * float | J
let verylongstring = " 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz \ 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz \ 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz \ 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz \ 0123456789ABCDEFGHIJKLMNOP...
let bigint = Int64 . to_int 0x123456789ABCDEF0L
let rec fib n = if n < 2 then 1 else fib ( n - 1 ) + fib ( n - 2 )
let test_out filename = let oc = open_out_bin filename in output_value oc 1 ; output_value oc ( - 1 ) ; output_value oc 258 ; output_value oc 20000 ; output_value oc 0x12345678 ; output_value oc bigint ; output_value oc " foobargeebuz " ; output_value oc longstring ; output_value oc very...
let test n b = print_string " Test " ; print_int n ; if b then print_string " passed . \ n " else print_string " FAILED . \ n " ; flush stderr
let test_in filename = let ic = open_in_bin filename in test 1 ( input_value ic = 1 ) ; test 2 ( input_value ic = ( - 1 ) ) ; test 3 ( input_value ic = 258 ) ; test 4 ( input_value ic = 20000 ) ; test 5 ( input_value ic = 0x12345678 ) ; test 6 ( input_value ic = b...
let test_string ( ) = let s = Marshal . to_string 1 [ ] in test 101 ( Marshal . from_string s 0 = 1 ) ; let s = Marshal . to_string ( - 1 ) [ ] in test 102 ( Marshal . from_string s 0 = ( - 1 ) ) ; let s = Marshal . to_string 258 [ ] in test 103 ( Marsha...
let marshal_to_buffer s start len v flags = ignore ( Marshal . to_buffer s start len v flags ) ; ;
let test_buffer ( ) = let s = String . create 512 in marshal_to_buffer s 0 512 1 [ ] ; test 201 ( Marshal . from_string s 0 = 1 ) ; marshal_to_buffer s 0 512 ( - 1 ) [ ] ; test 202 ( Marshal . from_string s 0 = ( - 1 ) ) ; marshal_to_buffer s 0 512 258 [ ...
let test_size ( ) = let s = Marshal . to_string ( G ( A , G ( B 2 , G ( C 3 . 14 , G ( D " glop " , E ' e ' ) ) ) ) ) [ ] in test 300 ( Marshal . header_size + Marshal . data_size s 0 = String . length s ) : string -> int -> ' a -> Marshal . ext...
let test_block ( ) = let s = static_alloc 512 in marshal_to_block s 512 1 [ ] ; test 401 ( marshal_from_block s 512 = 1 ) ; marshal_to_block s 512 ( - 1 ) [ ] ; test 402 ( marshal_from_block s 512 = ( - 1 ) ) ; marshal_to_block s 512 258 [ ] ; test 403 ( m...
let counter = ref 0
let rec make_big n = if n <= 0 then begin incr counter ; B ! counter end else begin let l = make_big ( n - 1 ) in let r = make_big ( n - 1 ) in G ( l , r ) end
let rec check_big n x = if n <= 0 then begin match x with B k -> incr counter ; k = ! counter | _ -> false end else begin match x with G ( l , r ) -> check_big ( n - 1 ) l && check_big ( n - 1 ) r | _ -> false end
let main ( ) = if Array . length Sys . argv <= 2 then begin test_out " intext . data " ; test_in " intext . data " ; test_out " intext . data " ; test_in " intext . data " ; Sys . remove " intext . data " ; test_string ( ) ; test_buffer ( ) ; test_size ( ...
let _ = Printexc . catch main ( ) ; exit 0
let labltk_write_create_p ~ w wname = w " val create :\ n ? name : string ->\ n " ; begin try let option = Hashtbl . find types_table " options " in let classdefs = List . assoc wname option . subtypes in let tklabels = List . map ~ f : gettklabel classdefs in let l = List . map classdef...
let camltk_write_create_p ~ w wname = w " val create : ? name : string -> widget -> options list -> widget \ n " ; w " \ n \ n " ; ;
let camltk_write_named_create_p ~ w wname = w " val create_named : widget -> string -> options list -> widget \ n " ; w " \ n \ n " ; ; ;
let labltk_write_function_type ~ w def = if not def . safe then w " \ n " ; w " val " ; w def . ml_name ; w " : " ; let us , ls , os = let tys = types_of_template def . template in let rec replace_args ~ u ~ l ~ o = function [ ] -> u , l , o | ( _ , List ( Subtyp...
let camltk_write_function_type ~ w def = if not def . safe then w " \ n " ; w " val " ; w def . ml_name ; w " : " ; let us , os = let tys = types_of_template def . template in let rec replace_args ~ u ~ o = function [ ] -> u , o | ( " " , _ as x ) :: ls -> repla...
let write_function_type ~ w def = if ! Flags . camltk then camltk_write_function_type ~ w def else labltk_write_function_type ~ w def
let write_external_type ~ w def = match def . template with | StringArg fname -> begin try let realname = find_in_path ! search_path ( fname ^ " . mli " ) in let ic = open_in_bin realname in try let code_list = Ppparse . parse_channel ic in close_in ic ; if not def . safe then w " \ n " ...
module LazyStream = struct type ' a t = Cons of ' a * ' a t Lazy . t | Nil let of_stream stream = let rec next stream = try Cons ( Stream . next stream , lazy ( next stream ) ) with Stream . Failure -> Nil in next stream let of_string str = str |> Stream . of_string |> of_stream let of...
let implode l = String . concat " " ( List . map ( String . make 1 ) l )
let explode s = let l = ref [ ] in String . iter ( fun c -> l := c :: ! l ) s ; List . rev ! l
let ( ) % f g = fun x -> g ( f x )
type ' token input = ' token LazyStream . t
type ( ' token , ' result ) parser = ' token input -> ( ' result * ' token input ) option
let parse parser input = match parser input with | Some ( res , _ ) -> Some res | None -> None
let return x input = Some ( x , input )
let ( ) >>= x f = fun input -> match x input with | Some ( result ' , input ' ) -> f result ' input ' | None -> None
let ( ) <|> x y = fun input -> match x input with | Some _ as ret -> ret | None -> y input
let rec scan x input = match x input with | Some ( result ' , input ' ) -> LazyStream . Cons ( result ' , lazy ( scan x input ' ) ) | None -> LazyStream . Nil
let mzero _ = None
let any = function | LazyStream . Cons ( token , input ' ) -> Some ( token , Lazy . force input ' ) | LazyStream . Nil -> None
let satisfy test = any >>= ( fun res -> if test res then return res else mzero )
let eof x = function LazyStream . Nil -> Some ( x , LazyStream . Nil ) | _ -> None
let ( ) => x f = x >>= fun r -> return ( f r )
let ( ) >> x y = x >>= fun _ -> y
let ( ) << x y = x >>= fun r -> y >>= fun _ -> return r
let ( ) <~> x xs = x >>= fun r -> xs >>= fun rs -> return ( r :: rs )
let rec choice = function [ ] -> mzero | h :: t -> ( h <|> choice t )
let rec count n x = if n > 0 then x <~> count ( n - 1 ) x else return [ ]
let between op ed x = op >> x << ed
let option default x = x <|> return default
let optional x = option ( ) ( x >> return ( ) )
let rec skip_many x = option ( ) ( x >>= fun _ -> skip_many x )
let skip_many1 x = x >> skip_many x
let rec many x = option [ ] ( x >>= fun r -> many x >>= fun rs -> return ( r :: rs ) )
let many1 x = x <~> many x
let sep_by1 x sep = x <~> many ( sep >> x )
let sep_by x sep = sep_by1 x sep <|> return [ ]
let end_by1 x sep = sep_by1 x sep << sep
let end_by x sep = end_by1 x sep <|> return [ ]
let chainl1 x op = let rec loop a = ( op >>= fun f -> x >>= fun b -> loop ( f a b ) ) <|> return a in x >>= loop
let chainl x op default = chainl1 x op <|> return default
let rec chainr1 x op = x >>= fun a -> ( op >>= fun f -> chainr1 x op >>= f a ) <|> return a
let chainr x op default = chainr1 x op <|> return default
let exactly x = satisfy ( ( ) = x )
let one_of l = satisfy ( fun x -> List . mem x l )
let none_of l = satisfy ( fun x -> not ( List . mem l x ) )
let range l r = satisfy ( fun x -> l <= x && x <= r )
let space = one_of [ ' ' ; ' \ t ' ; ' \ r ' ; ' \ n ' ]
let spaces = skip_many space
let newline = exactly ' \ n '
let tab = exactly ' \ t '
let upper = range ' A ' ' Z '
let lower = range ' a ' ' z '
let digit = range ' 0 ' ' 9 '
let letter = lower <|> upper
let alpha_num = letter <|> digit
let hex_digit = range ' a ' ' f ' <|> range ' A ' ' F '
let oct_digit = range ' 0 ' ' 7 '
let lexeme x = spaces >> x
let token s = let rec loop s i = if i >= String . length s then return s else exactly s . [ i ] >> loop s ( i + 1 ) in lexeme ( loop s 0 )
type num = Ratio of int * int
let rec num_of_string s = if String . contains s ' ' / then let len = String . length s in let delim = String . index s ' ' / in let numer = String . sub s 0 delim and denom = String . sub s ( delim + 1 ) ( len - delim - 1 ) in Ratio ( int_of_string numer , int_of_string denom...
let ( +/ ) ( Ratio ( a , b ) ) ( Ratio ( c , d ) ) = Ratio ( a * d + b * c , b * d ) |> simplify
let ( -/ ) ( Ratio ( a , b ) ) ( Ratio ( c , d ) ) = Ratio ( a * d - b * c , b * d ) |> simplify
let ( */ ) ( Ratio ( a , b ) ) ( Ratio ( c , d ) ) = Ratio ( a * c , b * d ) |> simplify
let ( // ) ( Ratio ( a , b ) ) ( Ratio ( c , d ) ) = Ratio ( a * d , b * c ) |> simplify
let minus_num ( Ratio ( a , b ) ) = Ratio ( - a , b )
let is_integer_num ( Ratio ( a , b ) ) = b = 1
let sign_num ( Ratio ( a , b ) ) = sign a
let int_of_num ( Ratio ( a , b ) ) = a / b
type exp = AddExp of exp * exp | SubExp of exp * exp | MulExp of exp * exp | DivExp of exp * exp | PosExp of exp | NegExp of exp | Number of num | Call of call | Assign of assign | Loop of exp * assign | Ask of call list
type program = stmt list
type value = NumVal of num | FuncVal of num * num list
let kwd s = let rec loop s i = if i >= String . length s then return s else satisfy ( fun c -> Char . lowercase c = s . [ i ] ) >> loop s ( i + 1 ) in lexeme ( loop s 0 )
let comma_list x = sep_by1 x ( token " , " )
let parens = between ( token " ( " ) ( token " ) " )
let bracks = between ( token " [ " ) ( token " ] " )
let braces = between ( token " { " ) ( token " } " )
let reserved = [ " function " ; " is " ; " of " ; " assign " ; " and " ; " to " ; " do " ; " what " ]
let ident = ( spaces >> letter <~> many alpha_num ) => implode % String . lowercase >>= function | s when List . mem s reserved -> mzero | s -> return s
let digits = spaces >> many1 digit => implode