text
stringlengths
12
786k
let to_int32 x = Constant . to_int32 x
let zero w = Bits0 . create w
let pp fmt t = Caml . Format . fprintf fmt " % s " ( to_bstr t )
module _ = Pretty_printer . Register ( struct type nonrec t = Bits0 . t let module_name = " Hardcaml . Bits " let to_string = to_bstr end )
module T = struct open Bin_prot . Std module For_sexp = struct type t = { width : int ; data : bytes } [ @@ deriving sexp ] end type t = bytes [ @@ deriving compare , bin_io ] let width t = Int64 . to_int_trunc ( Bytes . unsafe_get_int64 t 0 ) let offset_for_data = 8 let sexp_of_t ...
module Comparable = Comparable . Make ( T )
let words_of_width width = ( width + bits_per_word - 1 ) lsr log_bits_per_word
let bytes_of_width width = words_of_width width lsl shift_bytes_to_words
let words t = words_of_width ( width t )
let number_of_data_bytes t = Bytes . length t - 8
let create width = let bytes = Bytes . make ( ( words_of_width width + 1 ) lsl shift_bytes_to_words ) ' \ 000 ' in Bytes . unsafe_set_int64 bytes 0 ( Int64 . of_int width ) ; bytes ; ;
let empty = create 0
let unsafe_get_byte ( t : t ) i = Bytes . unsafe_get t ( offset_for_data + i )
let unsafe_get_int64 ( t : t ) i = Bytes . unsafe_get_int64 t ( ( i lsl shift_bytes_to_words ) + offset_for_data ) ; ;
let unsafe_set_int64 ( t : t ) i x = Bytes . unsafe_set_int64 t ( ( i lsl shift_bytes_to_words ) + offset_for_data ) x ; ;
let mask ( t : t ) = let width = width t in let bits = width land width_mask in if bits <> 0 then ( let mask = Int64 . ( lsr ) ( - 1L ) ( 64 - bits ) in let word_pos = ( width - 1 ) lsr log_bits_per_word in let x = Int64 . ( land ) ( unsafe_get_int64 t word_pos ) mask in...
let init_byte ~ width ~ f = let t = create width in let num_bytes = words_of_width width lsl shift_bytes_to_words in for i = 0 to num_bytes - 1 do Bytes . unsafe_set t ( i + offset_for_data ) ( f i ) done ; mask t ; t ; ;
let init_int64 ~ width ~ f = let t = create width in let num_words = words_of_width width in for i = 0 to num_words - 1 do unsafe_set_int64 t i ( f i ) done ; mask t ; t ; ;
module type Bits = sig type t [ @@ deriving compare , sexp_of ] include Comb . S with type t := t include Comparator . S with type t := t val number_of_data_bytes : t -> int val unsafe_get_int64 : t -> int -> int64 val unsafe_set_int64 : t -> int -> int64 -> unit module Expert : sig val unsafe_u...
let ( mod ) = Caml . ( mod )
let nbits = Int . num_bits - 1
let words bits = ( bits + nbits - 1 ) / nbits
let word_index bit = bit / nbits
let m = - 1 lsr 1
let mask_bits n = if n = 0 then m else m lsr ( nbits - n )
let mask_bit n = 1 lsl n
let bo2 = nbits / 2
let mask_lo = mask_bits bo2
let mask_hi = mask_bits bo2 lsl bo2
let half_lo x = x land mask_lo
let half_hi x = ( x land mask_hi ) lsr bo2
let cbit = mask_bit bo2
let create_words bits = Array . create ~ len ( : words bits ) 0
let words_of_int bits i = let b = create_words bits in b . ( 0 ) <- i land m ; b ; ;
let get_word a n = a . ( n )
let set_word a n w = a . ( n ) <- w land m
module type Integer = sig include Int . S val nbits : int end
let convert_abits_and_string ( type t ) ( module X : Integer with type t = t ) = let ( . | ) = X . ( lor ) in let ( . & ) = X . ( land ) in let ( . << ) = X . shift_left in let one = X . of_int_exn 1 in let of_bstr b = let width = String . length b in let words ...
module XInt = struct include Int let nbits = num_bits - 1 end
let abits_int_of_bstr , bstr_of_abits_int = convert_abits_and_string ( module XInt )
module T = struct type t = int array * int [ @@ deriving compare ] let equal = [ % compare . equal : t ] let empty = create_words 0 , 0 let width = snd let is_empty ( _ , width ) = width = 0 let to_string x = bstr_of_abits_int ~ width ( : width x ) ( fst x ) let to_int ( da...
module Mutable = struct module T = struct type t = T . t [ @@ deriving compare ] let equal = T . equal let empty = T . empty let is_empty = T . is_empty let width = T . width let data s = fst s let to_string = T . to_string let to_int = T . to_int let to_bstr = T . to_bstr let mask s = ...
let pp fmt t = Caml . Format . fprintf fmt " % s " ( to_bstr t )
module PP = Pretty_printer . Register ( struct type nonrec t = t let module_name = " Hardcaml . Bits " let to_string = to_bstr end )
type t = { mutable vhd : IO . fd Vhd_format . F . Vhd . t option ; info : info ; id : string ; }
let connect path = Lwt_unix . LargeFile . stat path >>= fun _ -> Lwt . catch ( fun ( ) -> Lwt_unix . access path [ Lwt_unix . W_OK ] >>= fun ( ) -> return true ) ( fun _ -> return false ) >>= fun read_write -> Vhd_IO . openchain path read_write >>= fun vhd -> let open Vhd_fo...
let disconnect t = match t . vhd with | None -> return ( ) | Some vhd -> Vhd_IO . close vhd >>= fun ( ) -> t . vhd <- None ; return ( )
let get_info t = return t . info
let to_sectors bufs = let rec loop acc remaining = if Cstruct . len remaining = 0 then List . rev acc else let available = min 512 ( Cstruct . len remaining ) in loop ( Cstruct . sub remaining 0 available :: acc ) ( Cstruct . shift remaining available ) in List . concat ( List . map ...
let forall_sectors f offset bufs = let rec one offset = function | [ ] -> return ( ) | b :: bs -> f offset b >>= fun ( ) -> one ( Int64 . succ offset ) bs in one offset ( to_sectors bufs )
let zero = let buf = Cstruct . create 512 in for i = 0 to Cstruct . len buf - 1 do Cstruct . set_uint8 buf i 0 done ; buf
let read t offset bufs = match t . vhd with | None -> return ( Rresult . R . error ` Disconnected ) | Some vhd -> forall_sectors ( fun offset sector -> ( Vhd_IO . read_sector vhd offset sector >>= function | false -> Cstruct . blit zero 0 sector 0 512 ; return ( ) | true -> retur...
let write t offset bufs = match t . vhd with | None -> return ( Rresult . R . error ` Disconnected ) | Some vhd -> Vhd_IO . write vhd offset bufs >>= fun ( ) -> return ( Rresult . R . ok ( ) )
let mk_bmd_concept_with_loc desc loc = { concept_desc = desc ; concept_loc = loc ; }
let mk_bmd_concept cname1 cname2 ctype = mk_bmd_concept_with_loc ( cname1 , cname2 , ctype ) ( Parsing . symbol_start_pos ( ) , Parsing . symbol_end_pos ( ) )
let mk_bmd_type_with_loc desc loc = { type_desc = desc ; type_loc = loc ; }
let mk_bmd_type desc = mk_bmd_type_with_loc desc ( Parsing . symbol_start_pos ( ) , Parsing . symbol_end_pos ( ) )
let mk_bmd_string ( ) = mk_bmd_type BT_string
let mk_bmd_int ( ) = mk_bmd_type BT_int
let mk_bmd_real ( ) = mk_bmd_type BT_real
let mk_bmd_boolean ( ) = mk_bmd_type BT_boolean
let mk_bmd_date ( ) = mk_bmd_type BT_date
let mk_bmd_duration ( ) = mk_bmd_type BT_duration
let mk_bmd_rec fields = mk_bmd_type ( BT_rec fields )
let mk_bmd_enum values = mk_bmd_type ( BT_enum values )
let mk_bmd_ref cname = mk_bmd_type ( BT_ref cname )
let mk_bmd_schema_with_loc desc loc = { schema_desc = desc ; schema_loc = loc }
let mk_bmd_schema desc = mk_bmd_schema_with_loc desc ( Parsing . symbol_start_pos ( ) , Parsing . symbol_end_pos ( ) )
let airplane = mk_bmd_concept " airplane " ( Some " business entity " ) ( mk_bmd_rec [ ( " airplane id " , mk_bmd_string ( ) ) ; ( " average engine pressure ratio " , mk_bmd_int ( ) ) ; ( " average engine rpm " , mk_bmd_int ( ) ) ; ( " engine warnings...
let airplane_event = mk_bmd_concept " airplane event " ( Some " business event " ) ( mk_bmd_rec [ ( " aircraft id " , mk_bmd_string ( ) ) ; ( " engine " , mk_bmd_ref " engine " ) ; ] )
let engine = mk_bmd_concept " engine " None ( mk_bmd_rec [ ( " pressure ratio " , mk_bmd_int ( ) ) ; ( " rpm " , mk_bmd_int ( ) ) ; ] )
let airline_schema = mk_bmd_schema [ airplane ; airplane_event ; engine ; ]
let account_concept = mk_bmd_concept " account " ( Some " business entity " ) ( mk_bmd_rec [ ( " id " , mk_bmd_string ( ) ) ; ( " status " , mk_bmd_ref " account status " ) ; ] )
let account_status_concept = mk_bmd_concept " account status " None ( mk_bmd_enum [ " Excellent " ; " Good " ; " Fair " ; " Poor " ; " Risky " ; ] )
let transaction_concept = mk_bmd_concept " transaction " ( Some " business event " ) ( mk_bmd_rec [ ( " acount " , mk_bmd_ref " account " ) ; ( " amount " , mk_bmd_real ( ) ) ; ( " country code " , mk_bmd_string ( ) ) ; ] )
let authorization_response_concept = mk_bmd_concept " authorization response " ( Some " business event " ) ( mk_bmd_rec [ ( " account " , mk_bmd_ref " account " ) ; ( " message " , mk_bmd_string ( ) ) ; ( " transaction " , mk_bmd_string ( ) ) ; ] )
let creditcard_schema = mk_bmd_schema [ account_concept ; account_status_concept ; transaction_concept ; authorization_response_concept ; ]
let rec find_fields cname spec = begin match spec with | [ ] | BC_concept _ :: _ | BC_enum _ :: _ -> [ ] | BC_field ( cname ' , fname , btype ) :: spec -> if ( cname ' = cname ) then ( fname , btype ) :: ( find_fields cname spec ) else ( find_fields cname spec ) end
let bmd_rec_of_fields fields = mk_bmd_rec fields
let bmd_concept_of_concept spec cname1 cname2 = let fields = find_fields cname1 spec in mk_bmd_concept cname1 cname2 ( bmd_rec_of_fields fields )
let bmd_concept_of_enum cname enumlist = mk_bmd_concept cname None ( mk_bmd_enum enumlist )
let rec bmd_concepts_of_spec spec = begin match spec with | [ ] -> [ ] | BC_concept ( cname1 , cname2 ) :: spec -> ( bmd_concept_of_concept spec cname1 cname2 ) :: ( bmd_concepts_of_spec spec ) | BC_enum ( cname , enumlist ) :: spec -> ( bmd_concept_of_enum cname enumlist ) ::...
let bmd_schema_of_spec spec = mk_bmd_schema ( bmd_concepts_of_spec spec )
let entity_value_of_bmd c = let ( en , clean_en ) = c in let syns = [ clean_en ; " the " ^ clean_en ] in { e_val_value = en ; e_val_metadata = None ; e_val_synonyms = syns ; e_val_created = None ; e_val_updated = None ; }
let process_bmd_fields_from_type btype = begin match btype with | BT_rec rtype -> List . map fst rtype | BT_string | BT_int | BT_real | BT_boolean | BT_date | BT_duration | BT_enum _ | BT_ref _ -> [ ] end
let process_bmd_enums_from_type btype = begin match btype with | BT_enum encontent -> encontent | BT_rec _ | BT_string | BT_int | BT_real | BT_boolean | BT_date | BT_duration | BT_ref _ -> [ ] end
let bmd_type_of_concept c = let ( _ , _ , bt ) = c . concept_desc in bt
let bmd_name_of_concept c = let ( bn , _ , _ ) = c . concept_desc in bn
let process_bmd_fields bmd = let fields = List . concat ( List . map ( fun x -> process_bmd_fields_from_type ( bmd_type_of_concept x ) . type_desc ) bmd ) in process_entities fields
let process_bmd_enums bmd = let fields = List . concat ( List . map ( fun x -> process_bmd_enums_from_type ( bmd_type_of_concept x ) . type_desc ) bmd ) in process_entities fields
let process_bmd_entities bmd = let entities = List . map bmd_name_of_concept bmd in process_entities entities
let entity_values_of_bmd bmd = List . map entity_value_of_bmd bmd
let entities_of_bmd ( bmd : bmd_schema ) = let entity_of_bmd_entity = { e_def_entity = " entity " ; e_def_description = None ; e_def_source = None ; e_def_open_list = None ; e_def_values = entity_values_of_bmd ( process_bmd_entities bmd . schema_desc ) ; e_def_created = None ; e_def...
let patch_workspace_with_bmd ws bmd = { ws with ws_entities = entities_of_bmd bmd ; }
let patch_io_in workspace obmd = begin match obmd with | None -> workspace | Some bmd -> patch_workspace_with_bmd workspace bmd end
let patch_wcs_workspace wcs_cred ws_id ws_name bmd = let ws = Wcs . workspace ws_name ~ entities ( : entities_of_bmd bmd ) ( ) in Wcs_call . update_workspace wcs_cred ws_id ws
let bmd_find_entity entity_def_list entity_name = List . find ( fun x -> x . e_def_entity = entity_name ) entity_def_list
let bmd_getentity_values bmd entity_name = try List . map ( fun ( x : Wcs_j . entity_value ) -> x . e_val_value ) ( ( bmd_find_entity ( entities_of_bmd bmd ) entity_name ) . e_def_values ) with Not_found -> [ ]
type t = string list
let is_empty = function [ ] -> true | _ -> false