compose-cont.scm 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. ; Copyright (c) 1993-2008 by Richard Kelsey and Jonathan Rees. See file COPYING.
  2. (define (compose-continuation proc cont)
  3. (primitive-cwcc
  4. (lambda (k)
  5. (with-continuation cont ;(if cont cont null-continuation)
  6. (lambda ()
  7. (proc (primitive-cwcc
  8. (lambda (k2) (with-continuation k (lambda () k2))))))))))
  9. ; Old definition that relies on details of VM architecture:
  10. ;(define null-continuation #f)
  11. ;(define null-continuation (make-continuation 4 #f)) ;temp kludge
  12. ;(continuation-set! null-continuation 1 0)
  13. ;(continuation-set! null-continuation 2
  14. ; ;; op/trap = 140
  15. ; (segment-data->template (make-code-vector 1 140) #f '()))
  16. ;(put 'primitive-cwcc 'scheme-indent-hook 0)
  17. ;(put 'with-continuation 'scheme-indent-hook 1)
  18. ;(define compose-continuation
  19. ; (let ((tem
  20. ; (let ((cv (make-code-vector 6 0)))
  21. ; (code-vector-set! cv 0 op/push) ;push return value
  22. ; (code-vector-set! cv 1 op/local) ;fetch procedure
  23. ; (code-vector-set! cv 3 1) ;over = 1
  24. ; (code-vector-set! cv 4 op/call)
  25. ; (code-vector-set! cv 5 1) ;one argument
  26. ; (segment-data->template cv 0 '()))))
  27. ; (lambda (proc parent-cont)
  28. ; (let ((cont (make-continuation 4 #f)))
  29. ; (continuation-set! cont 0 parent-cont)
  30. ; (continuation-set! cont 1 0) ;pc
  31. ; (continuation-set! cont 2 tem) ;template
  32. ; (continuation-set! cont 3 (vector #f proc)) ;environment
  33. ; cont))))