text
stringlengths
0
601k
type record = ( string * loc ) list
type value = Z of int | B of bool | L of loc | Unit | R of record
type cmd = | PUSH of obj | POP | STORE | LOAD | JTR of command * command | MALLOC | BOX of int | UNBOX of string | BIND of string | UNBIND | GET | PUT | CALL | ADD | SUB | MUL | DIV | EQ | LESS | NOT
type proc = string * command * environment
type svalue = V of value | P of proc | M of ( string * evalue )
type stack = svalue list
type memory = ( loc * value ) list
type continuation = ( command * environment ) list
let debug_mode = ref false
let loc_to_str ( base , offset ) = Printf . sprintf " <% d , % d " > base offset
let val_to_str = function | Z i -> string_of_int i | B b -> string_of_bool b | R pair_list -> let pair_to_str ( s , l ) = Printf . sprintf " ( % s , % s ) " s ( loc_to_str l ) in " { " ^ ( String . concat " , " ( List . map pair_to_str pair_list ) ) ^ " } " | Unit -> " unit " | L l -> loc_to_str l
let rec cmd_to_str indent cmd = match cmd with | PUSH obj -> Printf . sprintf " push % s " ( obj_to_str indent obj ) | POP -> " pop " | STORE -> " store " | LOAD -> " load " | JTR ( c1 , c2 ) -> let c1_str = ( command_to_str ( " " ^ indent ) c1 ) in let c2_str = ( command_to_str ( " " ^ indent ) c2 ) in Printf . sprint...
let rec proc_to_str indent ( x , comm , env ) = let new_indent = ( " " ^ indent ) in let comm_str = command_to_str new_indent comm in let env_str = env_to_str new_indent env in Printf . sprintf " ( fun % s ->\ n % s \ n % s ) , Env =\ n % s " x comm_str new_indent env_str match ev with | Loc l -> loc_to_str l | Proc p ...
let sval_to_str = function | V v -> val_to_str v | P p -> proc_to_str " " p | M ( x , ev ) -> Printf . sprintf " ( % s , % s ) " x ( evalue_to_str " " ev )
let stack_to_str s = " [ " ^ ( String . concat " ; \ n " ( List . map sval_to_str s ) ) ^ " ] "
let mem_to_str m = let entry_to_str ( l , v ) = Printf . sprintf " % s : % s " ( loc_to_str l ) ( val_to_str v ) in String . concat " \ n " ( List . map entry_to_str m )
let cont_to_str k = let entry_to_str ( comm , env ) = let comm_str = command_to_str " " comm in let env_str = env_to_str " " env in Printf . sprintf " Command :\ n % s \ nEnv :\ n % s " comm_str env_str in String . concat " \ n ----------\ n " ( List . map entry_to_str k )
let lookup_env x e = try List . assoc x e with Not_found -> raise ( Error ( " Unbound name : " ^ x ) )
let lookup_record x r = try List . assoc x r with Not_found -> raise ( Error ( " Unfound field : " ^ x ) )
let load l m = try List . assoc l m with Not_found -> raise ( Error ( " Uninitialized location : % s " ^ ( loc_to_str l ) ) )
let store l v m = if List . mem_assoc l m then ( l , v ) :: ( List . remove_assoc l m ) else ( l , v ) :: m
let loc_id = ref 0
let malloc ( ) = let _ = loc_id := ! loc_id + 1 in ( ! loc_id , 0 )
let rec box_stack s i accum_list = if i = 0 then ( V ( R accum_list ) ) :: s else match s with | M ( x , Loc l ) :: s ' -> box_stack s ' ( i - 1 ) ( ( x , l ) :: accum_list ) | _ -> raise ( Error " Box ( ) : entry is not ( x , loc ) pair " )
let is_equal v1 v2 = match v1 , v2 with | Z z1 , Z z2 -> z1 = z2 | B b1 , B b2 -> b1 = b2 | R r1 , R r2 -> List . sort Pervasives . compare r1 = List . sort Pervasives . compare r2 | Unit , Unit -> true | L ( base1 , z1 ) , L ( base2 , z2 ) -> base1 = base2 && z1 = z2 | _ , _ -> false
let rec step = function | ( s , m , e , PUSH ( Val v ) :: c , k ) -> ( V v :: s , m , e , c , k ) | ( s , m , e , PUSH ( Id x ) :: c , k ) -> ( match lookup_env x e with | Loc l -> ( V ( L l ) :: s , m , e , c , k ) | Proc p -> ( P p :: s , m , e , c , k ) ) | ( s , m , e , PUSH ( Fn ( x , c ' ) ) :: c , k ) -> ( P ( x...
let rec run_helper ( s , m , e , c , k ) = match c , k with | [ ] , [ ] -> ( ) | _ -> let _ = if ! debug_mode then let _ = print_endline " ====== Machine state " ====== in let _ = print_newline ( ) in let _ = print_endline " ***** Command " ***** in let _ = print_endline ( command_to_str " " c ) in let _ = print_newlin...
let run c = run_helper ( [ ] , [ ] , [ ] , c , [ ] )
module type Cursor = sig type ' a t val next : ' a t -> ' a val has_next : ' a t -> bool end
module CursorList = struct type ' a t = { mutable visited : ' a seq ; [ @ ghost ] collection : ' a list ; [ @ ghost ] mutable to_visit : ' a list ; } let next c = match c . to_visit with | [ ] -> assert false | x :: r -> c . visited <- snoc c . visited x ; c . to_visit <- r ; x let has_next c = match c . to_visit with ...
let sum_cursor l = let s = ref 0 in let c = CursorList . create l in while CursorList . has_next c do let x = CursorList . next c in s := ! s + x done ; ! s
module Mem ( Eq : sig type elt val eq : elt -> elt -> bool struct let mem_cursor l x = let c = CursorList . create l in let exception Found in try while CursorList . has_next c do if Eq . eq ( CursorList . next c ) x then raise Found done ; false with Found -> true end
let ( . <> ) f g x = f ( g x )
module Capability = Capability open Protocol module Proto_request = Proto_request module Advertised_refs = Advertised_refs module Want = Want module Result = Result module Negotiation = Negotiation module Shallow = Shallow module Commands = Commands module Status = Status end
module Witness = struct type ' a send = | Proto_request : Proto_request . t send | Want : ( string , string ) Want . t send | Done : unit send | Flush : unit send | Commands : ( string , string ) Commands . t send | Send_pack : { side_band : bool ; stateless : bool } -> string send | Advertised_refs : ( string , string...
module Value = struct open Pkt_line type encoder = Encoder . encoder type decoder = Decoder . decoder include Witness type error = [ Protocol . Encoder . error | Protocol . Decoder . error ] let encode : type a . encoder -> a send -> a -> ( unit , [ > Encoder . error ] ) State . t = fun encoder w v -> let encoder_state...
type ( ' a , ' err ) t = ( ' a , ' err ) State . t = | Read of { buffer : bytes ; off : int ; len : int ; k : int -> ( ' a , ' err ) t ; eof : unit -> ( ' a , ' err ) t ; } | Write of { buffer : string ; off : int ; len : int ; k : int -> ( ' a , ' err ) t } | Return of ' a | Error of ' err
module Context = struct type t = State . Context . t type capabilities = State . Context . capabilities = { client_caps : Capability . t list ; server_caps : Capability . t list ; } let make = State . Context . make let with_decoder = State . Context . with_decoder let replace_server_caps = State . Context . replace_se...
let commands : _ send = Commands
let recv_pack ( ? side_band = false ) ( ? push_stdout = ignore ) ( ? push_stderr = ignore ) push_pack = Recv_pack { side_band ; push_pack ; push_stdout ; push_stderr }
let recv_flush : _ recv = Flush
let status sideband = Status sideband
let flush : _ send = Flush
let send_pack ( ? stateless = false ) side_band = Send_pack { side_band ; stateless }
let packet ~ trim = Packet trim
let send_advertised_refs : _ send = Advertised_refs
let recv_commands : _ recv = Commands
let pp_error ppf = function | # Protocol . Encoder . error as err -> Protocol . Encoder . pp_error ppf err | # Protocol . Decoder . error as err -> Protocol . Decoder . pp_error ppf err
module Unsafe = struct let write context packet = let encoder = State . Context . encoder context in Protocol . Encoder . unsafe_encode_packet encoder ~ packet end
module Log = ( val let src = Logs . Src . create " smart_flow " in Logs . src_log src : Logs . LOG )
type ( ' a , ' s ) raise = exn -> ( ' a , ' s ) io
let run : type fl s . s scheduler -> ( ' a , s ) raise -> ( fl , ' error , s ) flow -> fl -> ( ' res , [ ` Protocol of Smart . error ] ) Smart . t -> ( ' res , s ) io = fun { bind ; return } raise { recv ; send ; pp_error } flow fiber -> let ( >>= ) = bind in let tmp = Cstruct . create io_buffer_size in let failwithf f...
module Verbose = struct type ' a fiber = ' a Lwt . t let succ ( ) = Lwt . return_unit let print ( ) = Lwt . return_unit end
type handshake = uri0 : Uri . t -> uri1 : Uri . t -> Mimic . flow -> unit Lwt . t
let git_capabilities = Mimic . make ~ name " : git - capabilities "
let git_scheme = Mimic . make ~ name " : git - scheme "
let git_path = Mimic . make ~ name " : git - path "
let git_hostname = Mimic . make ~ name " : git - hostname "
let git_ssh_user = Mimic . make ~ name " : git - ssh - user "
let git_port = Mimic . make ~ name " : git - port "
let git_http_headers = Mimic . make ~ name " : git - http - headers "
let git_transmission : [ ` Git | ` Exec | ` HTTP of Uri . t * handshake ] Mimic . value = Mimic . make ~ name " : git - transmission "
let git_uri = Mimic . make ~ name " : git - uri "
module Endpoint = struct type t = { scheme : [ ` SSH of string | ` Git | ` HTTP of ( string * string ) list | ` HTTPS of ( string * string ) list | ` Scheme of string ] ; port : int option ; path : string ; hostname : string ; } let pp ppf edn = match edn with | { scheme = ` SSH user ; path ; hostname ; _ } -> Fmt . pf...
module Make ( Scheduler : Sigs . SCHED with type ' + a s = ' a Lwt . t ) ( Pack : APPEND with type ' + a fiber = ' a Lwt . t ) ( Index : APPEND with type ' + a fiber = ' a Lwt . t ) ( Uid : UID ) ( Ref : Sigs . REF ) = struct let src = Logs . Src . create " git - fetch " module Log = ( val Logs . src_log src : Logs . L...
module type APPEND = sig type ' a rd = < rd : unit ; . . > as ' a type ' a wr = < wr : unit ; . . > as ' a type ' a mode = | Rd : < rd : unit > mode | Wr : < wr : unit > mode | RdWr : < rd : unit ; wr : unit > mode type t type uid type ' a fd type error type ' + a fiber val pp_error : error Fmt . t val create : ? trunc...
module type UID = sig include Carton . UID include Sigs . UID with type t := t val hash : t -> int end
module type HTTP = sig type error val pp_error : error Fmt . t val get : ctx : Mimic . ctx -> ? headers ( : string * string ) list -> Uri . t -> ( unit * string , error ) result Lwt . t val post : ctx : Mimic . ctx -> ? headers ( : string * string ) list -> Uri . t -> string -> ( unit * string , error ) result Lwt . t ...
module type SMART_GIT = sig module type APPEND = APPEND module type UID = UID module type HTTP = HTTP module Endpoint : sig type t = private { scheme : [ ` SSH of string | ` Git | ` HTTP of ( string * string ) list | ` HTTPS of ( string * string ) list | ` Scheme of string ] ; port : int option ; path : string ; hostna...
let smart_home ~ view state = let buffer : GText . buffer = view # buffer in let iter = buffer # get_iter ` INSERT in if iter # chars_in_line > 1 then begin let offset0 = iter # set_line_offset 0 in let where = if view # options # smart_home then begin let initial_pos = iter # copy in let where = if Glib . Unichar . is...
let smart_end ~ view state = let buffer : GText . buffer = view # buffer in let backward_non_blank iter = let rec f it = let stop = it # backward_char in if [ " " ; " \ t " ; " \ r " ] |> List . for_all ( ( ) <> ( it # get_text ~ stop ) ) then it else f stop in f iter in let initial_pos = buffer # get_iter ` INSERT in ...
let rec smc : type a . int -> a dist -> a samples dist = fun n -> function | Conditional ( c , d ) -> let updated = fmap normalise @@ condition ' ( fun l -> Prob . to_float @@ ( List . sum ( module Prob ) ~ f : snd ) l ) @@ let * last_particles = smc n d in let new_particles = List . map ~ f ( : fun ( x , w ) -> Prob ....
let smc ' n d = let * l = smc n d in let l = List . map ~ f ( : fun ( x , y ) -> ( x , Dist . Prob . to_float y ) ) l in categorical l
let smcStandard n d = prior ' ( smc n d )
let smcStandard ' n d = prior ' ( smc ' n d )
let smcMultiple k n d = fmap flatten ( importance k ( smc n d ) )
let smcMultiple ' k n d = importance ' k ( smc ' n d )
let _ = let s = Fd . interval 0 9 and e = Fd . interval 0 9 and n = Fd . interval 0 9 and d = Fd . interval 0 9 and m = Fd . interval 0 9 and o = Fd . interval 0 9 and r = Fd . interval 0 9 and y = Fd . interval 0 9 in Cstr . post ( fd2e m >~ i2e 0 ) 0 ; Cstr . post ( fd2e s >~ i2e 0 ) 0 ; let digits = [ | s ; e ; n ; ...
type answer = Sat | Unsat | Unknown | Error of string
type solver = Standard | NLSat | Both
let info = ref None
let log = ref " "
let stack = ref 0
let is_started ( ) = None != ! info
let start ( ) = end
let push ( ) = write " ( push ) " ; incr stack
let pop ( ) = write " ( pop ) \ n " ; decr stack
let push_pop fn = try in result
module Cont : sig type ( ' a , ' r ) t val get : ( ' a , ' a ) t -> ' a val ( let * ) : ( ' a , ' r ) t -> ( ' a -> ( ' b , ' r ) t ) -> ( ' b , ' r ) t val return : ' a -> ( ' a , ' r ) t val return1 : ( ' a -> ' b ) -> ' a -> ( ' b , ' r ) t val return2 : ( ' a -> ' b -> ' c ) -> ' a -> ' b -> ( ' c , ' r ) t val fol...
module Variables : sig type t val init : unit -> t val add : t -> ( string * Term . t ) list -> t val permanently_add : t -> string -> Term . t -> unit val mem : t -> string -> bool val find : t -> string -> Term . t module StringMap = Map . Make ( String ) type t = { uninterpreted : Term . t VarMap . t ; bound : Term ...
let print verbosity i fs = Format . ( ( if verbosity >= i then fprintf else ifprintf ) stdout ) fs
module Session = struct type env = { verbosity : int ; logic : string ; types : type_t VarMap . t ; variables : Variables . t ; context : Context . t ; param : Param . t ; model : Model . t option } let to_SMT2 { logic ; context ; _ } = let log = Context . to_sexp context in let sl = List [ Atom " set - logic " ; Atom ...
module ParseType = struct type t = ( type_t , type_t ) Cont . t let atom types s = return ( if VarMap . mem types s then VarMap . find types s else match s with | " Bool " -> Type . bool ( ) | " Int " -> Type . int ( ) | " Real " -> Type . real ( ) | _ -> raise ( Yices_SMT2_exception ( " ParseType . atom does not under...
module ParseTerm = struct open Session type t = ( term_t , term_t ) Cont . t let atom env s = return ( match s with | _ when Variables . mem env . variables s -> Variables . find env . variables s | " true " -> Term . true0 ( ) | " false " -> Term . false0 ( ) | _ -> let aux s = try Term . Arith . parse_rational s with...
module ParseInstruction = struct open Session let get_model env = match env . model with | Some m -> m | None -> Context . get_model env . context ~ keep_subst : true let display = { width = 80 ; height = 80 ; offset = 0 } let iter f n = let n = int_of_string n in for _i = 1 to n do f ( ) done let parse session sexp = ...
module SMT2 = struct let load_file filename = let ic = open_in filename in let bytes = IO . read_all_bytes ic in close_in ic ; let is_in_string = ref false in let is_escaped = ref false in let aux i = function | _ when ! is_escaped -> is_escaped := false ; ( ) | ' ' \\ -> is_escaped := true ; ( ) | ' ' | -> is_in_strin...
module type IO = sig type ' a t val return : ' a -> ' a t val bind : ' a t -> ( ' a -> ' b t ) -> ' b t val fail : exn -> ' a t type ic type oc val open_connection : host : string -> service : string -> ( ic * oc ) t val shutdown_connection : ic -> unit t val read_line : ic -> string t val print_line : oc -> string -> ...
module type S = sig type ' a monad type handle type request = [ | ` Helo of string | ` From of string | ` To of string | ` Data | ` Msg_body of string | ` Quit ] type response = [ | ` Ok of int * string | ` Failure of int * string ] module Addr : sig type t val of_string : string -> t val to_string : t -> string end ex...
module Make ( IO : IO ) = struct type ' a monad = ' a IO . t type handle = { ic : IO . ic ; oc : IO . oc ; name : string } type request = [ | ` Helo of string | ` From of string | ` To of string | ` Data | ` Msg_body of string | ` Quit ] type response = [ | ` Ok of int * string | ` Failure of int * string ] module Addr...
type direction = North | South | East | West