read-form.scm 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. ;;; Ported from Scheme 48 1.9. See file COPYING for notices and license.
  2. ;;;
  3. ;;; Port Author: Andrew Whatson
  4. ;;;
  5. ;;; Original Authors: Richard Kelsey, Jonathan Rees, Mike Sperber
  6. ;;;
  7. ;;; scheme48-1.9.2/scheme/bcomp/read-form.scm
  8. (define-module (prescheme bcomp read-form)
  9. #:use-module (prescheme scheme48)
  10. #:use-module (prescheme filename)
  11. #:use-module (prescheme bcomp package)
  12. #:export (read-forms $note-file-package))
  13. ;; The value of $NOTE-FILE-PACKAGE is called whenever a file is loaded into
  14. ;; a package. env/debug.scm uses this to associate packages with files so
  15. ;; that code stuffed to the REPL will be eval'ed in the correct package.
  16. ;;
  17. ;; Is there any point in having this be a fluid?
  18. (define $note-file-package
  19. (make-fluid (make-cell (lambda (filename package)
  20. (values)))))
  21. (define (read-forms pathname package script?)
  22. (let* ((filename (namestring pathname #f *scheme-file-type*))
  23. (truename (translate filename))
  24. (port (open-input-file truename))
  25. (reader (package-reader package)))
  26. (dynamic-wind
  27. (lambda ()
  28. (if (not port)
  29. (assertion-violation 'read-forms "attempt to throw back into READ-FORMS")))
  30. (lambda ()
  31. ((fluid-cell-ref $note-file-package) filename package)
  32. (let ((o-port (current-noise-port)))
  33. (display truename o-port)
  34. (force-output o-port)
  35. (really-read-forms port reader script?)))
  36. (lambda ()
  37. (close-input-port port)
  38. (set! port #f)))))
  39. (define (really-read-forms port reader script?)
  40. (if script?
  41. (skip-line port))
  42. (let loop ((forms '()))
  43. (let ((form (reader port)))
  44. (if (eof-object? form)
  45. (reverse forms)
  46. (loop (cons form forms))))))
  47. (define (skip-line port)
  48. (let loop ()
  49. (let ((char (read-char port)))
  50. (if (and (not (eof-object? char))
  51. (not (char=? #\newline char)))
  52. (loop)))))