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

Contents of /slime/swank-backend.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.155 - (show annotations)
Sat Oct 4 19:13:41 2008 UTC (5 years, 6 months ago) by heller
Branch: MAIN
Changes since 1.154: +17 -8 lines
Some cleanups for compilation commands.

* slime.el ([defstruct] slime-compilation-result): Rename result
slot as successp.
(slime-make-compilation-finished-continuation): Deleted.
slime-eval-async preserves the current buffer and preserving the
window-configuration was always a questionable feature.
(slime-compilation-finished): Simplified.
(slime-show-note-counts): Also show the success/failure flag.
(slime-recompile-locations): Take a continuation as argument
rather than messing around with compilation-finished-hooks.
(slime-aggregate-compilation-results): New function.
(slime-xref-recompilation-cont): Renamed from
slime-make-xref-recompilation-cont.
(slime-compiler-results): Deleted.
(slime-goto-first-note-after-compilation): Replaced with hook
function slime-goto-first-note.
(slime-compilation-just-finished): Deleted.
(slime-to-lisp-filename-function): Use convert-standard-filename.
* swank.lisp ([defstruct] compilation-result): Renamed from
swank-compilation-result.
(measure-time-interval): Return seconds as float.
(collect-notes): Renamed from swank-compiler.  Return a single
compilation-result.
(compile-multiple-strings-for-emacs): Return a list of
compilation-results instead of a single result with merged notes.

* swank-backend.lisp (filename-to-pathname): Renamed from
parse-emacs-filename.  Updated callers.
(pathname-to-filename): New function.  Use it where appropriate.

* swank-scl.lisp (pathname-to-filename): Implement it in the
backend to get rid of the #+scl in swank.lisp.

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

  ViewVC Help
Powered by ViewVC 1.1.5