cenv.scm 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. ; Part of Scheme 48 1.9. See file COPYING for notices and license.
  2. ; Authors: Richard Kelsey, Jonathan Rees, Mike Sperber
  3. ; Compile-time environments
  4. ; These are functions
  5. ; name -> node ; lexical variable
  6. ; binding ; package variable, any syntax
  7. ; #f ; free
  8. ;
  9. ; Special names are used to retrieve various values from compiler environments.
  10. (define-record-type compiler-specials :compiler-specials
  11. (make-compiler-specials lookup define! macro-eval package source-file-name)
  12. compiler-specials?
  13. (lookup compiler-specials-lookup)
  14. (define! compiler-specials-define!)
  15. (macro-eval compiler-specials-macro-eval)
  16. (package compiler-specials-package)
  17. (source-file-name compiler-specials-source-file-name))
  18. (define-record-type compiler-env :compiler-env
  19. (really-make-compiler-env specials alist)
  20. compiler-env?
  21. (specials compiler-env-specials)
  22. (alist compiler-env-alist))
  23. (define (lookup cenv name)
  24. (cond
  25. ((assq name (compiler-env-alist cenv)) => cdr)
  26. (else
  27. ((compiler-specials-lookup (compiler-env-specials cenv)) name))))
  28. (define (bind1 name binding cenv)
  29. (really-make-compiler-env (compiler-env-specials cenv)
  30. (cons (cons name binding) (compiler-env-alist cenv))))
  31. (define (bind names bindings cenv)
  32. (really-make-compiler-env (compiler-env-specials cenv)
  33. (append (map cons names bindings)
  34. (compiler-env-alist cenv))))
  35. ; Making the initial compiler environment.
  36. ;
  37. ; lookup : name -> binding or (binding . path) or #f
  38. ; define! : name type [static] -> void
  39. ; macro-eval : reflective tower, i.e. promise that returns
  40. ; (<eval> . <env>) for evaluating macro expanders
  41. (define (make-compiler-env lookup define! macro-eval package)
  42. (really-make-compiler-env (make-compiler-specials lookup define! macro-eval package #f)
  43. '()))
  44. ; EVAL function for evaluating macro expanders.
  45. (define (comp-env-macro-eval cenv)
  46. (compiler-specials-macro-eval (compiler-env-specials cenv)))
  47. ; Function for adding definitions to the outer package.
  48. (define (comp-env-define! cenv name type . maybe-value)
  49. (apply (compiler-specials-define! (compiler-env-specials cenv))
  50. name type maybe-value))
  51. ; The package on which the compiler environment is based. This is a
  52. ; temporary hack to keep the package-editing code working.
  53. (define (extract-package-from-comp-env cenv)
  54. (compiler-specials-package (compiler-env-specials cenv)))
  55. ; The name of the source file.
  56. ; This is used by the %FILE-NAME% special form,
  57. ; which is in turn used by the (MODULE ...) form to save the current file in
  58. ; each package,
  59. ; which is (finally) used to look up filenames in the correct directory.
  60. (define (bind-source-file-name filename env)
  61. (if filename
  62. (let ((specials (compiler-env-specials env)))
  63. (really-make-compiler-env (make-compiler-specials
  64. (compiler-specials-lookup specials)
  65. (compiler-specials-define! specials)
  66. (compiler-specials-macro-eval specials)
  67. (compiler-specials-package specials)
  68. filename)
  69. (compiler-env-alist env)))
  70. env))
  71. (define (source-file-name cenv)
  72. (compiler-specials-source-file-name (compiler-env-specials cenv)))