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.66/format.sml
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 977 - (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 : blume 977 val context = "c"
17 :     fun out l = app (fn x => TextIO.output (outs, x)) l
18 : blume 975
19 : blume 977 fun varlist [] = "[]"
20 :     | varlist [x] = concat ["[", x, "]"]
21 :     | varlist (h :: t) =
22 :     concat ("[" :: h :: foldr (fn (x, a) => ", " :: x :: a) ["]"] t)
23 : blume 975
24 : blume 977 fun cfc (front, args) =
25 :     (out [front];
26 :     app (fn x => out [" ", x]) (context :: args))
27 : blume 975
28 : blume 977 fun tos s = concat ["\"", String.toString s, "\""]
29 : blume 975
30 : blume 977 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 = (src, native), env, syms }) =
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 : blume 975
39 : blume 977 fun dodef (P.DEF d) =
40 :     (out [" val (", context, ", ", #lhs d, ") = "];
41 :     rhs (#rhs d);
42 :     out ["\n"])
43 : blume 975 in
44 : blume 977 out ["val thelibrary = fn ", context, " => (\n"];
45 :     out ["fn ", varlist imports, " => let\n"];
46 :     app dodef defs;
47 :     out [" in\n export ", context, " ", export,
48 :     "\n end\n\
49 :     \ | _ => raise Fail \"wrong number of input libraries\")\n"]
50 : blume 975 end
51 :     end

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