support for system options as context-sensitive config options;
authorwenzelm
Sun, 12 May 2013 18:22:44 +0200
changeset 51947 3301612c4893
parent 51946 449fbf64f4a5
child 51948 cb5dbc9a06f9
support for system options as context-sensitive config options;
src/Pure/ROOT.ML
src/Pure/config.ML
--- a/src/Pure/ROOT.ML	Sun May 12 18:20:16 2013 +0200
+++ b/src/Pure/ROOT.ML	Sun May 12 18:22:44 2013 +0200
@@ -67,6 +67,8 @@
 
 use "General/graph.ML";
 
+use "System/options.ML";
+
 
 (* concurrency within the ML runtime *)
 
@@ -113,7 +115,6 @@
 use "context.ML";
 use "context_position.ML";
 use "config.ML";
-use "System/options.ML";
 
 
 (* inner syntax *)
--- a/src/Pure/config.ML	Sun May 12 18:20:16 2013 +0200
+++ b/src/Pure/config.ML	Sun May 12 18:22:44 2013 +0200
@@ -27,6 +27,7 @@
   val declare_generic: {global: bool} -> string -> (Context.generic -> value) -> raw
   val declare_global: string -> (Context.generic -> value) -> raw
   val declare: string -> (Context.generic -> value) -> raw
+  val declare_option: string -> raw
   val name_of: 'a T -> string
 end;
 
@@ -138,6 +139,17 @@
 val declare_global = declare_generic {global = true};
 val declare = declare_generic {global = false};
 
+fun declare_option name =
+  let
+    val typ = Options.default_typ name;
+    val default =
+      if typ = Options.boolT then fn _ => Bool (Options.default_bool name)
+      else if typ = Options.intT then fn _ => Int (Options.default_int name)
+      else if typ = Options.realT then fn _ => Real (Options.default_real name)
+      else if typ = Options.stringT then fn _ => String (Options.default_string name)
+      else error ("Unknown type for option " ^ quote name ^ " : " ^ quote typ);
+  in declare name default end;
+
 fun name_of (Config {name, ...}) = name;