src/Tools/Code/code_eval.ML
changeset 39388 fdbb2c55ffc2
parent 38935 2cf3d8305b47
equal deleted inserted replaced
39387:6608c4838ff9 39388:fdbb2c55ffc2
     5 *)
     5 *)
     6 
     6 
     7 signature CODE_EVAL =
     7 signature CODE_EVAL =
     8 sig
     8 sig
     9   val target: string
     9   val target: string
    10   val eval: string option -> string * (unit -> 'a) option Unsynchronized.ref
    10   val eval: string option
       
    11     -> (Proof.context -> unit -> 'a) * ((unit -> 'a) -> Proof.context -> Proof.context) * string
    11     -> ((term -> term) -> 'a -> 'a) -> theory -> term -> string list -> 'a
    12     -> ((term -> term) -> 'a -> 'a) -> theory -> term -> string list -> 'a
    12   val setup: theory -> theory
    13   val setup: theory -> theory
    13 end;
    14 end;
    14 
    15 
    15 structure Code_Eval : CODE_EVAL =
    16 structure Code_Eval : CODE_EVAL =
    37   in (ml_code, (tycos_map, consts_map)) end;
    38   in (ml_code, (tycos_map, consts_map)) end;
    38 
    39 
    39 
    40 
    40 (** evaluation **)
    41 (** evaluation **)
    41 
    42 
    42 fun eval some_target reff postproc thy t args =
    43 fun eval some_target cookie postproc thy t args =
    43   let
    44   let
    44     val ctxt = ProofContext.init_global thy;
    45     val ctxt = ProofContext.init_global thy;
    45     fun evaluator naming program ((_, (_, ty)), t) deps =
    46     fun evaluator naming program ((_, (_, ty)), t) deps =
    46       let
    47       let
    47         val _ = if Code_Thingol.contains_dictvar t then
    48         val _ = if Code_Thingol.contains_dictvar t then
    53           |> fold (curry Graph.add_edge value_name) deps;
    54           |> fold (curry Graph.add_edge value_name) deps;
    54         val (program_code, [SOME value_name']) = Code_Target.produce_code_for thy
    55         val (program_code, [SOME value_name']) = Code_Target.produce_code_for thy
    55           (the_default target some_target) NONE "Code" [] naming program' [value_name];
    56           (the_default target some_target) NONE "Code" [] naming program' [value_name];
    56         val value_code = space_implode " "
    57         val value_code = space_implode " "
    57           (value_name' :: map (enclose "(" ")") args);
    58           (value_name' :: map (enclose "(" ")") args);
    58       in ML_Context.evaluate ctxt false reff (program_code, value_code) end;
    59       in ML_Context.value ctxt cookie (program_code, value_code) end;
    59   in Code_Thingol.dynamic_eval_value thy postproc evaluator t end;
    60   in Code_Thingol.dynamic_eval_value thy postproc evaluator t end;
    60 
    61 
    61 
    62 
    62 (** instrumentalization by antiquotation **)
    63 (** instrumentalization by antiquotation **)
    63 
    64