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 /sml/branches/blume-private-devel/src/compiler/Execution/main/execute.sml
ViewVC logotype

Annotation of /sml/branches/blume-private-devel/src/compiler/Execution/main/execute.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1401 - (view) (download)

1 : blume 902 (* execute.sml
2 :     *
3 :     * (C) 2001 Lucent Technologies, Bell labs
4 :     *)
5 :    
6 :     (*****************************************************************************
7 :     * EXECUTING THE EXECUTABLE *
8 :     *****************************************************************************)
9 :    
10 :     structure Execute : sig
11 :     val mkexec : CodeObj.csegments -> CodeObj.executable
12 :     val execute : { executable: CodeObj.executable,
13 :     imports: ImportTree.import list,
14 :     exportPid: PersStamps.persstamp option,
15 :     dynenv: DynamicEnv.env } -> DynamicEnv.env
16 :     end = struct
17 :     structure Obj = Unsafe.Object
18 :     type object = Obj.object
19 :    
20 :     val say = Control_Print.say
21 :     fun bug s = ErrorMsg.impossible ("Execute: " ^ s)
22 :    
23 :    
24 :     (** turn the byte-vector-like code segments into an executable closure *)
25 :     fun mkexec (cs : CodeObj.csegments) = let
26 :     val ex = CodeObj.exec (#c0 cs)
27 :     val nex =
28 :     if (Word8Vector.length (#data cs) > 0) then
29 :     (fn ivec =>
30 :     ex (Obj.mkTuple (Obj.toTuple ivec @
31 :     [CodeObj.mkLiterals (#data cs)])))
32 :     else (fn ivec => ex ivec)
33 :     in
34 :     foldl (fn (c, r) => (CodeObj.exec c) o r) nex (#cn cs)
35 :     end
36 :    
37 :     (** perform the execution of the excutable, output the new dynenv *)
38 :     fun execute {executable, imports, exportPid, dynenv} = let
39 :     val args : object = let
40 :     fun selObj (obj, i) =
41 :     Obj.nth(obj, i)
42 :     handle _ => bug "unexpected linkage interface in execute"
43 :     fun getObj ((p, n), zs) = let
44 :     fun get (obj, ImportTree.ITNODE [], z) = obj::z
45 :     | get (obj, ImportTree.ITNODE xl, z) = let
46 :     fun g ((i, n), x) = get (selObj(obj, i), n, x)
47 :     in foldr g z xl
48 :     end
49 :     val obj =
50 :     case DynamicEnv.look dynenv p of
51 :     SOME obj => obj
52 :     | NONE =>
53 :     (say ("lookup " ^ (PersStamps.toHex p) ^ "\n");
54 :     raise CompileExn.Compile
55 :     "imported objects not found or inconsistent")
56 :     in get(obj, n, zs)
57 :     end
58 :     in Obj.mkTuple (foldr getObj [] imports)
59 :     end
60 :     val result : object = executable args
61 :     in case exportPid of
62 :     NONE => DynamicEnv.empty
63 :     | SOME p => DynamicEnv.singleton (p, result)
64 :     end
65 :    
66 :     val execute = Stats.doPhase (Stats.makePhase "Execute") execute
67 :     end

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