From: Chris Hanson Date: Sun, 13 May 2018 04:23:21 +0000 (-0700) Subject: Major refactor to how printer methods work. X-Git-Tag: mit-scheme-pucked-x11-0.3.1~7^2~62 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=8a888d9cfd986cb2dd8ebd2e865971f593007cb2;p=mit-scheme.git 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. --- 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