A bunch of changes to implement R7RS exit/emergency-exit.
authorChris Hanson <org/chris-hanson/cph>
Mon, 14 May 2018 00:13:21 +0000 (17:13 -0700)
committerChris Hanson <org/chris-hanson/cph>
Mon, 14 May 2018 00:13:21 +0000 (17:13 -0700)
* The EXIT procedure has been removed.
* The %EXIT procedure has been renamed to EXIT.
* The EMERGENCY-EXIT procedure has been added.
* The optional argument to the above has been generalized to meet R7RS
  requirements.
* The QUIT procedure has been renamed to SUSPEND to more accurately reflect what
  it does.
* The names %EXIT and QUIT are deprecated aliases for EXIT and SUSPEND.

14 files changed:
src/6001/edextra.scm
src/6001/make.scm
src/edwin/basic.scm
src/edwin/dos.scm
src/edwin/editor.scm
src/edwin/intmod.scm
src/edwin/unix.scm
src/runtime/console-io.scm
src/runtime/gc.scm
src/runtime/global.scm
src/runtime/interrupt.scm
src/runtime/load.scm
src/runtime/runtime.pkg
src/runtime/swank.scm

index f9276683401515c2e6d2fac646a559b8967b0a92..1015f1272d937247a34e1ac71cc5a31963a8e3f9 100644 (file)
@@ -387,7 +387,7 @@ option the file from the problem set will not be installed.
 (set! default-homedir-pathname (lambda () student-work-directory))
 
 (set! editor-can-exit? #f)
-(set! scheme-can-quit? #f)
+(set! scheme-can-suspend? #f)
 (set! paranoid-exit? #t)
 
 (set-variable! enable-transcript-buffer #t)
index fb7265e1b0e12498a0e050a025168eb0149e4613..7d83658d02382941dc207fb725733ddbb5fdd922 100644 (file)
@@ -49,13 +49,9 @@ USA.
  (lambda (integer)
    integer
    (warn "EXIT has been disabled.")))
-(param:%exit-hook
- (lambda (integer)
-   integer
-   (warn "%EXIT has been disabled.")))
-(param:quit-hook
+(param:suspend-hook
  (lambda ()
-   (warn "QUIT has been disabled.")))
+   (warn "SUSPEND has been disabled.")))
 
 (let ((edwin-env (->environment '(EDWIN)))
       (student-env (->environment '(STUDENT))))
index 50b14d24aa6dc6282e8bc155589037354888d4c3..964796dd2c7d5e33a53f80188d79ac91595a3111 100644 (file)
@@ -315,13 +315,13 @@ For a normal exit, you should use \\[exit-recursive-edit], NOT this command."
 ;;;; Leaving Edwin
 
 ;; Set this to #F to indicate that returning from the editor has the
-;; same effect as calling %EXIT, or to prevent the editor from
+;; same effect as calling EXIT, or to prevent the editor from
 ;; returning to scheme.
 (define editor-can-exit? #t)
 
-;; Set this to #F to indicate that calling QUIT has the same effect
-;; as calling %EXIT, or to prevent the editor from suspending to the OS.
-(define scheme-can-quit?
+;; Set this to #F to indicate that calling SUSPEND has the same effect
+;; as calling EXIT, or to prevent the editor from suspending to the OS.
+(define scheme-can-suspend?
   #t)
 
 ;; Set this to #T to force the exit commands to always prompt for
@@ -334,7 +334,7 @@ With argument, saves visited file first."
   "P"
   (lambda (argument)
     (if argument (save-buffer (current-buffer) #f))
-    (if (and scheme-can-quit? (os/scheme-can-quit?))
+    (if (and scheme-can-suspend? (os/scheme-can-suspend?))
        (quit-scheme)
        (editor-error "Scheme cannot be suspended"))))
 
index 67952bcc369c1a35855f6e2f4ac94e88f1e5157e..b2e978af4996695c8aa552b3eab1c7f5e1d8213e 100644 (file)
@@ -35,11 +35,11 @@ USA.
 (define (os/restore-modes-to-updated-file! pathname modes)
   (set-file-modes! pathname (fix:or modes nt-file-mode/archive)))
 
-(define (os/scheme-can-quit?)
+(define (os/scheme-can-suspend?)
   #t)
 
 (define (os/quit dir)
-  (with-real-working-directory-pathname dir %quit))
+  (with-real-working-directory-pathname dir suspend))
 
 (define (with-real-working-directory-pathname dir thunk)
   (let ((inside (->namestring (directory-pathname-as-file dir)))
index 9c7e9e83e9441178a033025c82f6cd1464fd1544..424daa1fe31d0a1d481a7ec4153922e4aeb36830 100644 (file)
@@ -495,7 +495,7 @@ TRANSCRIPT    messages appear in transcript buffer, if it is enabled;
   (within-continuation editor-abort reset-editor))
 
 (define (exit-scheme)
-  (within-continuation editor-abort %exit))
+  (within-continuation editor-abort exit))
 
 (define (editor-grab-display editor receiver)
   (display-type/with-display-grabbed (editor-display-type editor)
index 2a8d5623e3cd003b1862bbb97aa6d811a8b69181..600e8f6f4f2c706d41eece3546b6e44d053b297c 100644 (file)
@@ -122,8 +122,8 @@ evaluated in the specified inferior REPL buffer."
                                    (detach-thread thread)
                                    thread))))
        (attach-buffer-interface-port! buffer port)
-       (parameterize* (list (cons param:%exit-hook inferior-repl/%exit)
-                            (cons param:quit-hook inferior-repl/quit))
+       (parameterize* (list (cons param:exit-hook inferior-repl/exit)
+                            (cons param:suspend-hook inferior-repl/suspend))
          (lambda ()
            (dynamic-wind
             (lambda () unspecific)
@@ -151,10 +151,10 @@ evaluated in the specified inferior REPL buffer."
      (set-working-directory-pathname!
       (buffer-default-directory (port/buffer port))))))
 
-(define (inferior-repl/%exit #!optional integer)
+(define (inferior-repl/exit #!optional integer)
   (exit-current-thread (if (default-object? integer) 0 integer)))
 
-(define (inferior-repl/quit)
+(define (inferior-repl/suspend)
   unspecific)
 \f
 (define (current-repl-buffer #!optional buffer)
index f48c5d5e58ec7eba9658646dadbc80baae41ee8d..65996c018020b8a3e7191bc4139405f9db8e41a2 100644 (file)
@@ -643,12 +643,12 @@ option, instead taking -P <filename>."
 \f
 ;;;; Miscellaneous
 
-(define (os/scheme-can-quit?)
+(define (os/scheme-can-suspend?)
   (subprocess-job-control-available?))
 
 (define (os/quit dir)
   dir                                  ; ignored
-  (%quit))
+  (suspend))
 
 (define (os/set-file-modes-writeable! pathname)
   (set-file-modes! pathname #o777))
index 587209934a06207a8ac9f83c573d1cbce890ba79..c722b0a85a2e50d2503c9412425b4ad6747c09a0 100644 (file)
@@ -121,8 +121,8 @@ USA.
          (if (let ((condition (nearest-repl/condition)))
                (and condition
                     (condition/error? condition)))
-             (%exit 1)
-             (%exit))))
+             (exit 'eof)
+             (exit))))
     char))
 
 (define (operation/read-finish port)
index 37fab3f8a6f803e67af34a6098fc724926985123..68d6a02a01fd1346098b2b2602e7629c3b1e0823 100644 (file)
@@ -137,7 +137,7 @@ USA.
         (if (nearest-cmdl/batch-mode?)
             (lambda (port)
               (newline port)
-              (%exit 1))
+              (exit 'gc-out-of-space))
             (lambda (port)
               port
               (with-gc-notification! #t gc-clean))))))))
index c9a01cb51173b239af420b0b4cb1fb3350e7fb99..79077ebaa6304f55a4f1458c7ba5707995dd45ca 100644 (file)
@@ -75,32 +75,19 @@ USA.
 (define (host-big-endian?)
   host-big-endian?-saved)
 
-(define host-big-endian?-saved)
-
-(define ephemeron-type)
-
-(define (initialize-package!)
-  ;; Assumptions:
-  ;; * Word length is 32 or 64 bits.
-  ;; * Type codes are at most 8 bits.
-  ;; * Zero is a non-pointer type code.
-  (set! host-big-endian?-saved
-       (case (object-datum
-              (vector-ref
-               (object-new-type (ucode-type vector)
-                                "\000\001\002\000\000\003\004\000")
-               1))
-         ((#x00010200 #x0001020000030400) #t)
-         ((#x00020100 #x0004030000020100) #f)
-         (else (error "Unable to determine endianness of host."))))
-  (add-secondary-gc-daemon! clean-obarray)
-  (set! param:exit-hook (make-settable-parameter default/exit))
-  (set! param:%exit-hook (make-settable-parameter default/%exit))
-  (set! param:quit-hook (make-settable-parameter default/quit))
-  ;; Kludge until the next released version, to avoid a bootstrapping
-  ;; failure.
-  (set! ephemeron-type (microcode-type 'ephemeron))
-  unspecific)
+;; Assumptions:
+;; * Word length is 32 or 64 bits.
+;; * Type codes are at most 8 bits.
+;; * Zero is a non-pointer type code.
+(define-deferred host-big-endian?-saved
+  (case (object-datum
+        (vector-ref
+         (object-new-type (ucode-type vector)
+                          "\000\001\002\000\000\003\004\000")
+         1))
+    ((#x00010200 #x0001020000030400) #t)
+    ((#x00020100 #x0004030000020100) #f)
+    (else (error "Unable to determine endianness of host."))))
 \f
 ;;;; Potpourri
 
@@ -208,54 +195,48 @@ USA.
       (if (< (real-time-clock) end)
          (wait-loop)))))
 \f
-(define hook/exit #!default)
-(define hook/%exit #!default)
-(define hook/quit #!default)
-
-(define param:exit-hook)
-(define param:%exit-hook)
-(define param:quit-hook)
-
-(define (get-exit-hook)
-  (if (default-object? hook/exit)
-      (param:exit-hook)
-      hook/exit))
-
-(define (get-%exit-hook)
-  (if (default-object? hook/%exit)
-      (param:%exit-hook)
-      hook/%exit))
-
-(define (get-quit-hook)
-  (if (default-object? hook/quit)
-      (param:quit-hook)
-      hook/quit))
-
-(define (exit #!optional integer)
-  ((get-exit-hook) (if (default-object? integer) #f integer)))
+(define (exit #!optional object)
+  ((param:exit-hook) (exit-object->code object)))
 
-(define (default/exit integer)
-  (if (prompt-for-confirmation "Kill Scheme")
-      (%exit integer)))
+(define (default-exit code)
+  (event-distributor/invoke! event:before-exit)
+  (within-continuation root-continuation
+    (lambda ()
+      ((ucode-primitive exit-with-value 1) code))))
+
+(define-deferred param:exit-hook
+  (make-settable-parameter default-exit))
+
+(define (emergency-exit #!optional object)
+  ((ucode-primitive exit-with-value 1) (exit-object->code object)))
+
+(define (exit-object->code object)
+  (cond ((or (eq? #t object) (default-object? object))
+        normal-termination-code)
+       ((not object)
+        abnormal-termination-code)
+       ((and (exact-nonnegative-integer? object)
+             (< object (microcode-termination/code-limit)))
+        object)
+       ((and (interned-symbol? object)
+             (microcode-termination/name->code object)))
+       (else
+        abnormal-termination-code)))
 
-(define (%exit #!optional integer)
-  ((get-%exit-hook) integer))
+(define-deferred normal-termination-code
+  (microcode-termination/name->code 'halt))
 
-(define (default/%exit #!optional integer)
-  (event-distributor/invoke! event:before-exit)
-  (if (or (default-object? integer)
-         (not integer))
-      ((ucode-primitive exit 0))
-      ((ucode-primitive exit-with-value 1) integer)))
+(define-deferred abnormal-termination-code
+  (microcode-termination/name->code 'save-and-exit))
 
-(define (quit)
-  ((get-quit-hook)))
+(define (suspend)
+  ((param:suspend-hook)))
 
-(define (%quit)
-  (with-absolutely-no-interrupts (ucode-primitive halt))
-  unspecific)
+(define (default-suspend)
+  (with-absolutely-no-interrupts (ucode-primitive halt)))
 
-(define default/quit %quit)
+(define-deferred param:suspend-hook
+  (make-settable-parameter default-suspend))
 \f
 (define user-initial-environment
   (*make-environment system-global-environment
@@ -416,6 +397,10 @@ USA.
                       (else (vector-set! obarray index tail))))
               (find-broken-entry (vector-ref obarray index) #f)
               (loop index))))))))
+
+(add-boot-init!
+ (lambda ()
+   (add-secondary-gc-daemon! clean-obarray)))
 \f
 (define (impurify object)
   object)
@@ -678,7 +663,7 @@ USA.
   ((ucode-primitive make-ephemeron 2) (canonicalize key) (canonicalize datum)))
 
 (define (ephemeron? object)
-  (object-type? ephemeron-type object))
+  (object-type? (ucode-type ephemeron) object))
 
 (define-guarantee ephemeron "ephemeron")
 
index 052b780eb37997a5e5ac881d53f2454e4f06bc63..a17229581adb163ad73f0e1125bfaec7f5f5969c 100644 (file)
@@ -98,7 +98,7 @@ USA.
       (bind-condition-handler (list condition-type:serious-condition)
          (lambda (condition)
            condition
-           (%exit))
+           (exit))
        (lambda ()
          (bind-condition-handler (list condition-type:warning)
              (lambda (condition)
@@ -108,8 +108,8 @@ USA.
              (if (not (disk-save (merge-pathnames "scheme_suspend"
                                                   (user-homedir-pathname))
                                  true))
-                 (%exit))))))
-      (%exit)))
+                 (exit))))))
+      (exit)))
 
 (define (gc-out-of-space-handler . args)
   args
index 53a1a2f2c98df1b5e9a0c9d43072b02c3349eac8..e33a90a7d85e31436be9b54e7ad34e0a000bb927 100644 (file)
@@ -672,7 +672,7 @@ ADDITIONAL OPTIONS supported by this band:\n")
            (newline)
            (write-string description)
            (newline)))))
-  (%exit 0))
+  (exit))
 \f
 (define (initialize-command-line-parsers)
   (set! *command-line-parsers* '())
@@ -715,7 +715,7 @@ ADDITIONAL OPTIONS supported by this band:\n")
                            repl)))))
     "Evaluates the argument expressions as if in the REPL.")
   (simple-command-line-parser "help" show-command-line-options #f)
-  (simple-command-line-parser "version" (lambda () (%exit 0)) #f)
+  (simple-command-line-parser "version" (lambda () (exit)) #f)
   (set-command-line-parser!
    "args" collect-args
    (command-line-option-description
index 745096a5287b0d031e95dd12de3441abd42ac2ed..164176b066b06c7ecbf7bb94e2e42ebdee1a1892 100644 (file)
@@ -506,10 +506,10 @@ USA.
   (files "global")
   (parent (runtime))
   (export () deprecated:miscellaneous-global
+         (%exit exit)
+         (quit suspend)
          (with-values call-with-values))
   (export ()
-         %exit
-         %quit
          (*the-non-printing-object* unspecific)
          <hook-list>
          append-hook-to-list
@@ -520,8 +520,7 @@ USA.
          cell-contents
          cell?
          constant-procedure
-         default/exit
-         default/quit
+         emergency-exit                ;R7RS
          environment-link-name
          ephemeron-broken?
          ephemeron-datum
@@ -530,7 +529,7 @@ USA.
          eq?
          error-procedure
          eval
-         exit
+         exit                          ;R7RS
          false-procedure
          fasdump
          for-each-interned-symbol
@@ -538,9 +537,6 @@ USA.
          get-interrupt-enables
          hook-in-list?
          hook-list?
-         hook/exit
-         hook/%exit
-         hook/quit
          hook/scode-eval
          host-big-endian?
          hunk3-cons
@@ -573,14 +569,13 @@ USA.
          object-type
          object-type?
          pa
-         param:%exit-hook
          param:exit-hook
-         param:quit-hook
+         param:suspend-hook
          pointer-type-code?
          primitive-procedure-arity
          primitive-procedure-documentation
          pwd
-         quit
+         suspend
          (reference-barrier identity-procedure)
          remove-hook-from-list
          run-hooks-in-list
@@ -625,8 +620,7 @@ USA.
   (export (runtime)
          strip-angle-brackets)
   (import (runtime thread)
-         with-obarray-lock)
-  (initialization (initialize-package!)))
+         with-obarray-lock))
 
 (define-package (runtime merge-sort)
   (files "msort")
@@ -3253,6 +3247,9 @@ USA.
          microcode-system-call-error/code->name
          microcode-system-call-error/name->code
          microcode-system-call/code->name)
+  (export (runtime miscellaneous-global)
+         microcode-termination/code-limit
+         microcode-termination/name->code)
   (export (runtime save/restore)
          read-microcode-tables!)
   (initialization (initialize-package!)))
@@ -3929,11 +3926,13 @@ USA.
          standard-breakpoint-hook
          ve
          with-repl-eval-boundary)
+  (export (runtime debugger)
+         write-restarts)
   (export (runtime emacs-interface)
          hook/error-decision
          set-cmdl/port!)
-  (export (runtime debugger)
-         write-restarts)
+  (export (runtime miscellaneous-global)
+         root-continuation)
   (export (runtime working-directory)
          cmdl/set-default-directory)
   (initialization (initialize-package!)))
index eff60c528a64fc33ba73c1afdb780cea6d347e45..ef69b465a038dfafcd54873526faba31b0e6fea1 100644 (file)
@@ -585,7 +585,7 @@ USA.
 
 (define (swank:quit-lisp socket)
   socket
-  (%exit))
+  (exit))
 \f
 ;;;; Some unimplemented stuff.