/[slime]/slime/swank-backend.lisp
ViewVC logotype

Contents of /slime/swank-backend.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.95 - (hide annotations)
Mon Jan 30 19:56:55 2006 UTC (8 years, 2 months ago) by heller
Branch: MAIN
Changes since 1.94: +2 -0 lines
Patch from Ian Eslick.

Show slot values for metaclasses that override the default storage
locations for objects slots (i.e. where the default slot-boundp
returns nil) in the inspector.

* swank.lisp (inspect-for-emacs standard-object): Use
slot-value-using-class and slot-boundp-using-class.

* swank-backend.lisp: Add slot-value-using-class and
slot-boundp-using-class to the swank-mop package.
1 lgorrie 1.85 ;;; -*- Mode: lisp; indent-tabs-mode: nil; outline-regexp: ";;;;;*" -*-
2 lgorrie 1.1 ;;;
3 lgorrie 1.13 ;;; slime-backend.lisp --- SLIME backend interface.
4 lgorrie 1.1 ;;;
5 lgorrie 1.13 ;;; Created by James Bielman in 2003. Released into the public domain.
6 lgorrie 1.85 ;;;
7     ;;;; Frontmatter
8 lgorrie 1.1 ;;;
9 lgorrie 1.13 ;;; This file defines the functions that must be implemented
10     ;;; separately for each Lisp. Each is declared as a generic function
11     ;;; for which swank-<implementation>.lisp provides methods.
12 lgorrie 1.1
13 heller 1.36 (defpackage :swank-backend
14 lgorrie 1.1 (:use :common-lisp)
15 heller 1.36 (:export #:sldb-condition
16     #:original-condition
17     #:compiler-condition
18     #:message
19     #:short-message
20     #:condition
21     #:severity
22     #:location
23     #:location-p
24     #:location-buffer
25     #:location-position
26     #:position-p
27     #:position-pos
28     #:print-output-to-string
29 mbaringer 1.42 #:quit-lisp
30 crhodes 1.62 #:references
31 mbaringer 1.67 #:unbound-slot-filler
32     ;; inspector related symbols
33     #:inspector
34     #:inspect-for-emacs
35     #:raw-inspection
36     #:fancy-inspection
37 heller 1.70 #:label-value-line
38     #:label-value-line*
39 mbaringer 1.67 ))
40 lgorrie 1.1
41 mbaringer 1.65 (defpackage :swank-mop
42     (:use)
43     (:export
44     ;; classes
45     #:standard-generic-function
46     #:standard-slot-definition
47     #:standard-method
48     #:standard-class
49 mbaringer 1.68 #:eql-specializer
50     #:eql-specializer-object
51 mbaringer 1.65 ;; standard-class readers
52     #:class-default-initargs
53     #:class-direct-default-initargs
54     #:class-direct-slots
55     #:class-direct-subclasses
56     #:class-direct-superclasses
57     #:class-finalized-p
58     #:class-name
59     #:class-precedence-list
60     #:class-prototype
61     #:class-slots
62 mbaringer 1.68 #:specializer-direct-methods
63 mbaringer 1.65 ;; generic function readers
64     #:generic-function-argument-precedence-order
65     #:generic-function-declarations
66     #:generic-function-lambda-list
67     #:generic-function-methods
68     #:generic-function-method-class
69     #:generic-function-method-combination
70     #:generic-function-name
71     ;; method readers
72     #:method-generic-function
73     #:method-function
74     #:method-lambda-list
75     #:method-specializers
76     #:method-qualifiers
77     ;; slot readers
78     #:slot-definition-allocation
79     #:slot-definition-documentation
80     #:slot-definition-initargs
81     #:slot-definition-initform
82     #:slot-definition-initfunction
83     #:slot-definition-name
84     #:slot-definition-type
85     #:slot-definition-readers
86 lgorrie 1.79 #:slot-definition-writers
87 heller 1.95 #:slot-boundp-using-class
88     #:slot-value-using-class
89 lgorrie 1.79 ;; generic function protocol
90 lgorrie 1.82 #:compute-applicable-methods-using-classes
91     #:finalize-inheritance))
92 mbaringer 1.65
93 heller 1.36 (in-package :swank-backend)
94 lgorrie 1.1
95    
96 lgorrie 1.21 ;;;; Metacode
97    
98     (defparameter *interface-functions* '()
99     "The names of all interface functions.")
100    
101     (defparameter *unimplemented-interfaces* '()
102     "List of interface functions that are not implemented.
103     DEFINTERFACE adds to this list and DEFIMPLEMENTATION removes.")
104    
105 heller 1.52 (defmacro definterface (name args documentation &rest default-body)
106 lgorrie 1.21 "Define an interface function for the backend to implement.
107     A generic function is defined with NAME, ARGS, and DOCUMENTATION.
108    
109     If a DEFAULT-BODY is supplied then NO-APPLICABLE-METHOD is specialized
110     to execute the body if the backend doesn't provide a specific
111     implementation.
112    
113     Backends implement these functions using DEFIMPLEMENTATION."
114 lgorrie 1.43 (check-type documentation string "a documentation string")
115 lgorrie 1.21 (flet ((gen-default-impl ()
116 mbaringer 1.73 `(defmethod ,name ,args ,@default-body)))
117 heller 1.76 `(progn (defgeneric ,name ,args (:documentation ,documentation))
118     (pushnew ',name *interface-functions*)
119     ,(if (null default-body)
120     `(pushnew ',name *unimplemented-interfaces*)
121     (gen-default-impl))
122     ;; see <http://www.franz.com/support/documentation/6.2/doc/pages/variables/compiler/s_cltl1-compile-file-toplevel-compatibility-p_s.htm>
123     (eval-when (:compile-toplevel :load-toplevel :execute)
124     (export ',name :swank-backend))
125     ',name)))
126 lgorrie 1.21
127     (defmacro defimplementation (name args &body body)
128 heller 1.25 `(progn (defmethod ,name ,args ,@body)
129     (if (member ',name *interface-functions*)
130     (setq *unimplemented-interfaces*
131     (remove ',name *unimplemented-interfaces*))
132     (warn "DEFIMPLEMENTATION of undefined interface (~S)" ',name))
133     ',name))
134 lgorrie 1.21
135     (defun warn-unimplemented-interfaces ()
136     "Warn the user about unimplemented backend features.
137     The portable code calls this function at startup."
138     (warn "These Swank interfaces are unimplemented:~% ~A"
139     (sort (copy-list *unimplemented-interfaces*) #'string<)))
140    
141 heller 1.69 (defun import-to-swank-mop (symbol-list)
142     (dolist (sym symbol-list)
143     (let* ((swank-mop-sym (find-symbol (symbol-name sym) :swank-mop)))
144     (when swank-mop-sym
145     (unintern swank-mop-sym :swank-mop))
146     (import sym :swank-mop)
147     (export sym :swank-mop))))
148    
149     (defun import-swank-mop-symbols (package except)
150     "Import the mop symbols from PACKAGE to SWANK-MOP.
151     EXCEPT is a list of symbol names which should be ignored."
152     (do-symbols (s :swank-mop)
153     (unless (member s except :test #'string=)
154     (let ((real-symbol (find-symbol (string s) package)))
155 heller 1.76 (assert real-symbol () "Symbol ~A not found in package ~A" s package)
156 heller 1.69 (unintern s :swank-mop)
157     (import real-symbol :swank-mop)
158     (export real-symbol :swank-mop)))))
159    
160 heller 1.88 (defvar *gray-stream-symbols*
161     '(:fundamental-character-output-stream
162     :stream-write-char
163     :stream-fresh-line
164     :stream-force-output
165     :stream-finish-output
166     :fundamental-character-input-stream
167     :stream-read-char
168     :stream-listen
169     :stream-unread-char
170     :stream-clear-input
171     :stream-line-column
172 jsnellman 1.90 :stream-read-char-no-hang
173     ;; STREAM-LINE-LENGTH is an extension to gray streams that's apparently
174 dcrosher 1.91 ;; supported by CMUCL, OpenMCL, SBCL and SCL.
175     #+(or cmu openmcl sbcl scl)
176 jsnellman 1.90 :stream-line-length))
177 heller 1.88
178     (defun import-from (package symbol-names &optional (to-package *package*))
179     "Import the list of SYMBOL-NAMES found in the package PACKAGE."
180     (dolist (name symbol-names)
181     (multiple-value-bind (symbol found) (find-symbol (string name) package)
182     (assert found () "Symbol ~A not found in package ~A" name package)
183     (import symbol to-package))))
184    
185 lgorrie 1.21
186 heller 1.46 ;;;; Utilities
187    
188     (defmacro with-struct ((conc-name &rest names) obj &body body)
189     "Like with-slots but works only for structs."
190     (flet ((reader (slot) (intern (concatenate 'string
191     (symbol-name conc-name)
192     (symbol-name slot))
193     (symbol-package conc-name))))
194     (let ((tmp (gensym "OO-")))
195     ` (let ((,tmp ,obj))
196     (symbol-macrolet
197     ,(loop for name in names collect
198     (typecase name
199     (symbol `(,name (,(reader name) ,tmp)))
200     (cons `(,(first name) (,(reader (second name)) ,tmp)))
201     (t (error "Malformed syntax in WITH-STRUCT: ~A" name))))
202     ,@body)))))
203 lgorrie 1.54
204    
205 lgorrie 1.13 ;;;; TCP server
206    
207 heller 1.29 (definterface create-socket (host port)
208     "Create a listening TCP socket on interface HOST and port PORT .")
209 lgorrie 1.13
210 lgorrie 1.21 (definterface local-port (socket)
211     "Return the local port number of SOCKET.")
212 lgorrie 1.1
213 lgorrie 1.21 (definterface close-socket (socket)
214     "Close the socket SOCKET.")
215 lgorrie 1.1
216 heller 1.93 (definterface accept-connection (socket &key external-format
217     buffering)
218     "Accept a client connection on the listening socket SOCKET.
219     Return a stream for the new connection.")
220 heller 1.16
221 heller 1.31 (definterface add-sigio-handler (socket fn)
222 lgorrie 1.21 "Call FN whenever SOCKET is readable.")
223 heller 1.16
224 heller 1.31 (definterface remove-sigio-handlers (socket)
225     "Remove all sigio handlers for SOCKET.")
226    
227     (definterface add-fd-handler (socket fn)
228     "Call FN when Lisp is waiting for input and SOCKET is readable.")
229    
230     (definterface remove-fd-handlers (socket)
231     "Remove all fd-handlers for SOCKET.")
232 heller 1.18
233 heller 1.36 (definterface preferred-communication-style ()
234     "Return one of the symbols :spawn, :sigio, :fd-handler, or NIL."
235     nil)
236    
237 lgorrie 1.13 ;;; Base condition for networking errors.
238 msimmons 1.50 (define-condition network-error (simple-error) ())
239 lgorrie 1.13
240 heller 1.74 (definterface emacs-connected ()
241 lgorrie 1.13 "Hook called when the first connection from Emacs is established.
242     Called from the INIT-FN of the socket server that accepts the
243     connection.
244 lgorrie 1.1
245 lgorrie 1.13 This is intended for setting up extra context, e.g. to discover
246 heller 1.74 that the calling thread is the one that interacts with Emacs."
247 mbaringer 1.73 nil)
248 lgorrie 1.1
249    
250 heller 1.20 ;;;; Unix signals
251    
252     (defconstant +sigint+ 2)
253    
254 heller 1.36 (definterface call-without-interrupts (fn)
255     "Call FN in a context where interrupts are disabled."
256     (funcall fn))
257 heller 1.20
258 heller 1.32 (definterface getpid ()
259     "Return the (Unix) process ID of this superior Lisp.")
260    
261     (definterface lisp-implementation-type-name ()
262     "Return a short name for the Lisp implementation."
263     (lisp-implementation-type))
264 heller 1.20
265 heller 1.51 (definterface default-directory ()
266     "Return the default directory."
267     (directory-namestring (truename *default-pathname-defaults*)))
268    
269 heller 1.39 (definterface set-default-directory (directory)
270     "Set the default directory.
271     This is used to resolve filenames without directory component."
272     (setf *default-pathname-defaults* (truename (merge-pathnames directory)))
273 heller 1.51 (default-directory))
274    
275     (definterface call-with-syntax-hooks (fn)
276     "Call FN with hooks to handle special syntax."
277     (funcall fn))
278 heller 1.39
279 heller 1.52 (definterface default-readtable-alist ()
280 heller 1.77 "Return a suitable initial value for SWANK:*READTABLE-ALIST*."
281 heller 1.52 '())
282    
283 heller 1.58 (definterface quit-lisp ()
284     "Exit the current lisp image.")
285    
286 heller 1.20
287 lgorrie 1.1 ;;;; Compilation
288 dbarlow 1.8
289 lgorrie 1.21 (definterface call-with-compilation-hooks (func)
290 lgorrie 1.47 "Call FUNC with hooks to record compiler conditions.")
291 lgorrie 1.13
292 vsedach 1.14 (defmacro with-compilation-hooks ((&rest ignore) &body body)
293 lgorrie 1.47 "Execute BODY as in CALL-WITH-COMPILATION-HOOKS."
294 vsedach 1.14 (declare (ignore ignore))
295 dbarlow 1.8 `(call-with-compilation-hooks (lambda () (progn ,@body))))
296 lgorrie 1.1
297 pseibel 1.64 (definterface swank-compile-string (string &key buffer position directory)
298 lgorrie 1.47 "Compile source from STRING. During compilation, compiler
299 lgorrie 1.1 conditions must be trapped and resignalled as COMPILER-CONDITIONs.
300    
301     If supplied, BUFFER and POSITION specify the source location in Emacs.
302    
303     Additionally, if POSITION is supplied, it must be added to source
304 pseibel 1.64 positions reported in compiler conditions.
305    
306     If DIRECTORY is specified it may be used by certain implementations to
307     rebind *DEFAULT-PATHNAME-DEFAULTS* which may improve the recording of
308     source information.")
309 lgorrie 1.1
310 lgorrie 1.43 (definterface operate-on-system (system-name operation-name &rest keyword-args)
311     "Perform OPERATION-NAME on SYSTEM-NAME using ASDF.
312     The KEYWORD-ARGS are passed on to the operation.
313     Example:
314     \(operate-on-system \"SWANK\" \"COMPILE-OP\" :force t)"
315     (unless (member :asdf *features*)
316     (error "ASDF is not loaded."))
317 heller 1.30 (with-compilation-hooks ()
318 lgorrie 1.43 (let ((operate (find-symbol "OPERATE" :asdf))
319     (operation (find-symbol operation-name :asdf)))
320     (when (null operation)
321     (error "Couldn't find ASDF operation ~S" operation-name))
322     (apply operate operation system-name keyword-args))))
323 mbaringer 1.26
324 heller 1.86 (definterface swank-compile-file (filename load-p &optional external-format)
325 lgorrie 1.1 "Compile FILENAME signalling COMPILE-CONDITIONs.
326 lgorrie 1.21 If LOAD-P is true, load the file after compilation.")
327 lgorrie 1.1
328 heller 1.72 (deftype severity ()
329     '(member :error :read-error :warning :style-warning :note))
330 lgorrie 1.13
331     ;; Base condition type for compiler errors, warnings and notes.
332     (define-condition compiler-condition (condition)
333     ((original-condition
334     ;; The original condition thrown by the compiler if appropriate.
335     ;; May be NIL if a compiler does not report using conditions.
336     :type (or null condition)
337     :initarg :original-condition
338     :accessor original-condition)
339    
340     (severity :type severity
341     :initarg :severity
342     :accessor severity)
343    
344     (message :initarg :message
345     :accessor message)
346    
347 heller 1.30 (short-message :initarg :short-message
348     :initform nil
349     :accessor short-message)
350 crhodes 1.62
351     (references :initarg :references
352     :initform nil
353     :accessor references)
354 heller 1.30
355 lgorrie 1.13 (location :initarg :location
356     :accessor location)))
357 heller 1.30
358 lgorrie 1.17
359 lgorrie 1.13 ;;;; Streams
360    
361 lgorrie 1.21 (definterface make-fn-streams (input-fn output-fn)
362 lgorrie 1.13 "Return character input and output streams backended by functions.
363     When input is needed, INPUT-FN is called with no arguments to
364     return a string.
365     When output is ready, OUTPUT-FN is called with the output as its
366     argument.
367    
368     Output should be forced to OUTPUT-FN before calling INPUT-FN.
369    
370 lgorrie 1.21 The streams are returned as two values.")
371 lgorrie 1.13
372 lgorrie 1.60 (definterface make-stream-interactive (stream)
373     "Do any necessary setup to make STREAM work interactively.
374     This is called for each stream used for interaction with the user
375     \(e.g. *standard-output*). An implementation could setup some
376     implementation-specific functions to control output flushing at the
377     like."
378 mbaringer 1.73 (declare (ignore stream))
379 lgorrie 1.60 nil)
380    
381 lgorrie 1.1
382     ;;;; Documentation
383    
384 heller 1.36 (definterface arglist (name)
385 mbaringer 1.65 "Return the lambda list for the symbol NAME. NAME can also be
386     a lisp function object, on lisps which support this.
387    
388     The result can be a list or the :not-available if the arglist
389     cannot be determined."
390     (declare (ignore name))
391     :not-available)
392 heller 1.36
393 mbaringer 1.65 (definterface function-name (function)
394     "Return the name of the function object FUNCTION.
395    
396     The result is either a symbol, a list, or NIL if no function name is available."
397     (declare (ignore function))
398     nil)
399 lgorrie 1.1
400 lgorrie 1.21 (definterface macroexpand-all (form)
401 lgorrie 1.1 "Recursively expand all macros in FORM.
402 lgorrie 1.21 Return the resulting form.")
403 lgorrie 1.1
404 heller 1.94 (definterface compiler-macroexpand-1 (form &optional env)
405     "Call the compiler-macro for form.
406     If FORM is a function call for which a compiler-macro has been
407     defined, invoke the expander function using *macroexpand-hook* and
408     return the results and T. Otherwise, return the original form and
409     NIL."
410     (let ((fun (and (consp form) (compiler-macro-function (car form)))))
411     (if fun
412     (let ((result (funcall *macroexpand-hook* fun form env)))
413     (values result (not (eq result form))))
414     (values form nil))))
415    
416     (definterface compiler-macroexpand (form &optional env)
417     "Repetitively call `compiler-macroexpand-1'."
418     (labels ((frob (form expanded)
419     (multiple-value-bind (new-form newly-expanded)
420     (compiler-macroexpand-1 form env)
421     (if newly-expanded
422     (frob new-form t)
423     (values new-form expanded)))))
424     (frob form env)))
425    
426 lgorrie 1.21 (definterface describe-symbol-for-emacs (symbol)
427 lgorrie 1.1 "Return a property list describing SYMBOL.
428    
429     The property list has an entry for each interesting aspect of the
430     symbol. The recognised keys are:
431    
432 heller 1.86 :VARIABLE :FUNCTION :SETF :SPECIAL-OPERATOR :MACRO :COMPILER-MACRO
433     :TYPE :CLASS :ALIEN-TYPE :ALIEN-STRUCT :ALIEN-UNION :ALIEN-ENUM
434 lgorrie 1.1
435     The value of each property is the corresponding documentation string,
436 heller 1.86 or :NOT-DOCUMENTED. It is legal to include keys not listed here (but
437     slime-print-apropos in Emacs must know about them).
438 lgorrie 1.1
439     Properties should be included if and only if they are applicable to
440     the symbol. For example, only (and all) fbound symbols should include
441     the :FUNCTION property.
442    
443     Example:
444     \(describe-symbol-for-emacs 'vector)
445     => (:CLASS :NOT-DOCUMENTED
446     :TYPE :NOT-DOCUMENTED
447 lgorrie 1.21 :FUNCTION \"Constructs a simple-vector from the given objects.\")")
448    
449     (definterface describe-definition (name type)
450     "Describe the definition NAME of TYPE.
451     TYPE can be any value returned by DESCRIBE-SYMBOL-FOR-EMACS.
452    
453     Return a documentation string, or NIL if none is available.")
454 lgorrie 1.2
455    
456     ;;;; Debugging
457    
458 heller 1.92 (definterface install-debugger-globally (function)
459     "Install FUNCTION as the debugger for all threads/processes. This
460     usually involves setting *DEBUGGER-HOOK* and, if the implementation
461     permits, hooking into BREAK as well."
462     (setq *debugger-hook* function))
463    
464 lgorrie 1.21 (definterface call-with-debugging-environment (debugger-loop-fn)
465 lgorrie 1.2 "Call DEBUGGER-LOOP-FN in a suitable debugging environment.
466    
467     This function is called recursively at each debug level to invoke the
468     debugger loop. The purpose is to setup any necessary environment for
469     other debugger callbacks that will be called within the debugger loop.
470    
471     For example, this is a reasonable place to compute a backtrace, switch
472 lgorrie 1.21 to safe reader/printer settings, and so on.")
473 lgorrie 1.2
474 heller 1.80 (definterface call-with-debugger-hook (hook fun)
475     "Call FUN and use HOOK as debugger hook.
476    
477     HOOK should be called for both BREAK and INVOKE-DEBUGGER."
478     (let ((*debugger-hook* hook))
479     (funcall fun)))
480    
481 lgorrie 1.2 (define-condition sldb-condition (condition)
482     ((original-condition
483     :initarg :original-condition
484 heller 1.5 :accessor original-condition))
485 heller 1.63 (:report (lambda (condition stream)
486     (format stream "Condition in debugger code~@[: ~A~]"
487     (original-condition condition))))
488 lgorrie 1.2 (:documentation
489     "Wrapper for conditions that should not be debugged.
490    
491     When a condition arises from the internals of the debugger, it is not
492     desirable to debug it -- we'd risk entering an endless loop trying to
493     debug the debugger! Instead, such conditions can be reported to the
494     user without (re)entering the debugger by wrapping them as
495     `sldb-condition's."))
496    
497 heller 1.36 (definterface compute-backtrace (start end)
498 lgorrie 1.3 "Return a list containing a backtrace of the condition current
499     being debugged. The results are unspecified if this function is
500 heller 1.36 called outside the dynamic contour CALL-WITH-DEBUGGING-ENVIRONMENT.
501    
502     START and END are zero-based indices constraining the number of frames
503     returned. Frame zero is defined as the frame which invoked the
504     debugger. If END is nil, return the frames from START to the end of
505     the stack.")
506 lgorrie 1.3
507 heller 1.36 (definterface print-frame (frame stream)
508     "Print frame to stream.")
509 heller 1.70
510 lgorrie 1.21 (definterface frame-source-location-for-emacs (frame-number)
511     "Return the source location for FRAME-NUMBER.")
512 lgorrie 1.3
513 lgorrie 1.21 (definterface frame-catch-tags (frame-number)
514 lgorrie 1.3 "Return a list of XXX list of what? catch tags for a debugger
515     stack frame. The results are undefined unless this is called
516     within the dynamic contour of a function defined by
517 lgorrie 1.21 DEFINE-DEBUGGER-HOOK.")
518 lgorrie 1.3
519 lgorrie 1.21 (definterface frame-locals (frame-number)
520 heller 1.57 "Return a list of XXX local variable designators define me
521 lgorrie 1.3 for a debugger stack frame. The results are undefined unless
522     this is called within the dynamic contour of a function defined
523 lgorrie 1.21 by DEFINE-DEBUGGER-HOOK.")
524 heller 1.37
525 heller 1.57 (definterface frame-var-value (frame var)
526     "Return the value of VAR in FRAME.
527     FRAME is the number of the frame in the backtrace.
528     VAR is the number of the variable in the frame.")
529    
530 heller 1.37 (definterface disassemble-frame (frame-number)
531     "Disassemble the code for the FRAME-NUMBER.
532     The output should be written to standard output.
533 heller 1.84 FRAME-NUMBER is a non-negative integer.")
534 heller 1.37
535 lgorrie 1.21 (definterface eval-in-frame (form frame-number)
536 lgorrie 1.3 "Evaluate a Lisp form in the lexical context of a stack frame
537     in the debugger. The results are undefined unless called in the
538     dynamic contour of a function defined by DEFINE-DEBUGGER-HOOK.
539    
540     FRAME-NUMBER must be a positive integer with 0 indicating the
541     frame which invoked the debugger.
542    
543     The return value is the result of evaulating FORM in the
544 lgorrie 1.21 appropriate context.")
545 heller 1.22
546     (definterface return-from-frame (frame-number form)
547     "Unwind the stack to the frame FRAME-NUMBER and return the value(s)
548     produced by evaluating FORM in the frame context to its caller.
549    
550     Execute any clean-up code from unwind-protect forms above the frame
551     during unwinding.
552    
553     Return a string describing the error if it's not possible to return
554     from the frame.")
555    
556     (definterface restart-frame (frame-number)
557     "Restart execution of the frame FRAME-NUMBER with the same arguments
558     as it was called originally.")
559 lgorrie 1.3
560 lgorrie 1.49 (definterface format-sldb-condition (condition)
561     "Format a condition for display in SLDB."
562     (princ-to-string condition))
563    
564     (definterface condition-references (condition)
565     "Return a list of documentation references for a condition.
566     Each reference is one of:
567     (:ANSI-CL
568     {:FUNCTION | :SPECIAL-OPERATOR | :MACRO | :SECTION | :GLOSSARY }
569     symbol-or-name)
570     (:SBCL :NODE node-name)"
571 mbaringer 1.73 (declare (ignore condition))
572 lgorrie 1.49 '())
573 heller 1.52
574 heller 1.69 (definterface condition-extras (condition)
575     "Return a list of extra for the debugger.
576     The allowed elements are of the form:
577     (:SHOW-FRAME-SOURCE frame-number)"
578 mbaringer 1.73 (declare (ignore condition))
579 heller 1.69 '())
580    
581 heller 1.71 (definterface activate-stepping (frame-number)
582     "Prepare the frame FRAME-NUMBER for stepping.")
583 heller 1.69
584     (definterface sldb-break-on-return (frame-number)
585     "Set a breakpoint in the frame FRAME-NUMBER.")
586    
587     (definterface sldb-break-at-start (symbol)
588     "Set a breakpoint on the beginning of the function for SYMBOL.")
589 heller 1.52
590 lgorrie 1.49
591 lgorrie 1.3
592 heller 1.36 ;;;; Definition finding
593    
594     (defstruct (:location (:type list) :named
595 lgorrie 1.45 (:constructor make-location
596     (buffer position &optional hints)))
597     buffer position
598     ;; Hints is a property list optionally containing:
599     ;; :snippet SOURCE-TEXT
600     ;; This is a snippet of the actual source text at the start of
601     ;; the definition, which could be used in a text search.
602     hints)
603 heller 1.36
604     (defstruct (:error (:type list) :named (:constructor)) message)
605     (defstruct (:file (:type list) :named (:constructor)) name)
606     (defstruct (:buffer (:type list) :named (:constructor)) name)
607     (defstruct (:position (:type list) :named (:constructor)) pos)
608    
609     (definterface find-definitions (name)
610     "Return a list ((DSPEC LOCATION) ...) for NAME's definitions.
611    
612 heller 1.38 NAME is a \"definition specifier\".
613 heller 1.36
614 heller 1.38 DSPEC is a \"definition specifier\" describing the
615 heller 1.36 definition, e.g., FOO or (METHOD FOO (STRING NUMBER)) or
616 heller 1.38 \(DEFVAR FOO).
617    
618     LOCATION is the source location for the definition.")
619 heller 1.36
620 lgorrie 1.61 (definterface buffer-first-change (filename)
621     "Called for effect the first time FILENAME's buffer is modified."
622 mbaringer 1.73 (declare (ignore filename))
623 lgorrie 1.61 nil)
624    
625 heller 1.36
626     ;;;; XREF
627    
628     (definterface who-calls (function-name)
629     "Return the call sites of FUNCTION-NAME (a symbol).
630     The results is a list ((DSPEC LOCATION) ...).")
631    
632 heller 1.81 (definterface calls-who (function-name)
633     "Return the call sites of FUNCTION-NAME (a symbol).
634     The results is a list ((DSPEC LOCATION) ...).")
635    
636 heller 1.36 (definterface who-references (variable-name)
637     "Return the locations where VARIABLE-NAME (a symbol) is referenced.
638     See WHO-CALLS for a description of the return value.")
639    
640     (definterface who-binds (variable-name)
641     "Return the locations where VARIABLE-NAME (a symbol) is bound.
642     See WHO-CALLS for a description of the return value.")
643    
644     (definterface who-sets (variable-name)
645     "Return the locations where VARIABLE-NAME (a symbol) is set.
646     See WHO-CALLS for a description of the return value.")
647    
648     (definterface who-macroexpands (macro-name)
649     "Return the locations where MACRO-NAME (a symbol) is expanded.
650     See WHO-CALLS for a description of the return value.")
651    
652     (definterface who-specializes (class-name)
653     "Return the locations where CLASS-NAME (a symbol) is specialized.
654     See WHO-CALLS for a description of the return value.")
655    
656     ;;; Simpler variants.
657    
658     (definterface list-callers (function-name)
659     "List the callers of FUNCTION-NAME.
660     This function is like WHO-CALLS except that it is expected to use
661     lower-level means. Whereas WHO-CALLS is usually implemented with
662     special compiler support, LIST-CALLERS is usually implemented by
663     groveling for constants in function objects throughout the heap.
664    
665     The return value is as for WHO-CALLS.")
666    
667     (definterface list-callees (function-name)
668     "List the functions called by FUNCTION-NAME.
669     See LIST-CALLERS for a description of the return value.")
670    
671    
672 heller 1.23 ;;;; Profiling
673    
674     ;;; The following functions define a minimal profiling interface.
675    
676     (definterface profile (fname)
677     "Marks symbol FNAME for profiling.")
678    
679     (definterface profiled-functions ()
680     "Returns a list of profiled functions.")
681    
682     (definterface unprofile (fname)
683     "Marks symbol FNAME as not profiled.")
684    
685     (definterface unprofile-all ()
686     "Marks all currently profiled functions as not profiled."
687     (dolist (f (profiled-functions))
688     (unprofile f)))
689    
690     (definterface profile-report ()
691     "Prints profile report.")
692    
693     (definterface profile-reset ()
694     "Resets profile counters.")
695    
696     (definterface profile-package (package callers-p methods)
697     "Wrap profiling code around all functions in PACKAGE. If a function
698     is already profiled, then unprofile and reprofile (useful to notice
699     function redefinition.)
700    
701     If CALLERS-P is T names have counts of the most common calling
702     functions recorded.
703    
704     When called with arguments :METHODS T, profile all methods of all
705     generic functions having names in the given package. Generic functions
706     themselves, that is, their dispatch functions, are left alone.")
707    
708    
709 heller 1.19 ;;;; Inspector
710 lgorrie 1.56
711 mbaringer 1.67 (defclass inspector ()
712     ()
713     (:documentation "Super class of inspector objects.
714    
715     Implementations should sub class in order to dispatch off of the
716     inspect-for-emacs method."))
717    
718     (definterface make-default-inspector ()
719     "Return an inspector object suitable for passing to inspect-for-emacs.")
720    
721     (definterface inspect-for-emacs (object inspector)
722 heller 1.86 "Explain to Emacs how to inspect OBJECT.
723 mbaringer 1.67
724     The argument INSPECTOR is an object representing how to get at
725     the internals of OBJECT, it is usually an implementation specific
726     class used simply for dispatching to the proper method.
727    
728     The orgument INSPECTION-MODE is an object specifying how, and
729     what, to show to the user.
730    
731     Returns two values: a string which will be used as the title of
732     the inspector buffer and a list specifying how to render the
733     object for inspection.
734    
735 lgorrie 1.83 Every element of the list must be either a string, which will be
736 mbaringer 1.67 inserted into the buffer as is, or a list of the form:
737    
738     (:value object &optional format) - Render an inspectable
739     object. If format is provided it must be a string and will be
740     rendered in place of the value, otherwise use princ-to-string.
741    
742     (:newline) - Render a \\n
743    
744     (:action label lambda) - Render LABEL (a text string) which when
745     clicked will call LAMBDA.
746    
747     NIL - do nothing.")
748    
749 mbaringer 1.73 (defmethod inspect-for-emacs ((object t) (inspector t))
750 mbaringer 1.67 "Generic method for inspecting any kind of object.
751    
752     Since we don't know how to deal with OBJECT we simply dump the
753     output of CL:DESCRIBE."
754 mbaringer 1.73 (declare (ignore inspector))
755 heller 1.86 (values
756     "A value."
757     `("Type: " (:value ,(type-of object)) (:newline)
758     "Don't know how to inspect the object, dumping output of CL:DESCRIBE:"
759     (:newline) (:newline)
760     ,(with-output-to-string (desc) (describe object desc)))))
761 heller 1.70
762 heller 1.84 ;;; Utilities for inspector methods.
763 heller 1.70 ;;;
764     (defun label-value-line (label value)
765     "Create a control list which prints \"LABEL: VALUE\" in the inspector."
766     (list (princ-to-string label) ": " `(:value ,value) '(:newline)))
767    
768     (defmacro label-value-line* (&rest label-values)
769     ` (append ,@(loop for (label value) in label-values
770     collect `(label-value-line ,label ,value))))
771 heller 1.19
772 heller 1.29 (definterface describe-primitive-type (object)
773 heller 1.35 "Return a string describing the primitive type of object."
774 heller 1.36 (declare (ignore object))
775 heller 1.35 "N/A")
776 heller 1.19
777    
778 heller 1.36 ;;;; Multithreading
779 lgorrie 1.21 ;;;
780     ;;; The default implementations are sufficient for non-multiprocessing
781     ;;; implementations.
782 lgorrie 1.9
783 heller 1.89 (definterface initialize-multiprocessing ()
784     "Initialize multiprocessing, if necessary."
785     nil)
786 lgorrie 1.9
787 heller 1.89 (definterface startup-idle-and-top-level-loops ()
788     "This function is called directly through the listener, not in an RPC
789 lgorrie 1.9 from Emacs. This is to support interfaces such as CMUCL's
790     MP::STARTUP-IDLE-AND-TOP-LEVEL-LOOPS which does not return like a
791 lgorrie 1.21 normal function."
792     nil)
793 lgorrie 1.9
794 lgorrie 1.21 (definterface spawn (fn &key name)
795     "Create a new thread to call FN.")
796 lgorrie 1.17
797 heller 1.58 (definterface thread-id (thread)
798     "Return an Emacs-parsable object to identify THREAD.
799    
800     Ids should be comparable with equal, i.e.:
801     (equal (thread-id <t1>) (thread-id <t2>)) <==> (eq <t1> <t2>)")
802    
803     (definterface find-thread (id)
804     "Return the thread for ID.
805     ID should be an id previously obtained with THREAD-ID.
806     Can return nil if the thread no longer exists.")
807    
808 heller 1.28 (definterface thread-name (thread)
809     "Return the name of THREAD.
810 lgorrie 1.9
811     Thread names are be single-line strings and are meaningful to the
812 lgorrie 1.21 user. They do not have to be unique."
813 heller 1.28 (declare (ignore thread))
814 lgorrie 1.21 "The One True Thread")
815 lgorrie 1.9
816 heller 1.28 (definterface thread-status (thread)
817     "Return a string describing THREAD's state."
818     (declare (ignore thread))
819     "")
820    
821 lgorrie 1.21 (definterface make-lock (&key name)
822 lgorrie 1.17 "Make a lock for thread synchronization.
823 lgorrie 1.21 Only one thread may hold the lock (via CALL-WITH-LOCK-HELD) at a time."
824 heller 1.23 (declare (ignore name))
825 lgorrie 1.21 :null-lock)
826 lgorrie 1.9
827 lgorrie 1.21 (definterface call-with-lock-held (lock function)
828     "Call FUNCTION with LOCK held, queueing if necessary."
829 heller 1.24 (declare (ignore lock)
830     (type function function))
831 lgorrie 1.21 (funcall function))
832 heller 1.25
833     (definterface current-thread ()
834     "Return the currently executing thread."
835     0)
836 heller 1.28
837     (definterface all-threads ()
838     "Return a list of all threads.")
839    
840     (definterface thread-alive-p (thread)
841 heller 1.35 "Test if THREAD is termintated."
842     (member thread (all-threads)))
843 heller 1.25
844     (definterface interrupt-thread (thread fn)
845     "Cause THREAD to execute FN.")
846    
847 mbaringer 1.34 (definterface kill-thread (thread)
848     "Kill THREAD."
849     (declare (ignore thread))
850     nil)
851    
852 heller 1.25 (definterface send (thread object)
853     "Send OBJECT to thread THREAD.")
854    
855     (definterface receive ()
856 heller 1.84 "Return the next message from current thread's mailbox.")
857 mbaringer 1.78
858 heller 1.81 (definterface toggle-trace (spec)
859     "Toggle tracing of the function(s) given with SPEC.
860     SPEC can be:
861     (setf NAME) ; a setf function
862     (:defmethod NAME QUALIFIER... (SPECIALIZER...)) ; a specific method
863     (:defgeneric NAME) ; a generic function with all methods
864     (:call CALLER CALLEE) ; trace calls from CALLER to CALLEE.
865     (:labels TOPLEVEL LOCAL)
866     (:flet TOPLEVEL LOCAL) ")
867 mkoeppe 1.87
868    
869     ;;;; Weak datastructures
870    
871     (definterface make-weak-key-hash-table (&rest args)
872     "Like MAKE-HASH-TABLE, but weak w.r.t. the keys."
873     (apply #'make-hash-table args))
874    
875     (definterface make-weak-value-hash-table (&rest args)
876     "Like MAKE-HASH-TABLE, but weak w.r.t. the values."
877     (apply #'make-hash-table args))

  ViewVC Help
Powered by ViewVC 1.1.5