text
stringlengths
12
786k
let update_sequence_state = let create_command ~ debug ~ keyfile ~ fee ~ nonce ~ memo ~ zkapp_keyfile ~ sequence_state ( ) = let open Deferred . Let_syntax in let % map parties = update_sequence_state ~ debug ~ keyfile ~ fee ~ nonce ~ memo ~ zkapp_keyfile ~ sequence_state in Util . print_snapp_tr...
let update_token_symbol = let create_command ~ debug ~ keyfile ~ fee ~ nonce ~ memo ~ snapp_keyfile ~ token_symbol ~ auth ( ) = let open Deferred . Let_syntax in let % map parties = update_token_symbol ~ debug ~ keyfile ~ fee ~ nonce ~ memo ~ snapp_keyfile ~ token_symbol ~ auth in Util . print_...
let update_permissions = let create_command ~ debug ~ keyfile ~ fee ~ nonce ~ memo ~ zkapp_keyfile ~ permissions ~ current_auth ( ) = let open Deferred . Let_syntax in let % map parties = update_permissions ~ debug ~ keyfile ~ fee ~ nonce ~ memo ~ zkapp_keyfile ~ permissions ~ current_auth in U...
let test_zkapp_with_genesis_ledger = Command ( . let open Let_syntax in Command . async ~ summary : " Generate a trivial zkApp transaction and genesis ledger with \ verification key for testing " ( let % map keyfile = Param . flag " -- fee - payer - key " ~ doc : " KEYFILE Private key file fo...
let txn_commands = [ ( " create - zkapp - account " , create_zkapp_account ) create_zkapp_account ; ( " upgrade - zkapp " , upgrade_zkapp ) upgrade_zkapp ; ( " transfer - funds " , transfer_funds ) transfer_funds ; ( " update - state " , update_state ) update_state ; ( ...
let ( ) = Command . run ( Command . group ~ summary " : ZkApp test transaction " ~ preserve_subcommand_order ( ) : txn_commands )
let crc_table = Array . init 256 ( fun n -> let crc = ref ( Int32 . of_int n ) n in for j = 0 to 7 do crc := if Int32 . to_int ( Int32 . logand ( ! crc ) crc 1l ) 1l <> 0 then Int32 . logxor ( Int32 . shift_right_logical ( ! crc ) crc 1 ) 1 polynom else Int32 . shift_right...
let compress ( ? level = 6 ) 6 ( ? header = true ) true refill flush = let inbuf = Bytes . create buffer_size and outbuf = Bytes . create buffer_size in let zs = Extc . zlib_deflate_init2 level ( if header then max_wbits else - max_wbits ) max_wbits in let rec compr inpos inavail = if inavail...
let compress_direct ( ? level = 6 ) 6 ( ? header = true ) true flush = let outbuf = Bytes . create buffer_size in let zs = Extc . zlib_deflate_init2 level ( if header then max_wbits else - max_wbits ) max_wbits in let rec compr inbuf inpos inavail = if inavail = 0 then ( ) else begin let ...
let uncompress ( ? header = true ) true refill flush = let inbuf = Bytes . create buffer_size and outbuf = Bytes . create buffer_size in let zs = Extc . zlib_inflate_init2 ( if header then max_wbits else - max_wbits ) max_wbits in let rec uncompr inpos inavail = if inavail = 0 then begin let incoun...
let update_crc crc buf pos len = let c = ref ( Int32 . lognot crc ) crc in for i = pos to ( len + pos - 1 ) 1 do let b = Int32 . of_int ( int_of_char ( Bytes . get buf i ) i ) i in c := Int32 . logxor ( Array . get crc_table ( Int32 . to_int ( Int32 . logand ( Int32 . logx...
type location = Loc of int * int
let input_name = ref " "
let input_chan = ref stdin
let initialize iname = input_name := iname ; input_chan := open_in iname
let output_lines ff char1 char2 charline1 line1 line2 = let n1 = char1 - charline1 and n2 = char2 - charline1 in if line2 > line1 then fprintf ff " , line % d -% d , characters % d -% d :\ n " line1 line2 n1 n2 else fprintf ff " , line % d , characters % d -% d :\ n " line1 n1 n2 ; ( ...
let output_loc ff input seek line_flag ( Loc ( pos1 , pos2 ) ) = let pr_chars n c = for i = 1 to n do pp_print_char ff c done in let skip_line ( ) = try while input ( ) != ' \ n ' do ( ) done with End_of_file -> ( ) in let copy_line ( ) = let c = ref ' ' in begin try whil...
let output_location ff loc = let p = pos_in ! input_chan in fprintf ff " File " \% s " " \ ! input_name ; output_loc ff ( fun ( ) -> input_char ! input_chan ) ( seek_in ! input_chan ) true loc ; seek_in ! input_chan p
let output_input_name ff = fprintf ff " File " \% s " , \ line 1 :\ n " ! input_name
type carray = ( float , float64_elt , c_layout ) Array1 . t
type zarray = ( int32 , int32_elt , c_layout ) Array1 . t
let cmake n = let r = Array1 . create float64 c_layout n in Array1 . fill r 0 . 0 ; r
let zmake n = let r = Array1 . create int32 c_layout n in Array1 . fill r 0l ; r
let get_zin v i = Array1 . get v i <> 0l
let zzero zinvec length = for i = 0 to length - 1 do Array1 . set zinvec i 0l done
type ' s f_alloc = unit -> ' s
type ' s f_maxsize = ' s -> int * int
type ' s f_csize = ' s -> int
type ' s f_zsize = ' s -> int
type ( ' s , ' o ) f_step = ' s -> carray -> carray -> zarray -> float -> ' o
type ' s f_ders = ' s -> carray -> carray -> zarray -> carray -> float -> unit
type ' s f_zero = ' s -> carray -> zarray -> carray -> float -> unit
type ' s f_reset = ' s -> unit
type ' s f_horizon = ' s -> float
let time_eq f1 f2 = if abs_float ( f1 . - f2 ) < min_float then true else let rel_error = if abs_float f1 > abs_float f2 then abs_float ( ( f1 . - f2 ) . / f1 ) else abs_float ( ( f1 . - f2 ) . / f2 ) in ( rel_error <= 0 . 000001 )
let time_leq t1 t2 = t1 < t2 || time_eq t1 t2
let time_geq t1 t2 = t1 > t2 || time_eq t1 t2
module type STATE_SOLVER = sig type t type nvec val cmake : int -> nvec val unvec : nvec -> carray type rhsfn = float -> carray -> carray -> unit type dkyfn = nvec -> float -> int -> unit val initialize : rhsfn -> nvec -> t val reinitialize : t -> float -> nvec -> unit val step : t -> float -> nv...
module type STATE_SOLVER_SENS = sig include STATE_SOLVER type sensmat val smake : int -> int -> sensmat val arrays_of_sensmat : sensmat -> float array array type rhsfn = carray -> float -> carray -> carray -> unit type dkysensfn = sensmat -> float -> int -> unit val initialize : rhsfn -> carray -> nve...
module type ZEROC_SOLVER = sig type t type zcfn = float -> carray -> carray -> unit val initialize : int -> zcfn -> carray -> t val initialize_only : int -> zcfn -> carray -> t val reinitialize : t -> float -> carray -> unit val step : t -> float -> carray -> unit val takeoff : t -> bool val has_...
module type RUNTIME = sig val go : unit hsimu -> unit val check : bool hsimu -> int -> unit end
module type DISCRETE_RUNTIME = sig val go : float -> ( unit -> unit ) -> unit end
type file_kind = ZLS | ZLI ; ;
let file_dependencies_as kind source_file = try if Sys . file_exists source_file then begin match kind with | ZLS -> zls_file_dependencies source_file | ZLI -> zli_file_dependencies source_file end with x -> let report_err = function | Zlexer . Lexical_error ( err , range ) -> lexical_error err range...
let file_dependencies source_file = if Filename . check_suffix source_file " . zls " then file_dependencies_as ZLS source_file else if Filename . check_suffix source_file " . zli " then file_dependencies_as ZLI source_file else ( )
let usage = " Usage : zlsdep [ options ] < source files >\ nOptions are " :
let _ = try add_to_load_path Filename . current_dir_name ; Arg . parse [ " - I " , Arg . String add_to_load_path , " < dir > Add < dir > to the list of include directories " ; " - impl " , Arg . String ( file_dependencies_as ZLS ) , " < f > Process < f > as a . zls ...
sig val enable_logging : unit -> unit val min_step_size : float option ref val max_step_size : float option ref val max_sim_time : float option ref val speedup : float ref val step : ' s Zls . f_alloc -> ' s Zls . f_csize -> ' s Zls . f_zsize -> ' s Zls . f_horizon -> ' s Zls . f_maxsize ...
module Make ( SSolver : Zls . STATE_SOLVER ) ( ZSolver : Zls . ZEROC_SOLVER ) = let no_time_in_solver = - 1 . 0 let add_margin h = h . + ( 2 . 0 . * epsilon_float . * h ) let max_sim_time = ref None let min_step_size = ref None let max_step_size = ref None let always_reinit = ...
module Make ( SSolver : Zls . STATE_SOLVER ) = struct
module Solver = Zlsolve . Make ( SSolver ) ( Illinois )
let wait_next_instant = let delay = ref 0 . 0 in let rec wait_next_instant starting ending delta = let diff = ( delta . - ( ending . - starting ) ) . - ! delay in if diff > 0 . 0 then begin try delay := 0 . 0 ; ignore ( Unix . select [ ] [ ] [ ] diff ) ; false w...
let go ( Ztypes . Hsim { alloc = main_alloc ; maxsize = main_maxsize ; csize = main_csize ; zsize = main_zsize ; step = main_step ; derivative = main_ders ; crossings = main_zero ; reset = main_reset ; horizon = main_horizon ; } ) = let stepfn = Solver . step main_alloc main_csi...
let check ( Ztypes . Hsim { alloc = main_alloc ; maxsize = main_maxsize ; csize = main_csize ; zsize = main_zsize ; step = main_step ; derivative = main_ders ; crossings = main_zero ; reset = main_reset ; horizon = main_horizon ; } ) limit = let stepfn = Solver . step main_alloc...
module Make ( SSolver : Zls . STATE_SOLVER ) =
module Solver = Zlsolve . Make ( SSolver ) ( Illinois )
let _ = GMain . init ( )
let start_playing = ref true
let destroy ( ) = GMain . Main . quit ( )
let low_prio = Glib . int_of_priority ` LOW -> Glib . Timeout . id = " ml_g_timeout_add " main_ders main_step main_zero main_reset = val stepfn = Solver . step main_alloc main_csize main_zsize main_horizon main_maxsize main_ders main_step main_zero main_reset val mutable last_wall_clk = Unix . get...
let go ( Ztypes . Hsim { alloc = main_alloc ; maxsize = main_maxsize ; csize = main_csize ; zsize = main_zsize ; step = main_step ; derivative = main_ders ; crossings = main_zero ; reset = main_reset ; horizon = main_horizon ; } ) = let w = GWindow . window ~ title " : Simul...
let check _ _ = assert false
let _ = GMain . init ( )
let start_playing = ref false
let destroy ( ) = GMain . Main . quit ( )
let low_prio = Glib . int_of_priority ` LOW -> Glib . Timeout . id = " ml_g_timeout_add " val mutable period = 1 . 0 . / freq val mutable last_wall_clk = Unix . gettimeofday ( ) val mutable timer_id = None val mutable step_count = 0 method set_period v = period <- v method private cle...
let go freq main_step = let w = GWindow . window ~ title " : Simulator " ~ width : 250 ~ height : 70 ~ resizable : false ( ) in let outer_box = GPack . vbox ~ packing : w # add ( ) in let top_box = GPack . button_box ` HORIZONTAL ~ packing : outer_box # pack ~ child_width : 48 ...
type error = | Etype | Ehybrid_operator | Earray_operator | Eapplication
let error loc kind = raise ( Error ( loc , kind ) )
let message loc kind = begin match kind with | Etype -> eprintf " [ @% aTranslation to L --: This type cannot be translated . . ] " @@ output_location loc | Ehybrid_operator -> eprintf " [ @% aTranslation to L --: Hybrid operators are not treated . . ] " @@ output_location loc | Earr...
type return = { eqs : eq State . t ; env : tentry Env . t State . t ; assertion : exp State . t }
let empty = { eqs = State . empty ; env = State . empty ; assertion = State . empty }
let with_env ( { env = env0 } as return ) env = { return with env = State . cons env env0 }
let with_eq ( { eqs = eqs } as return ) eq = { return with eqs = State . cons eq eqs }
let par { eqs = eqs1 ; env = env1 ; assertion = as1 } { eqs = eqs2 ; env = env2 ; assertion = as2 } = { eqs = State . par eqs1 eqs2 ; env = State . par env1 env2 ; assertion = State . par as1 as2 }
let eq_make k x e ck = { eq_kind = k ; eq_ident = x ; eq_exp = e ; eq_clock = ck }
let on ck ln c = Ck_on ( ck , ln , c )
let relse res c = Res_else ( res , c )
let immediate = function | Eint ( i ) -> Lint ( i ) | Efloat ( f ) -> Lfloat ( f ) | Ebool ( b ) -> Lbool ( b ) | Echar ( c ) -> Lchar ( c ) | Estring ( s ) -> Lstring ( s ) | Evoid -> Lvoid
let constr0pat { p_desc = p_desc } = match p_desc with | Econstpat ( Ebool ( b ) ) -> Lboolpat ( b ) | Econstr0pat ( c ) -> Lconstr0pat ( c ) | _ -> assert false
let rec type_of loc { t_desc = ty } = match ty with | Deftypes . Tconstr ( q , [ ] , _ ) -> if q = Initial . int_ident then Tint else if q = Initial . int32_ident then Tint else if q = Initial . int64_ident then Tint else if q = Initial . bool_ident then Tbool else if q = Initial . ...
let type_expression loc ty_e = let { typ_body = ty } = Interface . scheme_of_type ty_e in type_of loc ty
let env_of_env loc env = Env . map ( fun { Deftypes . t_typ = ty } -> { t_typ = type_of loc ty } ) env
let operator loc op e_list = match op with | Eifthenelse -> Lapp ( Lifthenelse , e_list ) | Eunarypre -> Lapp ( Lunarypre , e_list ) | Eminusgreater -> Lapp ( Lminusgreater , e_list ) | Efby -> Lapp ( Lfby , e_list ) | Eup | Einitial | Edisc | Ehorizon -> error loc Ehybrid_operator...
let shared_variables { dv = dv } = dv
let get x name_to_exp = try Env . find x name_to_exp with | Not_found -> Llast ( x )
let rec expression ck { e_desc = desc ; e_loc = loc } = match desc with | Elocal ( id ) -> Llocal ( id ) | Eglobal { lname = lid } -> Lglobal ( lid ) | Econst ( im ) -> Lconst ( immediate im ) | Econstr0 ( lid ) -> Lconstr0 ( lid ) | Econstr1 _ -> assert false | Ela...
let split s_set ( { eqs = eqs } as return ) = let eq_name_exp , eqs = State . partition ( fun { eq_ident = id } -> S . mem id s_set ) eqs in let name_to_exp = State . fold ( fun { eq_ident = id ; eq_exp = e } acc -> Env . add id e acc ) eq_name_exp Env . empty in name_to_e...
let rec equation ck res { eq_desc = desc ; eq_write = defnames } = match desc with | EQeq ( { p_desc = Evarpat ( x ) } , e ) -> with_eq empty ( eq_make Def x ( expression ck e ) ck ) | EQinit ( x , e ) -> let e = expression ck e in with_eq empty ( eq_make ( Init ( res ) ...
let local ck res { l_eq = eq_list ; l_env = l_env ; l_loc = loc } = let return = equation_list ck res eq_list in with_env return ( env_of_env loc l_env )
let let_expression ck res n_output ( { e_desc = desc } as e ) = match desc with | Elet ( l , e ) -> let return = local ck res l in let e = expression ck e in with_eq return ( eq_make Def n_output e ck ) | _ -> let e = expression ck e in with_eq empty ( eq_make Def n_output e ck )
let kind = function | S | AS | A | AD -> A | D -> D | C -> assert false
let typedecl loc n params td = let decl { desc = desc } = match desc with | Eabstract_type -> Labstract_type | Evariant_type _ -> assert false | Erecord_type ( n_ty_list ) -> Lrecord_type | Eabbrev _ -> assert false in match params with | [ ] -> Ltypedecl ( n , decl td ) | _ -> asser...
let implementation lmm_nodes lmm_list impl = match impl . desc with | Eopen _ -> lmm_list | Etypedecl ( n , params , td ) -> typedecl impl . loc n params td :: lmm_list | Econstdecl ( n , _ , e ) -> if Zmisc . S . mem n lmm_nodes then Lconstdecl ( n , expression Ck_base e ) :: l...
let implementation_list lmm_nodes impl_list = rev ( fold_left ( implementation lmm_nodes ) [ ] impl_list )
let rec repeat n a = match n with | 0 -> [ ] | n -> a :: ( repeat ( n - 1 ) a )
let rec keep l n = match ( l , n ) with | ( _ , 0 ) -> invalid_arg " keep " | ( h :: _ , 1 ) -> h | ( _ :: t , n ) -> keep t ( n - 1 ) | _ -> invalid_arg " keep "
let rec drop l n = match ( l , n ) with | ( _ , 0 ) -> invalid_arg " drop " | ( _ :: t , 1 ) -> t | ( h :: t , n ) -> h :: ( drop t ( n - 1 ) ) | _ -> invalid_arg " drop "
let rec range n m = if n > m then [ ] else n :: ( range ( n + 1 ) m )
let separate n l = let rec f acc n l = match ( n , l ) with | ( 0 , _ ) -> ( acc , l ) | ( n , h :: t ) -> f ( h :: acc ) ( n - 1 ) t | _ -> assert false in if n > List . length l then invalid_arg " separate " else let ( p , l ) = f [ ] n l in ( List . ...