Eliminate uses of unparser/set-tagged-{pair,vector}-unparser!.
authorChris Hanson <org/chris-hanson/cph>
Sun, 13 May 2018 06:19:18 +0000 (23:19 -0700)
committerChris Hanson <org/chris-hanson/cph>
Sun, 13 May 2018 06:19:18 +0000 (23:19 -0700)
Also change their implementation to use define-print-method.

13 files changed:
src/compiler/base/object.scm
src/edwin/window.scm
src/runtime/dos-pathname.scm
src/runtime/gdatab.scm
src/runtime/make.scm
src/runtime/poplat.scm
src/runtime/printer.scm
src/runtime/prop1d.scm
src/runtime/random.scm
src/runtime/runtime.pkg
src/runtime/thread.scm
src/runtime/unix-pathname.scm
src/sf/pthmap.scm

index ccf95248155f91d28b86e728887f1ea47978ec31..136dc28de7d7ad6239241735769a92deaec95f07 100644 (file)
@@ -59,7 +59,14 @@ USA.
                               ;; Propagate this downward at construction time
                               ;; to avoid having to crawl upward at use time.
                               (and parent (vector-tag-noop parent)))))
-       (unparser/set-tagged-vector-method! tag tagged-vector/unparse)
+       (define-print-method (lambda (object)
+                              (and (vector? object)
+                                   (fix:> (vector-length object) 0)
+                                   (eq? tag (vector-ref object 0))))
+         (lambda (vector port)
+           (parameterize* (list (cons param:printer-radix 16))
+             (lambda ()
+               ((tagged-vector/unparser vector) vector port)))))
        tag))))
 
 (define (define-vector-tag-unparser tag unparser)
@@ -145,9 +152,4 @@ USA.
        ((tagged-vector? object)
         (vector-tag-description (tagged-vector/tag object)))
        (else
-        (error "Not a tagged vector" object))))
-
-(define (tagged-vector/unparse state vector)
-  (parameterize* (list (cons param:printer-radix 16))
-    (lambda ()
-      ((tagged-vector/unparser vector) state vector))))
+        (error "Not a tagged vector" object))))
\ No newline at end of file
index 84f744d0f9f481849851df2a1c227cdbd3d55a3b..e39fdac866e50b9e4a397271a369e57c795d1777 100644 (file)
@@ -334,7 +334,12 @@ USA.
 ;;;; Inferiors
 
 (define %inferior-tag
-  "inferior")
+  '|#[(edwin window) inferior]|)
+
+(define (%inferior? object)
+  (and (vector? object)
+       (fix:= 5 (vector-length object))
+       (eq? %inferior-tag (vector-ref object 0))))
 
 (define-integrable (%make-inferior window x-start y-start redisplay-flags)
   (vector %inferior-tag window x-start y-start redisplay-flags))
@@ -363,8 +368,8 @@ USA.
 (define-integrable (set-inferior-redisplay-flags! inferior redisplay-flags)
   (vector-set! inferior 4 redisplay-flags))
 
