/[cmucl]/src/pcl/fin.lisp
ViewVC logotype

Contents of /src/pcl/fin.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.23 - (hide annotations)
Fri Mar 19 15:19:03 2010 UTC (4 years, 1 month ago) by rtoy
Branch: MAIN
CVS Tags: sparc-tramp-assem-base, post-merge-intl-branch, release-20b-pre1, release-20b-pre2, sparc-tramp-assem-2010-07-19, GIT-CONVERSION, cross-sol-x86-merged, RELEASE_20b, cross-sol-x86-base, snapshot-2010-12, snapshot-2010-11, snapshot-2011-09, snapshot-2011-06, snapshot-2011-07, snapshot-2011-04, snapshot-2011-02, snapshot-2011-03, snapshot-2011-01, snapshot-2010-05, snapshot-2010-04, snapshot-2010-07, snapshot-2010-06, snapshot-2010-08, cross-sol-x86-2010-12-20, cross-sparc-branch-base, HEAD
Branch point for: cross-sparc-branch, RELEASE-20B-BRANCH, sparc-tramp-assem-branch, cross-sol-x86-branch
Changes since 1.22: +3 -2 lines
Merge intl-branch 2010-03-18 to HEAD.  To build, you need to use
boot-2010-02-1 as the bootstrap file.  You should probably also use
the new -P option for build.sh to generate and update the po files
while building.
1 wlott 1.1 ;;;-*-Mode:LISP; Package:(PCL Lisp 1000); Base:10; Syntax:Common-lisp -*-
2     ;;;
3     ;;; *************************************************************************
4     ;;; Copyright (c) 1985, 1986, 1987, 1988, 1989, 1990 Xerox Corporation.
5     ;;; All rights reserved.
6     ;;;
7     ;;; Use and copying of this software and preparation of derivative works
8     ;;; based upon this software are permitted. Any distribution of this
9     ;;; software or derivative works must comply with all applicable United
10     ;;; States export control laws.
11     ;;;
12     ;;; This software is made available AS IS, and Xerox Corporation makes no
13     ;;; warranty about the software, its performance or its conformity to any
14     ;;; specification.
15     ;;;
16     ;;; Any person obtaining a copy of this software is requested to send their
17     ;;; name and post office or electronic mail address to:
18     ;;; CommonLoops Coordinator
19     ;;; Xerox PARC
20     ;;; 3333 Coyote Hill Rd.
21     ;;; Palo Alto, CA 94304
22     ;;; (or send Arpanet mail to CommonLoops-Coordinator.pa@Xerox.arpa)
23     ;;;
24     ;;; Suggestions, comments and requests for improvements are also welcome.
25     ;;; *************************************************************************
26 pw 1.13
27 gerd 1.21 (file-comment
28 rtoy 1.23 "$Header: /tiger/var/lib/cvsroots/cmucl/src/pcl/fin.lisp,v 1.23 2010/03/19 15:19:03 rtoy Rel $")
29 dtc 1.11 ;;;
30 wlott 1.1
31     ;;
32     ;;;;;; FUNCALLABLE INSTANCES
33     ;;
34    
35     #|
36    
37     Generic functions are instances with meta class funcallable-standard-class.
38     Instances with this meta class are called funcallable-instances (FINs for
39     short). They behave something like lexical closures in that they have data
40     associated with them (which is used to store the slots) and are funcallable.
41     When a funcallable instance is funcalled, the function that is invoked is
42     called the funcallable-instance-function. The funcallable-instance-function
43     of a funcallable instance can be changed.
44    
45     This file implements low level code for manipulating funcallable instances.
46    
47     It is possible to implement funcallable instances in pure Common Lisp. A
48     simple implementation which uses lexical closures as the instances and a
49     hash table to record that the lexical closures are funcallable instances
50     is easy to write. Unfortunately, this implementation adds significant
51     overhead:
52    
53     to generic-function-invocation (1 function call)
54     to slot-access (1 function call or one hash table lookup)
55     to class-of a generic-function (1 hash-table lookup)
56    
57     In addition, it would prevent the funcallable instances from being garbage
58     collected. In short, the pure Common Lisp implementation really isn't
59     practical.
60    
61     Instead, PCL uses a specially tailored implementation for each Common Lisp and
62     makes no attempt to provide a purely portable implementation. The specially
63     tailored implementations are based on the lexical closure's provided by that
64     implementation and are fairly short and easy to write.
65    
66     Some of the implementation dependent code in this file was originally written
67     by someone in the employ of the vendor of that Common Lisp. That code is
68     explicitly marked saying who wrote it.
69    
70     |#
71    
72 phg 1.9 (in-package :pcl)
73 rtoy 1.23 (intl:textdomain "cmucl")
74 wlott 1.1
75     ;;;
76     ;;; The first part of the file contains the implementation dependent code to
77     ;;; implement funcallable instances. Each implementation must provide the
78     ;;; following functions and macros:
79     ;;;
80     ;;; ALLOCATE-FUNCALLABLE-INSTANCE-1 ()
81     ;;; should create and return a new funcallable instance. The
82     ;;; funcallable-instance-data slots must be initialized to NIL.
83     ;;; This is called by allocate-funcallable-instance and by the
84     ;;; bootstrapping code.
85     ;;;
86     ;;; FUNCALLABLE-INSTANCE-P (x)
87     ;;; the obvious predicate. This should be an INLINE function.
88     ;;; it must be funcallable, but it would be nice if it compiled
89     ;;; open.
90     ;;;
91     ;;; SET-FUNCALLABLE-INSTANCE-FUNCTION (fin new-value)
92     ;;; change the fin so that when it is funcalled, the new-value
93     ;;; function is called. Note that it is legal for new-value
94     ;;; to be copied before it is installed in the fin, specifically
95     ;;; there is no accessor for a FIN's function so this function
96     ;;; does not have to preserve the actual new value. The new-value
97     ;;; argument can be any funcallable thing, a closure, lambda
98     ;;; compiled code etc. This function must coerce those values
99     ;;; if necessary.
100     ;;; NOTE: new-value is almost always a compiled closure. This
101     ;;; is the important case to optimize.
102     ;;;
103     ;;; FUNCALLABLE-INSTANCE-DATA-1 (fin data-name)
104     ;;; should return the value of the data named data-name in the fin.
105     ;;; data-name is one of the symbols in the list which is the value
106     ;;; of funcallable-instance-data. Since data-name is almost always
107     ;;; a quoted symbol and funcallable-instance-data is a constant, it
108     ;;; is possible (and worthwhile) to optimize the computation of
109     ;;; data-name's offset in the data part of the fin.
110     ;;; This must be SETF'able.
111     ;;;
112    
113 pw 1.14 (declaim (notinline called-fin-without-function))
114 ram 1.6 (defun called-fin-without-function (&rest args)
115     (declare (ignore args))
116 rtoy 1.23 (error _"~@<Attempt to funcall a funcallable instance without first ~
117 gerd 1.20 setting its function.~@:>"))
118 wlott 1.1
119    
120 ram 1.3 ;;;; Implementation of funcallable instances for CMU Common Lisp:
121 wlott 1.1 ;;;
122 pw 1.10 (defstruct (pcl-funcallable-instance
123     (:alternate-metaclass kernel:funcallable-instance
124     kernel:random-pcl-class
125     kernel:make-random-pcl-class)
126     (:type kernel:funcallable-structure)
127     (:constructor allocate-funcallable-instance-1 ())
128     (:conc-name nil))
129     ;;
130     ;; PCL wrapper is in the layout slot.
131     ;;
132     ;; PCL data vector.
133     (pcl-funcallable-instance-slots nil)
134     ;;
135     ;; The debug-name for this function.
136 pmai 1.17 (funcallable-instance-name nil)
137     ;;
138     ;; Hash code.
139     (hash-code (get-instance-hash-code) :type fixnum))
140    
141 pw 1.10 ;;; Note: returns true for non-pcl funcallable structures.
142 ram 1.3 (import 'kernel:funcallable-instance-p)
143    
144 pw 1.13
145 ram 1.3 ;;; SET-FUNCALLABLE-INSTANCE-FUNCTION -- Interface
146     ;;;
147     ;;; Set the function that is called when FIN is called.
148     ;;;
149 wlott 1.2 (defun set-funcallable-instance-function (fin new-value)
150 ram 1.6 (declare (type function new-value))
151 ram 1.3 (assert (funcallable-instance-p fin))
152 pw 1.10 (setf (kernel:funcallable-instance-function fin) new-value))
153 wlott 1.2

  ViewVC Help
Powered by ViewVC 1.1.5