author | wenzelm |
Sat, 26 Jan 2008 20:01:37 +0100 | |
changeset 25985 | 8d69087f6a4b |
parent 25919 | 8b1c0d434824 |
child 26011 | d55224947082 |
permissions | -rw-r--r-- |
22525 | 1 |
(* Title: HOL/Library/Eval.thy |
2 |
ID: $Id$ |
|
3 |
Author: Florian Haftmann, TU Muenchen |
|
4 |
*) |
|
5 |
||
6 |
header {* A simple term evaluation mechanism *} |
|
7 |
||
8 |
theory Eval |
|
25763 | 9 |
imports ATP_Linkup Code_Message |
22525 | 10 |
begin |
11 |
||
25763 | 12 |
subsection {* Type reflection *} |
13 |
||
14 |
subsubsection {* Definition *} |
|
15 |
||
16 |
types vname = message_string; |
|
17 |
types "class" = message_string; |
|
18 |
types sort = "class list" |
|
19 |
||
20 |
datatype "typ" = |
|
21 |
Type message_string "typ list" |
|
22 |
| TFree vname sort |
|
23 |
||
24 |
abbreviation |
|
25 |
Fun :: "typ \<Rightarrow> typ \<Rightarrow> typ" where |
|
26 |
"Fun ty1 ty2 \<equiv> Type (STR ''fun'') [ty1, ty2]" |
|
27 |
||
28 |
locale (open) pure_term_syntax = -- {* FIXME drop this *} |
|
29 |
fixes pure_term_Type :: "message_string \<Rightarrow> typ list \<Rightarrow> typ" (infixl "{\<struct>}" 120) |
|
30 |
and pure_term_TFree :: "vname \<Rightarrow> sort \<Rightarrow> typ" ("\<lbrace>_\<Colon>_\<rbrace>" [118, 118] 117) |
|
31 |
and pure_term_Fun :: "typ \<Rightarrow> typ \<Rightarrow> typ" (infixr "\<rightarrow>" 114) |
|
32 |
||
33 |
parse_translation {* |
|
34 |
let |
|
35 |
fun Type_tr [tyco, tys] = Lexicon.const @{const_syntax Type} $ tyco $ tys |
|
36 |
| Type_tr ts = raise TERM ("Type_tr", ts); |
|
37 |
fun TFree_tr [v, sort] = Lexicon.const @{const_syntax TFree} $ v $ sort |
|
38 |
| TFree_tr ts = raise TERM ("TFree_tr", ts); |
|
39 |
fun Fun_tr [ty1, ty2] = Lexicon.const @{const_syntax Fun} $ ty1 $ ty2 |
|
40 |
| Fun_tr ts = raise TERM("Fun_tr", ts); |
|
41 |
in [ |
|
25985 | 42 |
("\<^fixed>pure_term_Type", Type_tr), |
43 |
("\<^fixed>pure_term_TFree", TFree_tr), |
|
44 |
("\<^fixed>pure_term_Fun", Fun_tr) |
|
25763 | 45 |
] end |
46 |
*} |
|
47 |
||
48 |
notation (output) |
|
49 |
Type (infixl "{\<struct>}" 120) |
|
50 |
and |
|
51 |
TFree ("\<lbrace>_\<Colon>_\<rbrace>" [118, 118] 117) |
|
52 |
and |
|
53 |
Fun (infixr "\<rightarrow>" 114) |
|
54 |
||
55 |
ML {* |
|
56 |
structure Eval_Aux = |
|
57 |
struct |
|
58 |
||
59 |
val mk_sort = HOLogic.mk_list @{typ class} o map Message_String.mk; |
|
60 |
||
61 |
fun mk_typ f (Type (tyco, tys)) = |
|
62 |
@{term Type} $ Message_String.mk tyco |
|
63 |
$ HOLogic.mk_list @{typ typ} (map (mk_typ f) tys) |
|
64 |
| mk_typ f (TFree v) = |
|
65 |
f v; |
|
66 |
||
67 |
end; |
|
68 |
*} |
|
69 |
||
70 |
||
71 |
subsubsection {* Class @{text typ_of} *} |
|
22525 | 72 |
|
23062 | 73 |
class typ_of = |
74 |
fixes typ_of :: "'a\<Colon>{} itself \<Rightarrow> typ" |
|
22525 | 75 |
|
76 |
ML {* |
|
25763 | 77 |
structure Eval_Aux = |
22525 | 78 |
struct |
79 |
||
25763 | 80 |
open Eval_Aux; |
81 |
||
82 |
fun mk_typ_of ty = |
|
22525 | 83 |
Const (@{const_name typ_of}, Term.itselfT ty --> @{typ typ}) |
84 |
$ Logic.mk_type ty; |
|
85 |
||
25536 | 86 |
end |
22525 | 87 |
*} |
88 |
||
89 |
setup {* |
|
90 |
let |
|
25763 | 91 |
open Eval_Aux; |
25536 | 92 |
fun define_typ_of ty lthy = |
93 |
let |
|
94 |
val lhs = Const (@{const_name typ_of}, Term.itselfT ty --> @{typ typ}) |
|
95 |
$ Free ("T", Term.itselfT ty); |
|
25763 | 96 |
val rhs = mk_typ (fn v => mk_typ_of (TFree v)) ty; |
25603 | 97 |
val eq = Syntax.check_term lthy (HOLogic.mk_Trueprop (HOLogic.mk_eq (lhs, rhs))) |
25536 | 98 |
in lthy |> Specification.definition (NONE, (("", []), eq)) end; |
99 |
fun interpretator tyco thy = |
|
100 |
let |
|
101 |
val sorts = replicate (Sign.arity_number thy tyco) @{sort typ_of}; |
|
25864 | 102 |
val vs = Name.names Name.context "'a" sorts; |
103 |
val ty = Type (tyco, map TFree vs); |
|
25536 | 104 |
in |
105 |
thy |
|
25864 | 106 |
|> TheoryTarget.instantiation ([tyco], vs, @{sort typ_of}) |
25569 | 107 |
|> define_typ_of ty |
108 |
|> snd |
|
109 |
|> Class.prove_instantiation_instance (K (Class.intro_classes_tac [])) |
|
110 |
|> LocalTheory.exit |
|
111 |
|> ProofContext.theory_of |
|
25536 | 112 |
end; |
113 |
in TypedefPackage.interpretation interpretator end |
|
22525 | 114 |
*} |
115 |
||
25536 | 116 |
instantiation "prop" :: typ_of |
117 |
begin |
|
118 |
||
25666 | 119 |
definition |
120 |
"typ_of (T\<Colon>prop itself) = Type (STR ''prop'') []" |
|
25536 | 121 |
|
122 |
instance .. |
|
123 |
||
124 |
end |
|
125 |
||
126 |
instantiation itself :: (typ_of) typ_of |
|
127 |
begin |
|
128 |
||
129 |
definition |
|
25666 | 130 |
"typ_of (T\<Colon>'a itself itself) = Type (STR ''itself'') [typ_of TYPE('a\<Colon>typ_of)]" |
25536 | 131 |
|
132 |
instance .. |
|
133 |
||
134 |
end |
|
135 |
||
136 |
instantiation set :: (typ_of) typ_of |
|
137 |
begin |
|
138 |
||
139 |
definition |
|
25666 | 140 |
"typ_of (T\<Colon>'a set itself) = Type (STR ''set'') [typ_of TYPE('a\<Colon>typ_of)]" |
25536 | 141 |
|
142 |
instance .. |
|
143 |
||
144 |
end |
|
145 |
||
22525 | 146 |
|
25763 | 147 |
subsubsection {* Code generator setup *} |
148 |
||
149 |
lemma [code func]: |
|
150 |
includes pure_term_syntax |
|
151 |
shows "tyco1 {\<struct>} tys1 = tyco2 {\<struct>} tys2 \<longleftrightarrow> tyco1 = tyco2 |
|
152 |
\<and> list_all2 (op =) tys1 tys2" |
|
153 |
by (auto simp add: list_all2_eq [symmetric]) |
|
154 |
||
155 |
code_type "typ" |
|
156 |
(SML "Term.typ") |
|
157 |
||
158 |
code_const Type and TFree |
|
159 |
(SML "Term.Type/ (_, _)" and "Term.TFree/ (_, _)") |
|
160 |
||
161 |
code_reserved SML Term |
|
162 |
||
163 |
||
164 |
||
165 |
subsection {* Term representation *} |
|
166 |
||
167 |
subsubsection {* Definition *} |
|
168 |
||
169 |
datatype "term" = |
|
170 |
Const message_string "typ" (infix "\<Colon>\<subseteq>" 112) |
|
171 |
| Fix vname "typ" (infix ":\<epsilon>" 112) |
|
172 |
| App "term" "term" (infixl "\<bullet>" 110) |
|
173 |
| Abs "vname \<times> typ" "term" (infixr "\<mapsto>" 111) |
|
174 |
| Bnd nat |
|
175 |
||
176 |
code_datatype Const App Fix |
|
177 |
||
178 |
abbreviation |
|
179 |
Apps :: "term \<Rightarrow> term list \<Rightarrow> term" (infixl "{\<bullet>}" 110) where |
|
180 |
"t {\<bullet>} ts \<equiv> foldl (op \<bullet>) t ts" |
|
181 |
abbreviation |
|
182 |
Abss :: "(vname \<times> typ) list \<Rightarrow> term \<Rightarrow> term" (infixr "{\<mapsto>}" 111) where |
|
183 |
"vs {\<mapsto>} t \<equiv> foldr (op \<mapsto>) vs t" |
|
184 |
||
185 |
ML {* |
|
186 |
structure Eval_Aux = |
|
187 |
struct |
|
188 |
||
189 |
open Eval_Aux; |
|
190 |
||
191 |
fun mk_term f g (Const (c, ty)) = |
|
192 |
@{term Const} $ Message_String.mk c $ g ty |
|
193 |
| mk_term f g (t1 $ t2) = |
|
194 |
@{term App} $ mk_term f g t1 $ mk_term f g t2 |
|
195 |
| mk_term f g (Free v) = f v; |
|
196 |
||
197 |
end; |
|
198 |
*} |
|
199 |
||
200 |
||
201 |
subsubsection {* Class @{text term_of} *} |
|
22525 | 202 |
|
203 |
class term_of = typ_of + |
|
23062 | 204 |
constrains typ_of :: "'a\<Colon>{} itself \<Rightarrow> typ" |
22525 | 205 |
fixes term_of :: "'a \<Rightarrow> term" |
206 |
||
207 |
ML {* |
|
25763 | 208 |
structure Eval_Aux = |
22525 | 209 |
struct |
210 |
||
25763 | 211 |
open Eval_Aux; |
212 |
||
22525 | 213 |
local |
214 |
fun term_term_of ty = |
|
215 |
Const (@{const_name term_of}, ty --> @{typ term}); |
|
216 |
in |
|
217 |
val class_term_of = Sign.intern_class @{theory} "term_of"; |
|
218 |
fun mk_terms_of_defs vs (tyco, cs) = |
|
219 |
let |
|
220 |
val dty = Type (tyco, map TFree vs); |
|
221 |
fun mk_eq c = |
|
222 |
let |
|
223 |
val lhs : term = term_term_of dty $ c; |
|
25763 | 224 |
val rhs : term = mk_term |
22525 | 225 |
(fn (v, ty) => term_term_of ty $ Free (v, ty)) |
25763 | 226 |
(mk_typ (fn (v, sort) => mk_typ_of (TFree (v, sort)))) c |
22525 | 227 |
in |
25559 | 228 |
HOLogic.mk_Trueprop (HOLogic.mk_eq (lhs, rhs)) |
22525 | 229 |
end; |
230 |
in map mk_eq cs end; |
|
231 |
fun mk_term_of t = |
|
232 |
term_term_of (Term.fastype_of t) $ t; |
|
233 |
end; |
|
234 |
||
235 |
end; |
|
236 |
*} |
|
237 |
||
238 |
setup {* |
|
239 |
let |
|
25763 | 240 |
open Eval_Aux; |
22525 | 241 |
fun thy_note ((name, atts), thms) = |
242 |
PureThy.add_thmss [((name, thms), atts)] #-> (fn [thms] => pair (name, thms)); |
|
243 |
fun thy_def ((name, atts), t) = |
|
244 |
PureThy.add_defs_i false [((name, t), atts)] #-> (fn [thm] => pair (name, thm)); |
|
25536 | 245 |
fun prep_dtyp thy vs tyco = |
246 |
let |
|
247 |
val (_, cs) = DatatypePackage.the_datatype_spec thy tyco; |
|
248 |
val prep_typ = map_atyps (fn TFree (v, sort) => |
|
249 |
TFree (v, (the o AList.lookup (op =) vs) v)); |
|
250 |
fun prep_c (c, tys) = list_comb (Const (c, tys ---> Type (tyco, map TFree vs)), |
|
251 |
map Free (Name.names Name.context "a" tys)); |
|
252 |
in (tyco, map (prep_c o (apsnd o map) prep_typ) cs) end; |
|
253 |
fun prep thy tycos = |
|
22525 | 254 |
let |
25536 | 255 |
val inter_sort = curry (Sorts.inter_sort (Sign.classes_of thy)) @{sort term_of}; |
256 |
val tyco = hd tycos; |
|
257 |
val (vs_proto, _) = DatatypePackage.the_datatype_spec thy tyco; |
|
258 |
val all_typs = maps (maps snd o snd o DatatypePackage.the_datatype_spec thy) tycos; |
|
259 |
fun add_tycos (Type (tyco, tys)) = insert (op =) tyco #> |
|
260 |
fold add_tycos tys |
|
261 |
| add_tycos _ = I; |
|
262 |
val dep_tycos = [] |> fold add_tycos all_typs |> subtract (op =) tycos; |
|
263 |
val sorts = map (inter_sort o snd) vs_proto; |
|
264 |
val vs = map fst vs_proto ~~ sorts; |
|
265 |
val css = map (prep_dtyp thy vs) tycos; |
|
25763 | 266 |
val defs = map (mk_terms_of_defs vs) css; |
25536 | 267 |
in if forall (fn tyco => can (Sign.arity_sorts thy tyco) @{sort term_of}) dep_tycos |
268 |
andalso not (tycos = [@{type_name typ}]) |
|
25864 | 269 |
then SOME (vs, defs) |
25536 | 270 |
else NONE |
22525 | 271 |
end; |
25559 | 272 |
fun prep' ctxt proto_eqs = |
273 |
let |
|
25603 | 274 |
val eqs as eq :: _ = map (Syntax.check_term ctxt) proto_eqs; |
25559 | 275 |
val (Free (v, ty), _) = |
276 |
(strip_comb o fst o HOLogic.dest_eq o HOLogic.dest_Trueprop) eq; |
|
277 |
in ((v, SOME ty, NoSyn), map (pair ("", [])) eqs) end; |
|
278 |
fun primrec primrecs ctxt = |
|
279 |
let |
|
280 |
val (fixes, eqnss) = split_list (map (prep' ctxt) primrecs); |
|
281 |
in PrimrecPackage.add_primrec fixes (flat eqnss) ctxt end; |
|
25536 | 282 |
fun interpretator tycos thy = case prep thy tycos |
25864 | 283 |
of SOME (vs, defs) => |
25536 | 284 |
thy |
25864 | 285 |
|> TheoryTarget.instantiation (tycos, vs, @{sort term_of}) |
25569 | 286 |
|> primrec defs |
287 |
|> snd |
|
288 |
|> Class.prove_instantiation_instance (K (Class.intro_classes_tac [])) |
|
289 |
|> LocalTheory.exit |
|
290 |
|> ProofContext.theory_of |
|
25536 | 291 |
| NONE => thy; |
292 |
in DatatypePackage.interpretation interpretator end |
|
22525 | 293 |
*} |
294 |
||
25666 | 295 |
abbreviation (in pure_term_syntax) (input) |
23062 | 296 |
intT :: "typ" |
297 |
where |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25864
diff
changeset
|
298 |
"intT \<equiv> Type (STR ''Int.int'') []" |
23062 | 299 |
|
25666 | 300 |
abbreviation (in pure_term_syntax) (input) |
23133 | 301 |
bitT :: "typ" |
302 |
where |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25864
diff
changeset
|
303 |
"bitT \<equiv> Type (STR ''Int.bit'') []" |
23133 | 304 |
|
25666 | 305 |
function (in pure_term_syntax) |
23062 | 306 |
mk_int :: "int \<Rightarrow> term" |
307 |
where |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25864
diff
changeset
|
308 |
"mk_int k = (if k = 0 then STR ''Int.Pls'' \<Colon>\<subseteq> intT |
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25864
diff
changeset
|
309 |
else if k = -1 then STR ''Int.Min'' \<Colon>\<subseteq> intT |
23062 | 310 |
else let (l, m) = divAlg (k, 2) |
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25864
diff
changeset
|
311 |
in STR ''Int.Bit'' \<Colon>\<subseteq> intT \<rightarrow> bitT \<rightarrow> intT \<bullet> mk_int l \<bullet> |
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25864
diff
changeset
|
312 |
(if m = 0 then STR ''Int.bit.B0'' \<Colon>\<subseteq> bitT else STR ''Int.bit.B1'' \<Colon>\<subseteq> bitT))" |
23062 | 313 |
by pat_completeness auto |
25666 | 314 |
termination (in pure_term_syntax) |
315 |
by (relation "measure (nat o abs)") (auto simp add: divAlg_mod_div) |
|
316 |
||
317 |
declare pure_term_syntax.mk_int.simps [code func] |
|
318 |
||
319 |
definition (in pure_term_syntax) |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25864
diff
changeset
|
320 |
"term_of_int_aux k = STR ''Int.number_class.number_of'' \<Colon>\<subseteq> intT \<rightarrow> intT \<bullet> mk_int k" |
25666 | 321 |
|
322 |
declare pure_term_syntax.term_of_int_aux_def [code func] |
|
23062 | 323 |
|
25569 | 324 |
instantiation int :: term_of |
325 |
begin |
|
326 |
||
327 |
definition |
|
25666 | 328 |
"term_of = pure_term_syntax.term_of_int_aux" |
25569 | 329 |
|
330 |
instance .. |
|
331 |
||
332 |
end |
|
23062 | 333 |
|
334 |
||
25763 | 335 |
subsubsection {* Code generator setup *} |
336 |
||
337 |
lemmas [code func del] = term.recs term.cases term.size |
|
338 |
lemmas [code func del] = term_of_message_string.simps |
|
339 |
lemma [code func, code func del]: "(t1\<Colon>term) = t2 \<longleftrightarrow> t1 = t2" .. |
|
22525 | 340 |
|
25763 | 341 |
code_type "term" |
342 |
(SML "Term.term") |
|
343 |
||
344 |
code_const Const and App and Fix |
|
345 |
(SML "Term.Const/ (_, _)" and "Term.$/ (_, _)" and "Term.Free/ (_, _)") |
|
22525 | 346 |
|
347 |
||
25763 | 348 |
subsection {* Evaluation setup *} |
22525 | 349 |
|
350 |
ML {* |
|
351 |
signature EVAL = |
|
352 |
sig |
|
24587 | 353 |
val eval_ref: (unit -> term) option ref |
24835
8c26128f8997
clarified relationship of code generator conversions and evaluations
haftmann
parents:
24659
diff
changeset
|
354 |
val eval_term: theory -> term -> term |
8c26128f8997
clarified relationship of code generator conversions and evaluations
haftmann
parents:
24659
diff
changeset
|
355 |
val evaluate: Proof.context -> term -> unit |
8c26128f8997
clarified relationship of code generator conversions and evaluations
haftmann
parents:
24659
diff
changeset
|
356 |
val evaluate': string -> Proof.context -> term -> unit |
8c26128f8997
clarified relationship of code generator conversions and evaluations
haftmann
parents:
24659
diff
changeset
|
357 |
val evaluate_cmd: string option -> Toplevel.state -> unit |
22525 | 358 |
end; |
359 |
||
24280 | 360 |
structure Eval = |
22525 | 361 |
struct |
362 |
||
24587 | 363 |
val eval_ref = ref (NONE : (unit -> term) option); |
22525 | 364 |
|
24835
8c26128f8997
clarified relationship of code generator conversions and evaluations
haftmann
parents:
24659
diff
changeset
|
365 |
fun eval_invoke thy code ((_, ty), t) deps _ = |
24916 | 366 |
CodeTarget.eval_invoke thy ("Eval.eval_ref", eval_ref) code (t, ty) []; |
24280 | 367 |
|
24835
8c26128f8997
clarified relationship of code generator conversions and evaluations
haftmann
parents:
24659
diff
changeset
|
368 |
fun eval_term thy = |
25763 | 369 |
Eval_Aux.mk_term_of |
24835
8c26128f8997
clarified relationship of code generator conversions and evaluations
haftmann
parents:
24659
diff
changeset
|
370 |
#> CodePackage.eval_term thy (eval_invoke thy) |
8c26128f8997
clarified relationship of code generator conversions and evaluations
haftmann
parents:
24659
diff
changeset
|
371 |
#> Code.postprocess_term thy; |
24280 | 372 |
|
24835
8c26128f8997
clarified relationship of code generator conversions and evaluations
haftmann
parents:
24659
diff
changeset
|
373 |
val evaluators = [ |
8c26128f8997
clarified relationship of code generator conversions and evaluations
haftmann
parents:
24659
diff
changeset
|
374 |
("code", eval_term), |
8c26128f8997
clarified relationship of code generator conversions and evaluations
haftmann
parents:
24659
diff
changeset
|
375 |
("SML", Codegen.eval_term), |
8c26128f8997
clarified relationship of code generator conversions and evaluations
haftmann
parents:
24659
diff
changeset
|
376 |
("normal_form", Nbe.norm_term) |
8c26128f8997
clarified relationship of code generator conversions and evaluations
haftmann
parents:
24659
diff
changeset
|
377 |
]; |
22525 | 378 |
|
24835
8c26128f8997
clarified relationship of code generator conversions and evaluations
haftmann
parents:
24659
diff
changeset
|
379 |
fun gen_evaluate evaluators ctxt t = |
24280 | 380 |
let |
381 |
val thy = ProofContext.theory_of ctxt; |
|
24835
8c26128f8997
clarified relationship of code generator conversions and evaluations
haftmann
parents:
24659
diff
changeset
|
382 |
val (evls, evl) = split_last evaluators; |
8c26128f8997
clarified relationship of code generator conversions and evaluations
haftmann
parents:
24659
diff
changeset
|
383 |
val t' = case get_first (fn f => try (f thy) t) evls |
8c26128f8997
clarified relationship of code generator conversions and evaluations
haftmann
parents:
24659
diff
changeset
|
384 |
of SOME t' => t' |
8c26128f8997
clarified relationship of code generator conversions and evaluations
haftmann
parents:
24659
diff
changeset
|
385 |
| NONE => evl thy t; |
8c26128f8997
clarified relationship of code generator conversions and evaluations
haftmann
parents:
24659
diff
changeset
|
386 |
val ty' = Term.type_of t'; |
24920 | 387 |
val p = Pretty.block [Pretty.quote (Syntax.pretty_term ctxt t'), |
24835
8c26128f8997
clarified relationship of code generator conversions and evaluations
haftmann
parents:
24659
diff
changeset
|
388 |
Pretty.fbrk, Pretty.str "::", Pretty.brk 1, |
24920 | 389 |
Pretty.quote (Syntax.pretty_typ ctxt ty')]; |
24280 | 390 |
in Pretty.writeln p end; |
391 |
||
24835
8c26128f8997
clarified relationship of code generator conversions and evaluations
haftmann
parents:
24659
diff
changeset
|
392 |
val evaluate = gen_evaluate (map snd evaluators); |
8c26128f8997
clarified relationship of code generator conversions and evaluations
haftmann
parents:
24659
diff
changeset
|
393 |
|
8c26128f8997
clarified relationship of code generator conversions and evaluations
haftmann
parents:
24659
diff
changeset
|
394 |
fun evaluate' name = gen_evaluate |
8c26128f8997
clarified relationship of code generator conversions and evaluations
haftmann
parents:
24659
diff
changeset
|
395 |
[(the o AList.lookup (op =) evaluators) name]; |
8c26128f8997
clarified relationship of code generator conversions and evaluations
haftmann
parents:
24659
diff
changeset
|
396 |
|
8c26128f8997
clarified relationship of code generator conversions and evaluations
haftmann
parents:
24659
diff
changeset
|
397 |
fun evaluate_cmd some_name raw_t state = |
22525 | 398 |
let |
22804 | 399 |
val ctxt = Toplevel.context_of state; |
24508
c8b82fec6447
replaced ProofContext.read_term/prop by general Syntax.read_term/prop;
wenzelm
parents:
24423
diff
changeset
|
400 |
val t = Syntax.read_term ctxt raw_t; |
24835
8c26128f8997
clarified relationship of code generator conversions and evaluations
haftmann
parents:
24659
diff
changeset
|
401 |
in case some_name |
8c26128f8997
clarified relationship of code generator conversions and evaluations
haftmann
parents:
24659
diff
changeset
|
402 |
of NONE => evaluate ctxt t |
8c26128f8997
clarified relationship of code generator conversions and evaluations
haftmann
parents:
24659
diff
changeset
|
403 |
| SOME name => evaluate' name ctxt t |
8c26128f8997
clarified relationship of code generator conversions and evaluations
haftmann
parents:
24659
diff
changeset
|
404 |
end; |
22525 | 405 |
|
406 |
end; |
|
407 |
*} |
|
408 |
||
22804 | 409 |
ML {* |
410 |
OuterSyntax.improper_command "value" "read, evaluate and print term" OuterKeyword.diag |
|
24835
8c26128f8997
clarified relationship of code generator conversions and evaluations
haftmann
parents:
24659
diff
changeset
|
411 |
(Scan.option (OuterParse.$$$ "(" |-- OuterParse.name --| OuterParse.$$$ ")") |
8c26128f8997
clarified relationship of code generator conversions and evaluations
haftmann
parents:
24659
diff
changeset
|
412 |
-- OuterParse.term |
8c26128f8997
clarified relationship of code generator conversions and evaluations
haftmann
parents:
24659
diff
changeset
|
413 |
>> (fn (some_name, t) => Toplevel.no_timing o Toplevel.keep |
8c26128f8997
clarified relationship of code generator conversions and evaluations
haftmann
parents:
24659
diff
changeset
|
414 |
(Eval.evaluate_cmd some_name t))); |
22804 | 415 |
*} |
416 |
||
22665 | 417 |
end |