373 then SOME (print_stmt false (name, stmt)) |
373 then SOME (print_stmt false (name, stmt)) |
374 else NONE |
374 else NONE |
375 | (_, (_, NONE)) => NONE) stmts); |
375 | (_, (_, NONE)) => NONE) stmts); |
376 val serialize_module = |
376 val serialize_module = |
377 if null presentation_stmt_names then serialize_module1 else pair "" o serialize_module2; |
377 if null presentation_stmt_names then serialize_module1 else pair "" o serialize_module2; |
378 fun check_destination destination = |
378 fun write_module width (SOME destination) (modlname, content) = |
379 (File.check destination; destination); |
379 let |
380 fun write_module width destination (modlname, content) = |
380 val _ = File.check destination; |
381 let |
381 val filename = case modlname |
382 val filename = case modlname |
382 of "" => Path.explode "Main.hs" |
383 of "" => Path.explode "Main.hs" |
383 | _ => (Path.ext "hs" o Path.explode o implode o separate "/" |
384 | _ => (Path.ext "hs" o Path.explode o implode o separate "/" |
384 o Long_Name.explode) modlname; |
385 o Long_Name.explode) modlname; |
385 val pathname = Path.append destination filename; |
386 val pathname = Path.append destination filename; |
386 val _ = File.mkdir_leaf (Path.dir pathname); |
387 val _ = File.mkdir_leaf (Path.dir pathname); |
387 in File.write pathname |
388 in File.write pathname |
388 ("{-# OPTIONS_GHC -fglasgow-exts #-}\n\n" |
389 ("{-# OPTIONS_GHC -fglasgow-exts #-}\n\n" |
389 ^ string_of_pretty width content) |
390 ^ string_of_pretty width content) |
390 end |
391 end |
391 | write_module width NONE (_, content) = writeln_pretty width content; |
392 in |
392 in |
393 Code_Target.mk_serialization |
393 Code_Target.mk_serialization |
394 (fn width => (fn NONE => K () o map (writeln_pretty width o snd) |
394 (fn width => fn destination => K () o map (write_module width destination)) |
395 | SOME file => K () o map (write_module width (check_destination file)))) |
395 (fn width => rpair [] o cat_lines o map (string_of_pretty width o snd)) |
396 (fn width => (rpair [] o cat_lines o map (string_of_pretty width o snd))) |
|
397 (map (uncurry print_module) includes |
396 (map (uncurry print_module) includes |
398 @ map serialize_module (Symtab.dest hs_program)) |
397 @ map serialize_module (Symtab.dest hs_program)) |
399 end; |
398 end; |
400 |
399 |
401 val literals = let |
400 val literals = let |