source: trunk/j/src/org/armedbear/lisp/source-transform.lisp @ 8514

Last change on this file since 8514 was 8514, checked in by piso, 16 years ago

GET-FUNCTION-INFO-VALUE
SET-FUNCTION-INFO-VALUE

File size: 2.5 KB
Line 
1;;; source-transform.lisp
2;;;
3;;; Copyright (C) 2004-2005 Peter Graves
4;;; $Id: source-transform.lisp,v 1.2 2005-02-09 18:38:38 piso Exp $
5;;;
6;;; This program is free software; you can redistribute it and/or
7;;; modify it under the terms of the GNU General Public License
8;;; as published by the Free Software Foundation; either version 2
9;;; of the License, or (at your option) any later version.
10;;;
11;;; This program is distributed in the hope that it will be useful,
12;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with this program; if not, write to the Free Software
18;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20(in-package #:system)
21
22(defun source-transform (name)
23  (get-function-info-value name :source-transform))
24
25(defun (setf source-transform) (transform name)
26  (set-function-info-value name :source-transform transform))
27
28(defmacro define-source-transform (name lambda-list &rest body)
29  (let* ((form (gensym))
30         (env (gensym))
31         (body (sys::parse-defmacro lambda-list form body name 'defmacro
32                                    :environment env))
33         (expander
34          (if (symbolp name)
35              `(lambda (,form) (block ,name ,body))
36              `(lambda (,form) (block ,(cadr name) ,body)))))
37    `(progn
38       (setf (source-transform ',name) ,expander)
39       ',name)))
40
41(defun expand-source-transform-1 (form)
42  (let ((expander nil)
43        (newdef nil))
44    (cond ((atom form)
45           (values form nil))
46          ((and (consp (car form))
47                (eq (caar form) 'SETF)
48                (setf expander (source-transform (car form))))
49           (values (setq newdef (funcall expander form))
50                   (not (eq newdef form))))
51          ((and (symbolp (car form))
52                (setf expander (source-transform (car form))))
53           (values (setq newdef (funcall expander form))
54                   (not (eq newdef form))))
55          (t
56           (values form nil)))))
57
58(defun expand-source-transform (form)
59  (let ((expanded-p nil))
60    (loop
61      (multiple-value-bind (expansion exp-p) (expand-source-transform-1 form)
62        (if exp-p
63            (setf form expansion
64                  expanded-p t)
65            (return))))
66    (values form expanded-p)))
67
68(provide :source-transform)
Note: See TracBrowser for help on using the repository browser.