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

View of /sml/trunk/src/compiler/TopLevel/interact/interact.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 95 - (download) (annotate)
Wed May 13 00:49:12 1998 UTC (21 years, 2 months ago) by monnier
File size: 3222 byte(s)
merged with 110.5
(* COPYRIGHT (c) 1996 Bell Laboratories. *)
(* interact.sml *)

functor Interact(EvalLoop : EVALLOOP) : INTERACT =
struct
  exception Interrupt = EvalLoop.Interrupt

 (* This is where CM can install itelf into.  Added for the purpose of
  * autoloading. (blume)
  *)
  type envref = EnvRef.envref

  fun installCompManager m = (#compManagerHook EvalLoop.stdParams) := m

  fun interact() = (
	EvalLoop.interact EvalLoop.stdParams;
	OS.Process.exit OS.Process.success)

  fun useFile (fname: string) =
      (app Control.Print.say ["[opening ",fname,"]\n"];
       EvalLoop.evalStream EvalLoop.stdParams
		  (fname,(TextIO.openIn fname
			  handle e as IO.Io _ =>
			      (app Control.Print.say["[use failed: ",
						     General.exnMessage e,
						     "]\n"];
			       raise ErrorMsg.Error))))

  fun useStream (stream: TextIO.instream) =
    EvalLoop.evalStream EvalLoop.stdParams ("<instream>", stream)

  fun useStreamSilently (name, stream) = 
      let (* use the usual evalloop params, but substitute a 
           * pretty-printer that does nothing.
           *)
          val {compManagerHook,
               baseEnvRef,
               localEnvRef,
               transform,
               instrument,
               perform,
               isolate,...} = EvalLoop.stdParams

          val params : EvalLoop.interactParams = 
              {compManagerHook = compManagerHook,
               baseEnvRef = baseEnvRef,
               localEnvRef = localEnvRef,
               transform = transform,
               instrument = instrument,
               perform = perform,
               isolate = isolate,
               printer = fn _ => fn _ => fn _ => () (* no-op printer *)
               }
      in
          EvalLoop.evalStream params (name, stream)
      end

  fun evalStream (stream: TextIO.instream, baseEnv: CMEnv.Env.environment) : 
      CMEnv.Env.environment =
      let val r = ref Environment.emptyEnv
	  val localEnvRef = {get=(fn()=> !r),set=(fn x=>r:=x)}
	  val b = ref baseEnv
	  val baseEnvRef = 
            {get=(fn()=> !b),set=(fn _ => raise Fail "evalStream")}
       in EvalLoop.evalStream
	    ({compManagerHook = ref NONE,
	      (* ????  should CM get its hands into that? *)
	      baseEnvRef = baseEnvRef,
	      localEnvRef=localEnvRef,
	      transform=(fn x => x), 
              instrument=(fn _ => fn x => x),
	      perform=(fn x => x),
	      isolate= #isolate EvalLoop.stdParams,
	      printer= #printer EvalLoop.stdParams})
	    ("<instream>", stream);
	  CMEnv.CM (#get localEnvRef ())
      end

  (* These mUse functions should really be part of the Open Compiler *)
  val mUseFile_hiddenList =
        ref [ [((fn () => (print "--mUseFile not reset!")),"Error!")] ];

  fun mUseFile_reset () = (mUseFile_hiddenList := [])
  fun mUseFile_add   f  = (mUseFile_hiddenList := (f::(!mUseFile_hiddenList)))
  fun mUseFile_list  () = (List.rev(!mUseFile_hiddenList))

  fun mUseFile (test) (fname: string) =
      let fun repeat test n = 
               if (test n) then (useFile fname; repeat test (n+1)) else ()
      in repeat test 0 end

end (* functor Interact *)

(*
 * $Log: interact.sml,v $
 * Revision 1.1.1.1  1998/04/08 18:39:16  george
 * Version 110.5
 *
 *)

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