src/HOL/Tools/Predicate_Compile/code_prolog.ML
author bulwahn
Sun Aug 01 10:15:43 2010 +0200 (2010-08-01)
changeset 38112 cf08f4780938
parent 38082 61280b97b761
child 38113 81f08bbb3be7
permissions -rw-r--r--
adding numbers as basic term in prolog code generation
bulwahn@38073
     1
(*  Title:      HOL/Tools/Predicate_Compile/code_prolog.ML
bulwahn@38073
     2
    Author:     Lukas Bulwahn, TU Muenchen
bulwahn@38073
     3
bulwahn@38073
     4
Prototype of an code generator for logic programming languages (a.k.a. Prolog)
bulwahn@38073
     5
*)
bulwahn@38073
     6
bulwahn@38073
     7
signature CODE_PROLOG =
bulwahn@38073
     8
sig
bulwahn@38112
     9
  datatype prol_term = Var of string | Cons of string | AppF of string * prol_term list
bulwahn@38112
    10
    | Number of int;
bulwahn@38079
    11
  datatype prem = Conj of prem list | NotRel of string * prol_term list
bulwahn@38079
    12
    | Rel of string * prol_term list | Eq of prol_term * prol_term | NotEq of prol_term * prol_term;
bulwahn@38079
    13
  type clause = ((string * prol_term list) * prem);
bulwahn@38073
    14
  type logic_program = clause list;
bulwahn@38079
    15
  type constant_table = (string * string) list
bulwahn@38079
    16
  
bulwahn@38079
    17
  val generate : Proof.context -> string list -> (logic_program * constant_table)
bulwahn@38079
    18
  val write_program : logic_program -> string
bulwahn@38079
    19
  val run : logic_program -> string -> string list -> int option -> prol_term list list
bulwahn@38073
    20
bulwahn@38079
    21
  val trace : bool Unsynchronized.ref
bulwahn@38073
    22
end;
bulwahn@38073
    23
bulwahn@38073
    24
structure Code_Prolog : CODE_PROLOG =
bulwahn@38073
    25
struct
bulwahn@38073
    26
bulwahn@38079
    27
(* diagnostic tracing *)
bulwahn@38079
    28
bulwahn@38079
    29
val trace = Unsynchronized.ref false
bulwahn@38079
    30
bulwahn@38079
    31
fun tracing s = if !trace then Output.tracing s else () 
bulwahn@38073
    32
(* general string functions *)
bulwahn@38073
    33
bulwahn@38073
    34
val first_upper = implode o nth_map 0 Symbol.to_ascii_upper o explode;
bulwahn@38073
    35
val first_lower = implode o nth_map 0 Symbol.to_ascii_lower o explode;
bulwahn@38073
    36
bulwahn@38073
    37
(* internal program representation *)
bulwahn@38073
    38
bulwahn@38112
    39
datatype prol_term = Var of string | Cons of string | AppF of string * prol_term list
bulwahn@38112
    40
  | Number of int;
bulwahn@38073
    41
bulwahn@38081
    42
fun string_of_prol_term (Var s) = "Var " ^ s
bulwahn@38075
    43
  | string_of_prol_term (Cons s) = "Cons " ^ s
bulwahn@38075
    44
  | string_of_prol_term (AppF (f, args)) = f ^ "(" ^ commas (map string_of_prol_term args) ^ ")" 
bulwahn@38112
    45
  | string_of_prol_term (Number n) = "Number " ^ string_of_int n
bulwahn@38075
    46
bulwahn@38079
    47
datatype prem = Conj of prem list | NotRel of string * prol_term list
bulwahn@38079
    48
    | Rel of string * prol_term list | Eq of prol_term * prol_term | NotEq of prol_term * prol_term;
bulwahn@38073
    49
bulwahn@38073
    50
fun dest_Rel (Rel (c, ts)) = (c, ts)
bulwahn@38073
    51
 
bulwahn@38079
    52
type clause = ((string * prol_term list) * prem);
bulwahn@38073
    53
bulwahn@38073
    54
type logic_program = clause list;
bulwahn@38073
    55
bulwahn@38073
    56
(* translation from introduction rules to internal representation *)
bulwahn@38073
    57
bulwahn@38079
    58
(** constant table **)
bulwahn@38079
    59
bulwahn@38079
    60
type constant_table = (string * string) list
bulwahn@38079
    61
