File: interact.sml

package info (click to toggle)
smlnj 110.79-8
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 82,564 kB
  • sloc: ansic: 32,532; asm: 6,314; sh: 2,296; makefile: 1,821; perl: 1,170; pascal: 295; yacc: 190; cs: 78; python: 77; lisp: 19
file content (48 lines) | stat: -rw-r--r-- 1,409 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
(* COPYRIGHT (c) 1996 Bell Laboratories. *)
(* interact.sml *)

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

  type envref = EnvRef.envref

  val installCompManagers = EvalLoop.installCompManagers

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

  val withErrorHandling = EvalLoop.withErrorHandling

  fun useFile fname =
      (app Control.Print.say ["[opening ",fname,"]\n"];
       EvalLoop.evalStream
	   (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 = EvalLoop.evalStream ("<instream>", stream)

  fun evalStream (stream, baseEnv) = let
      val r = ref Environment.emptyEnv
      val base = { set = fn _ => raise Fail "evalStream: #set base",
		   get = fn () => baseEnv }
      val loc = { set = fn e => r := e,
		  get = fn () => !r }
      val props = PropList.newHolder ()
      val state = { loc = loc, base = base, props = props }
  in
      EnvRef.locally (state,
		      fn () => (EvalLoop.evalStream ("<instream>", stream);
				!r))
  end

  local open SMLofNJ.Cont
  in val redump_heap_cont : string cont ref =
	 ref (callcc (fn ret => (callcc (fn k => throw ret k);
				 raise Fail "redump_heap_cont init")))
  end

end (* functor Interact *)