src/Tools/isac/MathEngBasic/istate-def.sml
author Walther Neuper <walther.neuper@jku.at>
Mon, 06 Apr 2020 11:44:36 +0200
changeset 59851 4dd533681fef
parent 59850 f3cac3053e7b
child 59852 ea7e6679080e
permissions -rw-r--r--
use "Rule_Set" for shorter identifiers
walther@59737
     1
(* Title:  interpreter-state for Lucas-Interpretation
walther@59737
     2
   Author: Walther Neuper 190724
walther@59737
     3
   (c) due to copyright terms
walther@59777
     4
walther@59777
     5
   Minimum of code required BEFORE Interpret/ 
walther@59737
     6
*)
walther@59737
     7
signature INTERPRETER_STATE_DEFINITION =
walther@59737
     8
sig
walther@59737
     9
walther@59737
    10
  datatype asap = ORundef | AssOnly | AssGen;
walther@59777
    11
  val asap2str: asap -> string 
walther@59737
    12
  type pstate
walther@59777
    13
  val e_pstate: pstate
walther@59777
    14
  val pstate2str: pstate -> string
walther@59814
    15
  val pstate2str': pstate -> string
walther@59737
    16
walther@59850
    17
  datatype T = RrlsState of Rule_Set.rrlsstate | Pstate of pstate | Uistate
walther@59846
    18
  val empty: T
walther@59844
    19
  val string_of: T -> string
walther@59844
    20
  val string_of': T -> string
walther@59737
    21
  val istates2str: T option * T option -> string
walther@59737
    22
walther@59851
    23
  val set_eval: Rule_Set.T -> pstate -> pstate
walther@59737
    24
  val set_act: term -> pstate -> pstate
walther@59737
    25
  val set_env_true: Env.T -> pstate -> pstate
walther@59737
    26
walther@59737
    27
end
walther@59737
    28
walther@59737
    29
(**)                   
walther@59737
    30
structure Istate_Def(**): INTERPRETER_STATE_DEFINITION(**) =
walther@59737
    31
struct
walther@59737
    32
(**)
walther@59737
    33
walther@59737
    34
open Celem                           
walther@59737
    35
walther@59737
    36
datatype asap = (* arg. of scan_dn1 _only_ for distinction w.r.t. Or                 *)
walther@59737
    37
  ORundef        (* undefined: set only by (topmost) Or                           *)
walther@59737
    38
| AssOnly       (* do not execute applicable Prog_Tac - there could be an associated
walther@59737
    39
	                 in parallel Or-branch                                         *)
walther@59844
    40
| AssGen;       (* no Associated(Weak) found within Or, thus continue scan
walther@59737
    41
                   search for _applicable_ stacs, execute and generate pt        *)
walther@59737
    42
(*this constructions doesnt allow arbitrary nesting of Or !!!                    *)
walther@59737
    43
fun asap2str ORundef = "ORundef"
walther@59737
    44
  | asap2str AssOnly = "AssOnly"
walther@59737
    45
  | asap2str AssGen = "AssGen"
walther@59737
    46
walther@59737
    47
type pstate =
walther@59737
    48
  {env: Env.T,          (* environment for variables in a program *)
walther@59767
    49
  path: TermC.path,     (* to the current location in a program   *)
walther@59851
    50
  eval: Rule_Set.T,       (* rule-set for evaluating a Prog_Expr    *)
walther@59737
    51
  form_arg: term option,(* argument of a curried function         *)
walther@59737
    52
  act_arg: term,        (* value for the curried argument         *)
walther@59779
    53
  or: asap,             (* flag for scanning tactical "Or"      !shall be dropped *)
walther@59784
    54
  found_accept: bool,   (* flag set after execution of a tactic !shall be dropped *)
walther@59779
    55
  assoc: bool}          (* is the tactic associated to input ?cont.search Unsafe_Step \<rightarrow> Safe_Step*)
walther@59777
    56
val e_pstate =
walther@59850
    57
  {env = [], path = [], eval = Rule_Set.e_rls, form_arg = NONE, act_arg = Rule.e_term,
walther@59784
    58
    or = ORundef, found_accept = false, assoc = false}
walther@59737
    59
fun topt2str NONE = "NONE"
walther@59781
    60
  | topt2str (SOME t) = "SOME " ^ Rule.term2str t;
walther@59784
    61
