109 -> (string -> string option) (*class syntax*) |
109 -> (string -> string option) (*class syntax*) |
110 -> (string -> Code_Printer.tyco_syntax option) |
110 -> (string -> Code_Printer.tyco_syntax option) |
111 -> (string -> Code_Printer.activated_const_syntax option) |
111 -> (string -> Code_Printer.activated_const_syntax option) |
112 -> ((Pretty.T -> string) * (Pretty.T -> unit)) |
112 -> ((Pretty.T -> string) * (Pretty.T -> unit)) |
113 -> Code_Thingol.program |
113 -> Code_Thingol.program |
114 -> string list (*selected statements*) |
114 -> (string list * string list) (*selected statements*) |
115 -> serialization; |
115 -> serialization; |
116 |
116 |
117 datatype description = Fundamental of { serializer: serializer, literals: Code_Printer.literals, |
117 datatype description = Fundamental of { serializer: serializer, literals: Code_Printer.literals, |
118 check: { env_var: string, make_destination: Path.T -> Path.T, |
118 check: { env_var: string, make_destination: Path.T -> Path.T, |
119 make_command: string -> Path.T -> string -> string } } |
119 make_command: string -> Path.T -> string -> string } } |
252 in (SOME name, (Symtab.update_new (name, syn) tab, naming')) end |
252 in (SOME name, (Symtab.update_new (name, syn) tab, naming')) end |
253 | NONE => (NONE, (tab, naming))) (Symtab.keys src_tab) |
253 | NONE => (NONE, (tab, naming))) (Symtab.keys src_tab) |
254 |>> map_filter I; |
254 |>> map_filter I; |
255 |
255 |
256 fun invoke_serializer thy abortable serializer literals reserved abs_includes |
256 fun invoke_serializer thy abortable serializer literals reserved abs_includes |
257 module_alias class instance tyco const module width args naming program2 names1 = |
257 module_alias class instance tyco const module_name width args naming program2 (names1, presentation_names) = |
258 let |
258 let |
259 val (names_class, class') = |
259 val (names_class, class') = |
260 activate_syntax (Code_Thingol.lookup_class naming) class; |
260 activate_syntax (Code_Thingol.lookup_class naming) class; |
261 val names_inst = map_filter (Code_Thingol.lookup_instance naming) |
261 val names_inst = map_filter (Code_Thingol.lookup_instance naming) |
262 (Symreltab.keys instance); |
262 (Symreltab.keys instance); |
273 val empty_funs = filter_out (member (op =) abortable) |
273 val empty_funs = filter_out (member (op =) abortable) |
274 (Code_Thingol.empty_funs program3); |
274 (Code_Thingol.empty_funs program3); |
275 val _ = if null empty_funs then () else error ("No code equations for " |
275 val _ = if null empty_funs then () else error ("No code equations for " |
276 ^ commas (map (Sign.extern_const thy) empty_funs)); |
276 ^ commas (map (Sign.extern_const thy) empty_funs)); |
277 in |
277 in |
278 serializer module args (Code_Thingol.labelled_name thy program2) reserved includes |
278 serializer module_name args (Code_Thingol.labelled_name thy program2) reserved includes |
279 (Symtab.lookup module_alias) (Symtab.lookup class') |
279 (if is_some module_name then K module_name else Symtab.lookup module_alias) |
280 (Symtab.lookup tyco') (Symtab.lookup const') |
280 (Symtab.lookup class') (Symtab.lookup tyco') (Symtab.lookup const') |
281 (Code_Printer.string_of_pretty width, Code_Printer.writeln_pretty width) |
281 (Code_Printer.string_of_pretty width, Code_Printer.writeln_pretty width) |
282 program4 names1 |
282 program4 (names1, presentation_names) |
283 end; |
283 end; |
284 |
284 |
285 fun mount_serializer thy alt_serializer target some_width module args naming program names = |
285 fun mount_serializer thy alt_serializer target some_width raw_module_name args naming program names destination = |
286 let |
286 let |
287 val ((targets, abortable), default_width) = Targets.get thy; |
287 val ((targets, abortable), default_width) = Targets.get thy; |
288 fun collapse_hierarchy target = |
288 fun collapse_hierarchy target = |
289 let |
289 let |
290 val data = case Symtab.lookup targets target |
290 val data = case Symtab.lookup targets target |
297 in (modify' #> modify naming, merge_target false target (data', data)) end |
297 in (modify' #> modify naming, merge_target false target (data', data)) end |
298 end; |
298 end; |
299 val (modify, data) = collapse_hierarchy target; |
299 val (modify, data) = collapse_hierarchy target; |
300 val serializer = the_default (case the_description data |
300 val serializer = the_default (case the_description data |
301 of Fundamental seri => #serializer seri) alt_serializer; |
301 of Fundamental seri => #serializer seri) alt_serializer; |
|
302 val presentation_names = stmt_names_of_destination destination; |
|
303 val module_name = if null presentation_names |
|
304 then raw_module_name else SOME "Code"; |
302 val reserved = the_reserved data; |
305 val reserved = the_reserved data; |
303 fun select_include names_all (name, (content, cs)) = |
306 fun select_include names_all (name, (content, cs)) = |
304 if null cs then SOME (name, content) |
307 if null cs then SOME (name, content) |
305 else if exists (fn c => case Code_Thingol.lookup_const naming c |
308 else if exists (fn c => case Code_Thingol.lookup_const naming c |
306 of SOME name => member (op =) names_all name |
309 of SOME name => member (op =) names_all name |
307 | NONE => false) cs |
310 | NONE => false) cs |
308 then SOME (name, content) else NONE; |
311 then SOME (name, content) else NONE; |
309 fun includes names_all = map_filter (select_include names_all) |
312 fun includes names_all = map_filter (select_include names_all) |
310 ((Symtab.dest o the_includes) data); |
313 ((Symtab.dest o the_includes) data); |
311 val module_alias = the_module_alias data; |
314 val module_alias = the_module_alias data |
312 val { class, instance, tyco, const } = the_name_syntax data; |
315 val { class, instance, tyco, const } = the_name_syntax data; |
313 val literals = the_literals thy target; |
316 val literals = the_literals thy target; |
314 val width = the_default default_width some_width; |
317 val width = the_default default_width some_width; |
315 in |
318 in |
316 invoke_serializer thy abortable serializer literals reserved |
319 invoke_serializer thy abortable serializer literals reserved |
317 includes module_alias class instance tyco const module width args naming (modify program) names |
320 includes module_alias class instance tyco const module_name width args |
|
321 naming (modify program) (names, presentation_names) destination |
318 end; |
322 end; |
319 |
323 |
320 in |
324 in |
321 |
325 |
322 fun serialize thy = mount_serializer thy NONE; |
326 fun serialize thy = mount_serializer thy NONE; |