text
stringlengths
0
601k
module Variable = struct module Internal = struct type t = { assigns_to_wire : Signal . t ; default : Signal . t } end type internal = Internal . t type t = { value : Signal . t ; internal : Internal . t } [ @@ deriving fields ] let sexp_of_t { value ; internal = _ } = [ % message " " ~ _ ( : value : Signal . t ) ] let...
type t = | Assign of Variable . t * Signal . t | If of Signal . t * t list * t list | Switch of Signal . t * ( Signal . t * t list ) list
type always = t [ @@ deriving sexp_of ]
type ' a case = ' a * t list [ @@ deriving sexp_of ]
type ' a cases = ' a case list [ @@ deriving sexp_of ]
let if_ sel on_true on_false = If ( sel , on_true , on_false )
let elif c t f = [ if_ c t f ]
let when_ sel on_true = if_ sel on_true [ ]
let unless sel on_false = if_ sel [ ] on_false
let switch sel cases = Switch ( sel , cases )
let proc s = if_ Signal . vdd s [ ]
let ( <-- ) ( a : Variable . t ) b = if Signal . width a . value <> Signal . width b then raise_s [ % message " attempt to assign expression to [ Always . variable ] of different width " ~ variable_name ( : Signal . names a . value : string list ) ~ guared_variable_width ( : Signal . width a . value : int ) ~ expressio...
let ( . <-- ) ( a : Variable . t ) b = a <-- Signal . of_int ~ width ( : Signal . width a . value ) b
let list_of_set s = Set . fold s ~ init [ ] : ~ f ( : fun l e -> e :: l )
let rec find_targets set statements = List . fold statements ~ init : set ~ f ( : fun set statement -> match statement with | Assign ( variable , _ ) -> Set . add set variable | If ( _ , t , f ) -> let set = find_targets set t in find_targets set f | Switch ( _ , cases ) -> List . fold cases ~ init : set ~ f ( : fun se...
let filter_by_target variable statements = let rec loops statements = List . filter_map statements ~ f : loop and loop statement = match statement with | Assign ( v , _ ) -> if Variable . equal v variable then Some statement else None | If ( s , t , f ) -> let t = loops t in let f = loops f in if List . is_empty t && L...
let rec compile_mux statements ~ default = match statements with | [ ] -> default | statement :: statements -> let default = match statement with | If ( s , t , f ) -> let s = Signal . reduce ~ f : Signal . ( |: ) ( Signal . bits_msb s ) in let t = compile_mux t ~ default in let f = compile_mux f ~ default in Signal . ...
let compile statements = let targets = list_of_set ( find_targets ( Set . empty ( module Variable ) ) statements ) in List . iter targets ~ f ( : fun target -> let statements = filter_by_target target statements in Signal . ( <== ) target . internal . assigns_to_wire ( compile_mux statements ~ default : target . intern...
module State_machine = struct type ' a t = { current : Signal . t ; is : ' a -> Signal . t ; set_next : ' a -> always ; switch : ? default : always list -> ' a cases -> always } [ @@ deriving sexp_of ] module Encoding = struct type t = | Binary | Gray | Onehot [ @@ deriving sexp_of ] let to_string t = [ % sexp ( t : t ...
type dep_type = System | Internal
type dependency_tag = Target of Name . t | Dependency of Libname . t
type cpkg_config = { cpkg_conf_libs : string list ; cpkg_conf_includes : filepath list }
type project_config = { project_dep_data : ( Libname . t , dep_type ) Hashtbl . t ; project_pkgdeps_dag : dependency_tag Dag . t ; project_targets_dag : Name . t Dag . t ; project_all_deps : dependency list ; project_file : Project . t ; project_ocamlcfg : ( string , string ) Hashtbl . t ; project_ocamlmkcfg : ( string...
let get_ocaml_config_key_hashtbl key h = try Hashtbl . find h key with Not_found -> raise ( OcamlConfigMissing key )
let getOcamlConfigKey key = get_ocaml_config_key_hashtbl key ( Prog . getOcamlConfig ( ) )
let get_ocaml_config_key key project = get_ocaml_config_key_hashtbl key project . project_ocamlcfg
let get_pkg_deps target project = let pkgs = Taskdep . linearize project . project_pkgdeps_dag Taskdep . FromParent [ Target target . target_name ] in List . rev ( list_filter_map ( fun pkg -> match pkg with Dependency d -> Some d | Target _ -> None ) pkgs )
let get_c_pkg cname project = try Hashtbl . find project . project_cpkgs cname with Not_found -> failwith ( sprintf " C package % s not found in the hashtbl : internal error " cname )
let is_pkg_internal project pkg = Hashtbl . find project . project_dep_data pkg = Internal
let is_pkg_system project pkg = Hashtbl . find project . project_dep_data pkg = System
let get_internal_library_deps project target = let internalDeps = Dag . getChildren project . project_targets_dag target . target_name in list_filter_map ( fun name -> match name with | Name . Lib lname -> Some lname | _ -> None ) internalDeps
let initializeSystemStdlib ocamlCfg = let ocaml_ver = Hashtbl . find ( Prog . getOcamlConfig ( ) ) " version " in let stdlibPath = fp ( get_ocaml_config_key_hashtbl " standard_library " ocamlCfg ) in let stdlibLibs = Filesystem . list_dir_pred_map ( fun n -> let ext = Filetype . of_filename n in if ext = Filetype . Fil...
let readOcamlMkConfig filename = let lines = Utils . read_file_with ( function " " -> None | s when s . [ 0 ] = ' ' # -> None | s -> Some s ) ( filename ^ " / Makefile . config " ) in let h = Hashtbl . create 32 in List . iter ( fun l -> let ( k , v ) = Utils . toKVeq l in Hashtbl . add h ( String . lowercase k ) ( def...
let prepare projFile user_flags = verbose Verbose " analyzing project \ n " ; %! let ocamlCfg = Prog . getOcamlConfig ( ) in let ocamlMkCfg = readOcamlMkConfig ( Hashtbl . find ocamlCfg " standard_library " ) in let depsTable = Hashtbl . create 16 in let cpkgsTable = Hashtbl . create 1 in let depsDag = Dag . init ( ) i...
module _ = struct let x = 13 , 37 end
module rec A : sig type t = B . t type t = A . t val x : int * int type t = B . t let x = 4 , 2 end type t type t let x = " foo " , " bar " end
let f ( module _ : S ) = ( )
type re = { mutable cell : string ; }
let s = { cell = " " }
module _ = struct let ( ) = s . cell <- " Hello World " ! end
let drop _ = ( )
let ( ) = drop s . cell
let malformed_string s = Format . kasprintf invalid_arg " Terminal . Ansi : malformed UTF - 8 string : % S " s
module Length_counter = struct type t = { mutable acc : int ; mutable state : [ ` Normal | ` Parsing_ansi_sequence | ` Ansi_parameter_bytes ] } let empty ( ) = { acc = 0 ; state = ` Normal } let is_initial_ansi_byte c = Char . equal c ' \ x1b ' let is_final_ansi_byte c = let c = Char . code c in c >= 0x40 && c <= 0x7e ...
let guess_printed_width s = let count = Length_counter . empty ( ) in Uutf . String . fold_utf_8 ( fun ( ) _ -> function | ` Malformed _ -> malformed_string s | ` Uchar c -> Length_counter . add count c ) ( ) s ; Length_counter . count count
let uchar_size u = match Uchar . to_int u with | u when u < 0 -> assert false | u when u <= 0x007F -> 1 | u when u <= 0x07FF -> 2 | u when u <= 0xFFFF -> 3 | u when u <= 0x10FFFF -> 4 | _ -> assert false
let string_equal : string -> string -> bool = ( = )
let truncate_to_width width s = if width < 0 then Format . kasprintf invalid_arg " Terminal . truncate_to_width : negative width % d requested " width ; let count = Length_counter . empty ( ) in try Uutf . String . fold_utf_8 ( fun ( ) i -> function | ` Malformed _ -> malformed_string s | ` Uchar c -> if Length_counter...
let move_up ppf = function 0 -> ( ) | n -> Format . fprintf ppf " \ x1b [ % dA " n
let move_down ppf = function 0 -> ( ) | n -> Format . fprintf ppf " \ x1b [ % dB " n
let apigw_response = ( module struct type t = Http . api_gateway_proxy_response let pp formatter t = Format . pp_print_text formatter ( t |> Http . API_gateway_response . to_yojson |> Lwt_main . run |> Yojson . Safe . pretty_to_string ) let equal = ( = ) end : Alcotest . TESTABLE with type t = Http . api_gateway_proxy_...
module Http_runtime = struct include Http type event = Http . API_gateway_request . t type response = Http . API_gateway_response . t end
let request = Test_common . make_test_request ( module Http . API_gateway_request ) " apigw_real "
let test_fixture = Test_common . test_fixture ( module Http . API_gateway_request )
let test_runtime = test_runtime_generic ( module Http_runtime ) ~ lift : Lwt . return request
let test_async_runtime = test_runtime_generic ( module Http_runtime ) ~ lift : id request
let response = Http . { status_code = 200 ; headers = StringMap . empty ; body = " Hello " ; is_base64_encoded = false }
let suite = [ " deserialize ( mock ) API Gateway Proxy Request " , ` Quick , test_fixture " apigw " ; ( " deserialize ( real world ) API Gateway Proxy Request " , ` Quick , test_fixture " apigw_real_trimmed " ) ; ( " successful handler invocation " , ` Quick , test_runtime ( fun _event _ctx -> Ok response ) ( fun outpu...
module Model = struct type t = unit [ @@ deriving sexp ] let init ( ) = ( ) let cutoff _ _ = true end
module Action = struct type t = unit [ @@ deriving sexp ] let should_log _ = true end
module State = struct type t = unit end
let apply_action _ _ _ ~ schedule_action : _ = ( )
let on_startup ~ schedule_action : _ _ = Async_kernel . return ( )
let view_resize_observer = let widget_id = Type_equal . Id . create ~ name " : my widget type " ( fun ( _ : ResizeObserver . resizeObserver Js . t * Dom_html . element Js . t ) -> Sexp . Atom " < resize - observer - widget " ) > in Vdom . Node . widget ~ id : widget_id ~ init ( : fun ( ) -> let div = Dom_html . documen...
let view_colorize_button = let widget_id = Type_equal . Id . create ~ name " : my widget type " ( fun _ -> Sexp . Atom " < my widget type " ) > in Vdom . Node . widget ~ id : widget_id ~ init ( : fun ( ) -> let button = Dom_html . document ## createElement ( " button " |> Js . string ) in button . ## innerHTML := " < b...
let raw_html = Vdom . Node . inner_html ~ tag " : div " ~ attr : Vdom . Attr . empty ~ this_html_is_sanitized_and_is_totally_safe_trust_me " :< b > bold </ b " > ; ;
let view _ ~ inject : _ = Incr . return ( Vdom . Node . div [ view_colorize_button ; view_resize_observer ; raw_html ] ) ; ;
let create model ~ old_model : _ ~ inject = let open Incr . Let_syntax in let % map apply_action = let % map model = model in apply_action model and view = view model ~ inject and model = model in Component . create ~ apply_action model view ; ;
type t = { k : Continuation . t ; args : Simple . t list ; trap_action : Trap_action . Option . t ; dbg : Debuginfo . t }
let print_or_elide_debuginfo ppf dbg = if Debuginfo . is_none dbg then Format . pp_print_string ppf " " else begin Format . pp_print_string ppf " " ; Debuginfo . print_compact ppf dbg end type nonrec t = t let [ @ ocamlformat " disable " ] print ppf { k ; args ; trap_action ; dbg ; } = let name , trap_action = match Co...
let create ? trap_action k ~ args ~ dbg = { k ; args ; trap_action ; dbg }
let goto k = { k ; args = [ ] ; trap_action = None ; dbg = Debuginfo . none }
let continuation t = t . k
let args t = t . args
let trap_action t = t . trap_action
let debuginfo t = t . dbg
let free_names { k ; args ; trap_action ; dbg = _ } = let default = Simple . List . free_names args in match trap_action with | None -> Name_occurrences . add_continuation default k ~ has_traps : false | Some trap_action -> Name_occurrences . add_continuation ( Name_occurrences . union default ( Trap_action . free_name...
let apply_renaming ( { k ; args ; trap_action ; dbg } as t ) perm = let k ' = Renaming . apply_continuation perm k in let args ' = Simple . List . apply_renaming args perm in let trap_action ' = Trap_action . Option . apply_renaming trap_action perm in if k == k ' && args == args ' && trap_action == trap_action ' then ...
let all_ids_for_export { k ; args ; trap_action ; dbg = _ } = List . fold_left ( fun ids arg -> Ids_for_export . add_simple ids arg ) ( Ids_for_export . add_continuation ( Trap_action . Option . all_ids_for_export trap_action ) k ) args
let update_continuation t continuation = { t with k = continuation }
let update_continuation_and_args t cont ~ args = if Continuation . equal t . k cont && args == t . args then t else { t with k = cont ; args }
let update_args t ~ args = if args == t . args then t else { t with args }
let with_debuginfo t ~ dbg = if dbg == t . dbg then t else { t with dbg }
let no_args t = match args t with [ ] -> true | _ :: _ -> false
let is_goto t = no_args t && Option . is_none ( trap_action t )
let is_goto_to t k = Continuation . equal ( continuation t ) k && is_goto t
let to_goto t = if no_args t && Option . is_none ( trap_action t ) then Some ( continuation t ) else None
let is_raise t = match t . trap_action with | Some ( Pop { exn_handler ; _ } ) -> Continuation . equal t . k exn_handler | Some ( Push _ ) | None -> false
let clear_trap_action t = { t with trap_action = None }
let to_one_arg_without_trap_action t = match t . trap_action with | Some _ -> None | None -> ( match t . args with [ arg ] -> Some arg | [ ] | _ :: _ :: _ -> None )
type used = | Used | Unused
type t = { original_params : Bound_parameters . t ; used_params : BP . Set . t ; used_extra_params : Bound_parameters . t ; extra_args : ( EA . t * used ) list Id . Map . t }
let print_used ppf = function | Used -> ( ) | Unused -> Format . fprintf ppf " @ unused "
let print_ea_used ppf t = Format . fprintf ppf " ( % a ) " ( Format . pp_print_list ~ pp_sep : Format . pp_print_space ( fun ppf ( ea , used ) -> Format . fprintf ppf " % a % a " EA . print ea print_used used ) ) t
let [ @ ocamlformat " disable " ] print ppf { original_params ; used_params ; used_extra_params ; extra_args ; } = Format . fprintf ppf " [ @< hov 1 ( >\ [ @< hov 1 ( > original_params @ ( % a ) ) ] @@ \ [ @< hov 1 ( > used_params @ % a ) ] @@ \ [ @< hov 1 ( > used_extra_params @ ( % a ) ) ] @@ \ [ @< hov 1 ( > extra_a...
let does_nothing t = Bound_parameters . cardinal t . original_params = BP . Set . cardinal t . used_params && Id . Map . is_empty t . extra_args
let create ~ original_params ~ used_params ~ extra_params ~ extra_args ~ used_extra_params = Bound_parameters . check_no_duplicates original_params ; Bound_parameters . check_no_duplicates extra_params ; if Bound_parameters . cardinal original_params < BP . Set . cardinal used_params then Misc . fatal_errorf " Must hav...
let original_params t = t . original_params
let used_params t = t . used_params
let used_extra_params t = t . used_extra_params