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