s/s/d tail call optimization

svn: r1389
This commit is contained in:
Jay McCarthy 2005-11-24 06:05:59 +00:00
parent 06c60a7f18
commit c478a29110

View File

@ -20,7 +20,7 @@
(if (procedure? (exn:invalid-xexpr-code exn)) (if (procedure? (exn:invalid-xexpr-code exn))
#t #t
(begin ((error-display-handler) (exn-message exn) exn) (begin ((error-display-handler) (exn-message exn) exn)
#f))))) #f)))))
;; replace-procedures : (proc -> url) xexpr/callbacks? -> xexpr? ;; replace-procedures : (proc -> url) xexpr/callbacks? -> xexpr?
;; Change procedures to the send/suspend of a k-url ;; Change procedures to the send/suspend of a k-url
@ -122,11 +122,18 @@
;; send/back a response generated from a procedure that may convert ;; send/back a response generated from a procedure that may convert
;; procedures to continuation urls ;; procedures to continuation urls
(define (send/suspend/dispatch response-generator) (define (send/suspend/dispatch response-generator)
(let/ec k0 ; This restores the tail position.
(send/back ; Note: Herman's syntactic strategy would fail without the new-request capture.
(response-generator ; (Moving this to the tail-position is not possible anyway, by the way.)
(opt-lambda (proc [expiration-handler (current-servlet-continuation-expiration-handler)]) (let ([thunk
(let/ec k1 (k0 (proc (send/suspend k1 expiration-handler))))))))) (let/ec k0
(send/back
(response-generator
(opt-lambda (proc [expiration-handler (current-servlet-continuation-expiration-handler)])
(let/ec k1
(let ([new-request (send/suspend k1 expiration-handler)])
(k0 (lambda () (proc new-request)))))))))])
(thunk)))
;; send/suspend/callback : xexpr/callback? -> void ;; send/suspend/callback : xexpr/callback? -> void
;; send/back a response with callbacks in it; send/suspend those callbacks. ;; send/back a response with callbacks in it; send/suspend those callbacks.