src/Tools/Code/code_runtime.ML
changeset 63163 b561284a4214
parent 63160 80a91e0e236e
child 63164 72aaf69328fc
equal deleted inserted replaced
63162:93e75d2f0d01 63163:b561284a4214
    76   #> fold (Code_Target.add_reserved target) ["oo", "ooo", "oooo", "upto", "downto", "orf", "andf"]);
    76   #> fold (Code_Target.add_reserved target) ["oo", "ooo", "oooo", "upto", "downto", "orf", "andf"]);
    77        (*avoid further pervasive infix names*)
    77        (*avoid further pervasive infix names*)
    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 exec ctxt verbose code =
    81 fun compile_ML verbose code context =
    82  (if Config.get ctxt trace then tracing code else ();
    82  (if Config.get_generic context trace then tracing code else ();
    83   ML_Context.exec (fn () =>
    83   ML_Context.exec (fn () => ML_Compiler0.ML ML_Env.context
    84     ML_Compiler0.ML ML_Env.context
    84     {line = 0, file = "generated code", verbose = verbose,
    85       {line = 0, file = "generated code", verbose = verbose, debug = false} code));
    85        debug = false} code) context);
    86 
    86 
    87 fun value ctxt (get, put, put_ml) (prelude, value) =
    87 fun value ctxt (get, put, put_ml) (prelude, value) =
    88   let
    88   let
    89     val code =
    89     val code =
    90       prelude ^ "\nval _ = Context.put_generic_context (SOME (Context.map_proof (" ^
    90       prelude ^ "\nval _ = Context.put_generic_context (SOME (Context.map_proof (" ^
    91       put_ml ^ " (fn () => " ^ value ^ ")) (Context.the_generic_context ())))";
    91       put_ml ^ " (fn () => " ^ value ^ ")) (Context.the_generic_context ())))";
    92     val ctxt' = ctxt
    92     val ctxt' = ctxt
    93       |> put (fn () => error ("Bad computation for " ^ quote put_ml))
    93       |> put (fn () => error ("Bad computation for " ^ quote put_ml))
    94       |> Context.proof_map (exec ctxt false code);
    94       |> Context.proof_map (compile_ML false code);
    95   in get ctxt' () end;
    95   in get ctxt' () end;
    96 
    96 
    97 
    97 
    98 (* computation as evaluation into ML language values *)
    98 (* computation as evaluation into ML language values *)
    99 
    99 
   414   (const, [(target, SOME (Code_Printer.simple_const_syntax (0, (K o K o K) const')))]));
   414   (const, [(target, SOME (Code_Printer.simple_const_syntax (0, (K o K o K) const')))]));
   415 
   415 
   416 fun process_reflection (code, (tyco_map, (constr_map, const_map))) module_name NONE thy =
   416 fun process_reflection (code, (tyco_map, (constr_map, const_map))) module_name NONE thy =
   417       thy
   417       thy
   418       |> Code_Target.add_reserved target module_name
   418       |> Code_Target.add_reserved target module_name
   419       |> Context.theory_map (exec (Proof_Context.init_global thy (*FIXME*)) true code)
   419       |> Context.theory_map (compile_ML true code)
   420       |> fold (add_eval_tyco o apsnd Code_Printer.str) tyco_map
   420       |> fold (add_eval_tyco o apsnd Code_Printer.str) tyco_map
   421       |> fold (add_eval_constr o apsnd Code_Printer.str) constr_map
   421       |> fold (add_eval_constr o apsnd Code_Printer.str) constr_map
   422       |> fold (add_eval_const o apsnd Code_Printer.str) const_map
   422       |> fold (add_eval_const o apsnd Code_Printer.str) const_map
   423   | process_reflection (code, _) _ (SOME file_name) thy =
   423   | process_reflection (code, _) _ (SOME file_name) thy =
   424       let
   424       let