src/Pure/codegen.ML
changeset 25376 87824cc5ff90
parent 25367 98b6b7f64e49
child 25400 e05b9fa43885
equal deleted inserted replaced
25375:9482ef88e5bc 25376:87824cc5ff90
   982   | pretty_counterex ctxt (SOME cex) =
   982   | pretty_counterex ctxt (SOME cex) =
   983       Pretty.chunks (Pretty.str "Counterexample found:\n" ::
   983       Pretty.chunks (Pretty.str "Counterexample found:\n" ::
   984         map (fn (s, t) =>
   984         map (fn (s, t) =>
   985           Pretty.block [Pretty.str (s ^ " ="), Pretty.brk 1, Syntax.pretty_term ctxt t]) cex);
   985           Pretty.block [Pretty.str (s ^ " ="), Pretty.brk 1, Syntax.pretty_term ctxt t]) cex);
   986 
   986 
   987 val auto_quickcheck = ref true;
   987 val auto_quickcheck = ref false;
   988 val auto_quickcheck_time_limit = ref 5000;
   988 val auto_quickcheck_time_limit = ref 5000;
   989 
   989 
   990 fun test_goal' int state =
   990 fun test_goal' int state =
   991   let
   991   let
   992     val ctxt = Proof.context_of state;
   992     val ctxt = Proof.context_of state;
   993     val assms = map term_of (Assumption.assms_of ctxt)
   993     val assms = map term_of (Assumption.assms_of ctxt);
   994     val params = get_test_params (Proof.theory_of state)
   994     val params = get_test_params (Proof.theory_of state);
   995     fun test state =
   995     fun report msg = (Output.priority ("Auto quickcheck: " ^ msg); state);
   996       let val _ = Output.priority "Auto quickcheck ..." in
   996     fun test () =
   997         case try (TimeLimit.timeLimit (Time.fromMilliseconds (!auto_quickcheck_time_limit))
   997       let
   998             (try ((test_goal true (params, []) 1 assms)))) state of
   998         val _ = Output.priority "Auto quickcheck ...";
   999           SOME NONE => (Output.priority "Cannot auto quickcheck."; state)
   999         val res = TimeLimit.timeLimit (Time.fromMilliseconds (!auto_quickcheck_time_limit))
  1000         | SOME (SOME (cex as SOME _)) => Proof.goal_message (fn () => Pretty.chunks [Pretty.str "",
  1000           (try (test_goal true (params, []) 1 assms)) state;
       
  1001       in
       
  1002         case res of
       
  1003           NONE => report "failed."
       
  1004         | SOME NONE => report "no counterexamples found."
       
  1005         | SOME cex => Proof.goal_message (fn () => Pretty.chunks [Pretty.str "",
  1001             Pretty.markup Markup.hilite [pretty_counterex ctxt cex]]) state
  1006             Pretty.markup Markup.hilite [pretty_counterex ctxt cex]]) state
  1002         | _ => (Output.priority "Auto quickcheck: no counterexamples found."; state)
  1007       end handle TimeLimit.TimeOut => report "timeout.";
  1003       end;
       
  1004   in
  1008   in
  1005     if int andalso !auto_quickcheck andalso not (!Toplevel.quiet)
  1009     if int andalso !auto_quickcheck andalso not (!Toplevel.quiet)
  1006     then test state
  1010     then test ()
  1007     else state
  1011     else state
  1008   end;
  1012   end;
  1009 
  1013 
  1010 val _ = Context.add_setup
  1014 val _ = Context.add_setup
  1011   (Context.theory_map (Specification.add_theorem_hook test_goal'));
  1015   (Context.theory_map (Specification.add_theorem_hook test_goal'));
  1124   OuterSyntax.command "consts_code"
  1128   OuterSyntax.command "consts_code"
  1125   "associate constants with target language code" K.thy_decl
  1129   "associate constants with target language code" K.thy_decl
  1126     (Scan.repeat1
  1130     (Scan.repeat1
  1127        (P.term --|
  1131        (P.term --|
  1128         P.$$$ "(" -- P.string --| P.$$$ ")" -- parse_attach) >>
  1132         P.$$$ "(" -- P.string --| P.$$$ ")" -- parse_attach) >>
  1129      (fn xs => Toplevel.theory (fn thy => fold (assoc_const o 
  1133      (fn xs => Toplevel.theory (fn thy => fold (assoc_const o
  1130        (fn ((const, mfx), aux) =>
  1134        (fn ((const, mfx), aux) =>
  1131          (const, (parse_mixfix (Sign.read_term thy) mfx, aux)))) xs thy)));
  1135          (const, (parse_mixfix (Sign.read_term thy) mfx, aux)))) xs thy)));
  1132 
  1136 
  1133 fun parse_code lib =
  1137 fun parse_code lib =
  1134   Scan.optional (P.$$$ "(" |-- P.enum "," P.xname --| P.$$$ ")") (!mode) --
  1138   Scan.optional (P.$$$ "(" |-- P.enum "," P.xname --| P.$$$ ")") (!mode) --