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/branches/SMLNJ/src/compiler/TopLevel/interact/interact.sml
ViewVC logotype

View of /sml/branches/SMLNJ/src/compiler/TopLevel/interact/interact.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 24 - (download) (annotate)
Thu Mar 12 00:49:58 1998 UTC (21 years, 6 months ago) by monnier
File size: 2988 byte(s)
*** empty log message ***
(* COPYRIGHT (c) 1996 Bell Laboratories. *)
(* interact.sml *)

signature INTERACT =
sig
  exception Interrupt

  val interact : unit -> unit
  val useFile : string -> unit

  val useStream : TextIO.instream -> unit
  val evalStream : TextIO.instream * SCEnv.Env.environment -> 
                       SCEnv.Env.environment

  val installCompManager:
      (Ast.dec *
       { get: unit -> SCEnv.Env.environment,
	 set: SCEnv.Env.environment -> unit } *
       { get: unit -> Environment.environment,
	 set: Environment.environment -> unit }
       -> unit) option
      -> unit

  (* The mUse functions should really be part of the Open Compiler *)
  val mUseFile : (int->bool) -> string -> unit
  val mUseFile_reset : unit -> unit
  val mUseFile_add : (((unit -> unit) * string)list) -> unit
  val mUseFile_list : unit -> (((unit -> unit)*string)list) list

end  (* signature INTERACT *)

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))))

  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

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

  fun evalStream (stream: TextIO.instream, baseEnv: SCEnv.Env.environment) : 
      SCEnv.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);
	  SCEnv.SC (#get localEnvRef ())
      end

end (* functor Interact *)

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