File: reconstruct.sml

package info (click to toggle)
smlnj 110.79-8
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 82,564 kB
  • sloc: ansic: 32,532; asm: 6,314; sh: 2,296; makefile: 1,821; perl: 1,170; pascal: 295; yacc: 190; cs: 78; python: 77; lisp: 19
file content (66 lines) | stat: -rw-r--r-- 1,655 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
(* reconstruct.sml
 *
 * (C) 2001 Lucent Technologies, Bell Labs
 *
 * author: Matthias Blume (blume@research.bell-labs.com)
 *)
local structure P = PortableGraph in
structure ReconstructPortable :> sig

    type lib type env type sym type syms type misc
    type graph = P.graph
    type context = (lib, env, sym, syms, graph, misc) PGOps.context

    val reconstruct : (context -> lib list -> graph) * int -> graph
end = struct

    type lib = P.varname
    type env = P.varname
    type sym = P.varname
    type syms = P.varname
    type misc = int * P.def list
    type graph = P.graph
    type context = (lib, env, sym, syms, graph, misc) PGOps.context

    fun reconstruct (gt, nlibs) = let

	fun varname i = "v" ^ Int.toString i

	fun Bind (r, (i, d)) = let
	    val v = varname i
	    val i' = i + 1
	    val d' = P.DEF { lhs = v, rhs = r } :: d
	in
	    ((i', d'), v)
	end

	fun Sgn m s =
	    Bind (P.SYM (P.SGN, s), m)
	fun Str m s =
	    Bind (P.SYM (P.STR, s), m)
	fun Fct m s =
	    Bind (P.SYM (P.FCT, s), m)
	fun Syms m sl =
	    Bind (P.SYMS sl, m)
	fun Imp m (l, ss) =
	    Bind (P.IMPORT { lib = l, syms = ss }, m)
	fun Com m (s, e, ss, n) =
	    Bind (P.COMPILE { src = (s, n), env = e, syms = ss }, m)
	fun Fil m (e, ss) =
	    Bind (P.FILTER { env = e, syms = ss }, m)
	fun Mer m el =
	    Bind (P.MERGE el, m)

	val imports = List.tabulate (nlibs, varname)

	fun Exp (i, d) e =
	    P.GRAPH { imports = imports, defs = rev d, export = e }
    in
	gt { Ops = { Sgn = Sgn, Str = Str, Fct = Fct,
		     Exp = Exp, Syms = Syms,
		     Imp = Imp, Com = Com, Fil = Fil, Mer = Mer },
	     Misc = (nlibs, []) }
	   imports
    end
end
end