escape.scm 947 B

123456789101112131415161718192021222324252627282930313233
  1. ; Copyright (c) 1993-2007 by Richard Kelsey and Jonathan Rees. See file COPYING.
  2. ; For an explanation, see comments in rts/low.scm.
  3. ; The debugger invokes EXTRACT-CONTINUATION on a "native" continuation
  4. ; as obtained by PRIMITIVE-CWCC in order to get a VM continuation.
  5. ; The distinction between native and VM continuations is useful when
  6. ; debugging a program running under a VM that's different from
  7. ; whatever machine is running the debugger.
  8. (define-record-type escape :escape
  9. (make-escape proc)
  10. (proc escape-procedure))
  11. (define (with-continuation esc thunk)
  12. (if esc
  13. ((escape-procedure esc) thunk)
  14. (let ((answer (thunk)))
  15. (signal 'vm-return answer) ;#f means halt
  16. (call-error "halt" answer))))
  17. (define (primitive-cwcc proc)
  18. (call-with-current-continuation
  19. (lambda (done)
  20. ((call-with-current-continuation
  21. (lambda (k)
  22. (call-with-values
  23. (lambda ()
  24. (proc (make-escape k)))
  25. done)))))))