source: project/chicken/trunk/private-namespace.scm @ 14236

Last change on this file since 14236 was 14236, checked in by felix winkelmann, 11 years ago

added er-macro-transformer

File size: 2.8 KB
Line 
1;;;; compiler-namespace.scm - A simple namespace system to keep compiler variables hidden
2;
3; Copyright (c) 2007, Felix L. Winkelmann
4; Copyright (c) 2008-2009, The Chicken Team
5; All rights reserved.
6;
7; Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
8; conditions are met:
9;
10;   Redistributions of source code must retain the above copyright notice, this list of conditions and the following
11;     disclaimer.
12;   Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
13;     disclaimer in the documentation and/or other materials provided with the distribution.
14;   Neither the name of the author nor the names of its contributors may be used to endorse or promote
15;     products derived from this software without specific prior written permission.
16;
17; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
18; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
19; AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
20; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25; POSSIBILITY OF SUCH DAMAGE.
26
27
28(cond-expand
29 (hygienic-macros
30  (define-syntax private
31    ;;XXX use er-macro-transformer
32    (lambda (form r c)
33      (let ((namespace (cadr form))
34            (vars (cddr form)))
35        (##sys#check-symbol namespace 'private)
36        (let* ((str (symbol->string namespace)) ; somewhat questionable (renaming)
37               (prefix (string-append
38                        (string (integer->char (string-length str)))
39                        (symbol->string namespace))))
40          (for-each
41           (lambda (var)
42             (put! 
43              var 'c:namespace
44              (##sys#string->qualified-symbol prefix (symbol->string var))))
45           vars)
46          '(##core#undefined) ) ) ) ) )
47 (else
48  (define-macro (private . args)
49    (let ((namespace (car args))
50          (vars (cdr args)))
51      (##sys#check-symbol namespace 'private)
52      (let* ((str (symbol->string namespace))
53             (prefix (string-append
54                      (string (integer->char (string-length str)))
55                      (symbol->string namespace))))
56        (for-each
57         (lambda (var)
58           (put! 
59            var 'c:namespace
60            (##sys#string->qualified-symbol prefix (symbol->string var))))
61         vars)
62        '(void) ) ) ) ) )
63
64(set! ##sys#alias-global-hook
65  (lambda (var . assign)                ; must work with old chicken
66    (or (get var 'c:namespace) var) ) )
Note: See TracBrowser for help on using the repository browser.