bulwahn@38073
    62
(* assuming no clashing *)
bulwahn@38079
    63
fun mk_constant_table consts =
bulwahn@38079
    64
  AList.make (first_lower o Long_Name.base_name) consts
bulwahn@38079
    65
bulwahn@38079
    66
fun declare_consts consts constant_table =
bulwahn@38079
    67
  fold (fn c => AList.update (op =) (c, first_lower (Long_Name.base_name c))) consts constant_table
bulwahn@38079
    68
  
bulwahn@38079
    69
fun translate_const constant_table c =
bulwahn@38079
    70
  case AList.lookup (op =) constant_table c of
bulwahn@38079
    71
    SOME c' => c'
bulwahn@38079
    72
  | NONE => error ("No such constant: " ^ c)
bulwahn@38073
    73
bulwahn@38079
    74
fun inv_lookup _ [] _ = NONE
bulwahn@38079
    75
  | inv_lookup eq ((key, value)::xs) value' =
bulwahn@38079
    76
      if eq (value', value) then SOME key
bulwahn@38079
    77
      else inv_lookup eq xs value';
bulwahn@38079
    78
bulwahn@38079
    79
fun restore_const constant_table c =
bulwahn@38079
    80
  case inv_lookup (op =) constant_table c of
bulwahn@38079
    81
    SOME c' => c'
bulwahn@38079
    82
  | NONE => error ("No constant corresponding to "  ^ c)
bulwahn@38079
    83
  
bulwahn@38079
    84
(** translation of terms, literals, premises, and clauses **)
bulwahn@38079
    85
bulwahn@38079
    86
fun translate_term ctxt constant_table t =
bulwahn@38112
    87
  case try HOLogic.dest_number t of
bulwahn@38112
    88
    SOME (@{typ "int"}, n) => Number n
bulwahn@38112
    89
  | NONE =>
bulwahn@38112
    90
      (case strip_comb t of
bulwahn@38112
    91
        (Free (v, T), []) => Var v 
bulwahn@38112
    92
      | (Const (c, _), []) => Cons (translate_const constant_table c)
bulwahn@38112
    93
      | (Const (c, _), args) =>
bulwahn@38112
    94
        AppF (translate_const constant_table c, map (translate_term ctxt constant_table) args)
bulwahn@38112
    95
      | _ => error ("illegal term for translation: " ^ Syntax.string_of_term ctxt t))
bulwahn@38073
    96
bulwahn@38079
    97
fun translate_literal ctxt constant_table t =
bulwahn@38073
    98
  case strip_comb t of
bulwahn@38079
    99
    (Const (@{const_name "op ="}, _), [l, r]) =>
bulwahn@38079
   100
      Eq (pairself (translate_term ctxt constant_table) (l, r))
bulwahn@38079
   101
  | (Const (c, _), args) =>
bulwahn@38079
   102
      Rel (translate_const constant_table c, map (translate_term ctxt constant_table) args)
bulwahn@38073
   103
  | _ => error ("illegal literal for translation: " ^ Syntax.string_of_term ctxt t)
bulwahn@38073
   104
bulwahn@38073
   105
fun NegRel_of (Rel lit) = NotRel lit
bulwahn@38073
   106
  | NegRel_of (Eq eq) = NotEq eq
bulwahn@38073
   107
  
bulwahn@38079
   108
fun translate_prem ctxt constant_table t =  
bulwahn@38073
   109
    case try HOLogic.dest_not t of
bulwahn@38079
   110
      SOME t => NegRel_of (translate_literal ctxt constant_table t)
bulwahn@38079
   111
    | NONE => translate_literal ctxt constant_table t
bulwahn@38073
   112
bulwahn@38079
   113
fun translate_intros ctxt gr const constant_table =
bulwahn@38073
   114
  let
bulwahn@38073
   115
    val intros = Graph.get_node gr const
bulwahn@38073
   116
    val (intros', ctxt') = Variable.import_terms true (map prop_of intros) ctxt
bulwahn@38079
   117
    val constant_table' = declare_consts (fold Term.add_const_names intros' []) constant_table
bulwahn@38073
   118
    fun translate_intro intro =
bulwahn@38073
   119
      let
bulwahn@38073
   120
        val head = HOLogic.dest_Trueprop (Logic.strip_imp_concl intro)
