eliminate use of Thy_Info 10: arg. ctxt for Rule.to_string finished
1 (* Title: interpreter-state for Lucas-Interpretation
2 Author: Walther Neuper 190724
3 (c) due to copyright terms
5 Minimum of code required BEFORE Interpret/
7 signature INTERPRETER_STATE_DEFINITION =
10 datatype asap = ORundef | AssOnly | AssGen;
11 val asap2str: asap -> string
14 val pstate2str: pstate -> string
15 val pstate2str': pstate -> string
17 datatype T = RrlsState of Rule_Set.rrlsstate | Pstate of pstate | Uistate
19 val string_of: Proof.context -> T -> string
20 val string_of': T -> string
21 val istates2str: Proof.context -> T option * T option -> string
23 val set_eval: Rule_Set.T -> pstate -> pstate
24 val set_act: term -> pstate -> pstate
25 val set_env_true: Env.T -> pstate -> pstate
30 structure Istate_Def(**): INTERPRETER_STATE_DEFINITION(**) =
34 datatype asap = (* arg. of scan_dn1 _only_ for distinction w.r.t. Or *)
35 ORundef (* undefined: set only by (topmost) Or *)
36 | AssOnly (* do not execute applicable Prog_Tac - there could be an associated
37 in parallel Or-branch *)
38 | AssGen; (* no Associated(Weak) found within Or, thus continue scan
39 search for _applicable_ stacs, execute and generate pt *)
40 (*this constructions doesnt allow arbitrary nesting of Or !!! *)
41 fun asap2str ORundef = "ORundef"
42 | asap2str AssOnly = "AssOnly"
43 | asap2str AssGen = "AssGen"
46 {env: Env.T, (* environment for variables in a program *)
47 path: TermC.path, (* to the current location in a program *)
48 eval: Rule_Set.T, (* rule-set for evaluating a Prog_Expr *)
49 form_arg: term option,(* argument of a curried function *)
50 act_arg: term, (* value for the curried argument *)
51 or: asap, (* flag for scanning tactical "Or" !shall be dropped *)
52 found_accept: bool, (* flag set after execution of a tactic !shall be dropped *)
53 assoc: bool} (* is the tactic associated to input ?cont.search Unsafe_Step \<rightarrow> Safe_Step*)
55 {env = [], path = [], eval = Rule_Set.empty, form_arg = NONE, act_arg = TermC.empty,
56 or = ORundef, found_accept = false, assoc = false}
57 fun topt2str NONE = "NONE"
60 val ctxt = Proof_Context.init_global (Know_Store.get_via_last_thy "Isac_Knowledge")
62 "SOME " ^ UnparseC.term_in_ctxt ctxt t
64 fun pstate2str {env, path, eval, form_arg, act_arg, or, found_accept, assoc} =
66 val ctxt = Proof_Context.init_global (Know_Store.get_via_last_thy "Isac_Knowledge")
68 "(" ^ Env.env2str env ^ ", " ^ TermC.string_of_path path ^ ", " ^ Rule_Set.id eval ^ ", " ^
69 topt2str form_arg ^ ", \n" ^ UnparseC.term_in_ctxt ctxt act_arg ^ ", " ^ asap2str or ^ ", " ^
70 bool2str found_accept ^ ", " ^ bool2str assoc ^ ")"
72 fun pstate2str' {env, path, eval, form_arg, act_arg, or, found_accept, assoc} =
74 val ctxt = Proof_Context.init_global (Know_Store.get_via_last_thy "Isac_Knowledge")
76 "(" ^ Env.env2str' env ^ ", " ^ TermC.string_of_path path ^ ", " ^ Rule_Set.id eval ^ ", " ^
77 topt2str form_arg ^ ", " ^ UnparseC.term_in_ctxt ctxt act_arg ^ ", " ^ asap2str or ^ ", " ^
78 bool2str found_accept ^ ", " ^ bool2str assoc ^ ")"
81 (* for handling type T see fun resume_prog, +? *)
82 datatype T = (*interpreter state*)
83 Uistate (*undefined in modspec, in '_deriv'ation*)
84 | Pstate of pstate (*for script interpreter*)
85 | RrlsState of Rule_Set.rrlsstate; (*for reverse rewriting*)
86 val empty = Pstate e_pstate;
88 fun rta2str ctxt (r, (t, a)) =
89 "\n(" ^ Rule.to_string ctxt r ^ ", (" ^ UnparseC.term_in_ctxt ctxt t ^ ", " ^
90 UnparseC.terms_in_ctxt ctxt a ^ "))";
91 fun string_of _ Uistate = "Uistate"
92 | string_of _ (Pstate pst) =
93 "Pstate " ^ pstate2str pst
94 | string_of ctxt (RrlsState (t, t1, rss, rtas)) =
95 "RrlsState (" ^ UnparseC.term t ^ ", " ^ UnparseC.term_in_ctxt ctxt t1 ^ ", " ^
96 (strs2str o (map (strs2str o (map (Rule.to_string ctxt))))) rss ^ ", " ^
97 (strs2str o (map (rta2str ctxt))) rtas ^ ")";
98 fun string_of' Uistate = "Uistate"
99 | string_of' (Pstate pst) =
100 "Pstate " ^ pstate2str' pst
101 | string_of' (RrlsState _) = raise ERROR "istate2str: drop RrlsState"
102 fun istates2str _ (NONE, NONE) = "(#NONE, #NONE)"
103 | istates2str ctxt (NONE, SOME ist) = "(#NONE,\n#SOME " ^ string_of ctxt ist ^ ")"
104 | istates2str ctxt (SOME ist, NONE) = "(#SOME " ^ string_of ctxt ist ^ ",\n #NONE)"
105 | istates2str ctxt (SOME i1, SOME i2) =
106 "(#SOME " ^ string_of ctxt i1 ^ ",\n #SOME " ^ string_of ctxt i2 ^ ")";
109 fun set_eval e {env, path, form_arg, act_arg, or, found_accept, assoc, ...} =
110 {env = env, path = path, eval = e, form_arg = form_arg, act_arg = act_arg,
111 or = or, found_accept = found_accept, assoc = assoc}
112 fun set_act act {env, path, eval, form_arg, or, found_accept, assoc, ...} =
113 {env = env, path = path, eval = eval, form_arg = form_arg, act_arg = act,
114 or = or, found_accept = found_accept, assoc = assoc}
115 fun set_env_true env {path, eval, form_arg, act_arg, or, found_accept, ...} =
116 {env = env, path = path, eval = eval, form_arg = form_arg, act_arg = act_arg,
117 or = or, found_accept = found_accept, assoc = true}