src/Tools/Code/code_runtime.ML
changeset 63160 80a91e0e236e
parent 63159 84c6dd947b75
child 63163 b561284a4214
equal deleted inserted replaced
63159:84c6dd947b75 63160:80a91e0e236e
    26   val static_value_exn: 'a cookie -> { ctxt: Proof.context, target: string option,
    26   val static_value_exn: 'a cookie -> { ctxt: Proof.context, target: string option,
    27     lift_postproc: (term -> term) -> 'a -> 'a, consts: string list }
    27     lift_postproc: (term -> term) -> 'a -> 'a, consts: string list }
    28     -> Proof.context -> term -> 'a Exn.result
    28     -> Proof.context -> term -> 'a Exn.result
    29   val dynamic_holds_conv: Proof.context -> conv
    29   val dynamic_holds_conv: Proof.context -> conv
    30   val static_holds_conv: { ctxt: Proof.context, consts: string list } -> Proof.context -> conv
    30   val static_holds_conv: { ctxt: Proof.context, consts: string list } -> Proof.context -> conv
    31   val static_value': (Proof.context -> term -> 'a) cookie
    31   val fully_static_value: (Proof.context -> term -> 'a) cookie
    32     -> { ctxt: Proof.context, lift_postproc: (term -> term) -> 'a -> 'a,
    32     -> { ctxt: Proof.context, lift_postproc: (term -> term) -> 'a -> 'a,
    33            consts: (string * typ) list, T: typ }
    33            consts: (string * typ) list, T: typ }
    34     -> Proof.context -> term -> 'a option (*EXPERIMENTAL!*)
    34     -> Proof.context -> term -> 'a option (*EXPERIMENTAL!*)
    35   val static_value_strict': (Proof.context -> term -> 'a) cookie
    35   val fully_static_value_strict: (Proof.context -> term -> 'a) cookie
    36     -> { ctxt: Proof.context, lift_postproc: (term -> term) -> 'a -> 'a,
    36     -> { ctxt: Proof.context, lift_postproc: (term -> term) -> 'a -> 'a,
    37            consts: (string * typ) list, T: typ }
    37            consts: (string * typ) list, T: typ }
    38     -> Proof.context -> term -> 'a (*EXPERIMENTAL!*)
    38     -> Proof.context -> term -> 'a (*EXPERIMENTAL!*)
    39   val static_value_exn': (Proof.context -> term -> 'a) cookie
    39   val fully_static_value_exn: (Proof.context -> term -> 'a) cookie
    40     -> { ctxt: Proof.context, lift_postproc: (term -> term) -> 'a -> 'a,
    40     -> { ctxt: Proof.context, lift_postproc: (term -> term) -> 'a -> 'a,
    41            consts: (string * typ) list, T: typ }
    41            consts: (string * typ) list, T: typ }
    42     -> Proof.context -> term -> 'a Exn.result (*EXPERIMENTAL!*)
    42     -> Proof.context -> term -> 'a Exn.result (*EXPERIMENTAL!*)
    43   val code_reflect: (string * string list option) list -> string list -> string
    43   val code_reflect: (string * string list option) list -> string list -> string
    44     -> string option -> theory -> theory
    44     -> string option -> theory -> theory
   199     K (check_holds_oracle ctxt' (build_computation_text ctxt NONE program (map Constant deps)) vs_t o reject_vars ctxt'));
   199     K (check_holds_oracle ctxt' (build_computation_text ctxt NONE program (map Constant deps)) vs_t o reject_vars ctxt'));
   200 
   200 
   201 end; (*local*)
   201 end; (*local*)
   202 
   202 
   203 
   203 
   204 (** full static evaluation -- still with limited coverage! **)
   204 (** fully static evaluation -- still with limited coverage! **)
   205 
   205 
   206 fun evaluation_code ctxt module_name program tycos consts =
   206 fun evaluation_code ctxt module_name program tycos consts =
   207   let
   207   let
   208     val thy = Proof_Context.theory_of ctxt;
   208     val thy = Proof_Context.theory_of ctxt;
   209     val (ml_modules, target_names) =
   209     val (ml_modules, target_names) =
   291     print_of_term_funs { typ_sign_for = typ_sign_for,
   291     print_of_term_funs { typ_sign_for = typ_sign_for,
   292       ml_name_for_const = ml_name_for_const,
   292       ml_name_for_const = ml_name_for_const,
   293       ml_name_for_typ = ml_name_for_typ } Ts
   293       ml_name_for_typ = ml_name_for_typ } Ts
   294   end;
   294   end;
   295 
   295 
   296 fun compile_evaluator cookie ctxt cs_code cTs T { program, deps } =
   296 fun compile_computation cookie ctxt cs_code cTs T { program, deps } =
   297   let
   297   let
   298     val (context_code, (_, const_map)) =
   298     val (context_code, (_, const_map)) =
   299       evaluation_code ctxt structure_generated program [] cs_code;
   299       evaluation_code ctxt structure_generated program [] cs_code;
   300     val ml_name_for_const = the o AList.lookup (op =) const_map;
   300     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
   301     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);
   302     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;
   303   in fn ctxt' => fn t => fn _ => fn _ => Exn.interruptible_capture (of_term ctxt') t end;
   304 
   304 
   305 fun static_value_exn' cookie { ctxt, lift_postproc, consts, T } =
   305 fun fully_static_value_exn cookie { ctxt, lift_postproc, consts, T } =
   306   let
   306   let
   307     val thy = Proof_Context.theory_of ctxt;
   307     val thy = Proof_Context.theory_of ctxt;
   308     val cs_code = map (Axclass.unoverload_const thy) consts;
   308     val cs_code = map (Axclass.unoverload_const thy) consts;
   309     val cTs = map2 (fn (_, T) => fn c => (c, T)) consts cs_code;
   309     val cTs = map2 (fn (_, T) => fn c => (c, T)) consts cs_code;
   310     val evaluator = Code_Thingol.static_value { ctxt = ctxt,
   310     val computation = Code_Thingol.static_value { ctxt = ctxt,
   311       lift_postproc = Exn.map_res o lift_postproc, consts = cs_code }
   311       lift_postproc = Exn.map_res o lift_postproc, consts = cs_code }
   312       (compile_evaluator cookie ctxt cs_code cTs T);
   312       (compile_computation cookie ctxt cs_code cTs T);
   313   in fn ctxt' =>
   313   in fn ctxt' =>
   314     evaluator ctxt' o reject_vars ctxt' o Syntax.check_term ctxt' o Type.constraint T
   314     computation ctxt' o reject_vars ctxt' o Syntax.check_term ctxt' o Type.constraint T
   315   end;
   315   end;
   316 
   316 
   317 fun static_value_strict' cookie = Exn.release ooo static_value_exn' cookie;
   317 fun fully_static_value_strict cookie = Exn.release ooo fully_static_value_exn cookie;
   318 
   318 
   319 fun static_value' cookie = partiality_as_none ooo static_value_exn' cookie;
   319 fun fully_static_value cookie = partiality_as_none ooo fully_static_value_exn cookie;
   320 
   320 
   321 
   321 
   322 (** code antiquotation **)
   322 (** code antiquotation **)
   323 
   323 
   324 local
   324 local