source: trunk/j/src/org/armedbear/lisp/fdefinition.lisp @ 8548

Last change on this file since 8548 was 8548, checked in by piso, 17 years ago

Work in progress.

File size: 2.9 KB
Line 
1;;; fdefinition.lisp
2;;;
3;;; Copyright (C) 2005 Peter Graves
4;;; $Id: fdefinition.lisp,v 1.2 2005-02-12 03:29:33 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 check-redefinition (name)
23  (when (and *warn-on-redefinition* (fboundp name))
24    (cond ((symbolp name)
25           (let ((old-definition (symbol-function name))
26                 (old-source (source-pathname name))
27                 (current-source (or *fasl-source* *load-truename* :top-level)))
28             (unless (equal old-source current-source)
29               (if (eq current-source :top-level)
30                   (style-warn "redefining ~S at top level" name)
31                   (let ((*package* +cl-package+))
32                     (style-warn "redefining ~S in ~S" name current-source)))))))))
33
34(defun record-source-information (name &optional source-pathname source-position)
35  (unless source-pathname
36    (setf source-pathname (or *fasl-source* *load-truename* :top-level)))
37  (let ((source (if source-position
38                    (cons source-pathname source-position)
39                    source-pathname)))
40    (cond ((symbolp name)
41           (%put name '%source source)))))
42
43(defun fset (name function &optional source-position arglist)
44  (cond ((symbolp name)
45         (check-redefinition name)
46         (record-source-information name nil source-position)
47         (when arglist
48           (%set-arglist function arglist))
49         (%set-symbol-function name function))
50        ((and (consp name) (eq (car name) 'SETF))
51         (check-redefinition name)
52         (record-source-information name nil source-position)
53         ;; FIXME arglist
54         (setf (get (cadr name) '%SETF-FUNCTION) function))
55        (t
56         (error 'type-error "~S is not a valid function name." name)))
57  (when (functionp function) ; FIXME Is this test needed?
58    (%set-lambda-name function name)))
59
60(defun fdefinition (name)
61  (cond ((symbolp name)
62         (symbol-function name))
63        ((and (consp name) (eq (car name) 'SETF))
64         (or (get (cadr name) '%setf-function)
65             (error 'undefined-function :name name)))
66        (t
67         (error 'type-error "~S is not a valid function name." name))))
68
69(defun %set-fdefinition (name function)
70  (fset name function))
71
72(defsetf fdefinition %set-fdefinition)
Note: See TracBrowser for help on using the repository browser.