build.scm 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. ; Copyright (c) 1993-2008 by Richard Kelsey and Jonathan Rees. See file COPYING.
  2. ; Commands for writing images.
  3. ; A heap image written using ,dump or ,build can be invoked with
  4. ; s48 -i <filename> [-h <heap size>] [-a <argument>]
  5. ; For images made with ,build <exp> <filename>, <argument> is passed as
  6. ; a string to the procedure that is the result of <exp>.
  7. ; dump <filename>
  8. (define-command-syntax 'dump "<filename>"
  9. "write the current heap to an image file"
  10. '(filename &opt form))
  11. (define (dump filename . maybe-info)
  12. (let ((info (if (null? maybe-info) "(suspended image)" (car maybe-info)))
  13. (context (user-context))
  14. (env (environment-for-commands)))
  15. (build-image #f
  16. (lambda (arg)
  17. (with-interaction-environment env
  18. (lambda ()
  19. (restart-command-processor arg
  20. context
  21. (lambda ()
  22. (greet-user info))
  23. values))))
  24. filename)))
  25. ; build <exp> <filename>
  26. (define-command-syntax 'build "<exp> <filename> <option> ..."
  27. "build a heap image file with <exp> as entry procedure, <option> can be no-warnings"
  28. '(expression filename &rest name))
  29. (define (build exp filename . options)
  30. (build-image (not (memq 'no-warnings options))
  31. (eval exp (environment-for-commands))
  32. filename))
  33. (define (build-image no-warnings? start filename)
  34. (let ((filename (translate filename)))
  35. (write-line (string-append "Writing " filename) (command-output))
  36. (write-image (x->os-byte-vector filename)
  37. (stand-alone-resumer no-warnings? start)
  38. (string->os-byte-vector ""))
  39. #t))
  40. (define (stand-alone-resumer warnings? start)
  41. (make-usual-resumer ;sets up exceptions, interrupts, and current input & output
  42. warnings?
  43. (lambda (arg)
  44. (call-with-current-continuation
  45. (lambda (halt)
  46. (with-handler (simple-condition-handler halt (current-error-port))
  47. (lambda ()
  48. (start arg))))))))
  49. ; Simple condition handler for stand-alone programs.
  50. (define (simple-condition-handler halt port)
  51. (lambda (c punt)
  52. (cond ((violation? c)
  53. (display-condition c port)
  54. (halt 3))
  55. ((serious-condition? c)
  56. (display-condition c port)
  57. (halt 1))
  58. ((warning? c)
  59. (display-condition c port)) ;Proceed
  60. ((interrupt-condition? c)
  61. ;; (and ... (= (cadr c) interrupt/keyboard)) ?
  62. (halt 2))
  63. (else
  64. (punt)))))
  65. ;(define interrupt/keyboard (enum interrupt keyboard))