debug-packages.scm 6.5 KB

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