1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
;;; simple hook timing tests
(set! (*s7* 'heap-size) 1024000)
(let ((H (make-hook 'x)))
(set! (hook-functions H)
(list (lambda (h)
(if (not (let? h))
(display h)))
(lambda (h)
(unless (let? h)
(newline)))))
(define (thook)
(do ((i 0 (+ i 1)))
((= i 1000))
(H i)))
(H 32)
(thook)
(set! (car (hook-functions H))
(lambda (h)
(let-ref h 'result)))
(H 32)
(thook)
(set! (hook-functions H) (cdr (hook-functions H)))
(H 32)
(thook))
;;; --------------------------------
(let* ((size 100000)
(v (make-vector size)))
(define (tmake)
(do ((i 0 (+ i 1)))
((= i size))
(let ((j i))
(set! (v i) (make-hook 'x 'y))
(set! (hook-functions (v i))
(list (lambda (h)
(let-set! h 'result j)))))))
(define (trun)
(do ((i 0 (+ i 1)))
((= i size))
(unless (= ((v i) 0) i)
(format *stderr* "~D: ~D~%" i ((v i) 0)))
(let ((j i))
(set! (hook-functions (v i))
(list (car (hook-functions (v i)))
(lambda (h)
(let-set! h 'result (+ (let-ref h 'result) j))))))))
(define (trun1)
(do ((i 0 (+ i 1)))
((= i size))
(unless (= ((v i) 0) (* 2 i))
(format *stderr* "~D: ~D~%" i ((v i) 0)))))
(tmake)
(trun)
(trun1))
;;; --------------------------------
(let ((hook-result #f))
(let-temporarily (((hook-functions *unbound-variable-hook*) ; variable
(list (lambda (hook)
(set! hook-result (let-ref hook 'variable))))))
(define (f)
(do ((i 0 (+ i 1)))
((= i 1000))
(let ((val (catch #t (lambda () (+ 1 _an_undefined_variable_i_hope_)) (lambda (type info) type))))
(unless (eq? hook-result '_an_undefined_variable_i_hope_)
(format *stderr* "unbound variable hook: ~S~%" val)))))
(f)
(f)))
(let-temporarily (((hook-functions *missing-close-paren-hook*) ; no locals
(list (lambda (h)
(let-set! h 'result 'incomplete-expr)))))
(define (f)
(do ((i 0 (+ i 1)))
((= i 1000))
(let ((val (catch #t (lambda () (eval-string "(+ 1 2")) (lambda args (car args)))))
(unless (eq? val 'incomplete-expr)
(format *stderr* "missing close paren hook: ~S~%" val)))))
(f)
(f))
(let ((hook-result #f))
(let-temporarily (((hook-functions *load-hook*) ; name
(list (lambda (hook)
(set! hook-result (let-ref hook 'name))))))
(with-output-to-file "load-hook-test.scm"
(lambda ()
(format #t "(define (load-hook-test val) (+ val 1))")))
(define (f)
(do ((i 0 (+ i 1)))
((= i 1000))
(load "load-hook-test.scm")
(unless (equal? hook-result "load-hook-test.scm")
(format *stderr* "load hook: ~S~%" hook-result))))
(f)
(f)))
(let ((hook-type #f)
(hook-data #f))
(define (f)
(do ((i 0 (+ i 1)))
((= i 1000))
(catch #t ; why can't this be 'read-error?
(lambda ()
(let-temporarily (((hook-functions *read-error-hook*)
(list (lambda (hook)
(set! hook-type (hook 'type))
;; why isn't this 'read-error? #t=unknown_sharp_constant, #f=unknown_string_constant (read_string_constant)
(set! hook-data (let-ref hook 'data))))))
(eval-string "(+ 1 #T)")))
(lambda (type info)
'error))
(unless (and (eq? hook-type #t)
(string=? hook-data "T"))
(format *stderr* "error-hook: ~S ~S~%" hook-type hook-data))))
(f)
(f))
;;; --------------------------------
(let ((H3 (make-hook 'x '(y 32))))
(set! (hook-functions H3)
(list (lambda (h)
(let-set! h 'result ((let-ref h 'x) (let-ref h 'y))))))
(unless (= (H3 (lambda (y) (+ y 1))) 33)
(format *stderr* "H3: ~S~%" (H3 (lambda (y) (+ y 1)))))
(define H4 (make-hook 'z))
(set! (hook-functions H4)
(list (lambda (h)
(let-set! h 'result (+ (let-ref h 'z) (H3 (lambda (y) (+ y 1))))))))
(unless (= (H4 12) 45)
(format *stderr* "H4: ~S~%" (H4 12)))
(define H5 (make-hook))
(set! (hook-functions H5)
(list (lambda (h)
(let-set! h 'result 100))
(lambda (h)
(let-set! h 'result
(+ (sqrt (let-ref h 'result))
(H4 12))))))
(define (f)
(do ((i 0 (+ i 1)))
((= i 100000))
(unless (= (H5) 55)
(format *stderr* "H5: ~S~%" (H5)))))
(f)
(f))
(exit)
|