src/Pure/codegen.ML
changeset 42360 da8817d01e7c
parent 41636 934b4ad9b611
child 42411 ff997038e8eb
equal deleted inserted replaced
42359:6ca5407863ed 42360:da8817d01e7c
   819     (code'', del_nodes ["<Top>"] gr')
   819     (code'', del_nodes ["<Top>"] gr')
   820   end;
   820   end;
   821 
   821 
   822 val generate_code_i = gen_generate_code Sign.cert_term;
   822 val generate_code_i = gen_generate_code Sign.cert_term;
   823 val generate_code =
   823 val generate_code =
   824   gen_generate_code (Syntax.read_term o ProofContext.allow_dummies o ProofContext.init_global);
   824   gen_generate_code (Syntax.read_term o Proof_Context.allow_dummies o Proof_Context.init_global);
   825 
   825 
   826 
   826 
   827 (**** Reflection ****)
   827 (**** Reflection ****)
   828 
   828 
   829 val strip_tname = implode o tl o raw_explode;
   829 val strip_tname = implode o tl o raw_explode;
   870 val test_fn : (int -> term list option) Unsynchronized.ref =
   870 val test_fn : (int -> term list option) Unsynchronized.ref =
   871   Unsynchronized.ref (fn _ => NONE);
   871   Unsynchronized.ref (fn _ => NONE);
   872 
   872 
   873 fun test_term ctxt t =
   873 fun test_term ctxt t =
   874   let
   874   let
   875     val thy = ProofContext.theory_of ctxt;
   875     val thy = Proof_Context.theory_of ctxt;
   876     val (code, gr) = setmp_CRITICAL mode ["term_of", "test"]
   876     val (code, gr) = setmp_CRITICAL mode ["term_of", "test"]
   877       (generate_code_i thy [] "Generated") [("testf", t)];
   877       (generate_code_i thy [] "Generated") [("testf", t)];
   878     val Ts = map snd (fst (strip_abs t));
   878     val Ts = map snd (fst (strip_abs t));
   879     val args = map_index (fn (i, T) => ("arg" ^ string_of_int i, T)) Ts;
   879     val args = map_index (fn (i, T) => ("arg" ^ string_of_int i, T)) Ts;
   880     val s = "structure TestTerm =\nstruct\n\n" ^
   880     val s = "structure TestTerm =\nstruct\n\n" ^
   904 
   904 
   905 val eval_result = Unsynchronized.ref (fn () => Bound 0);
   905 val eval_result = Unsynchronized.ref (fn () => Bound 0);
   906 
   906 
   907 fun eval_term thy t =
   907 fun eval_term thy t =
   908   let
   908   let
   909     val ctxt = ProofContext.init_global thy;  (* FIXME *)
   909     val ctxt = Proof_Context.init_global thy;  (* FIXME *)
   910     val e =
   910     val e =
   911       let
   911       let
   912         val _ = (null (Term.add_tvars t []) andalso null (Term.add_tfrees t [])) orelse
   912         val _ = (null (Term.add_tvars t []) andalso null (Term.add_tfrees t [])) orelse
   913           error "Term to be evaluated contains type variables";
   913           error "Term to be evaluated contains type variables";
   914         val _ = (null (Term.add_vars t []) andalso null (Term.add_frees t [])) orelse
   914         val _ = (null (Term.add_vars t []) andalso null (Term.add_frees t [])) orelse