src/HOL/Tools/Mirabelle/Tools/mirabelle.ML
author nipkow
Wed, 02 Sep 2009 12:20:17 +0200
changeset 32489 071e4ae83149
parent 32475 d2c97fc18704
child 32495 6decc1ffdbed
permissions -rw-r--r--
added "using" to blacklist
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32381
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
     1
(* Title:  mirabelle.ML
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
     2
   Author: Jasmin Blanchette and Sascha Boehme
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
     3
*)
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
     4
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
     5
signature MIRABELLE =
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
     6
sig
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
     7
  type action
32385
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
     8
  val register : string * action -> theory -> theory
32381
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
     9
32396
e756600502cc keep the modified (tested) theory,
boehmes
parents: 32385
diff changeset
    10
  val logfile : string Config.T
32381
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    11
  val timeout : int Config.T
32382
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    12
  val start_line : int Config.T
98674ac811c4 Mirabelle tool script conforming to standard Isabelle tool interface,
boehmes
parents: 32381
diff changeset
    13
  val end_line : int Config.T
32381
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    14
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    15
  val goal_thm_of : Proof.state -> thm
32469
1ad7d4fc0954 Mirabelle: added preliminary documentation,
boehmes
parents: 32468
diff changeset
    16
  val can_apply : Time.time -> (Proof.context -> int -> tactic) ->
1ad7d4fc0954 Mirabelle: added preliminary documentation,
boehmes
parents: 32468
diff changeset
    17
    Proof.state -> bool
32381
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    18
  val theorems_in_proof_term : Thm.thm -> Thm.thm list
32385
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    19
  val theorems_of_sucessful_proof : Toplevel.state option -> Thm.thm list
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    20
  val get_setting : (string * string) list -> string * string -> string
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    21
  val get_int_setting : (string * string) list -> string * int -> int
32381
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    22
end
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    23
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    24
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    25
32385
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    26
signature MIRABELLE_EXT =
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    27
sig
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    28
  include MIRABELLE
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    29
  val setup : theory -> theory
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    30
  val step_hook : Toplevel.transition -> Toplevel.state -> Toplevel.state ->
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    31
    unit
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    32
end
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    33
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    34
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    35
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    36
structure Mirabelle : MIRABELLE_EXT =
32381
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    37
struct
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    38
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    39
(* Mirabelle core *)
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    40
32472
7b92a8b8daaf Mirabelle: actions are responsible for their log messages, output is better readable
boehmes
parents: 32469
diff changeset
    41
type action = {pre: Proof.state, post: Toplevel.state option,
7b92a8b8daaf Mirabelle: actions are responsible for their log messages, output is better readable
boehmes
parents: 32469
diff changeset
    42
  timeout: Time.time, log: string -> unit} -> unit
32381
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    43
32385
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    44
structure Actions = TheoryDataFun
32381
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    45
(
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    46
  type T = action Symtab.table
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    47
  val empty = Symtab.empty
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    48
  val copy = I
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    49
  val extend = I
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    50
  fun merge _ = Symtab.merge (K true)
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    51
)
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    52
32385
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
    53
val register = Actions.map o Symtab.update_new
32381
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    54
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    55
val (logfile, setup1) = Attrib.config_string "mirabelle_logfile" ""
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    56
val (timeout, setup2) = Attrib.config_int "mirabelle_timeout" 30
32469
1ad7d4fc0954 Mirabelle: added preliminary documentation,
boehmes
parents: 32468
diff changeset
    57
val (start_line, setup3) = Attrib.config_int "mirabelle_start_line" 0
1ad7d4fc0954 Mirabelle: added preliminary documentation,
boehmes
parents: 32468
diff changeset
    58
val (end_line, setup4) = Attrib.config_int "mirabelle_end_line" ~1
32381
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    59
32469
1ad7d4fc0954 Mirabelle: added preliminary documentation,
boehmes
parents: 32468
diff changeset
    60
val setup = setup1 #> setup2 #> setup3 #> setup4
32381
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    61
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    62
local
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    63
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    64
fun log thy s =
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    65
  let fun append_to n = if n = "" then K () else File.append (Path.explode n)
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    66
  in append_to (Config.get_thy thy logfile) (s ^ "\n") end
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    67
  (* FIXME: with multithreading and parallel proofs enabled, we might need to
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    68
     encapsulate this inside a critical section *)
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    69
32472
7b92a8b8daaf Mirabelle: actions are responsible for their log messages, output is better readable
boehmes
parents: 32469
diff changeset
    70
fun log_block thy msg = log thy (msg ^ "\n------------------")
7b92a8b8daaf Mirabelle: actions are responsible for their log messages, output is better readable
boehmes
parents: 32469
diff changeset
    71
