byte-code-test.scm 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. ; Part of Scheme 48 1.9. See file COPYING for notices and license.
  2. ; Authors: Richard Kelsey, Jonathan Rees, Mike Sperber
  3. ; Test various of the byte-codes
  4. ;(let ((system (make-system '("~/s48/x48/boot/byte-code-test.scm") 'resume #f)))
  5. ; (write-system system "~/s48/x48/boot/byte-code-test.image"))
  6. (define *tests* '())
  7. (define *output-channel* #f)
  8. (define (make-test . args)
  9. (set! *tests* (cons args *tests*)))
  10. (define (run-test string compare result proc)
  11. (write-string string *output-channel*)
  12. (write-string "..." *output-channel*)
  13. (write-string (if (compare (proc) result) "OK" "failed") *output-channel*)
  14. (newline *output-channel*))
  15. (make-test "testing test mechanism" (lambda (x y) (eq? x y)) 0 (lambda () 0))
  16. (make-test "primitive catch and throw" (lambda (x y) (eq? x y)) 10
  17. (lambda ()
  18. (* 10 (primitive-catch (lambda (k)
  19. (my-primitive-throw k 1)
  20. (message "after throw???")
  21. 2)))))
  22. (define (my-primitive-throw cont value)
  23. (with-continuation cont (lambda () value)))
  24. (define (message string)
  25. (write-string string *output-channel*)
  26. (newline channel))
  27. (define (write-string string channel)
  28. (channel-write string
  29. 0
  30. (string-length string)
  31. channel))
  32. (define (newline channel)
  33. (write-string "
  34. " channel))
  35. (define (resume arg in in-encoding out out-encoding error error-encoding)
  36. (set! *output-channel* out)
  37. (do ((tests (do ((tests *tests* (cdr tests))
  38. (r '() (cons (car tests) r)))
  39. ((eq? '() tests) r))
  40. (cdr tests)))
  41. ((eq? '() tests))
  42. (apply run-test (car tests)))
  43. (write-string "done" *output-channel*)
  44. (newline *output-channel*)
  45. (halt 0))
  46. (define *initial-bindings* '())
  47. (define (initial-env name)
  48. (let ((probe (assq name *initial-bindings*)))
  49. (if probe (cdr probe) (error "unbound" name))))
  50. (define (define-initial name val)
  51. (let* ((probe (assq name *initial-bindings*))
  52. (loc (if probe
  53. (cdr probe)
  54. (let ((loc (make-undefined-location name)))
  55. (set! *initial-bindings*
  56. (cons (cons name loc) *initial-bindings*))
  57. loc))))
  58. ;; (set-location-defined?! loc #t) - obsolescent?
  59. (set-contents! loc val)))
  60. (for-each (lambda (name val)
  61. (define-initial name val))
  62. '( cons car cdr + - * < = > list map append reverse)
  63. (list cons car cdr + - * < = > list map append reverse))
  64. (make-test "little env-lookup test" eq? car
  65. (lambda ()
  66. (contents (initial-env 'car))))
  67. (define (error string . stuff) (message string))