byte-code-test.scm 2.4 KB

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