text
stringlengths
12
786k
let rec a = ( incr r ; ! r ) :: b
let next = let r = ref 0 in fun ( ) -> incr r ; ! r
let ( ) = assert ( is_in_static_data next )
let ( ) = assert ( is_in_static_data No_argument )
let ( ) = assert ( is_in_static_data ( Some_argument " some string " ) )
let ( ) = let exn = try ( failwith [ @ inlined always ] ) " some other string " with exn -> exn in assert ( is_in_static_data exn )
let f x = let pair = if Sys . opaque_identity x then ( 1 , 2 ) , 3 else Is_static_flambda_dep . pair , 4 in let n = fst ( fst pair ) in let res = n , n in assert ( is_in_static_data res ) [ @@ inline never ]
let ( ) = f true ; f false
let ( ) = let f ( ) = let v = ( 1 , 2 ) in let eq = v == v in let n = if eq then 1 else 2 in let tuple = ( n , n ) in assert ( is_in_static_data tuple ) in ( f [ @ inlined never ] ) ( )
let ( ) = let f ( ) = let v = ( 1 , 2 ) in let eq = v != v in let n = if eq then 1 else 2 in let tuple = ( n , n ) in assert ( is_in_static_data tuple ) in ( f [ @ inlined never ] ) ( )
let ( ) = let f x = let v1 = Some x in let v2 = None in let eq = v1 == v2 in let n = if eq then 1 else 2 in let tuple = ( n , n ) in assert ( is_in_static_data tuple ) in ( f [ @ inlined never ] ) ( )
let ( ) = let f x = let v1 = Some x in let v2 = None in let eq = v1 != v2 in let n = if eq then 1 else 2 in let tuple = ( n , n ) in assert ( is_in_static_data tuple ) in ( f [ @ inlined never ] ) ( )
let ( ) = let f x = let v1 = ( 1 , 2 ) in let v2 = ( 3 , 2 ) in let eq = v1 == v2 in let n = if eq then 1 else 2 in let tuple = ( n , n ) in assert ( is_in_static_data tuple ) in ( f [ @ inlined never ] ) ( )
module Int = struct type t = int let compare ( a : int ) b = compare a b end
module IntMap = Map . Make ( Int )
let ( ) = let f ( ) = let a = IntMap . empty in let b = ( IntMap . add [ @ inlined ] ) 1 ( Some 1 ) a in assert ( is_in_static_data b ) ; let c = ( IntMap . add [ @ inlined ] ) 1 ( Some 2 ) b in assert ( is_in_static_data c ) ; let d = ( IntMap . add [ ...
let is_unboxing_beneficial_for_epa ( epa : Extra_param_and_args . t ) = Apply_cont_rewrite_id . Map . exists ( fun _ extra_arg -> match ( extra_arg : EPA . Extra_arg . t ) with | Already_in_scope _ -> true | New_let_binding _ | New_let_binding_with_named_args _ -> false ) epa . args
let rec filter_non_beneficial_decisions decision : U . decision = match ( decision : U . decision ) with | Do_not_unbox _ -> decision | Unbox ( Unique_tag_and_size { tag ; fields } ) -> let is_unboxing_beneficial , fields = List . fold_left_map ( fun is_unboxing_beneficial ( { epa ;...
kernel k_init : Spoc . Vector . vfloat64 -> Spoc . Vector . vfloat64 -> Spoc . Vector . vfloat64 -> int -> int -> unit = " kernels / Puissance " " init " kernel k_divide : Spoc . Vector . vfloat64 -> Spoc . Vector . vfloat64 -> int -> unit = " kernels / Puissance " " divi...
let size = ref 1024
let cpt = ref 0
let tot_time = ref 0 .
let measure_time f = let t0 = Unix . gettimeofday ( ) in let a = f ( ) in let t1 = Unix . gettimeofday ( ) in Printf . printf " temps % d : % F \ n " %! ! cpt ( t1 . - t0 ) ; tot_time := ! tot_time . + ( t1 . - t0 ) ; incr cpt ; a ; ;
let main a v n ( ) = let iter = ref 0 in let dev = Devices . init ( ) and vn = Vector . create Vector . float64 n and max = ( Vector . create Vector . float64 1 ) and max2 = ( Vector . create Vector . float64 1 ) and v_norme = Vector . create Vector . float64 n and norme = r...
let seq_iterate a v n ( ) = let iter = ref 0 and vn = Array . create n 0 . and norme = ref 1 . in let s = ref 0 . in let max = ref 0 . in while ! norme > eps && ! iter < max_iter do incr iter ; for i = 0 to n - 1 do s := 0 . ; for j = 0 to n - 1 do done ; vn . ( i ) ...
let external_iterate a v n ( ) = let iter = ref 0 and vn = Array . create n 0 . and norme = ref 1 . in let s = ref 0 . in let max = ref 0 . in while ! norme > eps && ! iter < max_iter do incr iter ; for i = 0 to n - 1 do s := 0 . ; for j = 0 to n - 1 do done ; vn . ( ...
let _ = Random . self_init ( ) ; let a = Vector . create Vector . float64 ( ! size * ! size ) and v = Vector . create Vector . float64 ! size in let seq_a = Array . create ( ! size * ! size ) 0 . and seq_v = Array . create ( ! size ) 0 . in for i = 0 to ! size - 1...
type location = label * ( code_index option )
type status_code = | Halted | Running | CodeIndexOutOfBound | StackIndexOutOfBound | HeapIndexOutOfBound | StackUnderflow
type stack_item = | STACK_INT of int | STACK_BOOL of bool | STACK_UNIT | STACK_HI of heap_index | STACK_RA of code_index | STACK_FP of stack_index
type heap_type = | HT_PAIR | HT_INL | HT_INR | HT_CLOSURE
type heap_item = | HEAP_INT of int | HEAP_BOOL of bool | HEAP_UNIT | HEAP_HI of heap_index | HEAP_CI of code_index | HEAP_HEADER of int * heap_type
type value_path = | STACK_LOCATION of offset | HEAP_LOCATION of offset
type instruction = | PUSH of stack_item | LOOKUP of value_path | UNARY of unary_oper | OPER of oper | ASSIGN | SWAP | POP | FST | SND | DEREF | APPLY | RETURN | MK_PAIR | MK_INL | MK_INR | MK_REF | MK_CLOSURE of location * int | TEST of location | CASE of location | GOTO of location | LABEL of la...
type listing = instruction list
type vm_state = { stack_bound : stack_index ; code_bound : code_index ; heap_bound : code_index ; stack : stack_item array ; heap : heap_item array ; code : instruction array ; mutable sp : stack_index ; mutable fp : stack_index ; mutable cp : code_index ; mutable hp : heap_index ; muta...
let get_instruction vm = Array . get vm . code vm . cp
let stack_top vm = Array . get vm . stack ( vm . sp - 1 )
let string_of_list sep f l = let rec aux f = function | [ ] -> " " | [ t ] -> ( f t ) | t :: rest -> ( f t ) ^ sep ^ ( aux f rest ) in " [ " ^ ( aux f l ) ^ " ] "
let string_of_status = function | Halted -> " halted " | Running -> " running " | CodeIndexOutOfBound -> " code index out - of - bound " | StackIndexOutOfBound -> " stack index out - of - bound " | HeapIndexOutOfBound -> " heap index out - of - bound " | StackUnderflow -> " stac...
let string_of_stack_item = function | STACK_INT i -> " STACK_INT " ^ ( string_of_int i ) | STACK_BOOL true -> " STACK_BOOL true " | STACK_BOOL false -> " STACK_BOOL false " | STACK_UNIT -> " STACK_UNIT " | STACK_HI i -> " STACK_HI " ^ ( string_of_int i ) | STACK_RA i -> " ST...
let string_of_heap_type = function | HT_PAIR -> " HT_PAIR " | HT_INL -> " HT_INL " | HT_INR -> " HT_INR " | HT_CLOSURE -> " HT_CLOSURE "
let string_of_heap_item = function | HEAP_INT i -> " HEAP_INT " ^ ( string_of_int i ) | HEAP_BOOL true -> " HEAP_BOOL true " | HEAP_BOOL false -> " HEAP_BOOL false " | HEAP_UNIT -> " HEAP_UNIT " | HEAP_HI i -> " HEAP_HI " ^ ( string_of_int i ) | HEAP_CI i -> " HEAP_CI " ^...
let string_of_value_path = function | STACK_LOCATION offset -> " STACK_LOCATION " ^ ( string_of_int offset ) | HEAP_LOCATION offset -> " HEAP_LOCATION " ^ ( string_of_int offset )
let string_of_location = function | ( l , None ) -> l | ( l , Some i ) -> l ^ " = " ^ ( string_of_int i )
let string_of_instruction = function | UNARY op -> " UNARY " ^ ( string_of_uop op ) | OPER op -> " OPER " ^ ( string_of_bop op ) | MK_PAIR -> " MK_PAIR " | FST -> " FST " | SND -> " SND " | MK_INL -> " MK_INL " | MK_INR -> " MK_INR " | MK_REF -> " MK_REF " | P...
let rec string_of_listing = function | [ ] -> " \ n " | ( LABEL l ) :: rest -> ( " \ n " ^ l ^ " " ) : ^ ( string_of_listing rest ) | i :: rest -> " \ n \ t " ^ ( string_of_instruction i ) ^ ( string_of_listing rest )
let string_of_installed_code ( code , size ) = let rec aux k = if size = k ^ ( string_of_instruction ( code . ( k ) ) ) ^ " \ n " ^ ( aux ( k + 1 ) ) in aux 0
let string_of_stack ( sp , stack ) = let rec aux carry j = if j = sp then carry else aux ( ( string_of_int j ) ^ " : " ^ ( string_of_stack_item ( Array . get stack j ) ) ^ " \ n " ^ carry ) ( j + 1 ) in aux " " 0
let string_of_heap vm = let rec aux k = if vm . hp <= k in " \ nHeap = \ n " ^ ( aux 0 )
let string_of_state vm = " cp = " ^ ( string_of_int vm . cp ) ^ " -> " ^ ( string_of_instruction ( get_instruction vm ) ) ^ " \ n " ^ " fp = " ^ ( string_of_int vm . fp ) ^ " \ n " ^ " Stack = \ n " ( ^ string_of_stack ( vm . sp , vm . stack ) ) ...
let rec string_of_heap_value a vm = match Array . get vm . heap a with | HEAP_INT i -> string_of_int i | HEAP_BOOL true -> " true " | HEAP_BOOL false -> " false " | HEAP_UNIT -> " ( ) " | HEAP_HI i -> string_of_heap_value i vm | HEAP_CI _ -> Errors . complain " string_of_heap_value...
let string_of_value vm = match stack_top vm with | STACK_INT i -> string_of_int i | STACK_BOOL true -> " true " | STACK_BOOL false -> " false " | STACK_UNIT -> " ( ) " | STACK_HI a -> string_of_heap_value a vm | STACK_RA _ -> Errors . complain " string_of_value : expecting value on st...
let readint ( ) = let _ = print_string " input > " in read_int ( )
let stack_to_heap_item = function | STACK_INT i -> HEAP_INT i | STACK_BOOL b -> HEAP_BOOL b | STACK_UNIT -> HEAP_UNIT | STACK_HI i -> HEAP_HI i | STACK_RA i -> HEAP_CI i | STACK_FP i -> Errors . complain " stack_to_heap_item : no frame pointer allowed on heap "
let heap_to_stack_item = function | HEAP_INT i -> STACK_INT i | HEAP_BOOL b -> STACK_BOOL b | HEAP_UNIT -> STACK_UNIT | HEAP_HI i -> STACK_HI i | HEAP_CI i -> STACK_RA i | HEAP_HEADER ( _ , _ ) -> Errors . complain " heap_to_stack_item : heap header not allowed on stack "
let advance_cp vm = if vm . cp < vm . code_bound then { vm with cp = vm . cp + 1 } else { vm with status = CodeIndexOutOfBound }
let goto ( i , vm ) = { vm with cp = i }
let pop ( n , vm ) = if 0 <= vm . sp - n then { vm with sp = vm . sp - n } else { vm with status = StackUnderflow }
let pop_top vm = let c = stack_top vm in ( c , pop ( 1 , vm ) )
let push ( c , vm ) = if vm . sp < vm . stack_bound then let _ = Array . set vm . stack vm . sp c in { vm with sp = vm . sp + 1 } else { vm with status = StackIndexOutOfBound }
let swap vm = let ( c1 , vm1 ) = pop_top vm in let ( c2 , vm2 ) = pop_top vm1 in push ( c2 , push ( c1 , vm2 ) )
let do_unary = function | ( NOT , STACK_BOOL m ) -> STACK_BOOL ( not m ) | ( NEG , STACK_INT m ) -> STACK_INT ( - m ) | ( READ , STACK_UNIT ) -> STACK_INT ( readint ( ) ) | ( op , _ ) -> Errors . complain ( " do_unary : malformed unary operator : " ^ ( str...
let do_oper = function | ( AND , STACK_BOOL m , STACK_BOOL n ) -> STACK_BOOL ( m && n ) | ( OR , STACK_BOOL m , STACK_BOOL n ) -> STACK_BOOL ( m || n ) | ( EQB , STACK_BOOL m , STACK_BOOL n ) -> STACK_BOOL ( m = n ) | ( LT , STACK_INT m , STACK_INT n ) -> STACK_BO...
let perform_op ( op , vm ) = let ( v_right , vm1 ) = pop_top vm in let ( v_left , vm2 ) = pop_top vm1 in push ( do_oper ( op , v_left , v_right ) , vm2 )
let perform_unary ( op , vm ) = let ( v , vm1 ) = pop_top vm in push ( do_unary ( op , v ) , vm1 )
let invoke_garbage_collection vm = None
let allocate ( n , vm ) = let hp1 = vm . hp in if hp1 + n < vm . heap_bound then ( hp1 , { vm with hp = vm . hp + n } ) else match invoke_garbage_collection vm with | None -> Errors . complain " allocate : heap exhausted " | Some vm2 -> if vm2 . hp + n < vm2 . heap_bound the...
let mk_pair vm = let ( v_right , vm1 ) = pop_top vm in let ( v_left , vm2 ) = pop_top vm1 in let ( a , vm3 ) = allocate ( 3 , vm2 ) in let header = HEAP_HEADER ( 3 , HT_PAIR ) in let _ = Array . set vm . heap a header in let _ = Array . set vm . heap ( a + 1 ) ( ...
let do_fst vm = let ( v , vm1 ) = pop_top vm in match v with | STACK_HI a -> ( match vm1 . heap . ( a ) with | HEAP_HEADER ( _ , HT_PAIR ) -> push ( heap_to_stack_item ( vm . heap . ( a + 1 ) ) , vm1 ) | _ -> Errors . complain " do_fst : unexpectd heap item " )...
let do_snd vm = let ( v , vm1 ) = pop_top vm in match v with | STACK_HI a -> ( match vm1 . heap . ( a ) with | HEAP_HEADER ( _ , HT_PAIR ) -> push ( heap_to_stack_item ( vm . heap . ( a + 2 ) ) , vm1 ) | _ -> Errors . complain " do_snd : unexpectd heap item " )...
let mk_inl vm = let ( v , vm1 ) = pop_top vm in let ( a , vm2 ) = allocate ( 2 , vm1 ) in let header = HEAP_HEADER ( 2 , HT_INL ) in let _ = Array . set vm2 . heap a header in let _ = Array . set vm2 . heap ( a + 1 ) ( stack_to_heap_item v ) in push ( STACK_HI a , ...
let mk_inr vm = let ( v , vm1 ) = pop_top vm in let ( a , vm2 ) = allocate ( 2 , vm1 ) in let header = HEAP_HEADER ( 2 , HT_INR ) in let _ = Array . set vm2 . heap a header in let _ = Array . set vm2 . heap ( a + 1 ) ( stack_to_heap_item v ) in push ( STACK_HI a , ...
let case ( i , vm ) = let ( c , vm1 ) = pop_top vm in match c with | STACK_HI a -> ( match vm1 . heap . ( a ) with | _ -> Errors . complain " case : runtime error , expecting union header in heap " ) | _ -> Errors . complain " case : runtime error , expecting heap index...
let mk_ref vm = let ( v , vm1 ) = pop_top vm in let ( a , vm2 ) = allocate ( 1 , vm1 ) in let _ = Array . set vm2 . heap a ( stack_to_heap_item v ) in push ( STACK_HI a , vm2 )
let deref vm = let ( v , vm1 ) = pop_top vm in match v with | STACK_HI a -> push ( heap_to_stack_item ( Array . get vm1 . heap a ) , vm1 ) | _ -> Errors . complain " deref "
let assign vm = let ( c1 , vm1 ) = pop_top vm in let ( c2 , vm2 ) = pop_top vm1 in match c2 with | STACK_HI a -> if vm . sp < vm . heap_bound then let _ = Array . set vm . heap a ( stack_to_heap_item c1 ) in push ( STACK_UNIT , vm ) else { vm with status = HeapIndexOutOfBound } ...
let test ( i , vm ) = pop ( 1 , if stack_top vm = STACK_BOOL true then advance_cp vm else { vm with cp = i } )
let return vm = let current_fp = vm . fp in match vm . stack . ( current_fp ) , vm . stack . ( vm . fp + 1 ) with | ( STACK_FP saved_fp , STACK_RA k ) -> let return_value = stack_top vm in push ( return_value , { vm with cp = k ; fp = saved_fp ; sp = current_fp - 2 } ...
let fetch fp vm = function | STACK_LOCATION offset -> vm . stack . ( fp + offset ) | HEAP_LOCATION offset -> ( match vm . stack . ( fp - 1 ) with | STACK_HI a -> heap_to_stack_item ( vm . heap . ( a + offset + 1 ) ) | _ -> Errors . complain " search : expecting closure...
let lookup fp vm vlp = push ( fetch fp vm vlp , vm )
let mk_closure = function | ( ( _ , Some i ) , n , vm ) -> let ( a , vm1 ) = allocate ( 2 + n , vm ) in let header = HEAP_HEADER ( 2 + n , HT_CLOSURE ) in let code_address = HEAP_CI i in let _ = vm1 . heap . ( a ) <- header in let _ = vm1 . heap . ( a + 1 ...
let apply vm = match stack_top vm with | STACK_HI a -> ( match vm . heap . ( a + 1 ) with | HEAP_CI i -> let new_fp = vm . sp in let saved_fp = STACK_FP vm . fp in let return_index = STACK_RA ( vm . cp + 1 ) in let new_vm = { vm with cp = i ; fp = new_fp } in push ( return_ind...
let step vm = match get_instruction vm with | UNARY op -> advance_cp ( perform_unary ( op , vm ) ) | OPER op -> advance_cp ( perform_op ( op , vm ) ) | MK_PAIR -> advance_cp ( mk_pair vm ) | FST -> advance_cp ( do_fst vm ) | SND -> advance_cp ( do_snd vm ) | MK_INL -> advanc...
let rec driver n vm = let _ = if Option . verbose then print_string ( " ========== state " ^ ( string_of_int n ) ^ " ==========\ n " ^ ( string_of_state vm ) ^ " \ n " ) else ( ) in if vm . status = Running then driver ( n + 1 ) ( step vm ) else vm
let map_instruction_labels f = function | GOTO ( lab , _ ) -> GOTO ( lab , Some ( f lab ) ) | TEST ( lab , _ ) -> TEST ( lab , Some ( f lab ) ) | CASE ( lab , _ ) -> CASE ( lab , Some ( f lab ) ) | MK_CLOSURE ( ( lab , _ ) , n ) -> MK_CLOSURE ( ...
let rec find l y = match l with | [ ] -> Errors . complain ( " Compile . find : " ^ y ^ " is not found " ) | ( x , v ) :: rest -> if x = y then v else find rest y
let load instr_list = let mk_label_to_address l = let rec aux carry k = function | [ ] -> carry | ( LABEL lab ) :: rest -> aux ( ( lab , k ) :: carry ) ( k + 1 ) rest | _ :: rest -> aux carry ( k + 1 ) rest in aux [ ] 0 l in let label_to_address = mk_label_to_address ins...
let initial_state l = let ( code_array , c_bound ) = load l in let _ = if Option . verbose then print_string ( " \ nInstalled Code = \ n " ^ ( string_of_installed_code ( code_array , c_bound ) ) ) else ( ) in { stack_bound = Option . stack_max ; heap_bound = Option . heap...
let first_frame vm = let saved_fp = STACK_FP 0 in let return_index = STACK_RA 0 in push ( return_index , push ( saved_fp , vm ) )
let run l = let vm = driver 1 ( first_frame ( initial_state l ) ) in match vm . status with | Halted -> vm | status -> Errors . complain ( " run : stopped wth status " ^ ( string_of_status status ) )
let new_label = let i = ref 0 in let get ( ) = let v = ! i in ( i := ( ! i ) + 1 ; " L " ^ ( string_of_int v ) ) in get
let positions l = let rec aux k = function | [ ] -> [ ] | a :: rest -> ( a , k ) :: ( aux ( k + 1 ) rest ) in aux 1 l
let rec comp vmap = function | Unit -> ( [ ] , [ PUSH STACK_UNIT ] ) | Boolean b -> ( [ ] , [ PUSH ( STACK_BOOL b ) ] ) | Integer n -> ( [ ] , [ PUSH ( STACK_INT n ) ] ) | UnaryOp ( op , e ) -> let ( defs , c ) = comp vmap e in ( defs , c @ [ ...
let compile e = let ( defs , c ) = comp [ ] e in let result = c @ [ HALT ] @ defs in let _ = if Option . verbose then print_string ( " \ nCompiled Code = \ n " ^ ( string_of_listing result ) ) else ( ) in result
let interpret e = run ( compile e )
let emit_x86 e = let base_name = String . sub Option . infile 0 ( ( String . length Option . infile ) - 6 ) in let out_chan = open_out ( base_name ^ " . s " ) in let tab ( c ) = output_string out_chan ( " \ t " ^ c ^ " \ n " ) in let cmd c comment = then " \ t ...
type jg_ast_mapper = { ast : jg_ast_mapper -> ast -> ast ; statement : jg_ast_mapper -> statement -> statement ; expression : jg_ast_mapper -> expression -> expression }
let arguments_definition self = List . map ( function | ( k , Some v ) -> ( k , Some ( self . expression self v ) ) | ( k , None ) -> ( k , None ) )
let arguments_application self = List . map ( fun ( k , v ) -> ( k , self . expression self v ) )