debug-packages.scm 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. ; Copyright (c) 1993-2007 by Richard Kelsey and Jonathan Rees. See file COPYING.
  2. ; Handy things for debugging the run-time system, byte code compiler,
  3. ; and linker.
  4. ; Alternative command processor. Handy for debugging the bigger one.
  5. (define (make-mini-command scheme)
  6. (define-structure mini-command (export command-processor)
  7. (open scheme
  8. ascii byte-vectors os-strings
  9. simple-signals simple-conditions handle
  10. display-conditions
  11. i/o) ; current-error-port
  12. (files (debug mini-command)))
  13. mini-command)
  14. ; Miniature EVAL, for debugging runtime system sans package system.
  15. (define-structures ((mini-eval evaluation-interface)
  16. (mini-environments
  17. (export interaction-environment
  18. scheme-report-environment
  19. set-interaction-environment!
  20. set-scheme-report-environment!)))
  21. (open scheme-level-2
  22. simple-signals) ;error
  23. (files (debug mini-eval)))
  24. (define (make-scheme environments evaluation) ;cf. initial-packages.scm
  25. (define-structure scheme scheme-interface
  26. (open scheme-level-2
  27. environments
  28. evaluation))
  29. scheme)
  30. ; Stand-alone system that doesn't contain a byte-code compiler.
  31. ; This is useful for various testing purposes.
  32. (define mini-scheme (make-scheme mini-environments mini-eval))
  33. (define mini-command (make-mini-command mini-scheme))
  34. (define-structure little-system (export start)
  35. (open scheme-level-1
  36. mini-command
  37. usual-resumer)
  38. (begin (define start
  39. (usual-resumer
  40. (lambda (args) (command-processor #f args))))))
  41. (define (link-little-system)
  42. (link-simple-system '(scheme/debug little)
  43. 'start
  44. little-system))
  45. ; --------------------
  46. ; Hack: smallest possible reified system.
  47. (define-structures ((mini-for-reification for-reification-interface)
  48. (mini-packages (export make-simple-package)))
  49. (open scheme-level-2
  50. features ;contents
  51. locations
  52. simple-signals) ;error
  53. (files (debug mini-package)))
  54. (define-structure mini-system (export start)
  55. (open mini-scheme
  56. mini-command
  57. mini-for-reification
  58. mini-packages
  59. mini-environments ;set-interaction-environment!
  60. usual-resumer
  61. simple-conditions handle ;error? with-handler
  62. simple-signals) ;error
  63. (files (debug mini-start)))
  64. (define (link-mini-system)
  65. (link-reified-system (list (cons 'scheme mini-scheme)
  66. (cons 'write-images write-images)
  67. (cons 'primitives primitives) ;just for fun
  68. (cons 'usual-resumer usual-resumer)
  69. (cons 'command mini-command))
  70. '(scheme/debug mini)
  71. 'start
  72. mini-system mini-for-reification))
  73. ; --------------------
  74. ; S-expression (nodes, really) interpreter
  75. (define-structure run evaluation-interface
  76. (open scheme-level-2
  77. tables
  78. packages ;package-uid package->environment link!
  79. compiler-envs ;bind-source-filename
  80. reading-forms ;read-forms $note-file-package
  81. syntactic ;scan-forms expand-forms
  82. locations
  83. nodes
  84. bindings
  85. meta-types
  86. mini-environments
  87. simple-signals
  88. fluids)
  89. (files (debug run)))
  90. ; Hack: an interpreter-based system.
  91. (define (link-medium-system) ;cf. initial.scm
  92. (def medium-scheme (make-scheme environments run))
  93. (let ()
  94. (def command (make-mini-command medium-scheme))
  95. (let ()
  96. (def medium-system
  97. ;; Cf. initial-packages.scm
  98. (make-initial-system medium-scheme command))
  99. (let ((structs (list (cons 'scheme medium-scheme)
  100. (cons 'primitives primitives) ;just for fun
  101. (cons 'usual-resumer usual-resumer)
  102. (cons 'command command))))
  103. (link-reified-system structs
  104. '(scheme/debug medium)
  105. `(start ',(map car structs))
  106. medium-system for-reification)))))
  107. ;;; load this into a Scheme implementation you trust, call TEST-ALL
  108. ;;; and (print-results "t1"). Repeate the same for the untrusted
  109. ;;; Scheme with a different filename and compare the files using diff.
  110. (define-structure test-bignum (export test-all print-results)
  111. (open scheme
  112. i/o
  113. bitwise)
  114. (begin
  115. (define *tests* '())
  116. (define (add-test! test) (set! *tests* (cons test *tests*)))
  117. (define (test-all) (for-each (lambda (t) (t)) *tests*))
  118. (define *results* '())
  119. (define (print-results fname)
  120. (with-output-to-file fname
  121. (lambda ()
  122. (for-each (lambda (x) (display x)(newline)) *results*))))
  123. (define (add! e) (set! *results* (cons e *results*)))
  124. (define (square-map f l1 l2)
  125. (if (null? l1)
  126. '()
  127. (letrec ((one-map (lambda (e1)
  128. (map (lambda (e2)
  129. (add! (f e1 e2)))
  130. l2))))
  131. (cons (one-map (car l1))
  132. (square-map f (cdr l1) l2)))))
  133. (define (printing-map f l)
  134. (for-each add!
  135. (map f l)))
  136. (define small-args '(-1234 -23 -2 -1 1 2 23 1234))
  137. (define fixnum-args (append (list -536870912 -536870911 536870911)
  138. small-args))
  139. (define usual-args
  140. (append (list -12345678901234567890 -1234567890 -536870913 536870912
  141. 536870913 1234567890 12345678901234567890)
  142. fixnum-args))
  143. (define small-args/0 (cons 0 small-args))
  144. (define fixnum-args/0 (cons 0 fixnum-args))
  145. (define usual-args/0 (cons 0 usual-args))
  146. (add-test! (lambda () (square-map + usual-args/0 usual-args/0)))
  147. (add-test! (lambda () (square-map - usual-args/0 usual-args/0)))
  148. (add-test! (lambda () (square-map * usual-args/0 usual-args/0)))
  149. (add-test! (lambda () (square-map / usual-args/0 usual-args)))
  150. (add-test! (lambda () (square-map quotient usual-args/0 usual-args)))
  151. (add-test! (lambda () (square-map remainder usual-args/0 usual-args)))
  152. (add-test! (lambda () (square-map arithmetic-shift usual-args/0 small-args)))
  153. (add-test! (lambda () (square-map bitwise-and usual-args/0 usual-args/0)))
  154. (add-test! (lambda () (square-map bitwise-ior usual-args/0 usual-args/0)))
  155. (add-test! (lambda () (square-map bitwise-xor usual-args/0 usual-args/0)))
  156. (add-test! (lambda () (printing-map bitwise-not usual-args/0)))
  157. ; (add-test! (lambda () (printing-map bit-count usual-args/0)))
  158. (add-test! (lambda () (square-map < usual-args/0 usual-args/0)))
  159. (add-test! (lambda () (square-map > usual-args/0 usual-args/0)))
  160. (add-test! (lambda () (square-map <= usual-args/0 usual-args/0)))
  161. (add-test! (lambda () (square-map >= usual-args/0 usual-args/0)))
  162. (add-test! (lambda () (square-map = usual-args/0 usual-args/0)))
  163. (add-test! (lambda () (printing-map abs usual-args/0)))
  164. ; (add-test! (lambda () (printing-map (lambda (x) (angle (abs x))) usual-args/0)))
  165. (add-test!
  166. (lambda ()
  167. (map (lambda (unary)
  168. (printing-map unary usual-args/0))
  169. (list integer? rational? real? complex? exact? real-part
  170. imag-part floor numerator denominator))))
  171. ))