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

Contents of /slime/swank-backend.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.141 - (show annotations)
Fri Aug 8 13:43:33 2008 UTC (5 years, 8 months ago) by heller
Branch: MAIN
Changes since 1.140: +0 -9 lines
Spawn the auto-flush thread in the front end.
This removes some copy&paste code in various backends.

* swank.lisp (auto-flush-loop): New function.
(open-streams): Use it.
* swank-backend.lisp (make-stream-interactive): Deleted.
1 ;;; -*- Mode: lisp; indent-tabs-mode: nil; outline-regexp: ";;;;;*" -*-
2 ;;;
3 ;;; slime-backend.lisp --- SLIME backend interface.
4 ;;;
5 ;;; Created by James Bielman in 2003. Released into the public domain.
6 ;;;
7 ;;;; Frontmatter
8 ;;;
9 ;;; 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
13 (defpackage :swank-backend
14 (:use :common-lisp)
15 (:export #:sldb-condition
16 #:original-condition
17 #:compiler-condition
18 #:message
19 #:short-message
20 #:condition
21 #:severity
22 #:with-compilation-hooks
23 #:location
24 #:location-p
25 #:location-buffer
26 #:location-position
27 #:position-p
28 #:position-pos
29 #:print-output-to-string
30 #:quit-lisp
31 #:references
32 #:unbound-slot-filler
33 #:declaration-arglist
34 #:type-specifier-arglist
35 ;; interrupt macro for the backend
36 #:*pending-slime-interrupts*
37 #:check-slime-interrupts
38 ;; inspector related symbols
39 #:emacs-inspect
40 #:label-value-line
41 #:label-value-line*
42
43 #:with-struct
44 ))
45
46 (defpackage :swank-mop
47 (:use)
48 (:export
49 ;; classes
50 #:standard-generic-function
51 #:standard-slot-definition
52 #:standard-method
53 #:standard-class
54 #:eql-specializer
55 #:eql-specializer-object
56 ;; standard-class readers
57 #:class-default-initargs
58 #:class-direct-default-initargs
59 #:class-direct-slots
60 #:class-direct-subclasses
61 #:class-direct-superclasses
62 #:class-finalized-p
63 #:class-name
64 #:class-precedence-list
65 #:class-prototype
66 #:class-slots
67 #:specializer-direct-methods
68 ;; generic function readers
69 #:generic-function-argument-precedence-order
70 #:generic-function-declarations
71 #:generic-function-lambda-list
72 #:generic-function-methods
73 #:generic-function-method-class
74 #:generic-function-method-combination
75 #:generic-function-name
76 ;; method readers
77 #:method-generic-function
78 #:method-function
79 #:method-lambda-list
80 #:method-specializers
81 #:method-qualifiers
82 ;; slot readers
83 #:slot-definition-allocation
84 #:slot-definition-documentation
85 #:slot-definition-initargs
86 #:slot-definition-initform
87 #:slot-definition-initfunction
88 #:slot-definition-name
89 #:slot-definition-type
90 #:slot-definition-readers
91 #:slot-definition-writers
92 #:slot-boundp-using-class
93 #:slot-value-using-class
94 #:slot-makunbound-using-class
95 ;; generic function protocol
96 #:compute-applicable-methods-using-classes
97 #:finalize-inheritance))
98
99 (in-package :swank-backend)
100
101
102 ;;;; Metacode
103
104 (defparameter *interface-functions* '()
105 "The names of all interface functions.")
106
107 (defparameter *unimplemented-interfaces* '()
108 "List of interface functions that are not implemented.
109 DEFINTERFACE adds to this list and DEFIMPLEMENTATION removes.")
110
111 (defmacro definterface (name args documentation &rest default-body)
112 "Define an interface function for the backend to implement.
113 A function is defined with NAME, ARGS, and DOCUMENTATION. This
114 function first looks for a function to call in NAME's property list
115 that is indicated by 'IMPLEMENTATION; failing that, it looks for a
116 function indicated by 'DEFAULT. If neither is present, an error is
117 signaled.
118
119 If a DEFAULT-BODY is supplied, then a function with the same body and
120 ARGS will be added to NAME's property list as the property indicated
121 by 'DEFAULT.
122
123 Backends implement these functions using DEFIMPLEMENTATION."
124 (check-type documentation string "a documentation string")
125 (assert (every #'symbolp args) ()
126 "Complex lambda-list not supported: ~S ~S" name args)
127 (labels ((gen-default-impl ()
128 `(setf (get ',name 'default) (lambda ,args ,@default-body)))
129 (args-as-list (args)
130 (destructuring-bind (req opt key rest) (parse-lambda-list args)
131 `(,@req ,@opt
132 ,@(loop for k in key append `(,(kw k) ,k))
133 ,@(or rest '(())))))
134 (parse-lambda-list (args)
135 (parse args '(&optional &key &rest)
136 (make-array 4 :initial-element nil)))
137 (parse (args keywords vars)
138 (cond ((null args)
139 (reverse (map 'list #'reverse vars)))
140 ((member (car args) keywords)
141 (parse (cdr args) (cdr (member (car args) keywords)) vars))
142 (t (push (car args) (aref vars (length keywords)))
143 (parse (cdr args) keywords vars))))
144 (kw (s) (intern (string s) :keyword)))
145 `(progn
146 (defun ,name ,args
147 ,documentation
148 (let ((f (or (get ',name 'implementation)
149 (get ',name 'default))))
150 (cond (f (apply f ,@(args-as-list args)))
151 (t (error "~S not implementated" ',name)))))
152 (pushnew ',name *interface-functions*)
153 ,(if (null default-body)
154 `(pushnew ',name *unimplemented-interfaces*)
155 (gen-default-impl))
156 ;; see <http://www.franz.com/support/documentation/6.2/doc/pages/variables/compiler/s_cltl1-compile-file-toplevel-compatibility-p_s.htm>
157 (eval-when (:compile-toplevel :load-toplevel :execute)
158 (export ',name :swank-backend))
159 ',name)))
160
161 (defmacro defimplementation (name args &body body)
162 (assert (every #'symbolp args) ()
163 "Complex lambda-list not supported: ~S ~S" name args)
164 `(progn
165 (setf (get ',name 'implementation) (lambda ,args ,@body))
166 (if (member ',name *interface-functions*)
167 (setq *unimplemented-interfaces*
168 (remove ',name *unimplemented-interfaces*))
169 (warn "DEFIMPLEMENTATION of undefined interface (~S)" ',name))
170 ',name))
171
172 (defun warn-unimplemented-interfaces ()
173 "Warn the user about unimplemented backend features.
174 The portable code calls this function at startup."
175 (warn "These Swank interfaces are unimplemented:~% ~A"
176 (sort (copy-list *unimplemented-interfaces*) #'string<)))
177
178 (defun import-to-swank-mop (symbol-list)
179 (dolist (sym symbol-list)
180 (let* ((swank-mop-sym (find-symbol (symbol-name sym) :swank-mop)))
181 (when swank-mop-sym
182 (unintern swank-mop-sym :swank-mop))
183 (import sym :swank-mop)
184 (export sym :swank-mop))))
185
186 (defun import-swank-mop-symbols (package except)
187 "Import the mop symbols from PACKAGE to SWANK-MOP.
188 EXCEPT is a list of symbol names which should be ignored."
189 (do-symbols (s :swank-mop)
190 (unless (member s except :test #'string=)
191 (let ((real-symbol (find-symbol (string s) package)))
192 (assert real-symbol () "Symbol ~A not found in package ~A" s package)
193 (unintern s :swank-mop)
194 (import real-symbol :swank-mop)
195 (export real-symbol :swank-mop)))))
196
197 (defvar *gray-stream-symbols*
198 '(:fundamental-character-output-stream
199 :stream-write-char
200 :stream-write-string
201 :stream-fresh-line
202 :stream-force-output
203 :stream-finish-output
204 :fundamental-character-input-stream
205 :stream-read-char
206 :stream-listen
207 :stream-unread-char
208 :stream-clear-input
209 :stream-line-column
210 :stream-read-char-no-hang
211 ;; STREAM-LINE-LENGTH is an extension to gray streams that's apparently
212 ;; supported by CMUCL, OpenMCL, SBCL and SCL.
213 #+(or cmu openmcl sbcl scl)
214 :stream-line-length))
215
216 (defun import-from (package symbol-names &optional (to-package *package*))
217 "Import the list of SYMBOL-NAMES found in the package PACKAGE."
218 (dolist (name symbol-names)
219 (multiple-value-bind (symbol found) (find-symbol (string name) package)
220 (assert found () "Symbol ~A not found in package ~A" name package)
221 (import symbol to-package))))
222
223
224 ;;;; Utilities
225
226 (defmacro with-struct ((conc-name &rest names) obj &body body)
227 "Like with-slots but works only for structs."
228 (flet ((reader (slot) (intern (concatenate 'string
229 (symbol-name conc-name)
230 (symbol-name slot))
231 (symbol-package conc-name))))
232 (let ((tmp (gensym "OO-")))
233 ` (let ((,tmp ,obj))
234 (symbol-macrolet
235 ,(loop for name in names collect
236 (typecase name
237 (symbol `(,name (,(reader name) ,tmp)))
238 (cons `(,(first name) (,(reader (second name)) ,tmp)))
239 (t (error "Malformed syntax in WITH-STRUCT: ~A" name))))
240 ,@body)))))
241
242
243 ;;;; TCP server
244
245 (definterface create-socket (host port)
246 "Create a listening TCP socket on interface HOST and port PORT .")
247
248 (definterface local-port (socket)
249 "Return the local port number of SOCKET.")
250
251 (definterface close-socket (socket)
252 "Close the socket SOCKET.")
253
254 (definterface accept-connection (socket &key external-format
255 buffering timeout)
256 "Accept a client connection on the listening socket SOCKET.
257 Return a stream for the new connection.")
258
259 (definterface add-sigio-handler (socket fn)
260 "Call FN whenever SOCKET is readable.")
261
262 (definterface remove-sigio-handlers (socket)
263 "Remove all sigio handlers for SOCKET.")
264
265 (definterface add-fd-handler (socket fn)
266 "Call FN when Lisp is waiting for input and SOCKET is readable.")
267
268 (definterface remove-fd-handlers (socket)
269 "Remove all fd-handlers for SOCKET.")
270
271 (definterface preferred-communication-style ()
272 "Return one of the symbols :spawn, :sigio, :fd-handler, or NIL."
273 nil)
274
275 (definterface set-stream-timeout (stream timeout)
276 "Set the 'stream 'timeout. The timeout is either the real number
277 specifying the timeout in seconds or 'nil for no timeout."
278 (declare (ignore stream timeout))
279 nil)
280
281 ;;; Base condition for networking errors.
282 (define-condition network-error (simple-error) ())
283
284 (definterface emacs-connected ()
285 "Hook called when the first connection from Emacs is established.
286 Called from the INIT-FN of the socket server that accepts the
287 connection.
288
289 This is intended for setting up extra context, e.g. to discover
290 that the calling thread is the one that interacts with Emacs."
291 nil)
292
293
294 ;;;; Unix signals
295
296 (defconstant +sigint+ 2)
297
298 (definterface call-without-interrupts (fn)
299 "Call FN in a context where interrupts are disabled."
300 (funcall fn))
301
302 (definterface getpid ()
303 "Return the (Unix) process ID of this superior Lisp.")
304
305 (definterface lisp-implementation-type-name ()
306 "Return a short name for the Lisp implementation."
307 (lisp-implementation-type))
308
309 (definterface default-directory ()
310 "Return the default directory."
311 (directory-namestring (truename *default-pathname-defaults*)))
312
313 (definterface set-default-directory (directory)
314 "Set the default directory.
315 This is used to resolve filenames without directory component."
316 (setf *default-pathname-defaults* (truename (merge-pathnames directory)))
317 (default-directory))
318
319 (definterface call-with-syntax-hooks (fn)
320 "Call FN with hooks to handle special syntax."
321 (funcall fn))
322
323 (definterface default-readtable-alist ()
324 "Return a suitable initial value for SWANK:*READTABLE-ALIST*."
325 '())
326
327 (definterface quit-lisp ()
328 "Exit the current lisp image.")
329
330
331 ;;;; Compilation
332
333 (definterface call-with-compilation-hooks (func)
334 "Call FUNC with hooks to record compiler conditions.")
335
336 (defmacro with-compilation-hooks ((&rest ignore) &body body)
337 "Execute BODY as in CALL-WITH-COMPILATION-HOOKS."
338 (declare (ignore ignore))
339 `(call-with-compilation-hooks (lambda () (progn ,@body))))
340
341 (definterface swank-compile-string (string &key buffer position directory debug)
342 "Compile source from STRING. During compilation, compiler
343 conditions must be trapped and resignalled as COMPILER-CONDITIONs.
344
345 If supplied, BUFFER and POSITION specify the source location in Emacs.
346
347 Additionally, if POSITION is supplied, it must be added to source
348 positions reported in compiler conditions.
349
350 If DIRECTORY is specified it may be used by certain implementations to
351 rebind *DEFAULT-PATHNAME-DEFAULTS* which may improve the recording of
352 source information.
353
354 If DEBUG is supplied, and non-NIL, it may be used by certain
355 implementations to compile with a debug optimization quality of its
356 value.
357
358 Should return T on successfull compilation, NIL otherwise.
359 ")
360
361 (definterface swank-compile-file (filename load-p external-format)
362 "Compile FILENAME signalling COMPILE-CONDITIONs.
363 If LOAD-P is true, load the file after compilation.
364 EXTERNAL-FORMAT is a value returned by find-external-format or
365 :default.
366
367 Should return T on successfull compilation, NIL otherwise.")
368
369 (deftype severity ()
370 '(member :error :read-error :warning :style-warning :note))
371
372 ;; Base condition type for compiler errors, warnings and notes.
373 (define-condition compiler-condition (condition)
374 ((original-condition
375 ;; The original condition thrown by the compiler if appropriate.
376 ;; May be NIL if a compiler does not report using conditions.
377 :type (or null condition)
378 :initarg :original-condition
379 :accessor original-condition)
380
381 (severity :type severity
382 :initarg :severity
383 :accessor severity)
384
385 (message :initarg :message
386 :accessor message)
387
388 (short-message :initarg :short-message
389 :initform nil
390 :accessor short-message)
391
392 (references :initarg :references
393 :initform nil
394 :accessor references)
395
396 (location :initarg :location
397 :accessor location)))
398
399 (definterface find-external-format (coding-system)
400 "Return a \"external file format designator\" for CODING-SYSTEM.
401 CODING-SYSTEM is Emacs-style coding system name (a string),
402 e.g. \"latin-1-unix\"."
403 (if (equal coding-system "iso-latin-1-unix")
404 :default
405 nil))
406
407 (definterface guess-external-format (filename)
408 "Detect the external format for the file with name FILENAME.
409 Return nil if the file contains no special markers."
410 ;; Look for a Emacs-style -*- coding: ... -*- or Local Variable: section.
411 (with-open-file (s filename :if-does-not-exist nil
412 :external-format (or (find-external-format "latin-1-unix")
413 :default))
414 (if s
415 (or (let* ((line (read-line s nil))
416 (p (search "-*-" line)))
417 (when p
418 (let* ((start (+ p (length "-*-")))
419 (end (search "-*-" line :start2 start)))
420 (when end
421 (%search-coding line start end)))))
422 (let* ((len (file-length s))
423 (buf (make-string (min len 3000))))
424 (file-position s (- len (length buf)))
425 (read-sequence buf s)
426 (let ((start (search "Local Variables:" buf :from-end t))
427 (end (search "End:" buf :from-end t)))
428 (and start end (< start end)
429 (%search-coding buf start end))))))))
430
431 (defun %search-coding (str start end)
432 (let ((p (search "coding:" str :start2 start :end2 end)))
433 (when p
434 (incf p (length "coding:"))
435 (loop while (and (< p end)
436 (member (aref str p) '(#\space #\tab)))
437 do (incf p))
438 (let ((end (position-if (lambda (c) (find c '(#\space #\tab #\newline)))
439 str :start p)))
440 (find-external-format (subseq str p end))))))
441
442
443 ;;;; Streams
444
445 (definterface make-fn-streams (input-fn output-fn)
446 "Return character input and output streams backended by functions.
447 When input is needed, INPUT-FN is called with no arguments to
448 return a string.
449 When output is ready, OUTPUT-FN is called with the output as its
450 argument.
451
452 Output should be forced to OUTPUT-FN before calling INPUT-FN.
453
454 The streams are returned as two values.")
455
456
457 ;;;; Documentation
458
459 (definterface arglist (name)
460 "Return the lambda list for the symbol NAME. NAME can also be
461 a lisp function object, on lisps which support this.
462
463 The result can be a list or the :not-available keyword if the
464 arglist cannot be determined."
465 (declare (ignore name))
466 :not-available)
467
468 (defgeneric declaration-arglist (decl-identifier)
469 (:documentation
470 "Return the argument list of the declaration specifier belonging to the
471 declaration identifier DECL-IDENTIFIER. If the arglist cannot be determined,
472 the keyword :NOT-AVAILABLE is returned.
473
474 The different SWANK backends can specialize this generic function to
475 include implementation-dependend declaration specifiers, or to provide
476 additional information on the specifiers defined in ANSI Common Lisp.")
477 (:method (decl-identifier)
478 (case decl-identifier
479 (dynamic-extent '(&rest vars))
480 (ignore '(&rest vars))
481 (ignorable '(&rest vars))
482 (special '(&rest vars))
483 (inline '(&rest function-names))
484 (notinline '(&rest function-name))
485 (optimize '(&any compilation-speed debug safety space speed))
486 (type '(type-specifier &rest args))
487 (ftype '(type-specifier &rest function-names))
488 (otherwise
489 (flet ((typespec-p (symbol) (member :type (describe-symbol-for-emacs symbol))))
490 (cond ((and (symbolp decl-identifier) (typespec-p decl-identifier))
491 '(&rest vars))
492 ((and (listp decl-identifier) (typespec-p (first decl-identifier)))
493 '(&rest vars))
494 (t :not-available)))))))
495
496 (defgeneric type-specifier-arglist (typespec-operator)
497 (:documentation
498 "Return the argument list of the type specifier belonging to
499 TYPESPEC-OPERATOR.. If the arglist cannot be determined, the keyword
500 :NOT-AVAILABLE is returned.
501
502 The different SWANK backends can specialize this generic function to
503 include implementation-dependend declaration specifiers, or to provide
504 additional information on the specifiers defined in ANSI Common Lisp.")
505 (:method (typespec-operator)
506 (declare (special *type-specifier-arglists*)) ; defined at end of file.
507 (typecase typespec-operator
508 (symbol (or (cdr (assoc typespec-operator *type-specifier-arglists*))
509 :not-available))
510 (t :not-available))))
511
512 (definterface function-name (function)
513 "Return the name of the function object FUNCTION.
514
515 The result is either a symbol, a list, or NIL if no function name is available."
516 (declare (ignore function))
517 nil)
518
519 (definterface macroexpand-all (form)
520 "Recursively expand all macros in FORM.
521 Return the resulting form.")
522
523 (definterface compiler-macroexpand-1 (form &optional env)
524 "Call the compiler-macro for form.
525 If FORM is a function call for which a compiler-macro has been
526 defined, invoke the expander function using *macroexpand-hook* and
527 return the results and T. Otherwise, return the original form and
528 NIL."
529 (let ((fun (and (consp form) (compiler-macro-function (car form)))))
530 (if fun
531 (let ((result (funcall *macroexpand-hook* fun form env)))
532 (values result (not (eq result form))))
533 (values form nil))))
534
535 (definterface compiler-macroexpand (form &optional env)
536 "Repetitively call `compiler-macroexpand-1'."
537 (labels ((frob (form expanded)
538 (multiple-value-bind (new-form newly-expanded)
539 (compiler-macroexpand-1 form env)
540 (if newly-expanded
541 (frob new-form t)
542 (values new-form expanded)))))
543 (frob form env)))
544
545 (definterface describe-symbol-for-emacs (symbol)
546 "Return a property list describing SYMBOL.
547
548 The property list has an entry for each interesting aspect of the
549 symbol. The recognised keys are:
550
551 :VARIABLE :FUNCTION :SETF :SPECIAL-OPERATOR :MACRO :COMPILER-MACRO
552 :TYPE :CLASS :ALIEN-TYPE :ALIEN-STRUCT :ALIEN-UNION :ALIEN-ENUM
553
554 The value of each property is the corresponding documentation string,
555 or :NOT-DOCUMENTED. It is legal to include keys not listed here (but
556 slime-print-apropos in Emacs must know about them).
557
558 Properties should be included if and only if they are applicable to
559 the symbol. For example, only (and all) fbound symbols should include
560 the :FUNCTION property.
561
562 Example:
563 \(describe-symbol-for-emacs 'vector)
564 => (:CLASS :NOT-DOCUMENTED
565 :TYPE :NOT-DOCUMENTED
566 :FUNCTION \"Constructs a simple-vector from the given objects.\")")
567
568 (definterface describe-definition (name type)
569 "Describe the definition NAME of TYPE.
570 TYPE can be any value returned by DESCRIBE-SYMBOL-FOR-EMACS.
571
572 Return a documentation string, or NIL if none is available.")
573
574
575 ;;;; Debugging
576
577 (definterface install-debugger-globally (function)
578 "Install FUNCTION as the debugger for all threads/processes. This
579 usually involves setting *DEBUGGER-HOOK* and, if the implementation
580 permits, hooking into BREAK as well."
581 (setq *debugger-hook* function))
582
583 (definterface call-with-debugging-environment (debugger-loop-fn)
584 "Call DEBUGGER-LOOP-FN in a suitable debugging environment.
585
586 This function is called recursively at each debug level to invoke the
587 debugger loop. The purpose is to setup any necessary environment for
588 other debugger callbacks that will be called within the debugger loop.
589
590 For example, this is a reasonable place to compute a backtrace, switch
591 to safe reader/printer settings, and so on.")
592
593 (definterface call-with-debugger-hook (hook fun)
594 "Call FUN and use HOOK as debugger hook.
595
596 HOOK should be called for both BREAK and INVOKE-DEBUGGER."
597 (let ((*debugger-hook* hook))
598 (funcall fun)))
599
600 (define-condition sldb-condition (condition)
601 ((original-condition
602 :initarg :original-condition
603 :accessor original-condition))
604 (:report (lambda (condition stream)
605 (format stream "Condition in debugger code~@[: ~A~]"
606 (original-condition condition))))
607 (:documentation
608 "Wrapper for conditions that should not be debugged.
609
610 When a condition arises from the internals of the debugger, it is not
611 desirable to debug it -- we'd risk entering an endless loop trying to
612 debug the debugger! Instead, such conditions can be reported to the
613 user without (re)entering the debugger by wrapping them as
614 `sldb-condition's."))
615
616 (definterface compute-sane-restarts (condition)
617 "This is an opportunity for Lisps such as CLISP to remove
618 unwanted restarts from the output of CL:COMPUTE-RESTARTS,
619 otherwise it should simply call CL:COMPUTE-RESTARTS, which is
620 what the default implementation does."
621 (compute-restarts condition))
622
623 ;;; The following functions in this section are supposed to be called
624 ;;; within the dynamic contour of CALL-WITH-DEBUGGING-ENVIRONMENT only.
625
626 (definterface compute-backtrace (start end)
627 "Returns a backtrace of the condition currently being debugged,
628 that is an ordered list consisting of frames. (What constitutes a
629 frame is implementation dependent, but PRINT-FRAME must be defined on
630 it.)
631
632 ``Ordered list'' means that the i-th. frame is associated to the
633 frame-number i.
634
635 START and END are zero-based indices constraining the number of frames
636 returned. Frame zero is defined as the frame which invoked the
637 debugger. If END is nil, return the frames from START to the end of
638 the stack.")
639
640 (definterface print-frame (frame stream)
641 "Print frame to stream.")
642
643 (definterface frame-source-location-for-emacs (frame-number)
644 "Return the source location for the frame associated to FRAME-NUMBER.")
645
646 (definterface frame-catch-tags (frame-number)
647 "Return a list of catch tags for being printed in a debugger stack
648 frame.")
649
650 (definterface frame-locals (frame-number)
651 "Return a list of ((&key NAME ID VALUE) ...) where each element of
652 the list represents a local variable in the stack frame associated to
653 FRAME-NUMBER.
654
655 NAME, a symbol; the name of the local variable.
656
657 ID, an integer; used as primary key for the local variable, unique
658 relatively to the frame under operation.
659
660 value, an object; the value of the local variable.")
661
662 (definterface frame-var-value (frame-number var-id)
663 "Return the value of the local variable associated to VAR-ID
664 relatively to the frame associated to FRAME-NUMBER.")
665
666 (definterface disassemble-frame (frame-number)
667 "Disassemble the code for the FRAME-NUMBER.
668 The output should be written to standard output.
669 FRAME-NUMBER is a non-negative integer.")
670
671 (definterface eval-in-frame (form frame-number)
672 "Evaluate a Lisp form in the lexical context of a stack frame
673 in the debugger.
674
675 FRAME-NUMBER must be a positive integer with 0 indicating the
676 frame which invoked the debugger.
677
678 The return value is the result of evaulating FORM in the
679 appropriate context.")
680
681 (definterface return-from-frame (frame-number form)
682 "Unwind the stack to the frame FRAME-NUMBER and return the value(s)
683 produced by evaluating FORM in the frame context to its caller.
684
685 Execute any clean-up code from unwind-protect forms above the frame
686 during unwinding.
687
688 Return a string describing the error if it's not possible to return
689 from the frame.")
690
691 (definterface restart-frame (frame-number)
692 "Restart execution of the frame FRAME-NUMBER with the same arguments
693 as it was called originally.")
694
695 (definterface format-sldb-condition (condition)
696 "Format a condition for display in SLDB."
697 (princ-to-string condition))
698
699 (definterface condition-extras (condition)
700 "Return a list of extra for the debugger.
701 The allowed elements are of the form:
702 (:SHOW-FRAME-SOURCE frame-number)
703 (:REFERENCES &rest refs)
704 "
705 (declare (ignore condition))
706 '())
707
708 (definterface activate-stepping (frame-number)
709 "Prepare the frame FRAME-NUMBER for stepping.")
710
711 (definterface sldb-break-on-return (frame-number)
712 "Set a breakpoint in the frame FRAME-NUMBER.")
713
714 (definterface sldb-break-at-start (symbol)
715 "Set a breakpoint on the beginning of the function for SYMBOL.")
716
717 (definterface sldb-stepper-condition-p (condition)
718 "Return true if SLDB was invoked due to a single-stepping condition,
719 false otherwise. "
720 (declare (ignore condition))
721 nil)
722
723 (definterface sldb-step-into ()
724 "Step into the current single-stepper form.")
725
726 (definterface sldb-step-next ()
727 "Step to the next form in the current function.")
728
729 (definterface sldb-step-out ()
730 "Stop single-stepping temporarily, but resume it once the current function
731 returns.")
732
733
734 ;;;; Definition finding
735
736 (defstruct (:location (:type list) :named
737 (:constructor make-location
738 (buffer position &optional hints)))
739 buffer position
740 ;; Hints is a property list optionally containing:
741 ;; :snippet SOURCE-TEXT
742 ;; This is a snippet of the actual source text at the start of
743 ;; the definition, which could be used in a text search.
744 hints)
745
746 (defstruct (:error (:type list) :named (:constructor)) message)
747 (defstruct (:file (:type list) :named (:constructor)) name)
748 (defstruct (:buffer (:type list) :named (:constructor)) name)
749 (defstruct (:position (:type list) :named (:constructor)) pos)
750
751 (definterface find-definitions (name)
752 "Return a list ((DSPEC LOCATION) ...) for NAME's definitions.
753
754 NAME is a \"definition specifier\".
755
756 DSPEC is a \"definition specifier\" describing the
757 definition, e.g., FOO or (METHOD FOO (STRING NUMBER)) or
758 \(DEFVAR FOO).
759
760 LOCATION is the source location for the definition.")
761
762 (definterface find-source-location (object)
763 "Returns the source location of OBJECT, or NIL.
764
765 That is the source location of the underlying datastructure of
766 OBJECT. E.g. on a STANDARD-OBJECT, the source location of the
767 respective DEFCLASS definition is returned, on a STRUCTURE-CLASS the
768 respective DEFSTRUCT definition, and so on."
769 ;; This returns one source location and not a list of locations. It's
770 ;; supposed to return the location of the DEFGENERIC definition on
771 ;; #'SOME-GENERIC-FUNCTION.
772 )
773
774
775 (definterface buffer-first-change (filename)
776 "Called for effect the first time FILENAME's buffer is modified."
777 (declare (ignore filename))
778 nil)
779
780
781
782 ;;;; XREF
783
784 (definterface who-calls (function-name)
785 "Return the call sites of FUNCTION-NAME (a symbol).
786 The results is a list ((DSPEC LOCATION) ...).")
787
788 (definterface calls-who (function-name)
789 "Return the call sites of FUNCTION-NAME (a symbol).
790 The results is a list ((DSPEC LOCATION) ...).")
791
792 (definterface who-references (variable-name)
793 "Return the locations where VARIABLE-NAME (a symbol) is referenced.
794 See WHO-CALLS for a description of the return value.")
795
796 (definterface who-binds (variable-name)
797 "Return the locations where VARIABLE-NAME (a symbol) is bound.
798 See WHO-CALLS for a description of the return value.")
799
800 (definterface who-sets (variable-name)
801 "Return the locations where VARIABLE-NAME (a symbol) is set.
802 See WHO-CALLS for a description of the return value.")
803
804 (definterface who-macroexpands (macro-name)
805 "Return the locations where MACRO-NAME (a symbol) is expanded.
806 See WHO-CALLS for a description of the return value.")
807
808 (definterface who-specializes (class-name)
809 "Return the locations where CLASS-NAME (a symbol) is specialized.
810 See WHO-CALLS for a description of the return value.")
811
812 ;;; Simpler variants.
813
814 (definterface list-callers (function-name)
815 "List the callers of FUNCTION-NAME.
816 This function is like WHO-CALLS except that it is expected to use
817 lower-level means. Whereas WHO-CALLS is usually implemented with
818 special compiler support, LIST-CALLERS is usually implemented by
819 groveling for constants in function objects throughout the heap.
820
821 The return value is as for WHO-CALLS.")
822
823 (definterface list-callees (function-name)
824 "List the functions called by FUNCTION-NAME.
825 See LIST-CALLERS for a description of the return value.")
826
827
828 ;;;; Profiling
829
830 ;;; The following functions define a minimal profiling interface.
831
832 (definterface profile (fname)
833 "Marks symbol FNAME for profiling.")
834
835 (definterface profiled-functions ()
836 "Returns a list of profiled functions.")
837
838 (definterface unprofile (fname)
839 "Marks symbol FNAME as not profiled.")
840
841 (definterface unprofile-all ()
842 "Marks all currently profiled functions as not profiled."
843 (dolist (f (profiled-functions))
844 (unprofile f)))
845
846 (definterface profile-report ()
847 "Prints profile report.")
848
849 (definterface profile-reset ()
850 "Resets profile counters.")
851
852 (definterface profile-package (package callers-p methods)
853 "Wrap profiling code around all functions in PACKAGE. If a function
854 is already profiled, then unprofile and reprofile (useful to notice
855 function redefinition.)
856
857 If CALLERS-P is T names have counts of the most common calling
858 functions recorded.
859
860 When called with arguments :METHODS T, profile all methods of all
861 generic functions having names in the given package. Generic functions
862 themselves, that is, their dispatch functions, are left alone.")
863
864
865 ;;;; Inspector
866
867 (defgeneric emacs-inspect (object)
868 (:documentation
869 "Explain to Emacs how to inspect OBJECT.
870
871 Returns a list specifying how to render the object for inspection.
872
873 Every element of the list must be either a string, which will be
874 inserted into the buffer as is, or a list of the form:
875
876 (:value object &optional format) - Render an inspectable
877 object. If format is provided it must be a string and will be
878 rendered in place of the value, otherwise use princ-to-string.
879
880 (:newline) - Render a \\n
881
882 (:action label lambda &key (refresh t)) - Render LABEL (a text
883 string) which when clicked will call LAMBDA. If REFRESH is
884 non-NIL the currently inspected object will be re-inspected
885 after calling the lambda.
886 "))
887
888 (defmethod emacs-inspect ((object t))
889 "Generic method for inspecting any kind of object.
890
891 Since we don't know how to deal with OBJECT we simply dump the
892 output of CL:DESCRIBE."
893 `("Type: " (:value ,(type-of object)) (:newline)
894 "Don't know how to inspect the object, dumping output of CL:DESCRIBE:"
895 (:newline) (:newline)
896 ,(with-output-to-string (desc) (describe object desc))))
897
898 ;;; Utilities for inspector methods.
899 ;;;
900 (defun label-value-line (label value &key (newline t))
901 "Create a control list which prints \"LABEL: VALUE\" in the inspector.
902 If NEWLINE is non-NIL a `(:newline)' is added to the result."
903 (list* (princ-to-string label) ": " `(:value ,value)
904 (if newline '((:newline)) nil)))
905
906 (defmacro label-value-line* (&rest label-values)
907 ` (append ,@(loop for (label value) in label-values
908 collect `(label-value-line ,label ,value))))
909
910 (definterface describe-primitive-type (object)
911 "Return a string describing the primitive type of object."
912 (declare (ignore object))
913 "N/A")
914
915
916 ;;;; Multithreading
917 ;;;
918 ;;; The default implementations are sufficient for non-multiprocessing
919 ;;; implementations.
920
921 (definterface initialize-multiprocessing (continuation)
922 "Initialize multiprocessing, if necessary and then invoke CONTINUATION.
923
924 Depending on the impleimentaion, this function may never return."
925 (funcall continuation))
926
927 (definterface spawn (fn &key name)
928 "Create a new thread to call FN.")
929
930 (definterface thread-id (thread)
931 "Return an Emacs-parsable object to identify THREAD.
932
933 Ids should be comparable with equal, i.e.:
934 (equal (thread-id <t1>) (thread-id <t2>)) <==> (eq <t1> <t2>)"
935 thread)
936
937 (definterface find-thread (id)
938 "Return the thread for ID.
939 ID should be an id previously obtained with THREAD-ID.
940 Can return nil if the thread no longer exists.")
941
942 (definterface thread-name (thread)
943 "Return the name of THREAD.
944
945 Thread names are be single-line strings and are meaningful to the
946 user. They do not have to be unique."
947 (declare (ignore thread))
948 "The One True Thread")
949
950 (definterface thread-status (thread)
951 "Return a string describing THREAD's state."
952 (declare (ignore thread))
953 "")
954
955 (definterface thread-description (thread)
956 "Return a string describing THREAD."
957 (declare (ignore thread))
958 "")
959
960 (definterface set-thread-description (thread description)
961 "Set THREAD's description to DESCRIPTION."
962 (declare (ignore thread description))
963 "")
964
965 (definterface make-lock (&key name)
966 "Make a lock for thread synchronization.
967 Only one thread may hold the lock (via CALL-WITH-LOCK-HELD) at a time
968 but that thread may hold it more than once."
969 (declare (ignore name))
970 :null-lock)
971
972 (definterface call-with-lock-held (lock function)
973 "Call FUNCTION with LOCK held, queueing if necessary."
974 (declare (ignore lock)
975 (type function function))
976 (funcall function))
977
978 (definterface current-thread ()
979 "Return the currently executing thread."
980 0)
981
982 (definterface all-threads ()
983 "Return a list of all threads.")
984
985 (definterface thread-alive-p (thread)
986 "Test if THREAD is termintated."
987 (member thread (all-threads)))
988
989 (definterface interrupt-thread (thread fn)
990 "Cause THREAD to execute FN.")
991
992 (definterface kill-thread (thread)
993 "Kill THREAD."
994 (declare (ignore thread))
995 nil)
996
997 (definterface send (thread object)
998 "Send OBJECT to thread THREAD.")
999
1000 (definterface receive ()
1001 "Return the next message from current thread's mailbox.")
1002
1003 (definterface receive-if (predicate)
1004 "Return the first message satisfiying PREDICATE.")
1005
1006 (defvar *pending-slime-interrupts*)
1007
1008 (defun check-slime-interrupts ()
1009 "Execute pending interrupts if any.
1010 This should be called periodically in operations which
1011 can take a long time to complete."
1012 (when (and (boundp '*pending-slime-interrupts*)
1013 *pending-slime-interrupts*)
1014 (funcall (pop *pending-slime-interrupts*))))
1015
1016 (definterface toggle-trace (spec)
1017 "Toggle tracing of the function(s) given with SPEC.
1018 SPEC can be:
1019 (setf NAME) ; a setf function
1020 (:defmethod NAME QUALIFIER... (SPECIALIZER...)) ; a specific method
1021 (:defgeneric NAME) ; a generic function with all methods
1022 (:call CALLER CALLEE) ; trace calls from CALLER to CALLEE.
1023 (:labels TOPLEVEL LOCAL)
1024 (:flet TOPLEVEL LOCAL) ")
1025
1026
1027 ;;;; Weak datastructures
1028
1029 (definterface make-weak-key-hash-table (&rest args)
1030 "Like MAKE-HASH-TABLE, but weak w.r.t. the keys."
1031 (apply #'make-hash-table args))
1032
1033 (definterface make-weak-value-hash-table (&rest args)
1034 "Like MAKE-HASH-TABLE, but weak w.r.t. the values."
1035 (apply #'make-hash-table args))
1036
1037 (definterface hash-table-weakness (hashtable)
1038 "Return nil or one of :key :value :key-or-value :key-and-value"
1039 (declare (ignore hashtable))
1040 nil)
1041
1042
1043 ;;;; Character names
1044
1045 (definterface character-completion-set (prefix matchp)
1046 "Return a list of names of characters that match PREFIX."
1047 ;; Handle the standard and semi-standard characters.
1048 (loop for name in '("Newline" "Space" "Tab" "Page" "Rubout"
1049 "Linefeed" "Return" "Backspace")
1050 when (funcall matchp prefix name)
1051 collect name))
1052
1053
1054 (defparameter *type-specifier-arglists*
1055 '((and . (&rest type-specifiers))
1056 (array . (&optional element-type dimension-spec))
1057 (base-string . (&optional size))
1058 (bit-vector . (&optional size))
1059 (complex . (&optional type-specifier))
1060 (cons . (&optional car-typespec cdr-typespec))
1061 (double-float . (&optional lower-limit upper-limit))
1062 (eql . (object))
1063 (float . (&optional lower-limit upper-limit))
1064 (function . (&optional arg-typespec value-typespec))
1065 (integer . (&optional lower-limit upper-limit))
1066 (long-float . (&optional lower-limit upper-limit))
1067 (member . (&rest eql-objects))
1068 (mod . (n))
1069 (not . (type-specifier))
1070 (or . (&rest type-specifiers))
1071 (rational . (&optional lower-limit upper-limit))
1072 (real . (&optional lower-limit upper-limit))
1073 (satisfies . (predicate-symbol))
1074 (short-float . (&optional lower-limit upper-limit))
1075 (signed-byte . (&optional size))
1076 (simple-array . (&optional element-type dimension-spec))
1077 (simple-base-string . (&optional size))
1078 (simple-bit-vector . (&optional size))
1079 (simple-string . (&optional size))
1080 (single-float . (&optional lower-limit upper-limit))
1081 (simple-vector . (&optional size))
1082 (string . (&optional size))
1083 (unsigned-byte . (&optional size))
1084 (values . (&rest typespecs))
1085 (vector . (&optional element-type size))
1086 ))

  ViewVC Help
Powered by ViewVC 1.1.5