spec.scm 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. ;;; Guile Scheme specification
  2. ;; Copyright (C) 2001, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
  3. ;;;; This library is free software; you can redistribute it and/or
  4. ;;;; modify it under the terms of the GNU Lesser General Public
  5. ;;;; License as published by the Free Software Foundation; either
  6. ;;;; version 3 of the License, or (at your option) any later version.
  7. ;;;;
  8. ;;;; This library is distributed in the hope that it will be useful,
  9. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. ;;;; Lesser General Public License for more details.
  12. ;;;;
  13. ;;;; You should have received a copy of the GNU Lesser General Public
  14. ;;;; License along with this library; if not, write to the Free Software
  15. ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  16. ;;; Code:
  17. (define-module (language scheme spec)
  18. #:use-module (system base compile)
  19. #:use-module (system base language)
  20. #:use-module (language scheme compile-tree-il)
  21. #:use-module (language scheme decompile-tree-il)
  22. #:export (scheme))
  23. ;;;
  24. ;;; Language definition
  25. ;;;
  26. (define-language scheme
  27. #:title "Scheme"
  28. #:reader (lambda (port env)
  29. ;; Use the binding of current-reader from the environment.
  30. ;; FIXME: Handle `read-options' as well?
  31. ((or (and=> (and=> (module-variable env 'current-reader)
  32. variable-ref)
  33. fluid-ref)
  34. read)
  35. port))
  36. #:compilers `((tree-il . ,compile-tree-il))
  37. #:decompilers `((tree-il . ,decompile-tree-il))
  38. #:evaluator (lambda (x module) (primitive-eval x))
  39. #:printer write
  40. #:make-default-environment
  41. (lambda ()
  42. ;; Ideally we'd duplicate the whole module hierarchy so that `set!',
  43. ;; `fluid-set!', etc. don't have any effect in the current environment.
  44. (let ((m (make-fresh-user-module)))
  45. ;; Provide a separate `current-reader' fluid so that
  46. ;; compile-time changes to `current-reader' are
  47. ;; limited to the current compilation unit.
  48. (module-define! m 'current-reader (make-fluid))
  49. ;; Default to `simple-format', as is the case until
  50. ;; (ice-9 format) is loaded. This allows
  51. ;; compile-time warnings to be emitted when using
  52. ;; unsupported options.
  53. (module-set! m 'format simple-format)
  54. m)))