for-debugging.scm 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. ; Copyright (c) 1993-2008 by Richard Kelsey and Jonathan Rees. See file COPYING.
  2. ; --------------------
  3. ; Fake interrupt and exception system.
  4. ; This needs to be reconciled with alt/primitives.scm.
  5. (define (with-exceptions thunk)
  6. (with-handler
  7. (lambda (c punt)
  8. (cond ((and (condition? c)
  9. (procedure? (get-exception-handler)))
  10. (handle-exception-carefully c))
  11. ((interrupt-condition? c)
  12. (if (not (deal-with-interrupt c))
  13. (punt)))
  14. ;; ((vm-return? c)
  15. ;; (vm-return (cadr c)))
  16. (else
  17. (punt))))
  18. thunk))
  19. (define (handle-exception-carefully c)
  20. (display "(Exception: ") (write c) (display ")") (newline)
  21. (noting-exceptional-context c
  22. (lambda ()
  23. (raise-exception (exception-opcode c)
  24. (exception-arguments c)))))
  25. (define (noting-exceptional-context c thunk)
  26. (call-with-current-continuation
  27. (lambda (k)
  28. ;; Save for future inspection, just in case.
  29. (set! *exceptional-context* (cons c k))
  30. (thunk))))
  31. (define *exceptional-context* #f)
  32. (define (deal-with-interrupt c)
  33. (noting-exceptional-context c
  34. (lambda ()
  35. (maybe-handle-interrupt
  36. (if (and (pair? (cdr c)) (integer? (cadr c)))
  37. (cadr c)
  38. (enum interrupt keyboard))))))
  39. ; (define (poll-for-interrupts) ...)
  40. ; Get the whole thing started
  41. (define (?start-with-exceptions entry-point arg)
  42. (with-exceptions
  43. (lambda ()
  44. (?start entry-point arg))))
  45. (define (in struct form)
  46. (eval form (structure-package struct)))