From 8a888d9cfd986cb2dd8ebd2e865971f593007cb2 Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Sat, 12 May 2018 21:23:21 -0700 Subject: [PATCH] Major refactor to how printer methods work. * Replaced define-unparser-method with define-print-method. A print method is an ordinary procedure that accepts an object and an output port as its arguments and prints whatever it wants to. The translation layer required by older unparser methods is no longer needed. * New standard-print-method is roughly equivalent to simple-unparser-method. * New bracketed-print-method is roughly equivalent to standard-unparser-method. * Changed the printer to handle standard-print-method specially when detecting cycles and shared structure, so that an object using that print method has its parts walked when looking for shared/cyclic structure. --- src/compiler/base/blocks.scm | 2 +- src/compiler/base/ctypes.scm | 2 +- src/compiler/base/enumer.scm | 2 +- src/compiler/base/lvalue.scm | 2 +- src/compiler/base/object.scm | 5 +- src/compiler/base/proced.scm | 2 +- src/compiler/base/rvalue.scm | 6 +- src/compiler/base/subprb.scm | 2 +- src/compiler/rtlbase/rtlobj.scm | 6 +- src/compiler/rtlbase/valclass.scm | 2 +- src/compiler/rtlopt/rcseht.scm | 2 +- src/compiler/rtlopt/rcserq.scm | 2 +- src/compiler/rtlopt/rdflow.scm | 2 +- src/cref/object.scm | 6 +- src/edwin/artdebug.scm | 7 +-- src/edwin/bufwin.scm | 4 +- src/edwin/calias.scm | 8 +-- src/edwin/clscon.scm | 2 +- src/edwin/comman.scm | 4 +- src/edwin/display.scm | 2 +- src/edwin/editor.scm | 8 +-- src/edwin/edtstr.scm | 4 +- src/edwin/keyparse.scm | 4 +- src/edwin/modes.scm | 2 +- src/edwin/struct.scm | 2 +- src/edwin/window.scm | 2 +- src/gdbm/gdbm.scm | 2 +- src/imail/imail-core.scm | 2 +- src/imail/imail-mime.scm | 2 +- src/runtime/binary-port.scm | 7 +-- src/runtime/boot.scm | 90 ++++++++++++++------------- src/runtime/bundle.scm | 17 ++--- src/runtime/condvar.scm | 2 +- src/runtime/defstr.scm | 7 +-- src/runtime/dispatch-tag.scm | 4 +- src/runtime/error.scm | 28 ++++----- src/runtime/ffi.scm | 6 +- src/runtime/gdbm.scm | 2 +- src/runtime/graphics.scm | 2 +- src/runtime/host-adapter.scm | 9 +++ src/runtime/http-io.scm | 8 +-- src/runtime/http-syntax.scm | 4 +- src/runtime/packag.scm | 4 +- src/runtime/pathname.scm | 4 +- src/runtime/poplat.scm | 2 +- src/runtime/predicate.scm | 3 +- src/runtime/printer.scm | 99 ++++++++++++++++++++++-------- src/runtime/prop1d.scm | 2 +- src/runtime/random.scm | 2 +- src/runtime/record.scm | 21 +++---- src/runtime/reference-trap.scm | 2 +- src/runtime/rfc2822-headers.scm | 4 +- src/runtime/runtime.pkg | 19 +++--- src/runtime/sfile.scm | 9 ++- src/runtime/syntax-environment.scm | 4 +- src/runtime/syntax-items.scm | 8 +-- src/runtime/textual-port.scm | 11 ++-- src/runtime/thread-queue.scm | 2 +- src/runtime/thread.scm | 4 +- src/runtime/url.scm | 8 +-- src/runtime/win32-registry.scm | 4 +- src/runtime/x11graph.scm | 2 +- src/sf/object.scm | 4 +- src/sf/pthmap.scm | 2 +- src/sos/class.scm | 2 +- src/sos/printer.scm | 4 +- src/win32/module.scm | 2 +- src/x11/x11-device.scm | 2 +- src/xml/rdf-struct.scm | 13 ++-- src/xml/xml-names.scm | 4 +- src/xml/xml-output.scm | 4 +- src/xml/xml-struct.scm | 4 +- 72 files changed, 292 insertions(+), 247 deletions(-) diff --git a/src/compiler/base/blocks.scm b/src/compiler/base/blocks.scm index 6b9e4230e..fdb904053 100644 --- a/src/compiler/base/blocks.scm +++ b/src/compiler/base/blocks.scm @@ -113,7 +113,7 @@ from the continuation, and then "glued" into place afterwards. block)) (define-vector-tag-unparser block-tag - (simple-unparser-method "LIAR:block" + (standard-print-method "LIAR:block" (lambda (block) (cons (enumeration/index->name block-types (block-type block)) (let ((procedure (block-procedure block))) diff --git a/src/compiler/base/ctypes.scm b/src/compiler/base/ctypes.scm index feb28518a..fed668187 100644 --- a/src/compiler/base/ctypes.scm +++ b/src/compiler/base/ctypes.scm @@ -59,7 +59,7 @@ USA. (make-scfg application '()))) (define-vector-tag-unparser application-tag - (simple-unparser-method + (standard-print-method (lambda (application) (case (application-type application) ((COMBINATION) "LIAR:combination") diff --git a/src/compiler/base/enumer.scm b/src/compiler/base/enumer.scm index 1bc378d44..d4aee06a1 100644 --- a/src/compiler/base/enumer.scm +++ b/src/compiler/base/enumer.scm @@ -38,7 +38,7 @@ USA. (define-structure (enumerand (conc-name enumerand/) (print-procedure - (simple-unparser-method "LIAR:enumerand" + (standard-print-method "LIAR:enumerand" (lambda (enumerand) (list (enumerand/name enumerand)))))) (enumeration false read-only true) diff --git a/src/compiler/base/lvalue.scm b/src/compiler/base/lvalue.scm index 2f9a4f8f4..bdec69508 100644 --- a/src/compiler/base/lvalue.scm +++ b/src/compiler/base/lvalue.scm @@ -98,7 +98,7 @@ USA. (variable-normal-offset variable))) (define-vector-tag-unparser variable-tag - (simple-unparser-method "LIAR:variable" + (standard-print-method "LIAR:variable" (lambda (variable) (list (variable-name variable))))) diff --git a/src/compiler/base/object.scm b/src/compiler/base/object.scm index 1ff8c1828..ccf952481 100644 --- a/src/compiler/base/object.scm +++ b/src/compiler/base/object.scm @@ -46,10 +46,9 @@ USA. (let ((root-tag (%make-vector-tag false 'OBJECT false false))) (set-vector-tag-%unparser! root-tag - (simple-unparser-method + (standard-print-method (lambda (object) - (string "LIAR:" (vector-tag-name (tagged-vector/tag object)))) - #f)) + (string "LIAR:" (vector-tag-name (tagged-vector/tag object)))))) (named-lambda (make-vector-tag parent name enumeration) (let ((tag (%make-vector-tag (or parent root-tag) diff --git a/src/compiler/base/proced.scm b/src/compiler/base/proced.scm index 98f117444..77d0786ac 100644 --- a/src/compiler/base/proced.scm +++ b/src/compiler/base/proced.scm @@ -108,7 +108,7 @@ USA. (lambda (procedure) (enumeration/index->name continuation-types (procedure-type procedure))))) - (simple-unparser-method + (standard-print-method (lambda (procedure) (if (eq? (get-type procedure) 'PROCEDURE) "LIAR:procedure" diff --git a/src/compiler/base/rvalue.scm b/src/compiler/base/rvalue.scm index 556dc5f0f..7b3621cfe 100644 --- a/src/compiler/base/rvalue.scm +++ b/src/compiler/base/rvalue.scm @@ -96,7 +96,7 @@ USA. constant)))) (define-vector-tag-unparser constant-tag - (simple-unparser-method "LIAR:constant" + (standard-print-method "LIAR:constant" (lambda (constant) (list (constant-value constant))))) @@ -114,7 +114,7 @@ USA. (make-rvalue reference-tag block lvalue safe?)) (define-vector-tag-unparser reference-tag - (simple-unparser-method "LIAR:reference" + (standard-print-method "LIAR:reference" (lambda (reference) (list (variable-name (reference-lvalue reference)))))) @@ -150,7 +150,7 @@ USA. (make-rvalue unassigned-test-tag block lvalue)) (define-vector-tag-unparser unassigned-test-tag - (simple-unparser-method "LIAR:unassigned-test" + (standard-print-method "LIAR:unassigned-test" (lambda (unassigned-test) (list (unassigned-test-lvalue unassigned-test))))) diff --git a/src/compiler/base/subprb.scm b/src/compiler/base/subprb.scm index 64fafacb7..e314c3b49 100644 --- a/src/compiler/base/subprb.scm +++ b/src/compiler/base/subprb.scm @@ -114,7 +114,7 @@ known that the continuation need not be used. (constructor virtual-continuation/%make) (conc-name virtual-continuation/) (print-procedure - (simple-unparser-method "LIAR:virtual-continuation" + (standard-print-method "LIAR:virtual-continuation" (lambda (continuation) (let ((type (virtual-continuation/type continuation))) (if type diff --git a/src/compiler/rtlbase/rtlobj.scm b/src/compiler/rtlbase/rtlobj.scm index 1de11688b..b4c4fdfd4 100644 --- a/src/compiler/rtlbase/rtlobj.scm +++ b/src/compiler/rtlbase/rtlobj.scm @@ -33,7 +33,7 @@ USA. (constructor make-rtl-expr (rgraph label entry-edge debugging-info)) (print-procedure - (simple-unparser-method "LIAR:rtl-expr" + (standard-print-method "LIAR:rtl-expr" (lambda (expression) (list (rtl-expr/label expression)))))) (rgraph false read-only true) @@ -53,7 +53,7 @@ USA. debugging-info next-continuation-offset stack-leaf?)) (print-procedure - (simple-unparser-method "LIAR:rtl-procedure" + (standard-print-method "LIAR:rtl-procedure" (lambda (procedure) (list (rtl-procedure/label procedure)))))) (rgraph false read-only true) @@ -87,7 +87,7 @@ USA. next-continuation-offset debugging-info)) (print-procedure - (simple-unparser-method "LIAR:rtl-continuation" + (standard-print-method "LIAR:rtl-continuation" (lambda (continuation) (list (rtl-continuation/label continuation)))))) (rgraph false read-only true) diff --git a/src/compiler/rtlbase/valclass.scm b/src/compiler/rtlbase/valclass.scm index 0c5fad011..df7bd08ac 100644 --- a/src/compiler/rtlbase/valclass.scm +++ b/src/compiler/rtlbase/valclass.scm @@ -32,7 +32,7 @@ USA. (conc-name value-class/) (constructor %make-value-class (name parent)) (print-procedure - (simple-unparser-method 'VALUE-CLASS + (standard-print-method 'VALUE-CLASS (lambda (class) (list (value-class/name class)))))) (name false read-only true) diff --git a/src/compiler/rtlopt/rcseht.scm b/src/compiler/rtlopt/rcseht.scm index a578b6eb7..fdc655ffc 100644 --- a/src/compiler/rtlopt/rcseht.scm +++ b/src/compiler/rtlopt/rcseht.scm @@ -47,7 +47,7 @@ USA. (define-structure (element (constructor %make-element) (constructor make-element (expression)) - (print-procedure (simple-unparser-method "LIAR:element" #f))) + (print-procedure (standard-print-method "LIAR:element"))) (expression false read-only true) (cost false) (in-memory? false) diff --git a/src/compiler/rtlopt/rcserq.scm b/src/compiler/rtlopt/rcserq.scm index bf5e5467d..51f87db5b 100644 --- a/src/compiler/rtlopt/rcserq.scm +++ b/src/compiler/rtlopt/rcserq.scm @@ -32,7 +32,7 @@ USA. (define-structure (quantity (copier quantity-copy) (print-procedure - (simple-unparser-method "LIAR:quantity" #f))) + (standard-print-method "LIAR:quantity"))) (number false read-only true) (first-register false) (last-register false)) diff --git a/src/compiler/rtlopt/rdflow.scm b/src/compiler/rtlopt/rdflow.scm index b0742afaf..6e08a6e39 100644 --- a/src/compiler/rtlopt/rdflow.scm +++ b/src/compiler/rtlopt/rdflow.scm @@ -72,7 +72,7 @@ USA. (conc-name rnode/) (constructor make-rnode (register)) (print-procedure - (simple-unparser-method 'RNODE + (standard-print-method 'RNODE (lambda (rnode) (list (rnode/register rnode)))))) (register false read-only true) diff --git a/src/cref/object.scm b/src/cref/object.scm index f6956190c..f2706bc09 100644 --- a/src/cref/object.scm +++ b/src/cref/object.scm @@ -51,7 +51,7 @@ USA. (constructor make-package (name parent)) (conc-name package/) (print-procedure - (simple-unparser-method 'package + (standard-print-method 'package (lambda (package) (list (package/name package)))))) (name #f read-only #t) @@ -107,7 +107,7 @@ USA. (constructor %make-binding (package name value-cell new?)) (conc-name binding/) (print-procedure - (simple-unparser-method 'binding + (standard-print-method 'binding (lambda (binding) (list (binding/name binding) (package/name (binding/package binding))))))) @@ -170,7 +170,7 @@ USA. (constructor %make-reference (package name)) (conc-name reference/) (print-procedure - (simple-unparser-method 'reference + (standard-print-method 'reference (lambda (reference) (list (reference/name reference) (package/name (reference/package reference))))))) diff --git a/src/edwin/artdebug.scm b/src/edwin/artdebug.scm index df8024479..1ecc3af5d 100644 --- a/src/edwin/artdebug.scm +++ b/src/edwin/artdebug.scm @@ -974,10 +974,9 @@ Prefix argument means do not kill the debugger buffer." (define-structure (unparser-literal (conc-name unparser-literal/) (print-procedure - (general-unparser-method - (lambda (instance port) - (write-string (unparser-literal/string instance) - port)))) + (lambda (instance port) + (write-string (unparser-literal/string instance) + port))) (constructor unparser-literal/make)) string) diff --git a/src/edwin/bufwin.scm b/src/edwin/bufwin.scm index d529a8a8c..ae36ce26e 100644 --- a/src/edwin/bufwin.scm +++ b/src/edwin/bufwin.scm @@ -501,7 +501,7 @@ USA. (define-structure (outline (constructor %make-outline) (print-procedure - (standard-unparser-method 'OUTLINE + (bracketed-print-method 'OUTLINE (lambda (outline port) (write-string "index: " port) (write (outline-index-length outline) port) @@ -569,7 +569,7 @@ USA. (define-structure (o3 (constructor %make-o3) (print-procedure - (standard-unparser-method 'O3 + (bracketed-print-method 'O3 (lambda (o3 port) (write-string "index: " port) (write (o3-index o3) port) diff --git a/src/edwin/calias.scm b/src/edwin/calias.scm index ec0e35701..be5c33efc 100644 --- a/src/edwin/calias.scm +++ b/src/edwin/calias.scm @@ -217,11 +217,9 @@ USA. (define-structure (special-key (constructor %make-special-key) (conc-name special-key/) (print-procedure - (standard-unparser-method 'special-key - (lambda (key port) - (write-char #\space port) - (write-string (special-key/name key) - port))))) + (standard-print-method 'special-key + (lambda (key) + (list (special-key/name key)))))) (symbol #f read-only #t) (bucky-bits #f read-only #t)) diff --git a/src/edwin/clscon.scm b/src/edwin/clscon.scm index 1b07c78b7..7e9887c3b 100644 --- a/src/edwin/clscon.scm +++ b/src/edwin/clscon.scm @@ -57,7 +57,7 @@ USA. (list->vector (map car transforms)) (list->vector (map cdr transforms)) (make-vector (length transforms) (lambda () #f)) - (standard-unparser-method name #f) + (standard-print-method name) class object-size)) class)))) diff --git a/src/edwin/comman.scm b/src/edwin/comman.scm index 345ca6e7e..b237842d8 100644 --- a/src/edwin/comman.scm +++ b/src/edwin/comman.scm @@ -31,7 +31,7 @@ USA. (define-structure (command (constructor %make-command ()) (print-procedure - (simple-unparser-method 'COMMAND + (standard-print-method 'COMMAND (lambda (command) (list (command-name command)))))) name @@ -103,7 +103,7 @@ USA. (define-structure (variable (constructor %make-variable ()) (print-procedure - (simple-unparser-method 'VARIABLE + (standard-print-method 'VARIABLE (lambda (variable) (list (variable-name variable)))))) name diff --git a/src/edwin/display.scm b/src/edwin/display.scm index a6cd0556a..32f92d75c 100644 --- a/src/edwin/display.scm +++ b/src/edwin/display.scm @@ -33,7 +33,7 @@ USA. (conc-name display-type/) (constructor %make-display-type) (print-procedure - (simple-unparser-method 'DISPLAY-TYPE + (standard-print-method 'DISPLAY-TYPE (lambda (display-type) (list (display-type/name display-type)))))) (name false read-only true) diff --git a/src/edwin/editor.scm b/src/edwin/editor.scm index 2f9deb0d5..9c7e9e83e 100644 --- a/src/edwin/editor.scm +++ b/src/edwin/editor.scm @@ -443,11 +443,9 @@ TRANSCRIPT messages appear in transcript buffer, if it is enabled; (constructor make-input-event (type operator . operands)) (conc-name input-event/) (print-procedure - (standard-unparser-method - 'input-event - (lambda (event port) - (write-char #\space port) - (write (input-event/type event) port))))) + (standard-print-method 'input-event + (lambda (event) + (list (input-event/type event)))))) (type #f read-only #t) (operator #f read-only #t) (operands #f read-only #t)) diff --git a/src/edwin/edtstr.scm b/src/edwin/edtstr.scm index 7f9e9588f..6d07c46c3 100644 --- a/src/edwin/edtstr.scm +++ b/src/edwin/edtstr.scm @@ -129,8 +129,8 @@ USA. (define (button-name button) (symbol->string (button-symbol button))) -(define-unparser-method button? - (simple-unparser-method (record-type-name