Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /pgraph/releases/release-110.71/format.sml
ViewVC logotype

Annotation of /pgraph/releases/release-110.71/format.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 975 - (view) (download)
Original Path: sml/trunk/src/cm/pgraph/format.sml

1 : blume 975 (* format.sml
2 :     *
3 :     * (C) 2001 Lucent Technologies, Bell Labs
4 :     *
5 :     * Format the list-of-edges dependency graph so it becomes a valid
6 :     * ML program.
7 :     *
8 :     * author: Matthias Blume (blume@research.bell-labs.com)
9 :     *)
10 :     structure FormatPortable : sig
11 :     val output : PortableGraph.graph * TextIO.outstream -> unit
12 :     end = struct
13 :     structure P = PortableGraph
14 :    
15 :     fun output (P.GRAPH { imports, defs, export }, outs) = let
16 :     val context = "C"
17 :     fun out l = app (fn x => TextIO.output (outs, x)) l
18 :    
19 :     fun varlist [] = "[]"
20 :     | varlist [x] = concat ["[", x, "]"]
21 :     | varlist (h :: t) =
22 :     concat ("[" :: h :: foldr (fn (x, a) => ", " :: x :: a) ["]"] t)
23 :    
24 :     fun cfc (front, args) =
25 :     (out [front];
26 :     app (fn x => out [" ", x]) (context :: args))
27 :    
28 :     fun tos s = concat ["\"", String.toString s, "\""]
29 :    
30 :     fun rhs (P.SYM (ns, n)) = cfc ("SYM", [tos ns, tos n])
31 :     | rhs (P.SYMS syms) = cfc ("SYMS", [varlist syms])
32 :     | rhs (P.IMPORT { lib, syms }) = cfc ("IMPORT", [lib, syms])
33 :     | rhs (P.COMPILE { src, env, syms, native }) =
34 :     cfc (if native then "NCOMPILE" else "COMPILE",
35 :     [tos src, env, syms])
36 :     | rhs (P.FILTER { env, syms }) = cfc ("FILTER", [env, syms])
37 :     | rhs (P.MERGE l) = cfc ("MERGE", [varlist l])
38 :    
39 :     fun dodef (P.DEF d) =
40 :     (out [" val (C, ", #lhs d, ") = "]; rhs (#rhs d); out ["\n"])
41 :     in
42 :     out ["val thelibrary = fn ", context, " => (\n"];
43 :     out ["fn ", varlist imports, " => let\n"];
44 :     app dodef defs;
45 :     out [" in\n EXPORT ", context, " ", export,
46 :     "\n end\n\
47 :     \ | _ => raise Fail \"wrong number of input libraries\")\n"]
48 :     end
49 :     end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0