oldprint.scm 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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
  15. ;;;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  16. ;;;; Boston, MA 02111-1307 USA
  17. ;;;;
  18. ;;; {Print}
  19. ;;;
  20. ;;; This code was removed from boot-9.scm by MDJ 970301
  21. ;;; <djurfeldt@nada.kth.se>. It is placed here for archival
  22. ;;; purposes.
  23. (define (print obj . args)
  24. (let ((default-args (list (current-output-port) 0 0 default-print-style #f)))
  25. (apply-to-args (append args (list-cdr-ref default-args (length args)))
  26. (lambda (port depth length style table)
  27. (cond
  28. ((and table (print-table-ref table obj))
  29. ((print-style-tag-hook style 'eq-val)
  30. obj port depth length style table))
  31. (else
  32. (and table (print-table-add! table obj))
  33. (cond
  34. ((print-style-max-depth? style depth)
  35. ((print-style-excess-depth-hook style)))
  36. ((print-style-max-length? style length)
  37. ((print-style-excess-length-hook style)))
  38. (else
  39. ((print-style-hook style obj)
  40. obj port depth length style table)))))))))
  41. (define (make-print-style) (make-vector 59 '()))
  42. (define (extend-print-style! style utag printer)
  43. (hashq-set! style utag printer))
  44. (define (print-style-hook style obj)
  45. (let ((type-tag (tag obj)))
  46. (or (hashq-ref style type-tag)
  47. (hashq-ref style (logand type-tag 255))
  48. print-obj)))
  49. (define (print-style-tag-hook style type-tag)
  50. (or (hashq-ref style type-tag)
  51. print-obj))
  52. (define (print-style-max-depth? style d) #f)
  53. (define (print-style-max-length? style l) #f)
  54. (define (print-style-excess-length-hook style)
  55. (hashq-ref style 'excess-length-hook))
  56. (define (print-style-excess-depth-hook style)
  57. (hashq-ref style 'excess-depth-hook))
  58. (define (make-print-table) (make-vector 59 '()))
  59. (define (print-table-ref table obj) (hashq-ref table obj))
  60. (define (print-table-add! table obj) (hashq-set! table obj (gensym 'ref)))
  61. (define (print-obj obj port depth length style table) (write obj port))
  62. (define (print-pair pair port depth length style table)
  63. (if (= 0 length)
  64. (display #\( port))
  65. (print (car pair) port (+ 1 depth) 0 style table)
  66. (cond
  67. ((and (pair? (cdr pair))
  68. (or (not table)
  69. (not (print-table-ref table (cdr pair)))))
  70. (display #\space port)
  71. (print (cdr pair) port depth (+ 1 length) style table))
  72. ((null? (cdr pair)) (display #\) port))
  73. (else (display " . " port)
  74. (print (cdr pair) port (+ 1 depth) 0
  75. style table)
  76. (display #\) port))))
  77. (define (print-vector obj port depth length style table)
  78. (if (= 0 length)
  79. (cond
  80. ((weak-key-hash-table? obj) (display "#wh(" port))
  81. ((weak-value-hash-table? obj) (display "#whv(" port))
  82. ((doubly-weak-hash-table? obj) (display "#whd(" port))
  83. (else (display "#(" port))))
  84. (if (< length (vector-length obj))
  85. (print (vector-ref obj length) port (+ 1 depth) 0 style table))
  86. (cond
  87. ((>= (+ 1 length) (vector-length obj)) (display #\) port))
  88. (else (display #\space port)
  89. (print obj port depth
  90. (+ 1 length)
  91. style table))))
  92. (define default-print-style (make-print-style))
  93. (extend-print-style! default-print-style utag_vector print-vector)
  94. (extend-print-style! default-print-style utag_wvect print-vector)
  95. (extend-print-style! default-print-style utag_pair print-pair)
  96. (extend-print-style! default-print-style 'eq-val
  97. (lambda (obj port depth length style table)
  98. (if (symbol? obj)
  99. (display obj)
  100. (begin
  101. (display "##" port)
  102. (display (print-table-ref table obj))))))