fun pstate2str {env, path, eval, form_arg, act_arg, or, found_accept, assoc} = (* for tests only *)
walther@59850
    62
  "(" ^  Env.env2str env ^ ", " ^ TermC.string_of_path path ^ ", " ^ Rule_Set.id_rls eval ^ ", " ^
walther@59737
    63
  topt2str form_arg ^ ", \n" ^ Rule.term2str act_arg ^ ", " ^ asap2str or ^ ", " ^
walther@59784
    64
  bool2str found_accept ^ ", " ^ bool2str assoc ^ ")";
walther@59814
    65
fun pstate2str' {env, path, eval, form_arg, act_arg, or, found_accept, assoc} = (* for tests only *)
walther@59850
    66
  "(" ^  Env.env2str' env ^ ", " ^ TermC.string_of_path path ^ ", " ^ Rule_Set.id_rls eval ^ ", " ^
walther@59814
    67
  topt2str form_arg ^ ", " ^ Rule.term2str act_arg ^ ", " ^ asap2str or ^ ", " ^
walther@59814
    68
  bool2str found_accept ^ ", " ^ bool2str assoc ^ ")";
walther@59737
    69
walther@59831
    70
(* for handling type T see fun resume_prog, +? *)
walther@59737
    71
datatype T =                 (*interpreter state*)
walther@59737
    72
	  Uistate                       (*undefined in modspec, in '_deriv'ation*)
walther@59737
    73
  | Pstate of pstate          (*for script interpreter*)
walther@59850
    74
  | RrlsState of Rule_Set.rrlsstate; (*for reverse rewriting*)
walther@59846
    75
val empty = Pstate e_pstate;
walther@59737
    76
walther@59850
    77
fun rta2str (r, (t, a)) = "\n(" ^ Rule_Set.rule2str r ^ ", (" ^ Rule.term2str t ^ ", " ^ Rule.terms2str a ^ "))";
walther@59844
    78
fun string_of Uistate = "Uistate"
walther@59844
    79
  | string_of (Pstate pst) = 
walther@59777
    80
    "Pstate " ^ pstate2str pst
walther@59844
    81
  | string_of (RrlsState (t, t1, rss, rtas)) =
walther@59737
    82
    "RrlsState (" ^ Rule.term2str t ^ ", " ^ Rule.term2str t1 ^ ", " ^
walther@59850
    83
    (strs2str o (map (strs2str o (map Rule_Set.rule2str)))) rss ^ ", " ^
walther@59737
    84
    (strs2str o (map rta2str)) rtas ^ ")";
walther@59844
    85
fun string_of' Uistate = "Uistate"
walther@59844
    86
  | string_of' (Pstate pst) = 
walther@59814
    87
    "Pstate " ^ pstate2str' pst
walther@59844
    88
  | string_of' (RrlsState _) = raise ERROR "istate2str: drop RrlsState"
walther@59737
    89
fun istates2str (NONE, NONE) = "(#NONE, #NONE)"  (* for tests only *)
walther@59844
    90
  | istates2str (NONE, SOME ist) = "(#NONE,\n#SOME " ^ string_of ist ^ ")"
walther@59844
    91
  | istates2str (SOME ist, NONE) = "(#SOME " ^ string_of ist ^ ",\n #NONE)"
walther@59844
    92
  | istates2str (SOME i1, SOME i2) = "(#SOME " ^ string_of i1 ^ ",\n #SOME " ^ string_of i2 ^ ")";
walther@59737
    93
walther@59737
    94
walther@59784
    95
fun set_eval e {env, path, form_arg, act_arg, or, found_accept, assoc, ...} =
walther@59737
    96
  {env = env, path = path, eval = e, form_arg = form_arg, act_arg = act_arg,
walther@59784
    97
    or = or, found_accept = found_accept, assoc = assoc}
walther@59784
    98
fun set_act act {env, path, eval, form_arg, or, found_accept, assoc, ...} =
walther@59737
    99
  {env = env, path = path, eval = eval, form_arg = form_arg, act_arg = act,
walther@59784
   100
    or = or, found_accept = found_accept, assoc = assoc}
walther@59784
   101
fun set_env_true env {path, eval, form_arg, act_arg, or, found_accept, ...} =
walther@59737
   102
  {env = env, path = path, eval = eval, form_arg = form_arg, act_arg = act_arg,
walther@59784
   103
    or = or, found_accept = found_accept, assoc = true}
walther@59737
   104
walther@59737
   105
(**)end(**)
walther@59737
   106