text
stringlengths
12
786k
let insert str idx sub = let a , b = break str idx in concat3 a sub b
let remove str idx len = if idx < 0 || len < 0 then raise Out_of_bounds else let ofs1 = move_l str 0 idx in let ofs2 = move_l str ofs1 len in unsafe_sub str 0 ofs1 ^ unsafe_sub str ofs2 ( String . length str - ofs2 ) ofs2
let replace str idx len repl = if idx < 0 || len < 0 then raise Out_of_bounds else let ofs1 = move_l str 0 idx in let ofs2 = move_l str ofs1 len in concat3 ( unsafe_sub str 0 ofs1 ) ofs1 repl ( unsafe_sub str ofs2 ( String . length str - ofs2 ) ofs2 ) ofs2
let rec rev_rec ( res : Bytes . t ) t str ofs_src ofs_dst = if ofs_src = String . length str then Bytes . unsafe_to_string res else begin let ofs_src ' = unsafe_next str ofs_src in let len = ofs_src ' - ofs_src in let ofs_dst = ofs_dst - len in String . unsafe_blit str ofs_src res ofs_dst len ; rev_rec res str ofs_src ' ofs_dst end
let rev str = let len = String . length str in rev_rec ( Bytes . create len ) len str 0 len
let concat sep l = match l with | [ ] -> " " | x :: l -> let sep_len = String . length sep in let len = List . fold_left ( fun len str -> len + sep_len + String . length str ) str ( String . length x ) x l in let res = Bytes . create len in String . unsafe_blit x 0 res 0 ( String . length x ) x ; ignore ( List . fold_left ( fun ofs str -> String . unsafe_blit sep 0 res ofs sep_len ; let ofs = ofs + sep_len in let len = String . length str in String . unsafe_blit str 0 res ofs len ; ofs + len ) len ( String . length x ) x l ) l ; Bytes . unsafe_to_string res
let rev_concat sep l = match l with | [ ] -> " " | x :: l -> let sep_len = String . length sep in let len = List . fold_left ( fun len str -> len + sep_len + String . length str ) str ( String . length x ) x l in let res = Bytes . create len in let ofs = len - String . length x in String . unsafe_blit x 0 res ofs ( String . length x ) x ; ignore ( List . fold_left ( fun ofs str -> let ofs = ofs - sep_len in String . unsafe_blit sep 0 res ofs sep_len ; let len = String . length str in let ofs = ofs - len in String . unsafe_blit str 0 res ofs len ; ofs ) ofs ofs l ) l ; Bytes . unsafe_to_string res
let rec explode_rec str ofs acc = if ofs = 0 then acc else let x , ofs = unsafe_extract_prev str ofs in explode_rec str ofs ( x :: acc ) acc
let explode str = explode_rec str ( String . length str ) str [ ]
let rec rev_explode_rec str ofs acc = if ofs = String . length str then acc else let x , ofs = unsafe_extract_next str ofs in rev_explode_rec str ofs ( x :: acc ) acc
let rev_explode str = rev_explode_rec str 0 [ ]
let implode l = let l = List . map singleton l in let len = List . fold_left ( fun len str -> len + String . length str ) str 0 l in let res = Bytes . create len in ignore ( List . fold_left ( fun ofs str -> let len = String . length str in String . unsafe_blit str 0 res ofs len ; ofs + len ) len 0 l ) l ; Bytes . unsafe_to_string res
let rev_implode l = let l = List . map singleton l in let len = List . fold_left ( fun len str -> len + String . length str ) str 0 l in let res = Bytes . create len in ignore ( List . fold_left ( fun ofs str -> let len = String . length str in let ofs = ofs - len in String . unsafe_blit str 0 res ofs len ; ofs ) ofs len l ) l ; Bytes . unsafe_to_string res
let rec iter_rec f str ofs = if ofs = String . length str then ( ) else begin let chr , ofs = unsafe_extract_next str ofs in f chr ; iter_rec f str ofs end
let iter f str = iter_rec f str 0
let rec rev_iter_rec f str ofs = if ofs = 0 then ( ) else begin let chr , ofs = unsafe_extract_prev str ofs in f chr ; rev_iter_rec f str ofs end
let rev_iter f str = rev_iter_rec f str ( String . length str ) str
let rec fold_rec f str ofs acc = if ofs = String . length str then acc else begin let chr , ofs = unsafe_extract_next str ofs in fold_rec f str ofs ( f chr acc ) acc end
let fold f str acc = fold_rec f str 0 acc
let rec rev_fold_rec f str ofs acc = if ofs = 0 then acc else begin let chr , ofs = unsafe_extract_prev str ofs in rev_fold_rec f str ofs ( f chr acc ) acc end
let rev_fold f str acc = rev_fold_rec f str ( String . length str ) str acc
let rec map_rec buf f str ofs = if ofs = String . length str then Buffer . contents buf else begin let chr , ofs = unsafe_extract_next str ofs in Buffer . add_string buf ( singleton ( f chr ) chr ) chr ; map_rec buf f str ofs end
let map f str = map_rec ( Buffer . create ( String . length str ) str ) str f str 0
let rec map_concat_rec buf f str ofs = if ofs = String . length str then Buffer . contents buf else begin let chr , ofs = unsafe_extract_next str ofs in Buffer . add_string buf ( f chr ) chr ; map_concat_rec buf f str ofs end
let map_concat f str = map_concat_rec ( Buffer . create ( String . length str ) str ) str f str 0
let rec rev_map_rec buf f str ofs = if ofs = 0 then Buffer . contents buf else begin let chr , ofs = unsafe_extract_prev str ofs in Buffer . add_string buf ( singleton ( f chr ) chr ) chr ; rev_map_rec buf f str ofs end
let rev_map f str = rev_map_rec ( Buffer . create ( String . length str ) str ) str f str ( String . length str ) str
let rec rev_map_concat_rec buf f str ofs = if ofs = 0 then Buffer . contents buf else begin let chr , ofs = unsafe_extract_prev str ofs in Buffer . add_string buf ( f chr ) chr ; rev_map_concat_rec buf f str ofs end
let rev_map_concat f str = rev_map_concat_rec ( Buffer . create ( String . length str ) str ) str f str ( String . length str ) str
let rec filter_rec buf f str ofs = if ofs = String . length str then Buffer . contents buf else begin let chr , ofs = unsafe_extract_next str ofs in if f chr then Buffer . add_string buf ( singleton chr ) chr ; filter_rec buf f str ofs end
let filter f str = filter_rec ( Buffer . create ( String . length str ) str ) str f str 0
let rec rev_filter_rec buf f str ofs = if ofs = 0 then Buffer . contents buf else begin let chr , ofs = unsafe_extract_prev str ofs in if f chr then Buffer . add_string buf ( singleton chr ) chr ; rev_filter_rec buf f str ofs end
let rev_filter f str = rev_filter_rec ( Buffer . create ( String . length str ) str ) str f str ( String . length str ) str
let rec filter_map_rec buf f str ofs = if ofs = String . length str then Buffer . contents buf else begin let chr , ofs = unsafe_extract_next str ofs in ( match f chr with | Some chr -> Buffer . add_string buf ( singleton chr ) chr | None -> ( ) ) ; filter_map_rec buf f str ofs end
let filter_map f str = filter_map_rec ( Buffer . create ( String . length str ) str ) str f str 0
let rec filter_map_concat_rec buf f str ofs = if ofs = String . length str then Buffer . contents buf else begin let chr , ofs = unsafe_extract_next str ofs in ( match f chr with | Some txt -> Buffer . add_string buf txt | None -> ( ) ) ; filter_map_concat_rec buf f str ofs end
let filter_map_concat f str = filter_map_concat_rec ( Buffer . create ( String . length str ) str ) str f str 0
let rec rev_filter_map_rec buf f str ofs = if ofs = 0 then Buffer . contents buf else begin let chr , ofs = unsafe_extract_prev str ofs in ( match f chr with | Some chr -> Buffer . add_string buf ( singleton chr ) chr | None -> ( ) ) ; rev_filter_map_rec buf f str ofs end
let rev_filter_map f str = rev_filter_map_rec ( Buffer . create ( String . length str ) str ) str f str ( String . length str ) str
let rec rev_filter_map_concat_rec buf f str ofs = if ofs = 0 then Buffer . contents buf else begin let chr , ofs = unsafe_extract_prev str ofs in ( match f chr with | Some txt -> Buffer . add_string buf txt | None -> ( ) ) ; rev_filter_map_concat_rec buf f str ofs end
let rev_filter_map_concat f str = rev_filter_map_concat_rec ( Buffer . create ( String . length str ) str ) str f str ( String . length str ) str
let rec for_all_rec f str ofs = if ofs = String . length str then true else let chr , ofs = unsafe_extract_next str ofs in f chr && for_all_rec f str ofs
let for_all f str = for_all_rec f str 0
let rec exists_rec f str ofs = if ofs = String . length str then false else let chr , ofs = unsafe_extract_next str ofs in f chr || exists_rec f str ofs
let exists f str = exists_rec f str 0
let rec count_rec f str ofs n = if ofs = String . length str then n else let chr , ofs = unsafe_extract_next str ofs in count_rec f str ofs ( if f chr then n + 1 else n ) n
let count f str = count_rec f str 0 0
let rec unsafe_sub_equal str ofs sub ofs_sub = if ofs_sub = String . length sub then true else ( String . unsafe_get str ofs = String . unsafe_get sub ofs_sub ) ofs_sub && unsafe_sub_equal str ( ofs + 1 ) 1 sub ( ofs_sub + 1 ) 1
let rec contains_rec str sub ofs = if ofs + String . length sub > String . length str then false else unsafe_sub_equal str ofs sub 0 || contains_rec str sub ( unsafe_next str ofs ) ofs
let contains str sub = contains_rec str sub 0
let starts_with str prefix = if String . length prefix > String . length str then false else unsafe_sub_equal str 0 prefix 0
let ends_with str suffix = let ofs = String . length str - String . length suffix in if ofs < 0 then false else unsafe_sub_equal str ofs suffix 0
let rec lfind predicate str ofs = if ofs = String . length str then ofs else let chr , ofs ' = unsafe_extract_next str ofs in if predicate chr then lfind predicate str ofs ' else ofs
let rec rfind predicate str ofs = if ofs = 0 then 0 else let chr , ofs ' = unsafe_extract_prev str ofs in if predicate chr then rfind predicate str ofs ' else ofs
let spaces = UCharInfo . load_property_tbl ` White_Space
let is_space ch = UCharTbl . Bool . get spaces ch
let strip ( ? predicate = is_space ) is_space str = let lofs = lfind predicate str 0 and rofs = rfind predicate str ( String . length str ) str in if lofs < rofs then unsafe_sub str lofs ( rofs - lofs ) lofs else " "
let lstrip ( ? predicate = is_space ) is_space str = let lofs = lfind predicate str 0 in unsafe_sub str lofs ( String . length str - lofs ) lofs
let rstrip ( ? predicate = is_space ) is_space str = let rofs = rfind predicate str ( String . length str ) str in unsafe_sub str 0 rofs
let lchop = function | " " -> " " | str -> let ofs = unsafe_next str 0 in unsafe_sub str ofs ( String . length str - ofs ) ofs
let rchop = function | " " -> " " | str -> let ofs = unsafe_prev str ( String . length str ) str in unsafe_sub str 0 ofs
let add buf char = let code = UChar . code char in if code < 0x80 then Buffer . add_char buf ( Char . unsafe_chr code ) code else if code <= 0x800 then begin Buffer . add_char buf ( Char . unsafe_chr ( ( code lsr 6 ) 6 lor 0xc0 ) 0xc0 ) 0xc0 ; Buffer . add_char buf ( Char . unsafe_chr ( ( code land 0x3f ) 0x3f lor 0x80 ) 0x80 ) 0x80 end else if code <= 0x10000 then begin Buffer . add_char buf ( Char . unsafe_chr ( ( code lsr 12 ) 12 lor 0xe0 ) 0xe0 ) 0xe0 ; Buffer . add_char buf ( Char . unsafe_chr ( ( ( code lsr 6 ) 6 land 0x3f ) 0x3f lor 0x80 ) 0x80 ) 0x80 ; Buffer . add_char buf ( Char . unsafe_chr ( ( code land 0x3f ) 0x3f lor 0x80 ) 0x80 ) 0x80 end else if code <= 0x10ffff then begin Buffer . add_char buf ( Char . unsafe_chr ( ( code lsr 18 ) 18 lor 0xf0 ) 0xf0 ) 0xf0 ; Buffer . add_char buf ( Char . unsafe_chr ( ( ( code lsr 12 ) 12 land 0x3f ) 0x3f lor 0x80 ) 0x80 ) 0x80 ; Buffer . add_char buf ( Char . unsafe_chr ( ( ( code lsr 6 ) 6 land 0x3f ) 0x3f lor 0x80 ) 0x80 ) 0x80 ; Buffer . add_char buf ( Char . unsafe_chr ( ( code land 0x3f ) 0x3f lor 0x80 ) 0x80 ) 0x80 end else invalid_arg " Zed_utf8 . add "
let extract str ofs = if ofs < 0 || ofs >= String . length str then raise Out_of_bounds else unsafe_extract str ofs
let next str ofs = if ofs < 0 || ofs >= String . length str then raise Out_of_bounds else unsafe_next str ofs
let extract_next str ofs = if ofs < 0 || ofs >= String . length str then raise Out_of_bounds else unsafe_extract_next str ofs
let prev str ofs = if ofs <= 0 || ofs > String . length str then raise Out_of_bounds else unsafe_prev str ofs
let extract_prev str ofs = if ofs <= 0 || ofs > String . length str then raise Out_of_bounds else unsafe_extract_prev str ofs
let alphabetic = UCharInfo . load_property_tbl ` Alphabetic
let escaped_char ch = match UChar . code ch with | 7 -> " \\ a " | 8 -> " \\ b " | 9 -> " \\ t " | 10 -> " \\ n " | 11 -> " \\ v " | 12 -> " \\ f " | 13 -> " \\ r " | 27 -> " \\ e " | 92 -> " " \\\\ | code when code >= 32 && code <= 126 -> String . make 1 ( Char . chr code ) code | _ when UCharTbl . Bool . get alphabetic ch -> singleton ch | code when code <= 127 -> Printf . sprintf " \\ x % 02x " code | code when code <= 0xffff -> Printf . sprintf " \\ u % 04x " code | code -> Printf . sprintf " \\ U % 06x " code
let add_escaped_char buf ch = match UChar . code ch with | 7 -> Buffer . add_string buf " \\ a " | 8 -> Buffer . add_string buf " \\ b " | 9 -> Buffer . add_string buf " \\ t " | 10 -> Buffer . add_string buf " \\ n " | 11 -> Buffer . add_string buf " \\ v " | 12 -> Buffer . add_string buf " \\ f " | 13 -> Buffer . add_string buf " \\ r " | 27 -> Buffer . add_string buf " \\ e " | 92 -> Buffer . add_string buf " " \\\\ | code when code >= 32 && code <= 126 -> Buffer . add_char buf ( Char . chr code ) code | _ when UCharTbl . Bool . get alphabetic ch -> add buf ch | code when code <= 127 -> Printf . bprintf buf " \\ x % 02x " code | code when code <= 0xffff -> Printf . bprintf buf " \\ u % 04x " code | code -> Printf . bprintf buf " \\ U % 06x " code
let escaped str = let buf = Buffer . create ( String . length str ) str in iter ( add_escaped_char buf ) buf str ; Buffer . contents buf
let add_escaped buf str = iter ( add_escaped_char buf ) buf str
let add_escaped_string buf enc str = match try Some ( CharEncoding . recode_string ~ in_enc : enc ~ out_enc : CharEncoding . utf8 str ) str with CharEncoding . Malformed_code -> None with | Some str -> add_escaped buf str | None -> String . iter ( function | ' \ x20 ' . . ' \ x7e ' as ch -> Buffer . add_char buf ch | ch -> Printf . bprintf buf " \\ y % 02x " ( Char . code ch ) ch ) ch str
let escaped_string enc str = let buf = Buffer . create ( String . length str ) str in add_escaped_string buf enc str ; Buffer . contents buf
module Convert ( ConvertUS : UnicodeString . Type ) Type = struct let of_list l = let buf = US . Buf . create 0 in let rec convert l = match l with | [ ] -> ( ) | c :: tl -> US . Buf . add_char buf c ; convert tl in convert l ; US . Buf . contents buf let of_array a = let buf = US . Buf . create 0 in for i = 0 to Array . length a - 1 do US . Buf . add_char buf a ( . i ) i done ; US . Buf . contents buf let to_uChars us = let first = US . first us and last = US . last us in let length = US . length us in let rec create acc i = if US . compare_index us i first >= 0 then create ( US . look us i :: acc ) acc ( US . prev us i ) i else acc in if length > 0 then create [ ] last else [ ] end
let array_rev a = let len = Array . length a - 1 in Array . init len ( fun i -> a ( . len - i ) i ) i
let rec list_compare ( ? compare = compare ) compare l1 l2 = match l1 , l2 with | [ ] , [ ] -> 0 | [ ] , _ -> - 1 | _ , [ ] -> 1 | h1 :: t1 , h2 :: t2 -> match compare h1 h2 with | 0 -> list_compare ~ compare t1 t2 | _ as r -> r
let array_compare ( ? compare = compare ) compare a1 a2 = let len1 = Array . length a1 and len2 = Array . length a2 in let rec compare_aux pos = let remain1 = len1 - pos and remain2 = len2 - pos in if remain1 <= 0 && remain2 <= 0 then 0 else if remain1 <= 0 && remain2 > 0 then - 1 else if remain1 > 0 && remain2 <= 0 then 1 else match compare a1 ( . pos ) pos a2 ( . pos ) pos with | 0 -> compare_aux ( pos + 1 ) 1 | _ as r -> r in compare_aux 0
let compile file = Modules . clear ( ) ; if ! no_stdlib then set_no_stdlib ( ) ; if Filename . check_suffix file " . zls " || Filename . check_suffix file " . zlus " then let filename = Filename . chop_extension file in let modname = String . capitalize_ascii ( Filename . basename filename ) in compile modname filename else if Filename . check_suffix file " . zli " then let filename = Filename . chop_suffix file " . zli " in let modname = String . capitalize_ascii ( Filename . basename filename ) in interface modname filename else if Filename . check_suffix file " . mli " then let filename = Filename . chop_suffix file " . mli " in let modname = String . capitalize_ascii ( Filename . basename filename ) in scalar_interface modname filename else raise ( Arg . Bad ( " don ' t know what to do with " ^ file ) )
let build file = Deps_tools . add_to_load_path Filename . current_dir_name ; let rec _build acc file = let deps = match ( Filename . extension file ) with | " . zls " -> Deps_tools . zls_dependencies file | " . zli " -> Deps_tools . zli_dependencies file | _ -> raise ( Arg . Bad ( " don ' t know what to do with " ^ file ) ) in let acc = List . fold_left _build acc deps in let basename = Filename . chop_extension file in if not ( SS . mem basename acc ) then begin compile file ; SS . add basename acc end else acc in ignore ( _build ( SS . empty ) file )
let doc_verbose = " \ t Set verbose mode "
let doc_vverbose = " \ t Set even more verbose mode " " < node > \ t Simulates the node < node > and generates a file < out . > ml \ n \ \ t \ t where < out > is equal to the argument of - o if the flag \ n \ \ t \ t has been set , or < node > otherwise " " \ t Use lablgtk2 interface . "
let errmsg = " Options are " :
let set_verbose ( ) = verbose := true ; Printexc . record_backtrace true
let set_vverbose ( ) = vverbose := true ; set_verbose ( )
let add_include d = Deps_tools . add_to_load_path d ; load_path := d :: ! load_path
let set_gtk ( ) = use_gtk := true ; match ! load_path with | [ stdlib ] -> add_include ( stdlib ^ " - gtk " ) | _ -> ( )
let main ( ) = try Arg . parse ( Arg . align [ " - v " , Arg . Unit set_verbose , doc_verbose ; " - vv " , Arg . Unit set_vverbose , doc_vverbose ; " - version " , Arg . Unit show_version , doc_version ; " - o " , Arg . String set_outname , doc_outname ; " - I " , Arg . String add_include , doc_include ; " - i " , Arg . Set print_types , doc_print_types ; " - ic " , Arg . Set print_causality_types , doc_print_causality_types ; " - ii " , Arg . Set print_initialization_types , doc_print_initialization_types ; " - where " , Arg . Unit locate_stdlib , doc_locate_stdlib ; " - stdlib " , Arg . String set_stdlib , doc_stdlib ; " - nostdlib " , Arg . Set no_stdlib , doc_no_stdlib ; " - typeonly " , Arg . Set typeonly , doc_typeonly ; " - s " , Arg . String set_simulation_node , doc_simulation ; " - sampling " , Arg . Float set_sampling_period , doc_sampling ; " - check " , Arg . Int set_check , doc_check ; " - gtk2 " , Arg . Unit set_gtk , doc_use_gtk ; " - dzero " , Arg . Set dzero , doc_dzero ; " - nocausality " , Arg . Set no_causality , doc_nocausality ; " - nopt " , Arg . Set no_opt , doc_no_opt ; " - nodeadcode " , Arg . Set no_deadcode , doc_no_deadcode ; " - noinit " , Arg . Set no_initialisation , doc_noinitialisation ; " - inline " , Arg . Int set_inlining_level , doc_inlining_level ; " - inlineall " , Arg . Set inline_all , doc_inline_all ; " - nosimplify " , Arg . Set no_simplify_causality_type , doc_nosimplify ; " - noreduce " , Arg . Set no_reduce , doc_noreduce ; " - zsign " , Arg . Set zsign , doc_zsign ; " - copy " , Arg . Set with_copy , doc_with_copy ; " - lmm " , Arg . String set_lmm_nodes , doc_lmm ; " - rif " , Arg . Set use_rif , doc_rif ; " - deps " , Arg . Set build_deps , doc_deps ; ] ) ( fun filename -> if ! build_deps then build filename else compile filename ) errmsg ; begin match ! simulation_node with | Some ( name ) -> Simulator . main ! outname name ! sampling_period ! number_of_checks ! use_gtk | _ -> ( ) end with | Zmisc . Error -> exit 2 ; ;
type kind = S | A | C | D | AD | AS | P
type ' a localized = { desc : ' a ; loc : Zlocation . location }
type type_expression = type_expression_desc localized | Etypevar of string | Etypeconstr of Lident . t * type_expression list | Etypetuple of type_expression list | Etypevec of type_expression * size | Etypefun of kind * Zident . t option * type_expression * type_expression | Sconst of int | Sglobal of Lident . t | Sname of Zident . t | Sop of size_op * size * size
type interface = interface_desc localized | Einter_open of name | Einter_typedecl of name * name list * type_decl | Einter_constdecl of name * type_expression | Eabstract_type | Eabbrev of type_expression | Evariant_type of constr_decl list | Erecord_type of ( name * type_expression ) list | Econstr0decl of name | Econstr1decl of name * type_expression list | Eopen of name | Etypedecl of name * name list * type_decl | Econstdecl of name * is_static * exp | Efundecl of name * funexp { f_kind : kind ; f_atomic : is_atomic ; f_args : pattern list ; f_body : exp ; mutable f_env : Deftypes . tentry Zident . Env . t ; f_loc : location } { mutable e_desc : desc ; e_loc : location ; mutable e_typ : Deftypes . typ ; mutable e_caus : Defcaus . tc ; mutable e_init : Definit . ti ; } | Elocal of Zident . t | Eglobal of { lname : Lident . t ; typ_instance : Deftypes . typ_instance } | Econst of immediate | Econstr0 of Lident . t | Econstr1 of Lident . t * exp list | Elast of Zident . t | Eapp of app * exp * exp list | Eop of op * exp list | Etuple of exp list | Erecord_access of exp * Lident . t | Erecord of ( Lident . t * exp ) list | Erecord_with of exp * ( Lident . t * exp ) list | Etypeconstraint of exp * type_expression | Epresent of exp present_handler list * exp option | Ematch of total ref * exp * exp match_handler list | Elet of local * exp | Eseq of exp * exp | Eperiod of exp period | Eblock of eq list block * exp | Efby | Eunarypre | Eifthenelse | Eminusgreater | Eup | Einitial | Edisc | Ehorizon | Etest | Eaccess | Eupdate | Eslice of size * size | Econcat | Eatomic { p_phase : ' a option ; p_period : ' a } { mutable p_desc : pdesc ; p_loc : location ; mutable p_typ : Deftypes . typ ; mutable p_caus : Defcaus . tc ; mutable p_init : Definit . ti ; } | Ewildpat | Econstpat of immediate | Econstr0pat of Lident . t | Econstr1pat of Lident . t * pattern list | Etuplepat of pattern list | Evarpat of Zident . t | Ealiaspat of pattern * Zident . t | Eorpat of pattern * pattern | Erecordpat of ( Lident . t * pattern ) list | Etypeconstraintpat of pattern * type_expression { eq_desc : eqdesc ; eq_loc : location ; eq_index : int ; eq_safe : bool ; mutable eq_write : Deftypes . defnames ; } | EQeq of pattern * exp | EQder of Zident . t * exp * exp option * exp present_handler list | EQinit of Zident . t * exp | EQnext of Zident . t * exp * exp option | EQpluseq of Zident . t * exp | EQautomaton of is_weak * state_handler list * state_exp option | EQpresent of eq list block present_handler list * eq list block option | EQmatch of total ref * exp * eq list block match_handler list | EQreset of eq list * exp | EQemit of Zident . t * exp option | EQblock of eq list block | EQand of eq list | EQbefore of eq list | EQforall of forall_handler { b_vars : vardec list ; b_locals : local list ; b_body : ' a ; b_loc : location ; mutable b_env : Deftypes . tentry Zident . Env . t ; mutable b_write : Deftypes . defnames } { vardec_name : Zident . t ; vardec_default : Deftypes . constant default option ; vardec_combine : Lident . t option ; vardec_loc : location ; } | Init of ' a | Default of ' a { l_rec : is_rec ; l_eq : eq list ; mutable l_env : Deftypes . tentry Zident . Env . t ; l_loc : location } { s_loc : location ; s_state : statepat ; s_body : eq list block ; s_trans : escape list ; mutable s_env : Deftypes . tentry Zident . Env . t ; mutable s_reset : bool } | Estate0pat of Zident . t | Estate1pat of Zident . t * Zident . t list | Estate0 of Zident . t | Estate1 of Zident . t * exp list { e_cond : scondpat ; e_reset : bool ; e_block : eq list block option ; e_next_state : state_exp ; mutable e_env : Deftypes . tentry Zident . Env . t ; mutable e_zero : bool } | Econdand of scondpat * scondpat | Econdor of scondpat * scondpat | Econdexp of exp | Econdpat of exp * pattern | Econdon of scondpat * exp { m_pat : pattern ; m_body : ' a ; mutable m_env : Deftypes . tentry Zident . Env . t ; m_reset : bool ; mutable m_zero : bool ; } { p_cond : scondpat ; p_body : ' a ; mutable p_env : Deftypes . tentry Zident . Env . t ; mutable p_zero : bool } { for_index : indexes_desc localized list ; for_init : init_desc localized list ; for_body : eq list block ; mutable for_in_env : Deftypes . tentry Zident . Env . t ; mutable for_out_env : Deftypes . tentry Zident . Env . t ; for_loc : location } | Einput of Zident . t * exp | Eoutput of Zident . t * Zident . t | Eindex of Zident . t * exp * exp | Einit_last of Zident . t * exp
let matmult_complex = kern cva cvb cvc n -> let mul = fun c d -> { re = c . re . * d . re . - c . im . * d . im ; im = c . im . * d . re . + c . re . * d . im ; } in let add = fun c d -> { re = c . re . + d . re ; im = c . im . + d . im ; } in let open Std in let row = thread_idx_y + block_dim_y * block_idx_y in let col = thread_idx_x + block_dim_x * block_idx_x in let mutable sum = { re = 0 . ; im = 0 . } in if row < n && col < n then ( for i = 0 to n - 1 do sum := add sum ( mul cva . [ < row * n + i ] > cvb . [ < i * n + col ] ) ; > done ; cvc . [ < row * n + col ] > <- sum ) else ( )
let devid = try int_of_string Sys . argv . ( 1 ) with _ -> 1
let cpt = ref 0
let tot_time = ref 0 .
let measure_time f s = let t0 = Unix . gettimeofday ( ) in let a = f ( ) in let t1 = Unix . gettimeofday ( ) in Printf . printf " % s : time % d : % Fs \ n " %! s ! cpt ( t1 . - t0 ) ; tot_time := ! tot_time . + ( t1 . - t0 ) ; incr cpt ; a ; ;
let mul = fun c d -> { re = c . re . * d . re . - c . im . * d . im ; im = c . im . * d . re . + c . re . * d . im ; }
let add = fun c d -> { re = c . re . + d . re ; im = c . im . + d . im ; }
type lol = mutable xim : float ; mutable yre : float ; mutable yim : float ; }