src/Tools/Code/code_preproc.ML
changeset 60697 e266d5463e9d
parent 60367 e201bd8973db
child 60805 4cc49ead6e75
equal deleted inserted replaced
60696:8304fb4fb823 60697:e266d5463e9d
    19   type code_graph
    19   type code_graph
    20   val cert: code_graph -> string -> Code.cert
    20   val cert: code_graph -> string -> Code.cert
    21   val sortargs: code_graph -> string -> sort list
    21   val sortargs: code_graph -> string -> sort list
    22   val all: code_graph -> string list
    22   val all: code_graph -> string list
    23   val pretty: Proof.context -> code_graph -> Pretty.T
    23   val pretty: Proof.context -> code_graph -> Pretty.T
    24   val obtain: bool -> theory -> string list -> term list -> code_algebra * code_graph
    24   val obtain: bool -> Proof.context -> string list -> term list -> code_algebra * code_graph
    25   val dynamic_conv: Proof.context
    25   val dynamic_conv: Proof.context
    26     -> (code_algebra -> code_graph -> term -> conv) -> conv
    26     -> (code_algebra -> code_graph -> term -> conv) -> conv
    27   val dynamic_value: Proof.context -> ((term -> term) -> 'a -> 'b)
    27   val dynamic_value: Proof.context -> ((term -> term) -> 'a -> 'b)
    28     -> (code_algebra -> code_graph -> term -> 'a) -> term -> 'b
    28     -> (code_algebra -> code_graph -> term -> 'a) -> term -> 'b
    29   val static_conv: { ctxt: Proof.context, consts: string list }
    29   val static_conv: { ctxt: Proof.context, consts: string list }
   534 );
   534 );
   535 
   535 
   536 
   536 
   537 (** retrieval and evaluation interfaces **)
   537 (** retrieval and evaluation interfaces **)
   538 
   538 
   539 fun obtain ignore_cache thy consts ts = apsnd snd
   539 fun obtain ignore_cache ctxt consts ts = apsnd snd
   540   (Wellsorted.change_yield (if ignore_cache then NONE else SOME thy)
   540   (Wellsorted.change_yield (if ignore_cache then NONE else SOME (Proof_Context.theory_of ctxt))
   541     (extend_arities_eqngr (Proof_Context.init_global thy) consts ts));
   541     (extend_arities_eqngr ctxt consts ts));
   542 
   542 
   543 fun dynamic_evaluator eval ctxt t =
   543 fun dynamic_evaluator eval ctxt t =
   544   let
   544   let
   545     val consts = fold_aterms
   545     val consts = fold_aterms
   546       (fn Const (c, _) => insert (op =) c | _ => I) t [];
   546       (fn Const (c, _) => insert (op =) c | _ => I) t [];
   547     val (algebra, eqngr) = obtain false (Proof_Context.theory_of ctxt) consts [t];
   547     val (algebra, eqngr) = obtain false ctxt consts [t];
   548   in eval algebra eqngr t end;
   548   in eval algebra eqngr t end;
   549 
   549 
   550 fun dynamic_conv ctxt conv =
   550 fun dynamic_conv ctxt conv =
   551   Sandwich.conversion (value_sandwich ctxt) (dynamic_evaluator conv) ctxt;
   551   Sandwich.conversion (value_sandwich ctxt) (dynamic_evaluator conv) ctxt;
   552 
   552 
   553 fun dynamic_value ctxt lift_postproc evaluator =
   553 fun dynamic_value ctxt lift_postproc evaluator =
   554   Sandwich.evaluation (value_sandwich ctxt) lift_postproc (dynamic_evaluator evaluator) ctxt;
   554   Sandwich.evaluation (value_sandwich ctxt) lift_postproc (dynamic_evaluator evaluator) ctxt;
   555 
   555 
   556 fun static_conv { ctxt, consts } conv =
   556 fun static_conv { ctxt, consts } conv =
   557   let
   557   let
   558     val (algebra, eqngr) = obtain true (Proof_Context.theory_of ctxt) consts [];
   558     val (algebra, eqngr) = obtain true ctxt consts [];
   559   in Sandwich.conversion (value_sandwich ctxt) (conv { algebra = algebra, eqngr = eqngr }) end;
   559   in Sandwich.conversion (value_sandwich ctxt) (conv { algebra = algebra, eqngr = eqngr }) end;
   560 
   560 
   561 fun static_value { ctxt, lift_postproc, consts } evaluator =
   561 fun static_value { ctxt, lift_postproc, consts } evaluator =
   562   let
   562   let
   563     val (algebra, eqngr) = obtain true (Proof_Context.theory_of ctxt) consts [];
   563     val (algebra, eqngr) = obtain true ctxt consts [];
   564   in Sandwich.evaluation (value_sandwich ctxt) lift_postproc (evaluator { algebra = algebra, eqngr = eqngr }) end;
   564   in Sandwich.evaluation (value_sandwich ctxt) lift_postproc (evaluator { algebra = algebra, eqngr = eqngr }) end;
   565 
   565 
   566 
   566 
   567 (** setup **)
   567 (** setup **)
   568 
   568