src/Tools/Code/code_runtime.ML
changeset 63164 72aaf69328fc
parent 63163 b561284a4214
child 63174 57c0d60e491c
child 63178 b9e1d53124f5
equal deleted inserted replaced
63163:b561284a4214 63164:72aaf69328fc
    78 
    78 
    79 val trace = Attrib.setup_config_bool @{binding "code_runtime_trace"} (K false);
    79 val trace = Attrib.setup_config_bool @{binding "code_runtime_trace"} (K false);
    80 
    80 
    81 fun compile_ML verbose code context =
    81 fun compile_ML verbose code context =
    82  (if Config.get_generic context trace then tracing code else ();
    82  (if Config.get_generic context trace then tracing code else ();
    83   ML_Context.exec (fn () => ML_Compiler0.ML ML_Env.context
    83   Code_Preproc.timed "compiling ML" Context.proof_of
       
    84     (ML_Context.exec (fn () => ML_Compiler0.ML ML_Env.context
    84     {line = 0, file = "generated code", verbose = verbose,
    85     {line = 0, file = "generated code", verbose = verbose,
    85        debug = false} code) context);
    86        debug = false} code)) context);
    86 
    87 
    87 fun value ctxt (get, put, put_ml) (prelude, value) =
    88 fun value ctxt (get, put, put_ml) (prelude, value) =
    88   let
    89   let
    89     val code =
    90     val code =
    90       prelude ^ "\nval _ = Context.put_generic_context (SOME (Context.map_proof (" ^
    91       prelude ^ "\nval _ = Context.put_generic_context (SOME (Context.map_proof (" ^
    91       put_ml ^ " (fn () => " ^ value ^ ")) (Context.the_generic_context ())))";
    92       put_ml ^ " (fn () => " ^ value ^ ")) (Context.the_generic_context ())))";
    92     val ctxt' = ctxt
    93     val ctxt' = ctxt
    93       |> put (fn () => error ("Bad computation for " ^ quote put_ml))
    94       |> put (fn () => error ("Bad computation for " ^ quote put_ml))
    94       |> Context.proof_map (compile_ML false code);
    95       |> Context.proof_map (compile_ML false code);
    95   in get ctxt' () end;
    96     val computator = get ctxt';
       
    97   in Code_Preproc.timed_exec "running ML" computator ctxt' end;
    96 
    98 
    97 
    99 
    98 (* computation as evaluation into ML language values *)
   100 (* computation as evaluation into ML language values *)
    99 
   101 
   100 type 'a cookie = (Proof.context -> unit -> 'a) * ((unit -> 'a) -> Proof.context -> Proof.context) * string;
   102 type 'a cookie = (Proof.context -> unit -> 'a) * ((unit -> 'a) -> Proof.context -> Proof.context) * string;
   298     val (context_code, (_, const_map)) =
   300     val (context_code, (_, const_map)) =
   299       evaluation_code ctxt structure_generated program [] cs_code;
   301       evaluation_code ctxt structure_generated program [] cs_code;
   300     val ml_name_for_const = the o AList.lookup (op =) const_map;
   302     val ml_name_for_const = the o AList.lookup (op =) const_map;
   301     val (ml_names, of_term_code) = print_of_term ctxt ml_name_for_const T cTs
   303     val (ml_names, of_term_code) = print_of_term ctxt ml_name_for_const T cTs
   302     val of_term = value ctxt cookie (context_code ^ "\n" ^ of_term_code, List.last ml_names);
   304     val of_term = value ctxt cookie (context_code ^ "\n" ^ of_term_code, List.last ml_names);
   303   in fn ctxt' => fn t => fn _ => fn _ => Exn.interruptible_capture (of_term ctxt') t end;
   305   in
       
   306     Code_Preproc.timed_value "computing" 
       
   307       (fn ctxt' => fn t => fn _ => fn _ => Exn.interruptible_capture (of_term ctxt') t)
       
   308   end;
   304 
   309 
   305 fun fully_static_value_exn cookie { ctxt, lift_postproc, consts, T } =
   310 fun fully_static_value_exn cookie { ctxt, lift_postproc, consts, T } =
   306   let
   311   let
   307     val thy = Proof_Context.theory_of ctxt;
   312     val thy = Proof_Context.theory_of ctxt;
   308     val cs_code = map (Axclass.unoverload_const thy) consts;
   313     val cs_code = map (Axclass.unoverload_const thy) consts;