1 ;;;; Copyright (C) 1997 Free Software Foundation, Inc.
3 ;;;; This program is free software; you can redistribute it and/or modify
4 ;;;; it under the terms of the GNU General Public License as published by
5 ;;;; the Free Software Foundation; either version 2, or (at your option)
6 ;;;; any later version.
8 ;;;; This program 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
11 ;;;; GNU General Public License for more details.
13 ;;;; You should have received a copy of the GNU General Public License
14 ;;;; along with this software; see the file COPYING. If not, write to
15 ;;;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
16 ;;;; Boston, MA 02111-1307 USA
20 (define-module (ice-9 syncase)
21 :use-module (ice-9 debug))
25 (define-public sc-macro
26 (procedure->memoizing-macro
30 ;;; Exported variables
32 (define-public sc-expand #f)
33 (define-public sc-expand3 #f)
34 (define-public install-global-transformer #f)
35 (define-public syntax-dispatch #f)
36 (define-public syntax-error #f)
38 (define-public bound-identifier=? #f)
39 (define-public datum->syntax-object #f)
40 (define-public define-syntax sc-macro)
41 (define-public eval-when sc-macro)
42 (define-public fluid-let-syntax sc-macro)
43 (define-public free-identifier=? #f)
44 (define-public generate-temporaries #f)
45 (define-public identifier? #f)
46 (define-public identifier-syntax sc-macro)
47 (define-public let-syntax sc-macro)
48 (define-public letrec-syntax sc-macro)
49 (define-public syntax sc-macro)
50 (define-public syntax-case sc-macro)
51 (define-public syntax-object->datum #f)
52 (define-public syntax-rules sc-macro)
53 (define-public with-syntax sc-macro)
54 (define-public include sc-macro)
56 (define primitive-syntax '(quote lambda letrec if set! begin define or
57 and let let* cond do quasiquote unquote
58 unquote-splicing case))
60 (for-each (lambda (symbol)
61 (set-symbol-property! symbol 'primitive-syntax #t))
64 ;;; Hooks needed by the syntax-case macro package
66 (define-public (void) *unspecified*)
69 (lambda (f first . rest)
72 (let andmap ((first first))
73 (let ((x (car first)) (first (cdr first)))
76 (and (f x) (andmap first)))))
77 (let andmap ((first first) (rest rest))
81 (rest (map cdr rest)))
84 (and (apply f (cons x xr)) (andmap first rest)))))))))
86 (define (error who format-string why what)
87 (start-stack 'syncase-stack
88 (scm-error 'misc-error
94 (define the-syncase-module (current-module))
96 (define (putprop symbol key binding)
97 (let* ((m (current-module))
98 (v (or (module-variable m symbol)
99 (module-make-local-var! m symbol))))
100 (if (assq 'primitive-syntax (symbol-pref symbol))
101 (if (eq? (current-module) the-syncase-module)
102 (set-object-property! (module-variable the-root-module symbol)
105 (variable-set! v sc-macro))
106 (set-object-property! v key binding)))
108 (define (getprop symbol key)
109 (let* ((m (current-module))
110 (v (module-variable m symbol)))
111 (and v (or (object-property v key)
112 (let ((root-v (module-local-variable the-root-module symbol)))
113 (and (equal? root-v v)
114 (object-property root-v key)))))))
116 (define generated-symbols (make-weak-key-hash-table 1019))
121 (system "mv -f psyntax.pp psyntax.pp~")
122 (let ((in (open-input-file "psyntax.ss"))
123 (out (open-output-file "psyntax.pp")))
124 (let loop ((x (read in)))
130 (write (sc-expand3 x 'c '(compile load eval)) out)
132 (loop (read in)))))))
134 ;;; Load the preprocessed code
138 (dynamic-wind (lambda ()
139 (set! old-debug (debug-options))
140 (set! old-read (read-options)))
142 (debug-disable 'debug 'procnames)
143 (read-disable 'positions)
144 (load-from-path "ice-9/psyntax.pp"))
146 (debug-options old-debug)
147 (read-options old-read))))
150 ;;; The following line is necessary only if we start making changes
151 ;; (load-from-path "ice-9/psyntax.ss")
153 (define internal-eval (nested-ref the-scm-module '(app modules guile eval)))
155 (define-public (eval x)
156 (internal-eval (if (and (pair? x)
157 (string=? (car x) "noexpand"))
161 ;;; Hack to make syncase macros work in the slib module
162 (let ((m (nested-ref the-root-module '(app modules ice-9 slib))))
164 (set-object-property! (module-local-variable m 'define)
168 (define-public syncase sc-expand)