eval.scm 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. ; Copyright (c) 1993-2008 by Richard Kelsey and Jonathan Rees. See file COPYING.
  2. ; This file contains things that tie together the compiler and the
  3. ; run-time system.
  4. ; EVAL
  5. (define (eval form package)
  6. (compile-and-run (list form) package #f #f))
  7. ; LOAD-INTO - load file into package.
  8. (define (load-into filename package)
  9. (really-load-into filename package #f #f))
  10. (define (load-script-into filename package)
  11. (really-load-into filename package #f #t))
  12. ; Evaluate forms as if they came from the given file.
  13. (define (eval-from-file forms package filename)
  14. (if filename
  15. ((fluid-cell-ref $note-file-package)
  16. filename package))
  17. (compile-and-run forms package filename #t))
  18. ; LOAD
  19. (define (load filename . package-option)
  20. (let ((package (if (null? package-option)
  21. (interaction-environment)
  22. (car package-option))))
  23. (really-load-into filename package #t #f)))
  24. ;----------------
  25. (define (really-load-into filename package note-undefined? script?)
  26. (force-output (current-output-port)) ; just to make the output nice
  27. (let ((forms (read-forms filename package script?)))
  28. (newline (current-noise-port)) ; READ-FORMS prints the filename
  29. (compile-and-run forms
  30. package
  31. filename
  32. note-undefined?)))
  33. (define (compile-and-run forms package maybe-filename note-undefined?)
  34. (let* ((env (if maybe-filename
  35. (bind-source-file-name maybe-filename
  36. (package->environment package))
  37. (package->environment package)))
  38. (template (compile-forms (map (lambda (form)
  39. (delay (expand-scanned-form form env)))
  40. (scan-forms forms env))
  41. maybe-filename
  42. (package-uid package))))
  43. (link! template package note-undefined?)
  44. (invoke-closure
  45. (make-closure template
  46. (package-uid package)))))