compilation enviroments are always modules; simplifications & refactorings
[bpt/guile.git] / module / language / scheme / spec.scm
1 ;;; Guile Scheme specification
2
3 ;; Copyright (C) 2001, 2009 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 ;;; Reader
30 ;;;
31
32 (read-enable 'positions)
33
34 ;;;
35 ;;; Language definition
36 ;;;
37
38 (define-language scheme
39 #:title "Guile Scheme"
40 #:version "0.5"
41 #:reader (lambda (port env)
42 ;; Use the binding of current-reader from the environment.
43 ;; FIXME: Handle `read-options' as well?
44 ((or (and=> (and=> (module-variable env 'current-reader)
45 variable-ref)
46 fluid-ref)
47 read)
48 port))
49
50 #:compilers `((tree-il . ,compile-tree-il))
51 #:decompilers `((tree-il . ,decompile-tree-il))
52 #:evaluator (lambda (x module) (primitive-eval x))
53 #:printer write
54 #:make-default-environment
55 (lambda ()
56 ;; Ideally we'd duplicate the whole module hierarchy so that `set!',
57 ;; `fluid-set!', etc. don't have any effect in the current environment.
58 (let ((m (make-fresh-user-module)))
59 ;; Provide a separate `current-reader' fluid so that
60 ;; compile-time changes to `current-reader' are
61 ;; limited to the current compilation unit.
62 (module-define! m 'current-reader (make-fluid))
63 m)))