-(unparser/set-tagged-vector-method! %inferior-tag
-  (bracketed-print-method 'INFERIOR
+(define-print-method %inferior?
+  (bracketed-print-method 'inferior
     (lambda (inferior port)
       (write-string " " port)
       (write (inferior-window inferior) port)
index 7e8351466c90dc17ccae5d232f24beb952f4f728..b26c33e974c893104f48071113291c77cca3a294 100644 (file)
@@ -198,7 +198,7 @@ USA.
   (string-append (print-device (%pathname-device pathname))
                 (print-directory (%pathname-directory pathname))
                 (print-name (%pathname-name pathname)
-                              (%pathname-type pathname))))
+                            (%pathname-type pathname))))
 
 (define (print-device device)
   (if (or (not device) (eq? device 'unspecific))
index bd45765e3f7ee044de8d29f9fc499f7814609100..1b02f2aac6c52868d7d485984a2e9d03fde86f20 100644 (file)
@@ -28,56 +28,27 @@ USA.
 ;;; package: (runtime global-database)
 
 (declare (usual-integrations))
-\f
-(define (initialize-package!)
-  (set! event:after-restore (make-event-distributor))
-  (set! event:after-restart (make-event-distributor))
-  (set! event:before-exit (make-event-distributor))
-  (set! tagged-pair-methods (make-1d-table))
-  (set! tagged-vector-methods (make-1d-table))
-  (set! named-structure-descriptions (make-1d-table))
-  unspecific)
 
-(define event:after-restore)
-(define event:after-restart)
-(define event:before-exit)
-(define tagged-pair-methods)
-(define tagged-vector-methods)
-(define named-structure-descriptions)
-
-(define (unparser/tagged-pair-method tag)
-  (1d-table/get tagged-pair-methods tag #f))
+(define-deferred event:after-restore (make-event-distributor))
+(define-deferred event:after-restart (make-event-distributor))
+(define-deferred event:before-exit (make-event-distributor))
+(define-deferred named-structure-descriptions (make-1d-table))
 
 (define (unparser/set-tagged-pair-method! tag method)
-  (1d-table/put! tagged-pair-methods tag method))
-
-(define (unparser/tagged-vector-method tag)
-  (1d-table/get tagged-vector-methods tag #f))
+  (define-print-method (lambda (object)
+                        (and (pair? object)
+                             (eq? tag (car object))))
+    method))
 
 (define (unparser/set-tagged-vector-method! tag method)
-  (1d-table/put! tagged-vector-methods tag method))
+  (define-print-method (lambda (object)
+                        (and (vector? object)
+                             (fix:> (vector-length object) 0)
+                             (eq? tag (vector-ref object 0))))
+    method))
 
 (define (named-structure/get-tag-description tag)
   (1d-table/get named-structure-descriptions tag #f))
 
 (define (named-structure/set-tag-description! tag description)
-  (1d-table/put! named-structure-descriptions tag description))
-
-;;; Support for old-style methods
-
-(define (add-unparser-special-pair! tag method)
-  (unparser/set-tagged-pair-method! tag (convert-old-method method)))
-
-(define (add-unparser-special-object! tag method)
-  (unparser/set-tagged-vector-method! tag (convert-old-method method)))
-
-(define (unparse-with-brackets thunk)
-  (write-string "#[")
-  (thunk)
-  (write-char #\]))
-
-(define (convert-old-method method)
-  (lambda (state object)
-    (parameterize* (list (cons current-output-port (unparser-state/port state)))
-      (lambda ()
-       (method object)))))
\ No newline at end of file
+  (1d-table/put! named-structure-descriptions tag description))
\ No newline at end of file
index 777fa43003fac84679ee1d63259f782d7a5f9e6d..6b6a5cdc410ed74a1579131c2af570924a689d10 100644 (file)
@@ -416,8 +416,6 @@ USA.
   (package-initialize '(runtime thread) 'initialize-low! #t) ;First 1d-table.
   (package-initialize '(runtime event-distributor) #f #t)
   (package-initialize '(runtime global-database) #f #t)
-  (package-initialize '(runtime population) 'initialize-unparser! #t)
-  (package-initialize '(runtime 1d-property) 'initialize-unparser! #t)
   (package-initialize '(runtime gc-finalizer) #f #t)
 
   ;; Load everything else.
index f1d233a334cb15d1e5e847273fa6a27d8edec756..4fd6b36c64a69be7c9be2c08c5057a76533db307 100644 (file)
@@ -32,16 +32,18 @@ USA.
 ;;; A population is a weak collection of objects.  A serial
 ;;; population is a population with a mutex to serialize its operations.
 
-(define (initialize-package!)
-  (set! population-of-populations (list population-tag (make-thread-mutex)))
-  (add-secondary-gc-daemon!/unsafe clean-all-populations!))
+(define-deferred population-of-populations
+  (list population-tag (make-thread-mutex)))
 
-(define (initialize-unparser!)
-  (unparser/set-tagged-pair-method! population-tag
-                                   (standard-print-method 'population)))
+(add-boot-init!
+ (lambda ()
+   (add-secondary-gc-daemon!/unsafe clean-all-populations!)))
 
-(define bogus-false '(bogus-false))
-(define population-tag '(population))
+(define-integrable population-tag
+  '|#[population]|)
+
+(define-integrable bogus-false
+  '|#[population false]|)
 
 (define-integrable (canonicalize object)
   (if (eq? object false) bogus-false object))
@@ -67,8 +69,6 @@ USA.
 (define (clean-all-populations!)
   (clean-population! population-of-populations)
   (map-over-population! population-of-populations clean-population!))
-
-(define population-of-populations)
 \f
 (define (make-population)
   (let ((population (list population-tag #f)))
@@ -94,6 +94,9 @@ USA.
   (and (pair? object)
        (eq? (car object) population-tag)))
 
+(define-print-method population?
+  (standard-print-method 'population))
+
 (define-guarantee population "population")
 
 (define (add-to-population! population object)
index 79a1e62b9bae4368078b0eaaf4210d017c1bde35..6e119dc78541c0bac165dce8c9919d6357db01ae 100644 (file)
@@ -413,7 +413,7 @@ USA.
          (if (string? name)
              (*print-string name context*)
              (print-object name context*))
-               (*print-char #\space context*)
+         (*print-char #\space context*)
          (*print-hash object context*)
          (cond (procedure
                 (procedure context*))
index 24a2301e3b308da4d52c1d94d53cae43142b6ea2..8d77bd28cf7cb43514e6da394d662d8638ab7ae1 100644 (file)
@@ -29,15 +29,12 @@ USA.
 
 (declare (usual-integrations))
 \f
-(define (initialize-package!)
-  (set! population-of-1d-tables (make-serial-population/unsafe))
-  (add-secondary-gc-daemon!/unsafe clean-1d-tables!))
+(define-deferred population-of-1d-tables
+  (make-serial-population/unsafe))
 
-(define (initialize-unparser!)
-  (unparser/set-tagged-pair-method! 1d-table-tag
-                                   (standard-print-method '1d-table)))
-
-(define population-of-1d-tables)
+(add-boot-init!
+ (lambda ()
+   (add-secondary-gc-daemon!/unsafe clean-1d-tables!)))
 
 (define (clean-1d-tables!)
   (for-each-inhabitant population-of-1d-tables 1d-table/clean!))
@@ -56,11 +53,14 @@ USA.
   (and (pair? object)
        (eq? (car object) 1d-table-tag)))
 
-(define 1d-table-tag
-  "1D table")
+(define-integrable 1d-table-tag
+  '|#[1D table]|)
+
+(define-integrable false-key
+  '|#[1D table false]|)
 
-(define false-key
-  "false key")
+(define-print-method 1d-table?
+  (standard-print-method '1d-table))
 
 (define-integrable (weak-cons car cdr)
   (system-pair-cons (ucode-type weak-cons) car cdr))
index 53eaa71be8813afa4d667f49100fa8a0117f894d..428b221f3fd03b932fafb0305d8514e3061027a7 100644 (file)
@@ -337,10 +337,14 @@ USA.
   (and (vector? object)
        (fix:= (vector-length object) 4)
        (eq? (vector-ref object 0) random-state-tag)))
+(register-predicate! random-state? 'random-state '<= vector?)
 
 (define-integrable random-state-tag
   '|#[(runtime random-number)random-state]|)
 
+(define-print-method random-state?
+  (standard-print-method 'random-state))
+
 (define-integrable (random-state-index s) (vector-ref s 1))
 (define-integrable (set-random-state-index! s x) (vector-set! s 1 x))
 
@@ -416,6 +420,6 @@ USA.
                                '#(index borrow vector)
                                '#(1 2 3)
                                (make-vector 3 (lambda () #f))
-                               (standard-print-method 'random-state)
+                               #f
                                random-state-tag
                                4)))
\ No newline at end of file
index cd69f2b5b87cab42f5a52137a6fad37316e45c7f..9373dae61fb0dc022d72a9f249d007a04ede2997 100644 (file)
@@ -1211,8 +1211,7 @@ USA.
          make-serial-population/unsafe
          add-to-population!/unsafe)
   (import (runtime gc-daemons)
-         add-secondary-gc-daemon!/unsafe)
-  (initialization (initialize-package!)))
+         add-secondary-gc-daemon!/unsafe))
 
 (define-package (runtime 2d-property)
   (files "prop2d")
@@ -2360,20 +2359,16 @@ USA.
 (define-package (runtime global-database)
   (files "gdatab")
   (parent (runtime))
+  (export () deprecated:global-database
+         unparser/set-tagged-pair-method!
+         unparser/set-tagged-vector-method!)
   (export ()
-         add-unparser-special-object!
-         add-unparser-special-pair!
          event:after-restart
          event:after-restore
          event:before-exit
-         named-structure/get-tag-description
-         named-structure/set-tag-description!
-         unparse-with-brackets
-         unparser/set-tagged-pair-method!
-         unparser/set-tagged-vector-method!
-         unparser/tagged-pair-method
-         unparser/tagged-vector-method)
-  (initialization (initialize-package!)))
+         named-structure/set-tag-description!)
+  (export (runtime record)
+         named-structure/get-tag-description))
 
 (define-package (runtime hash)
   (files "hash")
@@ -2400,7 +2395,8 @@ USA.
   (export () deprecated:hash-table
          (eq-hash-table-type key-weak-eq-hash-table-type)
          (eqv-hash-table-type key-weak-eqv-hash-table-type)
-         (hash-table-entry-type:key/datum-weak hash-table-entry-type:key&datum-weak)
+         (hash-table-entry-type:key/datum-weak
+          hash-table-entry-type:key&datum-weak)
          (hash-table/clean! hash-table-clean!)
          (hash-table/clear! hash-table-clear!)
          (hash-table/count hash-table-size)
@@ -3525,8 +3521,7 @@ USA.
          map-over-population
          map-over-population!
          population?
-         remove-from-population!)
-  (initialization (initialize-package!)))
+         remove-from-population!))
 
 (define-package (runtime pretty-printer)
   (files "pp")
index 6f0297ca0a5218307274cbc750b1646cea319ca0..774780f27242bd98ada8ff9d3c0d4a255680db3a 100644 (file)
@@ -136,7 +136,7 @@ USA.
                                '#(waiting-threads owner)
                                '#(1 2)
                                (vector 2 (lambda () #f))
-                               (standard-print-method 'thread-mutex)
+                               #f
                                thread-mutex-tag
                                3))
   (named-structure/set-tag-description! link-tag
@@ -145,10 +145,13 @@ USA.
                                '#(prev next item)
                                '#(1 2 3)
                                (vector 3 (lambda () #f))
-                               (standard-print-method 'link)
+                               #f
                                link-tag
                                4)))
 
+(define-print-method link?
+  (standard-print-method 'link))
+
 (define (reset-threads!)
   (reset-threads-low!)
   (reset-threads-high!))
@@ -1159,6 +1162,9 @@ USA.
   (waiting-threads (make-ring) read-only #t)
   (owner #f))
 
+(define-print-method thread-mutex?
+  (standard-print-method 'thread-mutex))
+
 (define-integrable (guarantee-thread-mutex mutex procedure)
   (if (not (thread-mutex? mutex))
       (error:wrong-type-argument mutex "thread-mutex" procedure)))
index 001a6ebc931904d8963efb4eda781d914e834d6b..7edb8c064c651d9f5624f0bbd4b7cfa97537b8de 100644 (file)
@@ -157,7 +157,7 @@ USA.
 (define (unix/pathname->namestring pathname)
   (string-append (print-directory (%pathname-directory pathname))
                 (print-name (%pathname-name pathname)
-                              (%pathname-type pathname))))
+                            (%pathname-type pathname))))
 
 (define (print-directory directory)
   (cond ((not directory)
index 15aa9e15cd6862a0a3009c2ddceb1e56de4b0de5..ae965e36f027c34f38087823fa5995e1f9ed1990 100644 (file)
@@ -39,10 +39,6 @@ USA.
 (define pathname-map/tag "pathname-map")
 (define pathname-map/root-node cdr)
 
-(unparser/set-tagged-pair-method!
- pathname-map/tag
- (standard-print-method "PATHNAME-MAP"))
-
 (declare (integrate-operator node/make))
 
 (define (node/make)
@@ -107,6 +103,9 @@ USA.
     (and (pair? object)
         (eq? (car object) pathname-map/tag))))
 
+(define-print-method pathname-map?
+  (standard-print-method 'pathname-map))
+
 (set! pathname-map/lookup
   (named-lambda (pathname-map/lookup map pathname if-found if-not)
     (let ((node