equal
deleted
inserted
replaced
61 (* check *) |
61 (* check *) |
62 |
62 |
63 fun check_name (Options tab) name = |
63 fun check_name (Options tab) name = |
64 let val opt = Symtab.lookup tab name in |
64 let val opt = Symtab.lookup tab name in |
65 if is_some opt andalso #typ (the opt) <> unknownT then the opt |
65 if is_some opt andalso #typ (the opt) <> unknownT then the opt |
66 else error ("Unknown option " ^ quote name) |
66 else error ("Unknown system option " ^ quote name) |
67 end; |
67 end; |
68 |
68 |
69 fun check_type options name typ = |
69 fun check_type options name typ = |
70 let val opt = check_name options name in |
70 let val opt = check_name options name in |
71 if #typ opt = typ then opt |
71 if #typ opt = typ then opt |
72 else error ("Ill-typed option " ^ quote name ^ " : " ^ #typ opt ^ " vs. " ^ typ) |
72 else error ("Ill-typed system option " ^ quote name ^ " : " ^ #typ opt ^ " vs. " ^ typ) |
73 end; |
73 end; |
74 |
74 |
75 |
75 |
76 (* typ *) |
76 (* typ *) |
77 |
77 |
87 fun get T parse options name = |
87 fun get T parse options name = |
88 let val opt = check_type options name T in |
88 let val opt = check_type options name T in |
89 (case parse (#value opt) of |
89 (case parse (#value opt) of |
90 SOME x => x |
90 SOME x => x |
91 | NONE => |
91 | NONE => |
92 error ("Malformed value for option " ^ quote name ^ |
92 error ("Malformed value for system option " ^ quote name ^ |
93 " : " ^ T ^ " =\n" ^ quote (#value opt))) |
93 " : " ^ T ^ " =\n" ^ quote (#value opt))) |
94 end; |
94 end; |
95 |
95 |
96 |
96 |
97 (* internal lookup and update *) |
97 (* internal lookup and update *) |
119 end; |
119 end; |
120 |
120 |
121 fun declare {name, typ, value} (Options tab) = |
121 fun declare {name, typ, value} (Options tab) = |
122 let |
122 let |
123 val options' = Options (Symtab.update_new (name, {typ = typ, value = value}) tab) |
123 val options' = Options (Symtab.update_new (name, {typ = typ, value = value}) tab) |
124 handle Symtab.DUP _ => error ("Duplicate declaration of option " ^ quote name); |
124 handle Symtab.DUP _ => error ("Duplicate declaration of system option " ^ quote name); |
125 val _ = |
125 val _ = |
126 typ = boolT orelse typ = intT orelse typ = realT orelse typ = stringT orelse |
126 typ = boolT orelse typ = intT orelse typ = realT orelse typ = stringT orelse |
127 error ("Unknown type for option " ^ quote name ^ " : " ^ quote typ); |
127 error ("Unknown type for system option " ^ quote name ^ " : " ^ quote typ); |
128 val _ = check_value options' name; |
128 val _ = check_value options' name; |
129 in options' end; |
129 in options' end; |
130 |
130 |
131 fun update name value (options as Options tab) = |
131 fun update name value (options as Options tab) = |
132 let |
132 let |
146 |
146 |
147 (** global default **) |
147 (** global default **) |
148 |
148 |
149 val global_default = Synchronized.var "Options.default" (NONE: T option); |
149 val global_default = Synchronized.var "Options.default" (NONE: T option); |
150 |
150 |
151 fun err_no_default () = error "No global default options"; |
151 fun err_no_default () = error "Missing default for system options within Isabelle process"; |
152 |
152 |
153 fun change_default f x y = |
153 fun change_default f x y = |
154 Synchronized.change global_default |
154 Synchronized.change global_default |
155 (fn SOME options => SOME (f x y options) |
155 (fn SOME options => SOME (f x y options) |
156 | NONE => err_no_default ()); |
156 | NONE => err_no_default ()); |