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 1453 - (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 : mblume 1453
12 :     exception Link (* For compilation manager to
13 :     * signal to interactive loop that
14 :     * error messages have been issued
15 :     * already. The interactive loop
16 :     * should simply discard this
17 :     * exception (keep quiet) and
18 :     * go to the next input prompt. *)
19 :    
20 :     val mkexec : { cs : CodeObj.csegments,
21 :     exnwrapper : exn -> exn } -> CodeObj.executable
22 : blume 902 val execute : { executable: CodeObj.executable,
23 :     imports: ImportTree.import list,
24 :     exportPid: PersStamps.persstamp option,
25 :     dynenv: DynamicEnv.env } -> DynamicEnv.env
26 :     end = struct
27 : mblume 1453
28 :     exception Link
29 :    
30 : blume 902 structure Obj = Unsafe.Object
31 :     type object = Obj.object
32 :    
33 :     val say = Control_Print.say
34 :     fun bug s = ErrorMsg.impossible ("Execute: " ^ s)
35 :    
36 :    
37 :     (** turn the byte-vector-like code segments into an executable closure *)
38 : mblume 1453 fun mkexec { cs : CodeObj.csegments, exnwrapper } = let
39 : blume 902 val ex = CodeObj.exec (#c0 cs)
40 :     val nex =
41 :     if (Word8Vector.length (#data cs) > 0) then
42 :     (fn ivec =>
43 :     ex (Obj.mkTuple (Obj.toTuple ivec @
44 :     [CodeObj.mkLiterals (#data cs)])))
45 :     else (fn ivec => ex ivec)
46 : mblume 1453 val executable =
47 :     foldl (fn (c, r) => (CodeObj.exec c) o r) nex (#cn cs)
48 : blume 902 in
49 : mblume 1453 fn args => (executable args handle e => raise exnwrapper e)
50 : blume 902 end
51 :    
52 :     (** perform the execution of the excutable, output the new dynenv *)
53 : mblume 1453 fun execute {executable, imports, exportPid, dynenv } = let
54 : blume 902 val args : object = let
55 :     fun selObj (obj, i) =
56 :     Obj.nth(obj, i)
57 :     handle _ => bug "unexpected linkage interface in execute"
58 :     fun getObj ((p, n), zs) = let
59 :     fun get (obj, ImportTree.ITNODE [], z) = obj::z
60 :     | get (obj, ImportTree.ITNODE xl, z) = let
61 :     fun g ((i, n), x) = get (selObj(obj, i), n, x)
62 :     in foldr g z xl
63 :     end
64 :     val obj =
65 :     case DynamicEnv.look dynenv p of
66 :     SOME obj => obj
67 :     | NONE =>
68 :     (say ("lookup " ^ (PersStamps.toHex p) ^ "\n");
69 :     raise CompileExn.Compile
70 :     "imported objects not found or inconsistent")
71 :     in get(obj, n, zs)
72 :     end
73 :     in Obj.mkTuple (foldr getObj [] imports)
74 :     end
75 :     val result : object = executable args
76 :     in case exportPid of
77 :     NONE => DynamicEnv.empty
78 :     | SOME p => DynamicEnv.singleton (p, result)
79 :     end
80 :    
81 :     val execute = Stats.doPhase (Stats.makePhase "Execute") execute
82 :     end

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