compose-cont.scm 1.5 KB

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