init.scm 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. ; Part of Scheme 48 1.9. See file COPYING for notices and license.
  2. ; Authors: Richard Kelsey, Jonathan Rees, Mike Sperber
  3. ; System entry and exit
  4. ; Entry point from OS executive. Procedures returned by USUAL-RESUMER
  5. ; are suitable for use as the second argument to WRITE-IMAGE.
  6. ;
  7. ; The placement of INITIALIZE-RECORDS! is questionable. Important parts
  8. ; of the system are not in place when it is run.
  9. (define (make-usual-resumer warn-about-undefined-imported-bindings?
  10. entry-point)
  11. ;; The argument list needs to be in sync with
  12. ;; S48-CALL-STARTUP-PROCEDURE in vm/interp/resume.scm, and
  13. ;; MAKE-STARTUP-PROCEDURE in bcomp/comp.scm.
  14. (lambda (resume-arg
  15. in in-encoding out out-encoding error error-encoding
  16. records)
  17. (initialize-rts in in-encoding out out-encoding error error-encoding
  18. (lambda ()
  19. (initialize-os-string-text-codec!)
  20. (run-initialization-thunks)
  21. (initialize-records! records)
  22. (if warn-about-undefined-imported-bindings?
  23. (warn-about-undefined-imported-bindings))
  24. (entry-point
  25. (map byte-vector->os-string
  26. (vector->list resume-arg)))))))
  27. (define (usual-resumer entry-point)
  28. (make-usual-resumer #t entry-point))
  29. (define (warn-about-undefined-imported-bindings)
  30. (let ((undefined-bindings (find-undefined-imported-bindings)))
  31. (do ((size (vector-length undefined-bindings))
  32. (i 0 (+ 1 i)))
  33. ((= i size))
  34. (debug-message "undefined imported binding "
  35. (shared-binding-name (vector-ref undefined-bindings i))))))
  36. (define (initialize-rts in in-encoding out out-encoding error error-encoding
  37. thunk)
  38. (initialize-session-data!)
  39. (initialize-dynamic-state!)
  40. (initialize-exceptions!
  41. (lambda ()
  42. (initialize-interrupts!
  43. spawn-on-root
  44. (lambda ()
  45. (initialize-external-events!)
  46. (let ((in-port (input-channel->port in))
  47. (out-port (output-channel->port out))
  48. (error-port (output-channel->port error 0))) ; zero-length buffer
  49. (set-encoding! in-port in-encoding)
  50. (set-encoding! out-port out-encoding)
  51. (set-encoding! error-port error-encoding)
  52. (initialize-i/o
  53. in-port out-port error-port
  54. (lambda ()
  55. (with-threads
  56. (lambda ()
  57. (root-scheduler thunk
  58. 200 ; thread quantum, in msec
  59. 300))))))))))) ; port-flushing quantum
  60. ; Leave the default if we can't find a suitable codec
  61. (define (set-encoding! port encoding)
  62. (cond
  63. ((find-text-codec encoding) =>
  64. (lambda (codec)
  65. (set-port-text-codec! port codec)))))
  66. ; This is primarily for LOAD-DYNAMIC-EXTERNALS; we don't want to
  67. ; refer to it directly here, because that would increase the size of
  68. ; the image by 100k.
  69. ; Use this with care: no efforts are being made to remove duplicates.
  70. (define *initialization-thunks* '())
  71. (define (add-initialization-thunk! thunk)
  72. (set! *initialization-thunks*
  73. (cons thunk *initialization-thunks*)))
  74. (define (run-initialization-thunks)
  75. (for-each (lambda (thunk) (thunk))
  76. *initialization-thunks*))
  77. ; Add the full/empty buffer handlers.
  78. (initialize-i/o-handlers! define-vm-exception-handler signal-vm-exception)