81 signature PRIVATE_CONTEXT = |
81 signature PRIVATE_CONTEXT = |
82 sig |
82 sig |
83 include CONTEXT |
83 include CONTEXT |
84 structure Theory_Data: |
84 structure Theory_Data: |
85 sig |
85 sig |
86 val declare: Object.T -> (Object.T -> Object.T) -> (Object.T -> Object.T) -> |
86 val declare: Object.T -> (Object.T -> Object.T) -> |
87 (Pretty.pp -> Object.T * Object.T -> Object.T) -> serial |
87 (Pretty.pp -> Object.T * Object.T -> Object.T) -> serial |
88 val get: serial -> (Object.T -> 'a) -> theory -> 'a |
88 val get: serial -> (Object.T -> 'a) -> theory -> 'a |
89 val put: serial -> ('a -> Object.T) -> 'a -> theory -> theory |
89 val put: serial -> ('a -> Object.T) -> 'a -> theory -> theory |
90 end |
90 end |
91 structure Proof_Data: |
91 structure Proof_Data: |
124 | NONE => sys_error "Invalid theory data identifier"); |
123 | NONE => sys_error "Invalid theory data identifier"); |
125 |
124 |
126 in |
125 in |
127 |
126 |
128 fun invoke_empty k = invoke (K o #empty) k (); |
127 fun invoke_empty k = invoke (K o #empty) k (); |
129 val invoke_copy = invoke #copy; |
|
130 val invoke_extend = invoke #extend; |
128 val invoke_extend = invoke #extend; |
131 fun invoke_merge pp = invoke (fn kind => #merge kind pp); |
129 fun invoke_merge pp = invoke (fn kind => #merge kind pp); |
132 |
130 |
133 fun declare_theory_data empty copy extend merge = |
131 fun declare_theory_data empty extend merge = |
134 let |
132 let |
135 val k = serial (); |
133 val k = serial (); |
136 val kind = {empty = empty, copy = copy, extend = extend, merge = merge}; |
134 val kind = {empty = empty, extend = extend, merge = merge}; |
137 val _ = CRITICAL (fn () => Unsynchronized.change kinds (Datatab.update (k, kind))); |
135 val _ = CRITICAL (fn () => Unsynchronized.change kinds (Datatab.update (k, kind))); |
138 in k end; |
136 in k end; |
139 |
137 |
140 val copy_data = Datatab.map' invoke_copy; |
|
141 val extend_data = Datatab.map' invoke_extend; |
138 val extend_data = Datatab.map' invoke_extend; |
142 |
139 |
143 fun merge_data pp (data1, data2) = |
140 fun merge_data pp (data1, data2) = |
144 Datatab.keys (Datatab.merge (K true) (data1, data2)) |
141 Datatab.keys (Datatab.merge (K true) (data1, data2)) |
145 |> Par_List.map (fn k => |
142 |> Par_List.map (fn k => |
339 let |
336 let |
340 val Theory ({self, draft, id, ids}, data, ancestry, history) = thy; |
337 val Theory ({self, draft, id, ids}, data, ancestry, history) = thy; |
341 val (self', data', ancestry') = |
338 val (self', data', ancestry') = |
342 if draft then (self, data, ancestry) (*destructive change!*) |
339 if draft then (self, data, ancestry) (*destructive change!*) |
343 else if #stage history > 0 |
340 else if #stage history > 0 |
344 then (NONE, copy_data data, ancestry) |
341 then (NONE, data, ancestry) |
345 else (NONE, extend_data data, make_ancestry [thy] (extend_ancestors_of thy)); |
342 else (NONE, extend_data data, make_ancestry [thy] (extend_ancestors_of thy)); |
346 val ids' = insert_id draft id ids; |
343 val ids' = insert_id draft id ids; |
347 val data'' = f data'; |
344 val data'' = f data'; |
348 val thy' = SYNCHRONIZED (fn () => |
345 val thy' = SYNCHRONIZED (fn () => |
349 (check_thy thy; create_thy self' draft' ids' data'' ancestry' history)); |
346 (check_thy thy; create_thy self' draft' ids' data'' ancestry' history)); |
355 |
352 |
356 fun copy_thy thy = |
353 fun copy_thy thy = |
357 let |
354 let |
358 val Theory ({draft, id, ids, ...}, data, ancestry, history) = thy; |
355 val Theory ({draft, id, ids, ...}, data, ancestry, history) = thy; |
359 val ids' = insert_id draft id ids; |
356 val ids' = insert_id draft id ids; |
360 val data' = copy_data data; |
|
361 val thy' = SYNCHRONIZED (fn () => |
357 val thy' = SYNCHRONIZED (fn () => |
362 (check_thy thy; create_thy NONE true ids' data' ancestry history)); |
358 (check_thy thy; create_thy NONE true ids' data ancestry history)); |
363 in thy' end; |
359 in thy' end; |
364 |
360 |
365 val pre_pure_thy = create_thy NONE true Inttab.empty |
361 val pre_pure_thy = create_thy NONE true Inttab.empty |
366 Datatab.empty (make_ancestry [] []) (make_history PureN 0); |
362 Datatab.empty (make_ancestry [] []) (make_history PureN 0); |
367 |
363 |
602 type T = Data.T; |
597 type T = Data.T; |
603 exception Data of T; |
598 exception Data of T; |
604 |
599 |
605 val kind = Context.Theory_Data.declare |
600 val kind = Context.Theory_Data.declare |
606 (Data Data.empty) |
601 (Data Data.empty) |
607 (fn Data x => Data (Data.copy x)) |
|
608 (fn Data x => Data (Data.extend x)) |
602 (fn Data x => Data (Data.extend x)) |
609 (fn pp => fn (Data x1, Data x2) => Data (Data.merge pp (x1, x2))); |
603 (fn pp => fn (Data x1, Data x2) => Data (Data.merge pp (x1, x2))); |
610 |
604 |
611 val get = Context.Theory_Data.get kind (fn Data x => x); |
605 val get = Context.Theory_Data.get kind (fn Data x => x); |
612 val put = Context.Theory_Data.put kind Data; |
606 val put = Context.Theory_Data.put kind Data; |