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

SCM Repository

[smlnj] View of /sml/trunk/src/compiler/TopLevel/main/execute.sml
ViewVC logotype

View of /sml/trunk/src/compiler/TopLevel/main/execute.sml

Parent Directory Parent Directory | Revision Log Revision Log

Revision 879 - (download) (annotate)
Thu Jul 19 18:59:38 2001 UTC (18 years, 7 months ago) by blume
File size: 2007 byte(s)
extensive organizational changes
(* execute.sml
 * (C) 2001 Lucent Technologies, Bell labs

 *                        EXECUTING THE EXECUTABLE                           *

structure Execute = struct
    structure Obj = Unsafe.Object
    type object = Obj.object

    val say = Control_Print.say
    fun bug s = ErrorMsg.impossible ("Execute: " ^ s)

    (** turn the byte-vector-like code segments into an executable closure *)
    fun mkexec (cs : CodeObj.csegments) = let
	val ex = CodeObj.exec (#c0 cs)
	val nex =
	    if (Word8Vector.length (#data cs) > 0) then
		(fn ivec =>
		    ex (Obj.mkTuple (Obj.toTuple ivec @
				     [CodeObj.mkLiterals (#data cs)])))
	    else (fn ivec => ex ivec)
	foldl (fn (c, r) => (CodeObj.exec c) o r) nex (#cn cs)

    (** perform the execution of the excutable, output the new dynenv *)
    fun execute {executable, imports, exportPid, dynenv} = let
	val args : object = let
            fun selObj (obj, i) =
		Obj.nth(obj, i)
		handle _ => bug "unexpected linkage interface in execute"
            fun getObj ((p, n), zs) = let
		fun get (obj, ImportTree.ITNODE [], z) = obj::z
                  | get (obj, ImportTree.ITNODE xl, z) = let
			fun g ((i, n), x) = get (selObj(obj, i), n, x)
                    in foldr g z xl
                val obj = 
                    DynamicEnv.look dynenv p
		    handle DynamicEnv.Unbound =>
			   (say ("lookup " ^ (PersStamps.toHex p) ^ "\n");
			    raise CompileExn.Compile
				  "imported objects not found or inconsistent")
            in get(obj, n, zs)
	in Obj.mkTuple (foldr getObj [] imports)
	val result : object = executable args
    in case exportPid of
	   NONE => DynamicEnv.empty
	 | SOME p => DynamicEnv.singleton (p, result)

    val execute = Stats.doPhase (Stats.makePhase "Execute") execute

ViewVC Help
Powered by ViewVC 1.0.0