bulwahn@38073
   121
        val prems = map HOLogic.dest_Trueprop (Logic.strip_imp_prems intro) 
bulwahn@38079
   122
        val prems' = Conj (map (translate_prem ctxt' constant_table') prems)
bulwahn@38079
   123
        val clause = (dest_Rel (translate_literal ctxt' constant_table' head), prems')
bulwahn@38073
   124
      in clause end
bulwahn@38079
   125
  in (map translate_intro intros', constant_table') end
bulwahn@38073
   126
bulwahn@38073
   127
fun generate ctxt const =
bulwahn@38073
   128
  let 
bulwahn@38073
   129
     fun strong_conn_of gr keys =
bulwahn@38073
   130
      Graph.strong_conn (Graph.subgraph (member (op =) (Graph.all_succs gr keys)) gr)
bulwahn@38073
   131
    val gr = Predicate_Compile_Core.intros_graph_of ctxt
bulwahn@38073
   132
    val scc = strong_conn_of gr const
bulwahn@38079
   133
    val constant_table = mk_constant_table (flat scc)
bulwahn@38073
   134
  in
bulwahn@38079
   135
    apfst flat (fold_map (translate_intros ctxt gr) (flat scc) constant_table)
bulwahn@38073
   136
  end
bulwahn@38073
   137
bulwahn@38073
   138
(* transform logic program *)
bulwahn@38073
   139
bulwahn@38073
   140
(** ensure groundness of terms before negation **)
bulwahn@38073
   141
bulwahn@38073
   142
fun add_vars (Var x) vs = insert (op =) x vs
bulwahn@38073
   143
  | add_vars (Cons c) vs = vs
bulwahn@38073
   144
  | add_vars (AppF (f, args)) vs = fold add_vars args vs
bulwahn@38073
   145
bulwahn@38073
   146
fun string_of_typ (Type (s, Ts)) = Long_Name.base_name s
bulwahn@38073
   147
bulwahn@38073
   148
fun mk_groundness_prems ts =
bulwahn@38073
   149
  let
bulwahn@38073
   150
    val vars = fold add_vars ts []
bulwahn@38081
   151
    fun mk_ground v =
bulwahn@38081
   152
      Rel ("ground", [Var v])
bulwahn@38073
   153
  in
bulwahn@38073
   154
    map mk_ground vars
bulwahn@38073
   155
  end
bulwahn@38073
   156
bulwahn@38073
   157
fun ensure_groundness_prem (NotRel (c, ts)) = Conj (mk_groundness_prems ts @ [NotRel (c, ts)]) 
bulwahn@38073
   158
  | ensure_groundness_prem (NotEq (l, r)) = Conj (mk_groundness_prems [l, r] @ [NotEq (l, r)])
bulwahn@38073
   159
  | ensure_groundness_prem (Conj ps) = Conj (map ensure_groundness_prem ps)
bulwahn@38073
   160
  | ensure_groundness_prem p = p
bulwahn@38073
   161
bulwahn@38073
   162
fun ensure_groundness_before_negation p =
bulwahn@38073
   163
  map (apsnd ensure_groundness_prem) p
bulwahn@38073
   164
bulwahn@38073
   165
(* code printer *)
bulwahn@38073
   166
bulwahn@38081
   167
fun write_term (Var v) = first_upper v
bulwahn@38079
   168
  | write_term (Cons c) = c
bulwahn@38079
   169
  | write_term (AppF (f, args)) = f ^ "(" ^ space_implode ", " (map write_term args) ^ ")" 
bulwahn@38112
   170
  | write_term (Number n) = string_of_int n
bulwahn@38073
   171
bulwahn@38073
   172
fun write_rel (pred, args) =
bulwahn@38073
   173
  pred ^ "(" ^ space_implode ", " (map write_term args) ^ ")" 
bulwahn@38073
   174
bulwahn@38073
   175
fun write_prem (Conj prems) = space_implode ", " (map write_prem prems)
bulwahn@38073
   176
  | write_prem (Rel p) = write_rel p  
bulwahn@38073
   177
  | write_prem (NotRel p) = "not(" ^ write_rel p ^ ")"
bulwahn@38073
   178
  | write_prem (Eq (l, r)) = write_term l ^ " = " ^ write_term r
bulwahn@38073
   179
  | write_prem (NotEq (l, r)) = write_term l ^ " \\= " ^ write_term r
bulwahn@38073
   180
bulwahn@38073
   181
fun write_clause (head, prem) =
bulwahn@38073
   182
  write_rel head ^ (if prem = Conj [] then "." else " :- " ^ write_prem prem ^ ".")
bulwahn@38073
   183
bulwahn@38073
   184
fun write_program p =
bulwahn@38073
   185
  cat_lines (map write_clause p) 
bulwahn@38073
   186
bulwahn@38078
   187
(** query templates **)
bulwahn@38078
   188
bulwahn@38073
   189
fun query_first rel vnames =
bulwahn@38073
   190
  "eval :- once("  ^ rel ^ "(" ^ space_implode ", " vnames ^ ")),\n" ^
bulwahn@38082
   191
  "writef('" ^ space_implode ";" (map (fn v => v ^ " = %w") vnames) ^
bulwahn@38082
   192
  "\\n', [" ^ space_implode ", " vnames ^ "]).\n"
bulwahn@38077
   193
  
bulwahn@38077
   194
fun query_firstn n rel vnames =
bulwahn@38077
   195
  "eval :- findnsols(" ^ string_of_int n ^ ", (" ^ space_implode ", " vnames ^ "), " ^
bulwahn@38077
   196
    rel ^ "(" ^ space_implode ", " vnames ^ "), Sols), writelist(Sols).\n" ^
bulwahn@38077
   197
    "writelist([]).\n" ^
bulwahn@38077
   198
    "writelist([(" ^ space_implode ", " vnames ^ ")|T]) :- " ^
bulwahn@38079
   199
    "writef('" ^ space_implode ";" (map (fn v => v ^ " = %w") vnames) ^
bulwahn@38079
   200
    "\\n', [" ^ space_implode ", " vnames ^ "]), writelist(T).\n"
bulwahn@38077
   201
  
bulwahn@38073
   202
val prelude =
bulwahn@38073
   203
  "#!/usr/bin/swipl -q -t main -f\n\n" ^
bulwahn@38077
   204
  ":- use_module(library('dialect/ciao/aggregates')).\n" ^
bulwahn@38073
   205
  ":- style_check(-singleton).\n\n" ^
bulwahn@38073
   206
  "main :- catch(eval, E, (print_message(error, E), fail)), halt.\n" ^
bulwahn@38073
   207
  "main :- halt(1).\n"
bulwahn@38075
   208
bulwahn@38075
   209
(* parsing prolog solution *)
bulwahn@38075
   210
bulwahn@38075
   211
val scan_atom =
bulwahn@38078
   212
  Scan.many1 (fn s => Symbol.is_ascii_lower s orelse Symbol.is_ascii_quasi s)
bulwahn@38075
   213
bulwahn@38075
   214
val scan_var =
bulwahn@38078
   215
  Scan.many1
bulwahn@38078
   216
    (fn s => Symbol.is_ascii_upper s orelse Symbol.is_ascii_digit s orelse Symbol.is_ascii_quasi s)
bulwahn@38075
   217
bulwahn@38076
   218
val scan_ident =
bulwahn@38076
   219
  Scan.repeat (Scan.one
bulwahn@38076
   220
    (fn s => Symbol.is_ascii_letter s orelse Symbol.is_ascii_digit s orelse Symbol.is_ascii_quasi s))
bulwahn@38076
   221
bulwahn@38075
   222
fun dest_Char (Symbol.Char s) = s
bulwahn@38075
   223
bulwahn@38075
   224
val string_of = concat o map (dest_Char o Symbol.decode)
bulwahn@38075
   225
bulwahn@38076
   226
val is_atom_ident = forall Symbol.is_ascii_lower
bulwahn@38076
   227
bulwahn@38076
   228
val is_var_ident =
bulwahn@38076
   229
  forall (fn s => Symbol.is_ascii_upper s orelse Symbol.is_ascii_digit s orelse Symbol.is_ascii_quasi s)
bulwahn@38078
   230
bulwahn@38078
   231
fun scan_terms xs = (((scan_term --| $$ ",") ::: scan_terms)
bulwahn@38078
   232
  || (scan_term >> single)) xs
bulwahn@38078
   233
and scan_term xs =
bulwahn@38081
   234
  ((scan_var >> (Var o string_of))
bulwahn@38078
   235
  || ((scan_atom -- ($$ "(" |-- scan_terms --| $$ ")"))
bulwahn@38079
   236
    >> (fn (f, ts) => AppF (string_of f, ts)))
bulwahn@38078
   237
  || (scan_atom >> (Cons o string_of))) xs
bulwahn@38079
   238
bulwahn@38075
   239
val parse_term = fst o Scan.finite Symbol.stopper
bulwahn@38077
   240
    (Scan.error (!! (fn _ => raise Fail "parsing prolog output failed")) scan_term)
bulwahn@38075
   241
  o explode
bulwahn@38075
   242
  
bulwahn@38079
   243
fun parse_solutions sol =
bulwahn@38075
   244
  let
bulwahn@38077
   245
    fun dest_eq s = case space_explode "=" s of
bulwahn@38075
   246
        (l :: r :: []) => parse_term (unprefix " " r)
bulwahn@38078
   247
      | _ => raise Fail "unexpected equation in prolog output"
bulwahn@38079
   248
    fun parse_solution s = map dest_eq (space_explode ";" s)
bulwahn@38075
   249
  in
bulwahn@38079
   250
    map parse_solution (fst (split_last (space_explode "\n" sol)))
bulwahn@38075
   251
  end 
bulwahn@38073
   252
  
bulwahn@38073
   253
(* calling external interpreter and getting results *)
bulwahn@38073
   254
bulwahn@38077
   255
fun run p query_rel vnames nsols =
bulwahn@38073
   256
  let
bulwahn@38073
   257
    val cmd = Path.named_root
bulwahn@38077
   258
    val query = case nsols of NONE => query_first | SOME n => query_firstn n 
bulwahn@38077
   259
    val prog = prelude ^ query query_rel vnames ^ write_program p
bulwahn@38079
   260
    val _ = tracing ("Generated prolog program:\n" ^ prog)
bulwahn@38073
   261
    val prolog_file = File.tmp_path (Path.basic "prolog_file")
bulwahn@38073
   262
    val _ = File.write prolog_file prog
bulwahn@38077
   263
    val (solution, _) = bash_output ("/usr/local/bin/swipl -f " ^ File.shell_path prolog_file)
bulwahn@38079
   264
    val _ = tracing ("Prolog returned solution(s):\n" ^ solution)
bulwahn@38079
   265
    val tss = parse_solutions solution
bulwahn@38073
   266
  in
bulwahn@38079
   267
    tss
bulwahn@38073
   268
  end
bulwahn@38073
   269
bulwahn@38075
   270
(* values command *)
bulwahn@38075
   271
bulwahn@38081
   272
fun restore_term ctxt constant_table (Var s, T) = Free (s, T)
bulwahn@38079
   273
  | restore_term ctxt constant_table (Cons s, T) = Const (restore_const constant_table s, T)
bulwahn@38079
   274
  | restore_term ctxt constant_table (AppF (f, args), T) =
bulwahn@38079
   275
    let
bulwahn@38079
   276
      val thy = ProofContext.theory_of ctxt
bulwahn@38079
   277
      val c = restore_const constant_table f
bulwahn@38079
   278
      val cT = Sign.the_const_type thy c
bulwahn@38079
   279
      val (argsT, resT) = strip_type cT
bulwahn@38079
   280
      val subst = Sign.typ_match thy (resT, T) Vartab.empty
bulwahn@38079
   281
      val argsT' = map (Envir.subst_type subst) argsT
bulwahn@38079
   282
    in
bulwahn@38079
   283
      list_comb (Const (c, Envir.subst_type subst cT),
bulwahn@38079
   284
        map (restore_term ctxt constant_table) (args ~~ argsT'))
bulwahn@38079
   285
    end
bulwahn@38079
   286
bulwahn@38075
   287
fun values ctxt soln t_compr =
bulwahn@38075
   288
  let
bulwahn@38075
   289
    val split = case t_compr of (Const (@{const_name Collect}, _) $ t) => t
bulwahn@38075
   290
      | _ => error ("Not a set comprehension: " ^ Syntax.string_of_term ctxt t_compr);
bulwahn@38075
   291
    val (body, Ts, fp) = HOLogic.strip_psplits split;
bulwahn@38075
   292
    val output_names = Name.variant_list (Term.add_free_names body [])
bulwahn@38075
   293
      (map (fn i => "x" ^ string_of_int i) (1 upto length Ts))
bulwahn@38080
   294
    val output_frees = rev (map2 (curry Free) output_names Ts)
bulwahn@38075
   295
    val body = subst_bounds (output_frees, body)
bulwahn@38075
   296
    val (pred as Const (name, T), all_args) =
bulwahn@38075
   297
      case strip_comb body of
bulwahn@38075
   298
        (Const (name, T), all_args) => (Const (name, T), all_args)
bulwahn@38075
   299
      | (head, _) => error ("Not a constant: " ^ Syntax.string_of_term ctxt head)
bulwahn@38075
   300
    val vnames =
bulwahn@38075
   301
      case try (map (fst o dest_Free)) all_args of
bulwahn@38075
   302
        SOME vs => vs
bulwahn@38075
   303
      | NONE => error ("Not only free variables in " ^ commas (map (Syntax.string_of_term ctxt) all_args))
bulwahn@38079
   304
    val _ = tracing "Generating prolog program..."
bulwahn@38079
   305
    val (p, constant_table) = generate ctxt [name]
bulwahn@38079
   306
    val _ = tracing "Running prolog program..."
bulwahn@38079
   307
    val tss = run p (translate_const constant_table name) (map first_upper vnames) soln
bulwahn@38079
   308
    val _ = tracing "Restoring terms..."
bulwahn@38079
   309
    fun mk_set_comprehension t =
bulwahn@38079
   310
      let
bulwahn@38079
   311
        val frees = Term.add_frees t []
bulwahn@38079
   312
        val uu as (uuN, uuT) = singleton (Variable.variant_frees ctxt [t]) ("uu", fastype_of t)
bulwahn@38079
   313
      in HOLogic.mk_Collect (uuN, uuT, fold (fn (s, T) => fn t => HOLogic.mk_exists (s, T, t))
bulwahn@38079
   314
        frees (HOLogic.mk_conj (HOLogic.mk_eq (Free uu, t), @{term "True"}))) end
bulwahn@38079
   315
    val set_comprs = map (fn ts =>
bulwahn@38079
   316
      mk_set_comprehension (HOLogic.mk_tuple (map (restore_term ctxt constant_table) (ts ~~ Ts)))) tss
bulwahn@38075
   317
  in
bulwahn@38079
   318
    foldl1 (HOLogic.mk_binop @{const_name sup}) (set_comprs @ [Free ("...", fastype_of t_compr)])
bulwahn@38075
   319
  end
bulwahn@38075
   320
bulwahn@38075
   321
fun values_cmd print_modes soln raw_t state =
bulwahn@38075
   322
  let
bulwahn@38075
   323
    val ctxt = Toplevel.context_of state
bulwahn@38075
   324
    val t = Syntax.read_term ctxt raw_t
bulwahn@38075
   325
    val t' = values ctxt soln t
bulwahn@38075
   326
    val ty' = Term.type_of t'
bulwahn@38075
   327
    val ctxt' = Variable.auto_fixes t' ctxt
bulwahn@38075
   328
    val p = Print_Mode.with_modes print_modes (fn () =>
bulwahn@38075
   329
      Pretty.block [Pretty.quote (Syntax.pretty_term ctxt' t'), Pretty.fbrk,
bulwahn@38075
   330
        Pretty.str "::", Pretty.brk 1, Pretty.quote (Syntax.pretty_typ ctxt' ty')]) ();
bulwahn@38075
   331
  in Pretty.writeln p end;
bulwahn@38075
   332
bulwahn@38075
   333
bulwahn@38075
   334
(* renewing the values command for Prolog queries *)
bulwahn@38075
   335
bulwahn@38075
   336
val opt_print_modes =
bulwahn@38075
   337
  Scan.optional (Parse.$$$ "(" |-- Parse.!!! (Scan.repeat1 Parse.xname --| Parse.$$$ ")")) [];
bulwahn@38075
   338
bulwahn@38075
   339
val _ = Outer_Syntax.improper_command "values" "enumerate and print comprehensions" Keyword.diag
bulwahn@38077
   340
  (opt_print_modes -- Scan.optional (Parse.nat >> SOME) NONE -- Parse.term
bulwahn@38075
   341
   >> (fn ((print_modes, soln), t) => Toplevel.keep
bulwahn@38075
   342
        (values_cmd print_modes soln t)));
bulwahn@38075
   343
bulwahn@38073
   344
end;