Commit | Line | Data |
---|---|---|
e6aa2a8a MD |
1 | ;;;; Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. |
2 | ;;;; | |
3 | ;;;; This program is free software; you can redistribute it and/or modify | |
4 | ;;;; it under the terms of the GNU General Public License as published by | |
5 | ;;;; the Free Software Foundation; either version 2, or (at your option) | |
6 | ;;;; any later version. | |
7 | ;;;; | |
8 | ;;;; This program is distributed in the hope that it will be useful, | |
9 | ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | ;;;; GNU General Public License for more details. | |
12 | ;;;; | |
13 | ;;;; You should have received a copy of the GNU General Public License | |
14 | ;;;; along with this software; see the file COPYING. If not, write to | |
15328041 JB |
15 | ;;;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
16 | ;;;; Boston, MA 02111-1307 USA | |
e6aa2a8a MD |
17 | ;;;; |
18 | \f | |
19 | ||
20 | ;;; {Print} | |
21 | ;;; | |
22 | ;;; This code was removed from boot-9.scm by MDJ 970301 | |
23 | ;;; <djurfeldt@nada.kth.se>. It is placed here for archival | |
24 | ;;; purposes. | |
25 | ||
26 | (define (print obj . args) | |
27 | (let ((default-args (list (current-output-port) 0 0 default-print-style #f))) | |
28 | (apply-to-args (append args (list-cdr-ref default-args (length args))) | |
29 | (lambda (port depth length style table) | |
30 | (cond | |
31 | ((and table (print-table-ref table obj)) | |
32 | ((print-style-tag-hook style 'eq-val) | |
33 | obj port depth length style table)) | |
34 | (else | |
35 | (and table (print-table-add! table obj)) | |
36 | (cond | |
37 | ((print-style-max-depth? style depth) | |
38 | ((print-style-excess-depth-hook style))) | |
39 | ((print-style-max-length? style length) | |
40 | ((print-style-excess-length-hook style))) | |
41 | (else | |
42 | ((print-style-hook style obj) | |
43 | obj port depth length style table))))))))) | |
44 | ||
45 | (define (make-print-style) (make-vector 59 '())) | |
46 | ||
47 | (define (extend-print-style! style utag printer) | |
48 | (hashq-set! style utag printer)) | |
49 | ||
50 | (define (print-style-hook style obj) | |
51 | (let ((type-tag (tag obj))) | |
52 | (or (hashq-ref style type-tag) | |
53 | (hashq-ref style (logand type-tag 255)) | |
54 | print-obj))) | |
55 | ||
56 | (define (print-style-tag-hook style type-tag) | |
57 | (or (hashq-ref style type-tag) | |
58 | print-obj)) | |
59 | ||
60 | (define (print-style-max-depth? style d) #f) | |
61 | (define (print-style-max-length? style l) #f) | |
62 | (define (print-style-excess-length-hook style) | |
63 | (hashq-ref style 'excess-length-hook)) | |
64 | (define (print-style-excess-depth-hook style) | |
65 | (hashq-ref style 'excess-depth-hook)) | |
66 | ||
67 | (define (make-print-table) (make-vector 59 '())) | |
68 | (define (print-table-ref table obj) (hashq-ref table obj)) | |
69 | (define (print-table-add! table obj) (hashq-set! table obj (gensym 'ref))) | |
70 | ||
71 | (define (print-obj obj port depth length style table) (write obj port)) | |
72 | ||
73 | (define (print-pair pair port depth length style table) | |
74 | (if (= 0 length) | |
75 | (display #\( port)) | |
76 | ||
77 | (print (car pair) port (+ 1 depth) 0 style table) | |
78 | ||
79 | (cond | |
80 | ((and (pair? (cdr pair)) | |
81 | (or (not table) | |
82 | (not (print-table-ref table (cdr pair))))) | |
83 | ||
84 | (display #\space port) | |
85 | (print (cdr pair) port depth (+ 1 length) style table)) | |
86 | ||
87 | ((null? (cdr pair)) (display #\) port)) | |
88 | ||
89 | (else (display " . " port) | |
90 | (print (cdr pair) port (+ 1 depth) 0 | |
91 | style table) | |
92 | (display #\) port)))) | |
93 | ||
94 | (define (print-vector obj port depth length style table) | |
95 | (if (= 0 length) | |
96 | (cond | |
97 | ((weak-key-hash-table? obj) (display "#wh(" port)) | |
98 | ((weak-value-hash-table? obj) (display "#whv(" port)) | |
99 | ((doubly-weak-hash-table? obj) (display "#whd(" port)) | |
100 | (else (display "#(" port)))) | |
101 | ||
102 | (if (< length (vector-length obj)) | |
103 | (print (vector-ref obj length) port (+ 1 depth) 0 style table)) | |
104 | ||
105 | (cond | |
106 | ((>= (+ 1 length) (vector-length obj)) (display #\) port)) | |
107 | (else (display #\space port) | |
108 | (print obj port depth | |
109 | (+ 1 length) | |
110 | style table)))) | |
111 | ||
112 | (define default-print-style (make-print-style)) | |
113 | ||
114 | (extend-print-style! default-print-style utag_vector print-vector) | |
115 | (extend-print-style! default-print-style utag_wvect print-vector) | |
116 | (extend-print-style! default-print-style utag_pair print-pair) | |
117 | (extend-print-style! default-print-style 'eq-val | |
118 | (lambda (obj port depth length style table) | |
119 | (if (symbol? obj) | |
120 | (display obj) | |
121 | (begin | |
122 | (display "##" port) | |
123 | (display (print-table-ref table obj)))))) |