build.scm 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 (os-string->byte-vector (x->os-string filename))
  37. (stand-alone-resumer no-warnings? start)
  38. (os-string->byte-vector (string->os-string "")))
  39. #t))
  40. (define (stand-alone-resumer warnings? start)
  41. (make-usual-resumer ;sets up exceptions, interrupts, and current input & output
  42. warnings?
  43. signal-condition
  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. (let ((c (coerce-to-condition c)))
  54. (cond ((error? c)
  55. (display-condition c port)
  56. (halt 1))
  57. ((warning? c)
  58. (display-condition c port)) ;Proceed
  59. ((interrupt? c)
  60. ;; (and ... (= (cadr c) interrupt/keyboard)) ?
  61. (halt 2))
  62. ((bug? c)
  63. (display-condition c port)
  64. (halt 3))
  65. (else
  66. (punt))))))
  67. ;(define interrupt/keyboard (enum interrupt keyboard))