author | haftmann |
Mon, 20 Jul 2009 08:31:12 +0200 | |
changeset 32077 | 3698947146b2 |
parent 31225 | df6945ac4193 |
child 32308 | c2b74affab85 |
child 32340 | b4632820e74c |
permissions | -rw-r--r-- |
30374
7311a1546d85
added predicate compiler, as formally checked prototype, not as user package
haftmann
parents:
diff
changeset
|
1 |
theory Predicate_Compile |
30972
5b65835ccc92
some experiements towards user interface for predicate compiler
haftmann
parents:
30953
diff
changeset
|
2 |
imports Complex_Main Lattice_Syntax Code_Eval |
30374
7311a1546d85
added predicate compiler, as formally checked prototype, not as user package
haftmann
parents:
diff
changeset
|
3 |
uses "predicate_compile.ML" |
7311a1546d85
added predicate compiler, as formally checked prototype, not as user package
haftmann
parents:
diff
changeset
|
4 |
begin |
7311a1546d85
added predicate compiler, as formally checked prototype, not as user package
haftmann
parents:
diff
changeset
|
5 |
|
30972
5b65835ccc92
some experiements towards user interface for predicate compiler
haftmann
parents:
30953
diff
changeset
|
6 |
text {* Package setup *} |
5b65835ccc92
some experiements towards user interface for predicate compiler
haftmann
parents:
30953
diff
changeset
|
7 |
|
30374
7311a1546d85
added predicate compiler, as formally checked prototype, not as user package
haftmann
parents:
diff
changeset
|
8 |
setup {* Predicate_Compile.setup *} |
7311a1546d85
added predicate compiler, as formally checked prototype, not as user package
haftmann
parents:
diff
changeset
|
9 |
|
30972
5b65835ccc92
some experiements towards user interface for predicate compiler
haftmann
parents:
30953
diff
changeset
|
10 |
text {* Experimental code *} |
30374
7311a1546d85
added predicate compiler, as formally checked prototype, not as user package
haftmann
parents:
diff
changeset
|
11 |
|
30810 | 12 |
ML {* |
31217 | 13 |
structure Predicate_Compile = |
30953 | 14 |
struct |
15 |
||
31217 | 16 |
open Predicate_Compile; |
30972
5b65835ccc92
some experiements towards user interface for predicate compiler
haftmann
parents:
30953
diff
changeset
|
17 |
|
31217 | 18 |
fun eval thy t_compr = |
19 |
let |
|
20 |
val t = Predicate_Compile.analyze_compr thy t_compr; |
|
21 |
val Type (@{type_name Predicate.pred}, [T]) = fastype_of t; |
|
22 |
fun mk_predT T = Type (@{type_name Predicate.pred}, [T]); |
|
23 |
val T1 = T --> @{typ term}; |
|
24 |
val T2 = T1 --> mk_predT T --> mk_predT @{typ term}; |
|
25 |
val t' = Const (@{const_name Predicate.map}, T2) (*FIXME*) |
|
26 |
$ Const (@{const_name Code_Eval.term_of}, T1) $ t; |
|
31225 | 27 |
in (T, Code_ML.eval NONE ("Predicate_Compile.eval_ref", eval_ref) Predicate.map thy t' []) end; |
30972
5b65835ccc92
some experiements towards user interface for predicate compiler
haftmann
parents:
30953
diff
changeset
|
28 |
|
31217 | 29 |
fun values ctxt k t_compr = |
30 |
let |
|
31 |
val thy = ProofContext.theory_of ctxt; |
|
32 |
val (T, t') = eval thy t_compr; |
|
33 |
in t' |> Predicate.yieldn k |> fst |> HOLogic.mk_list T end; |
|
30953 | 34 |
|
31217 | 35 |
fun values_cmd modes k raw_t state = |
30972
5b65835ccc92
some experiements towards user interface for predicate compiler
haftmann
parents:
30953
diff
changeset
|
36 |
let |
31217 | 37 |
val ctxt = Toplevel.context_of state; |
38 |
val t = Syntax.read_term ctxt raw_t; |
|
39 |
val t' = values ctxt k t; |
|
40 |
val ty' = Term.type_of t'; |
|
41 |
val ctxt' = Variable.auto_fixes t' ctxt; |
|
42 |
val p = PrintMode.with_modes modes (fn () => |
|
43 |
Pretty.block [Pretty.quote (Syntax.pretty_term ctxt' t'), Pretty.fbrk, |
|
44 |
Pretty.str "::", Pretty.brk 1, Pretty.quote (Syntax.pretty_typ ctxt' ty')]) (); |
|
45 |
in Pretty.writeln p end; |
|
46 |
||
47 |
end; |
|
48 |
||
49 |
local structure P = OuterParse in |
|
50 |
||
51 |
val opt_modes = Scan.optional (P.$$$ "(" |-- P.!!! (Scan.repeat1 P.xname --| P.$$$ ")")) []; |
|
52 |
||
53 |
val _ = OuterSyntax.improper_command "values" "enumerate and print comprehensions" OuterKeyword.diag |
|
54 |
(opt_modes -- Scan.optional P.nat ~1 -- P.term |
|
55 |
>> (fn ((modes, k), t) => Toplevel.no_timing o Toplevel.keep |
|
56 |
(Predicate_Compile.values_cmd modes k t))); |
|
30953 | 57 |
|
58 |
end; |
|
30810 | 59 |
*} |
30374
7311a1546d85
added predicate compiler, as formally checked prototype, not as user package
haftmann
parents:
diff
changeset
|
60 |
|
7311a1546d85
added predicate compiler, as formally checked prototype, not as user package
haftmann
parents:
diff
changeset
|
61 |
end |