;; toplevel. loaded to start reploop if interactive session (not -l )
;; modified
;; 20apr	interactive version of error handler==original version
;; 2jan
;; 4sep: split all non-toplevel stuff into "basics"

(set! autoload-notify? #f)	;be silent if script
(require 'basics)

;;; if we arrive here, this must be an interactive session
(set! autoload-notify? #t)
;(display 'toplevel)(newline)

;; interactive version of the error handler
(set! error-handler
  (lambda error-msg
    (error-print error-msg)
    (let loop ()
      (if (call-with-current-continuation
	   (lambda (control-point)
	     (push-frame control-point)
	     (rep-loop (the-environment))
	     #f))
	  ;; lambda will return #f on eof, in which case we fall out
	  ;; below the let, do pop-frame and invoke the next frame with #t.
	  ;; If the next frame is also an error, we are back here and
	  ;; go into this begin, which will in turn probably be exited with ^D
	  ;; The last frame will always be a toplevel frame.
	  (begin			;then
	    (pop-frame)
	    ;(format #t "errloop begin~%")
	    (loop)
	  );begin
      );if
    );let
    ;(format #t "error-handler past loop~%")
    (newline)
    (pop-frame)
    (let ((next-frame (car rep-frames)))
      (next-frame #t))
  );lambda
);set

(the-top-level)

