wneuper@59572
|
1 |
(* Title: interpreter-state for Lucas-Interpretation
|
wneuper@59572
|
2 |
Author: Walther Neuper 190724
|
wneuper@59572
|
3 |
(c) due to copyright terms
|
wneuper@59572
|
4 |
*)
|
wneuper@59572
|
5 |
signature INTERPRETER_STATE =
|
wneuper@59572
|
6 |
sig
|
wneuper@59572
|
7 |
datatype safe = Sundef | Safe | Unsafe | Helpless;
|
wneuper@59572
|
8 |
val safe2str : safe -> string
|
wneuper@59572
|
9 |
|
wneuper@59572
|
10 |
type scrstate
|
wneuper@59572
|
11 |
val e_scrstate : scrstate
|
wneuper@59572
|
12 |
val scrstate2str : Rule.subst * Celem.loc_ * term option * term * safe * bool -> string
|
wneuper@59572
|
13 |
|
wneuper@59583
|
14 |
datatype T = RrlsState of Rule.rrlsstate | Pstate of scrstate | Uistate
|
wneuper@59572
|
15 |
val istate2str : T -> string
|
wneuper@59572
|
16 |
val istates2str : T option * T option -> string
|
wneuper@59572
|
17 |
val e_istate : T
|
wneuper@59572
|
18 |
|
walther@59660
|
19 |
val get_act_env : scrstate -> (term * Env.T)
|
walther@59660
|
20 |
val get_subst : scrstate -> (Env.T * (term option * term))
|
walther@59660
|
21 |
val get_assoc : scrstate -> bool
|
walther@59660
|
22 |
|
walther@59660
|
23 |
val trans_ass: scrstate -> scrstate -> scrstate
|
walther@59660
|
24 |
val trans_env_act: scrstate -> scrstate -> scrstate
|
walther@59659
|
25 |
|
walther@59659
|
26 |
val append_path : Celem.loc_ -> scrstate -> scrstate
|
walther@59660
|
27 |
val append_path_form: (Celem.loc_ * term) -> scrstate -> scrstate
|
walther@59660
|
28 |
|
walther@59660
|
29 |
val upd_form : term -> scrstate -> scrstate
|
walther@59659
|
30 |
val upd_curr : term option -> scrstate -> scrstate
|
walther@59660
|
31 |
val upd_env: Env.T -> scrstate -> scrstate
|
walther@59660
|
32 |
val upd_env': term -> scrstate -> scrstate
|
walther@59660
|
33 |
val upd_form_env: (term * Env.T) -> scrstate -> scrstate
|
walther@59660
|
34 |
(*val upd_act_env: (term * Env.T) -> scrstate -> scrstate*)
|
walther@59660
|
35 |
val upd_subst: Env.T -> (term * term) -> scrstate -> scrstate
|
walther@59660
|
36 |
val upd_subst_true: (term option * term) -> scrstate -> scrstate
|
walther@59660
|
37 |
val upd_subst_false: (term option * term) -> scrstate -> scrstate
|
walther@59659
|
38 |
|
wneuper@59572
|
39 |
end
|
wneuper@59572
|
40 |
|
walther@59659
|
41 |
(**)
|
wneuper@59572
|
42 |
structure Istate(**): INTERPRETER_STATE(**) =
|
wneuper@59572
|
43 |
struct
|
walther@59659
|
44 |
(**)
|
wneuper@59572
|
45 |
|
wneuper@59572
|
46 |
datatype safe = Sundef | Safe | Unsafe | Helpless;
|
wneuper@59572
|
47 |
fun safe2str Sundef = "Sundef"
|
wneuper@59572
|
48 |
| safe2str Safe = "Safe"
|
wneuper@59572
|
49 |
| safe2str Unsafe = "Unsafe"
|
wneuper@59572
|
50 |
| safe2str Helpless = "Helpless";
|
wneuper@59572
|
51 |
|
wneuper@59572
|
52 |
type scrstate = (* state for script interpreter *)
|
walther@59659
|
53 |
Env.T(*stack*) (* used to instantiate tac for checking associate
|
wneuper@59572
|
54 |
12.03.noticed: e_ not updated during execution ?!? *)
|
wneuper@59572
|
55 |
* Celem.loc_ (* location of tac in script *)
|
walther@59660
|
56 |
* term option (* FORMal ARGument of curried functions *)
|
walther@59660
|
57 |
* term (* ACTual ARGument (value) for execution of Tactic.T
|
wneuper@59572
|
58 |
updated also after a derivation by 'new_val' *)
|
wneuper@59572
|
59 |
* safe (* estimation of how result will be obtained *)
|
wneuper@59572
|
60 |
* bool; (* true = strongly .., false = weakly associated:
|
wneuper@59572
|
61 |
only used during ass_dn/up *)
|
wneuper@59572
|
62 |
val e_scrstate =
|
walther@59659
|
63 |
([]: Env.T, []:Celem.loc_, SOME Rule.e_term, Rule.e_term, Sundef, false) : scrstate
|
wneuper@59572
|
64 |
fun topt2str NONE = "NONE"
|
wneuper@59572
|
65 |
| topt2str (SOME t) = "SOME" ^ Rule.term2str t;
|
wneuper@59572
|
66 |
fun scrstate2str (env, loc_, topt, t, safe, bool) = (* for tests only *)
|
walther@59659
|
67 |
"(" ^ Env.env2str env ^ ", " ^ Celem.loc_2str loc_ ^ ", " ^ topt2str topt ^ ", \n" ^
|
wneuper@59572
|
68 |
Rule.term2str t ^ ", " ^ safe2str safe ^ ", " ^ bool2str bool ^ ")";
|
wneuper@59572
|
69 |
|
wneuper@59572
|
70 |
(* for handling type T see fun from_pblobj_or_detail', +? *)
|
wneuper@59572
|
71 |
datatype T = (*interpreter state*)
|
wneuper@59572
|
72 |
Uistate (*undefined in modspec, in '_deriv'ation*)
|
wneuper@59583
|
73 |
| Pstate of scrstate (*for script interpreter*)
|
wneuper@59572
|
74 |
| RrlsState of Rule.rrlsstate; (*for reverse rewriting*)
|
wneuper@59583
|
75 |
val e_istate = (Pstate ([], [], NONE, Rule.e_term, Sundef, false));
|
wneuper@59572
|
76 |
|
wneuper@59572
|
77 |
fun rta2str (r, (t, a)) = "\n(" ^ Rule.rule2str r ^ ",(" ^ Rule.term2str t ^", " ^ Rule.terms2str a ^ "))";
|
wneuper@59572
|
78 |
fun istate2str Uistate = "Uistate"
|
wneuper@59583
|
79 |
| istate2str (Pstate (e, l, to, t, s, b)) =
|
walther@59659
|
80 |
"Pstate ("^ Env.subst2str e ^ ",\n " ^
|
wneuper@59572
|
81 |
Celem.loc_2str l ^ ", " ^ Rule.termopt2str to ^ ",\n " ^
|
wneuper@59572
|
82 |
Rule.term2str t ^ ", " ^ safe2str s ^ ", " ^ bool2str b ^ ")"
|
wneuper@59572
|
83 |
| istate2str (RrlsState (t, t1, rss, rtas)) =
|
wneuper@59572
|
84 |
"RrlsState (" ^ Rule.term2str t ^ ", " ^ Rule.term2str t1 ^ ", " ^
|
wneuper@59572
|
85 |
(strs2str o (map (strs2str o (map Rule.rule2str)))) rss ^ ", " ^
|
wneuper@59572
|
86 |
(strs2str o (map rta2str)) rtas ^ ")";
|
wneuper@59572
|
87 |
fun istates2str (NONE, NONE) = "(#NONE, #NONE)" (* for tests only *)
|
wneuper@59572
|
88 |
| istates2str (NONE, SOME ist) = "(#NONE,\n#SOME " ^ istate2str ist ^ ")"
|
wneuper@59572
|
89 |
| istates2str (SOME ist, NONE) = "(#SOME " ^ istate2str ist ^ ",\n #NONE)"
|
wneuper@59572
|
90 |
| istates2str (SOME i1, SOME i2) = "(#SOME " ^ istate2str i1 ^ ",\n #SOME " ^ istate2str i2 ^ ")";
|
wneuper@59572
|
91 |
|
walther@59660
|
92 |
fun get_act_env (env, _, _, act_arg, _, _) = (act_arg, env)
|
walther@59660
|
93 |
fun get_assoc (_, _, _, _, _, ass) = ass
|
walther@59660
|
94 |
fun get_subst (env, _, form_arg, act_arg, _, _) = (env, (form_arg, act_arg))
|
walther@59659
|
95 |
|
walther@59660
|
96 |
fun trans_ass (_, _, _, _, _, ass) (env, path, form_arg, act_arg, safe, _) =
|
walther@59660
|
97 |
(env, path, form_arg, act_arg, safe, ass)
|
walther@59660
|
98 |
fun trans_env_act (env, _, _, act_arg, _, _) (_, path, form_arg, _, safe, ass) =
|
walther@59660
|
99 |
(env, path, form_arg, act_arg, safe, ass)
|
walther@59659
|
100 |
|
walther@59660
|
101 |
fun append_path path (env, p, form_arg, act_arg, safe, ass) =
|
walther@59660
|
102 |
(env, p @ path, form_arg, act_arg, safe, ass)
|
walther@59660
|
103 |
fun append_path_form (path, form_arg) (env, p, _, act_arg, safe, ass) =
|
walther@59660
|
104 |
(env, p @ path, SOME form_arg, act_arg, safe, ass)
|
walther@59660
|
105 |
|
walther@59660
|
106 |
fun upd_form form (env, path, _, act_arg, safe, ass) =
|
walther@59660
|
107 |
(env, path, SOME form, act_arg, safe, ass)
|
walther@59660
|
108 |
fun upd_curr form_arg (env, path, _, res, safe, ass) =
|
walther@59660
|
109 |
(env, path, form_arg, res, safe, ass)
|
walther@59660
|
110 |
fun upd_env env (_, path, form_arg, act_arg, safe, ass) =
|
walther@59660
|
111 |
(env, path, form_arg, act_arg, safe, ass)
|
walther@59660
|
112 |
fun upd_env' form (env, path, form_arg, act_arg, safe, ass) =
|
walther@59660
|
113 |
(Env.upd_env env (form, act_arg), path, form_arg, act_arg, safe, ass)
|
walther@59660
|
114 |
fun upd_form_env (form_arg, env) (_, path, _, act_arg, safe, ass) =
|
walther@59660
|
115 |
(env, path, SOME form_arg, act_arg, safe, ass)
|
walther@59660
|
116 |
(*fun upd_act_env (act_arg, env) (_, path, form_arg, _, safe, ass) =
|
walther@59660
|
117 |
(env, path, form_arg, act_arg, safe, ass)*)
|
walther@59660
|
118 |
fun upd_subst env (form_arg, act_arg) (_, path, _, _, safe, ass) =
|
walther@59660
|
119 |
(env, path, SOME form_arg, act_arg, safe, ass)
|
walther@59660
|
120 |
fun upd_subst_true (form_arg, act_arg) (env, path, _, _, safe, _) =
|
walther@59660
|
121 |
(env, path, form_arg, act_arg, safe, true)
|
walther@59660
|
122 |
fun upd_subst_false (form_arg, act_arg) (env, path, _, _, safe, _) =
|
walther@59660
|
123 |
(env, path, form_arg, act_arg, safe, false)
|
wneuper@59572
|
124 |
|
wneuper@59572
|
125 |
end
|
wneuper@59572
|
126 |
|