build.scm 2.4 KB

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