fun log_action thy name msg = log_block thy (name ^ ": " ^ msg)
7b92a8b8daaf Mirabelle: actions are responsible for their log messages, output is better readable
boehmes
parents: 32469
diff changeset
    72
7b92a8b8daaf Mirabelle: actions are responsible for their log messages, output is better readable
boehmes
parents: 32469
diff changeset
    73
fun capture_exns logf f x =
32469
1ad7d4fc0954 Mirabelle: added preliminary documentation,
boehmes
parents: 32468
diff changeset
    74
  let
1ad7d4fc0954 Mirabelle: added preliminary documentation,
boehmes
parents: 32468
diff changeset
    75
    fun f' x = f x
32472
7b92a8b8daaf Mirabelle: actions are responsible for their log messages, output is better readable
boehmes
parents: 32469
diff changeset
    76
      handle TimeLimit.TimeOut => logf "time out"
7b92a8b8daaf Mirabelle: actions are responsible for their log messages, output is better readable
boehmes
parents: 32469
diff changeset
    77
           | ERROR msg => logf ("error: " ^ msg)
7b92a8b8daaf Mirabelle: actions are responsible for their log messages, output is better readable
boehmes
parents: 32469
diff changeset
    78
  in (case try f' x of NONE => logf "exception" | _ => ()) end
32381
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    79
32472
7b92a8b8daaf Mirabelle: actions are responsible for their log messages, output is better readable
boehmes
parents: 32469
diff changeset
    80
fun apply_actions thy info (pre, post, time) actions =
7b92a8b8daaf Mirabelle: actions are responsible for their log messages, output is better readable
boehmes
parents: 32469
diff changeset
    81
  let
7b92a8b8daaf Mirabelle: actions are responsible for their log messages, output is better readable
boehmes
parents: 32469
diff changeset
    82
    val _ = log_block thy info
7b92a8b8daaf Mirabelle: actions are responsible for their log messages, output is better readable
boehmes
parents: 32469
diff changeset
    83
    fun apply (name, action) =
7b92a8b8daaf Mirabelle: actions are responsible for their log messages, output is better readable
boehmes
parents: 32469
diff changeset
    84
      let val st = {pre=pre, post=post, timeout=time, log=log_action thy name}
7b92a8b8daaf Mirabelle: actions are responsible for their log messages, output is better readable
boehmes
parents: 32469
diff changeset
    85
      in capture_exns (log_action thy name) action st end
7b92a8b8daaf Mirabelle: actions are responsible for their log messages, output is better readable
boehmes
parents: 32469
diff changeset
    86
  in List.app apply actions end
32381
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    87
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    88
fun in_range _ _ NONE = true
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    89
  | in_range l r (SOME i) = (l <= i andalso (r < 0 orelse i <= r))
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    90
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    91
fun only_within_range thy pos f x =
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    92
  let val l = Config.get_thy thy start_line and r = Config.get_thy thy end_line
32472
7b92a8b8daaf Mirabelle: actions are responsible for their log messages, output is better readable
boehmes
parents: 32469
diff changeset
    93
  in if in_range l r (Position.line_of pos) then f x else () end
32381
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    94
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    95
in
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    96
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    97
fun basic_hook tr pre post =
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    98
  let
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
    99
    val thy = Proof.theory_of pre
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   100
    val pos = Toplevel.pos_of tr
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   101
    val name = Toplevel.name_of tr
32472
7b92a8b8daaf Mirabelle: actions are responsible for their log messages, output is better readable
boehmes
parents: 32469
diff changeset
   102
    val st = (pre, post, Time.fromSeconds (Config.get_thy thy timeout))
7b92a8b8daaf Mirabelle: actions are responsible for their log messages, output is better readable
boehmes
parents: 32469
diff changeset
   103
7b92a8b8daaf Mirabelle: actions are responsible for their log messages, output is better readable
boehmes
parents: 32469
diff changeset
   104
    val str0 = string_of_int o the_default 0
7b92a8b8daaf Mirabelle: actions are responsible for their log messages, output is better readable
boehmes
parents: 32469
diff changeset
   105
    val loc = str0 (Position.line_of pos) ^ ":" ^ str0 (Position.column_of pos)
7b92a8b8daaf Mirabelle: actions are responsible for their log messages, output is better readable
boehmes
parents: 32469
diff changeset
   106
    val info = "\n\nat " ^ loc ^ " (" ^ name ^ "):"
32381
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   107
  in
32385
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
   108
    Actions.get thy
594890623c46 split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents: 32383
diff changeset
   109
    |> Symtab.dest
32472
7b92a8b8daaf Mirabelle: actions are responsible for their log messages, output is better readable
boehmes
parents: 32469
diff changeset
   110
    |> only_within_range thy pos (apply_actions thy info st)
32381
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   111
  end
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   112
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   113
end
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   114
32489
071e4ae83149 added "using" to blacklist
nipkow
parents: 32475
diff changeset
   115
val blacklist = ["disable_pr", "enable_pr", "done", ".", "using", "txt"]
32468
3e6f5365971e Mirabelle: explicit command blacklist, preliminary documentation
boehmes
parents: 32396
diff changeset
   116
32381
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   117
fun step_hook tr pre post =
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   118
 (* FIXME: might require wrapping into "interruptible" *)
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   119
  if can (Proof.assert_backward o Toplevel.proof_of) pre andalso
32468
3e6f5365971e Mirabelle: explicit command blacklist, preliminary documentation
boehmes
parents: 32396
diff changeset
   120
     not (member (op =) blacklist (Toplevel.name_of tr))
32381
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   121
  then basic_hook tr (Toplevel.proof_of pre) (SOME post)
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   122
  else ()   (* FIXME: add theory_hook here *)
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   123
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   124
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   125
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   126
(* Mirabelle utility functions *)
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   127
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   128
val goal_thm_of = snd o snd o Proof.get_goal
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   129
32472
7b92a8b8daaf Mirabelle: actions are responsible for their log messages, output is better readable
boehmes
parents: 32469
diff changeset
   130
fun can_apply time tac st =
32469
1ad7d4fc0954 Mirabelle: added preliminary documentation,
boehmes
parents: 32468
diff changeset
   131
  let
1ad7d4fc0954 Mirabelle: added preliminary documentation,
boehmes
parents: 32468
diff changeset
   132
    val (ctxt, (facts, goal)) = Proof.get_goal st
1ad7d4fc0954 Mirabelle: added preliminary documentation,
boehmes
parents: 32468
diff changeset
   133
    val full_tac = HEADGOAL (Method.insert_tac facts THEN' tac ctxt)
32381
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   134
  in
32472
7b92a8b8daaf Mirabelle: actions are responsible for their log messages, output is better readable
boehmes
parents: 32469
diff changeset
   135
    (case TimeLimit.timeLimit time (Seq.pull o full_tac) goal of
32381
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   136
      SOME (thm, _) => true
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   137
    | NONE => false)
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   138
  end
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   139
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   140
local
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   141
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   142
fun fold_body_thms f =
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   143
  let
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   144
    fun app n (PBody {thms, ...}) = thms |> fold (fn (i, (name, prop, body)) =>
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   145
      fn (x, seen) =>
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   146
        if Inttab.defined seen i then (x, seen)
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   147
        else
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   148
          let
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   149
            val body' = Future.join body
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   150
            val (x', seen') = app (n + (if name = "" then 0 else 1)) body'
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   151
              (x, Inttab.update (i, ()) seen)
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   152
        in (x' |> n = 0 ? f (name, prop, body'), seen') end)
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   153
  in fn bodies => fn x => #1 (fold (app 0) bodies (x, Inttab.empty)) end
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   154
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   155
in
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   156
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   157
fun theorems_in_proof_term thm =
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   158
  let
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   159
    val all_thms = PureThy.all_thms_of (Thm.theory_of_thm thm)
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   160
    fun collect (s, _, _) = if s <> "" then insert (op =) s else I
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   161
    fun member_of xs (x, y) = if member (op =) xs x then SOME y else NONE
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   162
    fun resolve_thms names = map_filter (member_of names) all_thms
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   163
  in
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   164
    resolve_thms (fold_body_thms collect [Thm.proof_body_of thm] [])
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   165
  end
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   166
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   167
end
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   168
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   169
fun theorems_of_sucessful_proof state =
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   170
  (case state of
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   171
    NONE => []
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   172
  | SOME st =>
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   173
      if not (Toplevel.is_proof st) then []
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   174
      else theorems_in_proof_term (goal_thm_of (Toplevel.proof_of st)))
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   175
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   176
fun get_setting settings (key, default) =
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   177
  the_default default (AList.lookup (op =) settings key)
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   178
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   179
fun get_int_setting settings (key, default) =
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   180
  (case Option.map Int.fromString (AList.lookup (op =) settings key) of
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   181
    SOME (SOME i) => i
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   182
  | SOME NONE => error ("bad option: " ^ key)
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   183
  | NONE => default)
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   184
11542bebe4d4 made Mirabelle a component
boehmes
parents:
diff changeset
   185
end