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 |
|
walther@59675
|
8 |
datatype appy_ = AppUndef_ | Napp_ | Skip_
|
walther@59667
|
9 |
type pstate
|
walther@59667
|
10 |
val e_scrstate: pstate
|
walther@59676
|
11 |
val scrstate2str: Rule.subst * Celem.loc_ * Rule.rls * term option * term * appy_ * bool -> string
|
wneuper@59572
|
12 |
|
walther@59667
|
13 |
datatype T = RrlsState of Rule.rrlsstate | Pstate of pstate | Uistate
|
walther@59664
|
14 |
val istate2str: T -> string
|
walther@59664
|
15 |
val istates2str: T option * T option -> string
|
walther@59664
|
16 |
val e_istate: T
|
wneuper@59572
|
17 |
|
walther@59667
|
18 |
val get_path: pstate -> Celem.loc_
|
walther@59669
|
19 |
val get_path_up: pstate -> Celem.loc_
|
walther@59671
|
20 |
val get_act: pstate -> term
|
walther@59676
|
21 |
val get_rls: pstate -> Rule.rls
|
walther@59667
|
22 |
val get_env: pstate -> Env.T
|
walther@59667
|
23 |
val get_act_env: pstate -> (term * Env.T)
|
walther@59668
|
24 |
(*val get_form_env: pstate -> (term option * Env.T)*)
|
walther@59667
|
25 |
val get_subst: pstate -> (Env.T * (term option * term))
|
walther@59667
|
26 |
val get_assoc: pstate -> bool
|
walther@59660
|
27 |
|
walther@59679
|
28 |
val trans_scan_down2: pstate -> pstate
|
walther@59679
|
29 |
val trans_scan_up2: pstate -> pstate
|
walther@59667
|
30 |
val trans_ass: pstate -> pstate -> pstate
|
walther@59667
|
31 |
val trans_env_act: pstate -> pstate -> pstate
|
walther@59659
|
32 |
|
walther@59667
|
33 |
val path_down: Celem.loc_ -> pstate -> pstate
|
walther@59667
|
34 |
val path_down_form: (Celem.loc_ * term) -> pstate -> pstate
|
walther@59667
|
35 |
val path_up: pstate -> pstate
|
walther@59667
|
36 |
val path_up_down: Celem.loc_ -> pstate -> pstate
|
walther@59660
|
37 |
|
walther@59676
|
38 |
val upd_form: term -> pstate -> pstate
|
walther@59676
|
39 |
val upd_path: Celem.loc_ -> pstate -> pstate
|
walther@59677
|
40 |
val upd_rls: Rule.rls -> pstate -> pstate
|
walther@59676
|
41 |
val upd_act: term -> pstate -> pstate
|
walther@59676
|
42 |
val upd_appy: appy_ -> pstate -> pstate
|
walther@59667
|
43 |
val upd_env: Env.T -> pstate -> pstate
|
walther@59676
|
44 |
val upd_env_true: Env.T -> pstate -> pstate
|
walther@59667
|
45 |
val upd_env': term -> pstate -> pstate
|
walther@59673
|
46 |
val upd_env'': Env.T * (term * term) -> pstate -> pstate
|
walther@59667
|
47 |
val upd_form_env: (term * Env.T) -> pstate -> pstate
|
walther@59667
|
48 |
val upd_act_env: (term * Env.T) -> pstate -> pstate
|
walther@59667
|
49 |
val upd_subst: Env.T -> (term * term) -> pstate -> pstate
|
walther@59667
|
50 |
val upd_subst_true: (term option * term) -> pstate -> pstate
|
walther@59667
|
51 |
val upd_subst_false: (term option * term) -> pstate -> pstate
|
walther@59659
|
52 |
|
wneuper@59572
|
53 |
end
|
wneuper@59572
|
54 |
|
walther@59668
|
55 |
(**)
|
wneuper@59572
|
56 |
structure Istate(**): INTERPRETER_STATE(**) =
|
wneuper@59572
|
57 |
struct
|
walther@59659
|
58 |
(**)
|
wneuper@59572
|
59 |
|
walther@59679
|
60 |
open Celem
|
walther@59679
|
61 |
|
walther@59675
|
62 |
datatype appy_ = (* as argument in nxt_up, nstep_up, from appy *)
|
walther@59675
|
63 |
(*Appy is only (final) returnvalue, not argument during search *)
|
walther@59675
|
64 |
AppUndef_
|
walther@59675
|
65 |
| Napp_ (* ev. detects 'script is not appropriate for this example' *)
|
walther@59675
|
66 |
| Skip_; (* detects 'script successfully finished'
|
walther@59675
|
67 |
also used as init-value for resuming; this works,
|
walther@59675
|
68 |
because 'nxt_up Or e1' treats as Appy *)
|
walther@59675
|
69 |
fun appy_2str AppUndef_ = "AppUndef_"
|
walther@59675
|
70 |
| appy_2str Napp_ = "Napp_"
|
walther@59675
|
71 |
| appy_2str Skip_ = "Skip_"
|
wneuper@59572
|
72 |
|
walther@59667
|
73 |
type pstate = (* state for script interpreter *)
|
walther@59659
|
74 |
Env.T(*stack*) (* used to instantiate tac for checking associate
|
wneuper@59572
|
75 |
12.03.noticed: e_ not updated during execution ?!? *)
|
wneuper@59572
|
76 |
* Celem.loc_ (* location of tac in script *)
|
walther@59676
|
77 |
* Rule.rls (* for evaluating Prog_Expr *)
|
walther@59668
|
78 |
* term option (*id FORMal ARGument of curried functions *)
|
walther@59668
|
79 |
* term (*vl ACTual ARGument (value) for execution of Tactic.T
|
wneuper@59572
|
80 |
updated also after a derivation by 'new_val' *)
|
walther@59675
|
81 |
* appy_ (* estimation of how result will be obtained *)
|
wneuper@59572
|
82 |
* bool; (* true = strongly .., false = weakly associated:
|
wneuper@59572
|
83 |
only used during ass_dn/up *)
|
wneuper@59572
|
84 |
val e_scrstate =
|
walther@59676
|
85 |
([]: Env.T, []:Celem.loc_, Rule.e_rls, NONE, Rule.e_term, AppUndef_, false) : pstate
|
wneuper@59572
|
86 |
fun topt2str NONE = "NONE"
|
wneuper@59572
|
87 |
| topt2str (SOME t) = "SOME" ^ Rule.term2str t;
|
walther@59676
|
88 |
fun scrstate2str (env, loc_, rls, topt, t, safe, bool) = (* for tests only *)
|
walther@59676
|
89 |
"(" ^ Env.env2str env ^ ", " ^ Celem.loc_2str loc_ ^ ", " ^ Rule.id_rls rls ^ ", " ^
|
walther@59676
|
90 |
topt2str topt ^ ", \n" ^ Rule.term2str t ^ ", " ^ appy_2str safe ^ ", " ^ bool2str bool ^ ")";
|
wneuper@59572
|
91 |
|
wneuper@59572
|
92 |
(* for handling type T see fun from_pblobj_or_detail', +? *)
|
wneuper@59572
|
93 |
datatype T = (*interpreter state*)
|
wneuper@59572
|
94 |
Uistate (*undefined in modspec, in '_deriv'ation*)
|
walther@59667
|
95 |
| Pstate of pstate (*for script interpreter*)
|
wneuper@59572
|
96 |
| RrlsState of Rule.rrlsstate; (*for reverse rewriting*)
|
walther@59676
|
97 |
val e_istate = (Pstate ([], [], Rule.e_rls, NONE, Rule.e_term, AppUndef_, false));
|
wneuper@59572
|
98 |
|
wneuper@59572
|
99 |
fun rta2str (r, (t, a)) = "\n(" ^ Rule.rule2str r ^ ",(" ^ Rule.term2str t ^", " ^ Rule.terms2str a ^ "))";
|
wneuper@59572
|
100 |
fun istate2str Uistate = "Uistate"
|
walther@59676
|
101 |
| istate2str (Pstate pst) =
|
walther@59676
|
102 |
"Pstate " ^ scrstate2str pst
|
wneuper@59572
|
103 |
| istate2str (RrlsState (t, t1, rss, rtas)) =
|
wneuper@59572
|
104 |
"RrlsState (" ^ Rule.term2str t ^ ", " ^ Rule.term2str t1 ^ ", " ^
|
wneuper@59572
|
105 |
(strs2str o (map (strs2str o (map Rule.rule2str)))) rss ^ ", " ^
|
wneuper@59572
|
106 |
(strs2str o (map rta2str)) rtas ^ ")";
|
wneuper@59572
|
107 |
fun istates2str (NONE, NONE) = "(#NONE, #NONE)" (* for tests only *)
|
wneuper@59572
|
108 |
| istates2str (NONE, SOME ist) = "(#NONE,\n#SOME " ^ istate2str ist ^ ")"
|
wneuper@59572
|
109 |
| istates2str (SOME ist, NONE) = "(#SOME " ^ istate2str ist ^ ",\n #NONE)"
|
wneuper@59572
|
110 |
| istates2str (SOME i1, SOME i2) = "(#SOME " ^ istate2str i1 ^ ",\n #SOME " ^ istate2str i2 ^ ")";
|
wneuper@59572
|
111 |
|
walther@59676
|
112 |
fun get_path (_, path, _, _,_, _, _) = path
|
walther@59676
|
113 |
fun get_path_up (ist as (_, path, _, _, _, _, _)) =
|
walther@59669
|
114 |
if length path > 1 then drop_last path else raise ERROR ("get_path_up [] with " ^ scrstate2str ist)
|
walther@59676
|
115 |
fun get_act (_, _, _, _, act_arg, _, _) = act_arg
|
walther@59676
|
116 |
fun get_rls (_, _, rls, _, _, _, _) = rls
|
walther@59676
|
117 |
fun get_env (env, _, _, _, _, _, _) = env
|
walther@59676
|
118 |
fun get_act_env (env, _, _, _, act_arg, _, _) = (act_arg, env)
|
walther@59676
|
119 |
fun get_assoc (_, _, _, _, _, _, ass) = ass
|
walther@59676
|
120 |
fun get_subst (env, _, _, form_arg, act_arg, _, _) = (env, (form_arg, act_arg))
|
walther@59659
|
121 |
|
walther@59679
|
122 |
fun trans_scan_down2 (env, _, rls, _, act_arg, _, _) =
|
walther@59679
|
123 |
(env, [R], rls, NONE, act_arg, AppUndef_, false)
|
walther@59679
|
124 |
fun trans_scan_up2 (env, path, rls, form_arg, act_arg, _, _) =
|
walther@59679
|
125 |
(env, path, rls, form_arg, act_arg, AppUndef_, false)
|
walther@59676
|
126 |
fun trans_ass (_, _, _, _,_, _, ass) (env, path, rls, form_arg, act_arg, safe, _) =
|
walther@59676
|
127 |
(env, path, rls, form_arg, act_arg, safe, ass)
|
walther@59676
|
128 |
fun trans_env_act (env, _, _, _, act_arg, _, _) (_, path, rls, form_arg, _, safe, ass) =
|
walther@59676
|
129 |
(env, path, rls, form_arg, act_arg, safe, ass)
|
walther@59659
|
130 |
|
walther@59676
|
131 |
fun path_down path (env, p, rls, form_arg, act_arg, safe, ass) =
|
walther@59676
|
132 |
(env, p @ path, rls, form_arg, act_arg, safe, ass)
|
walther@59676
|
133 |
fun path_down_form (path, form_arg) (env, p, rls, _, act_arg, safe, ass) =
|
walther@59676
|
134 |
(env, p @ path, rls, SOME form_arg, act_arg, safe, ass)
|
walther@59676
|
135 |
fun path_up (env, path, rls, form_arg, act_arg, safe, ass) =
|
walther@59676
|
136 |
(env, drop_last path, rls, form_arg, act_arg, safe, ass)
|
walther@59676
|
137 |
fun path_up_down path (env, p, rls, form_arg, act_arg, safe, ass) =
|
walther@59676
|
138 |
(env, (drop_last p) @ path, rls, form_arg, act_arg, safe, ass)
|
walther@59660
|
139 |
|
walther@59676
|
140 |
fun upd_form form (env, path, rls, _, act_arg, safe, ass) =
|
walther@59676
|
141 |
(env, path, rls, SOME form, act_arg, safe, ass)
|
walther@59676
|
142 |
fun upd_path path (env, _, rls, form_arg, act_arg, safe, ass) =
|
walther@59676
|
143 |
(env, path, rls, form_arg, act_arg, safe, ass)
|
walther@59677
|
144 |
fun upd_rls rls (env, path, _, form_arg, act_arg, safe, ass) =
|
walther@59677
|
145 |
(env, path, rls, form_arg, act_arg, safe, ass)
|
walther@59676
|
146 |
fun upd_act act (env, path, rls, form_arg, _, safe, ass) =
|
walther@59676
|
147 |
(env, path, rls, form_arg, act, safe, ass)
|
walther@59676
|
148 |
fun upd_appy app (env, path, rls, form_arg, act_arg, _, ass) =
|
walther@59676
|
149 |
(env, path, rls, form_arg, act_arg, app, ass)
|
walther@59664
|
150 |
|
walther@59676
|
151 |
fun upd_env env (_, path, rls, form_arg, act_arg, safe, ass) =
|
walther@59676
|
152 |
(env, path, rls, form_arg, act_arg, safe, ass)
|
walther@59676
|
153 |
fun upd_env_true env (_, path, rls, form_arg, act_arg, safe, _) =
|
walther@59676
|
154 |
(env, path, rls, form_arg, act_arg, safe, true)
|
walther@59676
|
155 |
fun upd_env' form (env, path, rls, form_arg, act_arg, safe, ass) =
|
walther@59676
|
156 |
(Env.upd_env env (form, act_arg), path, rls, form_arg, act_arg, safe, ass)
|
walther@59676
|
157 |
fun upd_env'' (env, (form, act)) (_, path, rls, _, _, safe, ass) =
|
walther@59676
|
158 |
(Env.upd_env env (form, act), path, rls, SOME form, act, safe, ass)
|
walther@59664
|
159 |
|
walther@59676
|
160 |
fun upd_form_env (form_arg, env) (_, path, rls, _, act_arg, safe, ass) =
|
walther@59676
|
161 |
(env, path, rls, SOME form_arg, act_arg, safe, ass)
|
walther@59676
|
162 |
fun upd_act_env (act_arg, env) (_, path, rls, form_arg, _, safe, ass) =
|
walther@59676
|
163 |
(env, path, rls, form_arg, act_arg, safe, ass)
|
walther@59664
|
164 |
|
walther@59676
|
165 |
fun upd_subst env (form_arg, act_arg) (_, path, rls, _, _, safe, ass) =
|
walther@59676
|
166 |
(env, path, rls, SOME form_arg, act_arg, safe, ass)
|
walther@59676
|
167 |
fun upd_subst_true (form_arg, act_arg) (env, path, rls, _, _, safe, _) =
|
walther@59676
|
168 |
(env, path, rls, form_arg, act_arg, safe, true)
|
walther@59676
|
169 |
fun upd_subst_false (form_arg, act_arg) (env, path, rls, _, _, safe, _) =
|
walther@59676
|
170 |
(env, path, rls, form_arg, act_arg, safe, false)
|
wneuper@59572
|
171 |
|
walther@59674
|
172 |
(**)end(**)
|
wneuper@59572
|
173 |
|