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

Contents of /slime/swank-backend.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.169 - (show annotations)
Sat Jan 10 12:25:16 2009 UTC (5 years, 3 months ago) by heller
Branch: MAIN
Changes since 1.168: +3 -2 lines
* swank-backend.lisp (swank-compile-file): Take output-file as
additional argument.  Update backends accordingly.

* swank.lisp (*fasl-directory*): New variable.
(fasl-pathname): New function.
(compile-file-for-emacs): Use it.
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 #:slime-interrupt-queued
39 ;; inspector related symbols
40 #:emacs-inspect
41 #:label-value-line
42 #:label-value-line*
43
44 #:with-struct
45 ))
46
47 (defpackage :swank-mop
48 (:use)
49 (:export
50 ;; classes
51 #:standard-generic-function
52 #:standard-slot-definition
53 #:standard-method
54 #:standard-class
55 #:eql-specializer
56 #:eql-specializer-object
57 ;; standard-class readers
58 #:class-default-initargs
59 #:class-direct-default-initargs
60 #:class-direct-slots
61 #:class-direct-subclasses
62 #:class-direct-superclasses
63 #:class-finalized-p
64 #:class-name
65 #:class-precedence-list
66 #:class-prototype
67 #:class-slots
68 #:specializer-direct-methods
69 ;; generic function readers
70 #:generic-function-argument-precedence-order
71 #:generic-function-declarations
72 #:generic-function-lambda-list
73 #:generic-function-methods
74 #:generic-function-method-class
75 #:generic-function-method-combination
76 #:generic-function-name
77 ;; method readers
78 #:method-generic-function
79 #:method-function
80 #:method-lambda-list
81 #:method-specializers
82 #:method-qualifiers
83 ;; slot readers
84 #:slot-definition-allocation
85 #:slot-definition-documentation
86 #:slot-definition-initargs
87 #:slot-definition-initform
88 #:slot-definition-initfunction
89 #:slot-definition-name
90 #:slot-definition-type
91 #:slot-definition-readers
92 #:slot-definition-writers
93 #:slot-boundp-using-class
94 #:slot-value-using-class
95 #:slot-makunbound-using-class
96 ;; generic function protocol
97 #:compute-applicable-methods-using-classes
98 #:finalize-inheritance))
99
100 (in-package :swank-backend)
101
102
103 ;;;; Metacode
104
105 (defparameter *interface-functions* '()
106 "The names of all interface functions.")
107
108 (defparameter *unimplemented-interfaces* '()
109 "List of interface functions that are not implemented.
110 DEFINTERFACE adds to this list and DEFIMPLEMENTATION removes.")
111
112 (defmacro definterface (name args documentation &rest default-body)
113 "Define an interface function for the backend to implement.
114 A function is defined with NAME, ARGS, and DOCUMENTATION. This
115 function first looks for a function to call in NAME's property list
116 that is indicated by 'IMPLEMENTATION; failing that, it looks for a
117 function indicated by 'DEFAULT. If neither is present, an error is
118 signaled.
119
120 If a DEFAULT-BODY is supplied, then a function with the same body and
121 ARGS will be added to NAME's property list as the property indicated
122 by 'DEFAULT.
123
124 Backends implement these functions using DEFIMPLEMENTATION."
125 (check-type documentation string "a documentation string")
126 (assert (every #'symbolp args) ()
127 "Complex lambda-list not supported: ~S ~S" name args)
128 (labels ((gen-default-impl ()
129 `(setf (get ',name 'default) (lambda ,args ,@default-body)))
130 (args-as-list (args)
131 (destructuring-bind (req opt key rest) (parse-lambda-list args)
132 `(,@req ,@opt
133 ,@(loop for k in key append `(,(kw k) ,k))
134 ,@(or rest '(())))))
135 (parse-lambda-list (args)
136 (parse args '(&optional &key &rest)
137 (make-array 4 :initial-element nil)))
138 (parse (args keywords vars)
139 (cond ((null args)
140 (reverse (map 'list #'reverse vars)))
141 ((member (car args) keywords)
142 (parse (cdr args) (cdr (member (car args) keywords)) vars))
143 (t (push (car args) (aref vars (length keywords)))
144 (parse (cdr args) keywords vars))))
145 (kw (s) (intern (string s) :keyword)))
146 `(progn
147 (defun ,name ,args
148 ,documentation
149 (let ((f (or (get ',name 'implementation)
150 (get ',name 'default))))
151 (cond (f (apply f ,@(args-as-list args)))
152 (t (error "~S not implementated" ',name)))))
153 (pushnew ',name *interface-functions*)
154 ,(if (null default-body)
155 `(pushnew ',name *unimplemented-interfaces*)
156 (gen-default-impl))
157 ;; see <http://www.franz.com/support/documentation/6.2/doc/pages/variables/compiler/s_cltl1-compile-file-toplevel-compatibility-p_s.htm>
158 (eval-when (:compile-toplevel :load-toplevel :execute)
159 (export ',name :swank-backend))
160 ',name)))
161
162 (defmacro defimplementation (name args &body body)
163 (assert (every #'symbolp args) ()
164 "Complex lambda-list not supported: ~S ~S" name args)
165 `(progn
166 (setf (get ',name 'implementation) (lambda ,args ,@body))
167 (if (member ',name *interface-functions*)
168 (setq *unimplemented-interfaces*
169 (remove ',name *unimplemented-interfaces*))
170 (warn "DEFIMPLEMENTATION of undefined interface (~S)" ',name))
171 ',name))
172
173 (defun warn-unimplemented-interfaces ()
174 "Warn the user about unimplemented backend features.
175 The portable code calls this function at startup."
176 (warn "These Swank interfaces are unimplemented:~% ~A"
177 (sort (copy-list *unimplemented-interfaces*) #'string<)))
178
179 (defun import-to-swank-mop (symbol-list)
180 (dolist (sym symbol-list)
181 (let* ((swank-mop-sym (find-symbol (symbol-name sym) :swank-mop)))
182 (when swank-mop-sym
183 (unintern swank-mop-sym :swank-mop))
184 (import sym :swank-mop)
185 (export sym :swank-mop))))
186
187 (defun import-swank-mop-symbols (package except)
188 "Import the mop symbols from PACKAGE to SWANK-MOP.
189 EXCEPT is a list of symbol names which should be ignored."
190 (do-symbols (s :swank-mop)
191 (unless (member s except :test #'string=)
192 (let ((real-symbol (find-symbol (string s) package)))
193 (assert real-symbol () "Symbol ~A not found in package ~A" s package)
194 (unintern s :swank-mop)
195 (import real-symbol :swank-mop)
196 (export real-symbol :swank-mop)))))
197
198 (defvar *gray-stream-symbols*
199 '(:fundamental-character-output-stream
200 :stream-write-char
201 :stream-write-string
202 :stream-fresh-line
203 :stream-force-output
204 :stream-finish-output
205 :fundamental-character-input-stream
206 :stream-read-char
207 :stream-peek-char
208 :stream-read-line
209 ;; STREAM-FILE-POSITION is not available on all implementations, or
210 ;; partially under a different name.
211 ; :stream-file-posiion
212 :stream-listen
213 :stream-unread-char
214 :stream-clear-input
215 :stream-line-column
216 :stream-read-char-no-hang
217 ;; STREAM-LINE-LENGTH is an extension to gray streams that's apparently
218 ;; supported by CMUCL, OpenMCL, SBCL and SCL.
219 #+(or cmu openmcl sbcl scl)
220 :stream-line-length))
221
222 (defun import-from (package symbol-names &optional (to-package *package*))
223 "Import the list of SYMBOL-NAMES found in the package PACKAGE."
224 (dolist (name symbol-names)
225 (multiple-value-bind (symbol found) (find-symbol (string name) package)
226 (assert found () "Symbol ~A not found in package ~A" name package)
227 (import symbol to-package))))
228
229
230 ;;;; Utilities
231
232 (defmacro with-struct ((conc-name &rest names) obj &body body)
233 "Like with-slots but works only for structs."
234 (flet ((reader (slot) (intern (concatenate 'string
235 (symbol-name conc-name)
236 (symbol-name slot))
237 (symbol-package conc-name))))
238 (let ((tmp (gensym "OO-")))
239 ` (let ((,tmp ,obj))
240 (symbol-macrolet
241 ,(loop for name in names collect
242 (typecase name
243 (symbol `(,name (,(reader name) ,tmp)))
244 (cons `(,(first name) (,(reader (second name)) ,tmp)))
245 (t (error "Malformed syntax in WITH-STRUCT: ~A" name))))
246 ,@body)))))
247
248
249 ;;;; TCP server
250
251 (definterface create-socket (host port)
252 "Create a listening TCP socket on interface HOST and port PORT .")
253
254 (definterface local-port (socket)
255 "Return the local port number of SOCKET.")
256
257 (definterface close-socket (socket)
258 "Close the socket SOCKET.")
259
260 (definterface accept-connection (socket &key external-format
261 buffering timeout)
262 "Accept a client connection on the listening socket SOCKET.
263 Return a stream for the new connection.")
264
265 (definterface add-sigio-handler (socket fn)
266 "Call FN whenever SOCKET is readable.")
267
268 (definterface remove-sigio-handlers (socket)
269 "Remove all sigio handlers for SOCKET.")
270
271 (definterface add-fd-handler (socket fn)
272 "Call FN when Lisp is waiting for input and SOCKET is readable.")
273
274 (definterface remove-fd-handlers (socket)
275 "Remove all fd-handlers for SOCKET.")
276
277 (definterface preferred-communication-style ()
278 "Return one of the symbols :spawn, :sigio, :fd-handler, or NIL."
279 nil)
280
281 (definterface set-stream-timeout (stream timeout)
282 "Set the 'stream 'timeout. The timeout is either the real number
283 specifying the timeout in seconds or 'nil for no timeout."
284 (declare (ignore stream timeout))
285 nil)
286
287 ;;; Base condition for networking errors.
288 (define-condition network-error (simple-error) ())
289
290 (definterface emacs-connected ()
291 "Hook called when the first connection from Emacs is established.
292 Called from the INIT-FN of the socket server that accepts the
293 connection.
294
295 This is intended for setting up extra context, e.g. to discover
296 that the calling thread is the one that interacts with Emacs."
297 nil)
298
299
300 ;;;; Unix signals
301
302 (defconstant +sigint+ 2)
303
304 (definterface call-without-interrupts (fn)
305 "Call FN in a context where interrupts are disabled."
306 (funcall fn))
307
308 (definterface getpid ()
309 "Return the (Unix) process ID of this superior Lisp.")
310
311 (definterface install-sigint-handler (function)
312 "Call FUNCTION on SIGINT (instead of invoking the debugger).
313 Return old signal handler."
314 (declare (ignore function))
315 nil)
316
317 (definterface call-with-user-break-handler (handler function)
318 "Install the break handler HANDLER while executing FUNCTION."
319 (let ((old-handler (install-sigint-handler handler)))
320 (unwind-protect (funcall function)
321 (install-sigint-handler old-handler))))
322
323 (definterface quit-lisp ()
324 "Exit the current lisp image.")
325
326 (definterface lisp-implementation-type-name ()
327 "Return a short name for the Lisp implementation."
328 (lisp-implementation-type))
329
330
331 ;; pathnames are sooo useless
332
333 (definterface filename-to-pathname (filename)
334 "Return a pathname for FILENAME.
335 A filename in Emacs may for example contain asterisks which should not
336 be translated to wildcards."
337 (parse-namestring filename))
338
339 (definterface pathname-to-filename (pathname)
340 "Return the filename for PATHNAME."
341 (namestring pathname))
342
343 (definterface default-directory ()
344 "Return the default directory."
345 (directory-namestring (truename *default-pathname-defaults*)))
346
347 (definterface set-default-directory (directory)
348 "Set the default directory.
349 This is used to resolve filenames without directory component."
350 (setf *default-pathname-defaults* (truename (merge-pathnames directory)))
351 (default-directory))
352
353
354 (definterface call-with-syntax-hooks (fn)
355 "Call FN with hooks to handle special syntax."
356 (funcall fn))
357
358 (definterface default-readtable-alist ()
359 "Return a suitable initial value for SWANK:*READTABLE-ALIST*."
360 '())
361
362
363 ;;;; Compilation
364
365 (definterface call-with-compilation-hooks (func)
366 "Call FUNC with hooks to record compiler conditions.")
367
368 (defmacro with-compilation-hooks ((&rest ignore) &body body)
369 "Execute BODY as in CALL-WITH-COMPILATION-HOOKS."
370 (declare (ignore ignore))
371 `(call-with-compilation-hooks (lambda () (progn ,@body))))
372
373 (definterface swank-compile-string (string &key buffer position filename
374 policy)
375 "Compile source from STRING.
376 During compilation, compiler conditions must be trapped and
377 resignalled as COMPILER-CONDITIONs.
378
379 If supplied, BUFFER and POSITION specify the source location in Emacs.
380
381 Additionally, if POSITION is supplied, it must be added to source
382 positions reported in compiler conditions.
383
384 If FILENAME is specified it may be used by certain implementations to
385 rebind *DEFAULT-PATHNAME-DEFAULTS* which may improve the recording of
386 source information.
387
388 If POLICY is supplied, and non-NIL, it may be used by certain
389 implementations to compile with a debug optimization quality of its
390 value.
391
392 Should return T on successfull compilation, NIL otherwise.
393 ")
394
395 (definterface swank-compile-file (input-file output-file load-p
396 external-format)
397 "Compile INPUT-FILE signalling COMPILE-CONDITIONs.
398 If LOAD-P is true, load the file after compilation.
399 EXTERNAL-FORMAT is a value returned by find-external-format or
400 :default.
401
402 Should return OUTPUT-TRUENAME, WARNINGS-P and FAILURE-p
403 like `compile-file'")
404
405 (deftype severity ()
406 '(member :error :read-error :warning :style-warning :note))
407
408 ;; Base condition type for compiler errors, warnings and notes.
409 (define-condition compiler-condition (condition)
410 ((original-condition
411 ;; The original condition thrown by the compiler if appropriate.
412 ;; May be NIL if a compiler does not report using conditions.
413 :type (or null condition)
414 :initarg :original-condition
415 :accessor original-condition)
416
417 (severity :type severity
418 :initarg :severity
419 :accessor severity)
420
421 (message :initarg :message
422 :accessor message)
423
424 (short-message :initarg :short-message
425 :initform nil
426 :accessor short-message)
427
428 (references :initarg :references
429 :initform nil
430 :accessor references)
431
432 (location :initarg :location
433 :accessor location)))
434
435 (definterface find-external-format (coding-system)
436 "Return a \"external file format designator\" for CODING-SYSTEM.
437 CODING-SYSTEM is Emacs-style coding system name (a string),
438 e.g. \"latin-1-unix\"."
439 (if (equal coding-system "iso-latin-1-unix")
440 :default
441 nil))
442
443 (definterface guess-external-format (pathname)
444 "Detect the external format for the file with name pathname.
445 Return nil if the file contains no special markers."
446 ;; Look for a Emacs-style -*- coding: ... -*- or Local Variable: section.
447 (with-open-file (s pathname :if-does-not-exist nil
448 :external-format (or (find-external-format "latin-1-unix")
449 :default))
450 (if s
451 (or (let* ((line (read-line s nil))
452 (p (search "-*-" line)))
453 (when p
454 (let* ((start (+ p (length "-*-")))
455 (end (search "-*-" line :start2 start)))
456 (when end
457 (%search-coding line start end)))))
458 (let* ((len (file-length s))
459 (buf (make-string (min len 3000))))
460 (file-position s (- len (length buf)))
461 (read-sequence buf s)
462 (let ((start (search "Local Variables:" buf :from-end t))
463 (end (search "End:" buf :from-end t)))
464 (and start end (< start end)
465 (%search-coding buf start end))))))))
466
467 (defun %search-coding (str start end)
468 (let ((p (search "coding:" str :start2 start :end2 end)))
469 (when p
470 (incf p (length "coding:"))
471 (loop while (and (< p end)
472 (member (aref str p) '(#\space #\tab)))
473 do (incf p))
474 (let ((end (position-if (lambda (c) (find c '(#\space #\tab #\newline)))
475 str :start p)))
476 (find-external-format (subseq str p end))))))
477
478
479 ;;;; Streams
480
481 (definterface make-output-stream (write-string)
482 "Return a new character output stream.
483 The stream calls WRITE-STRING when output is ready.")
484
485 (definterface make-input-stream (read-string)
486 "Return a new character input stream.
487 The stream calls READ-STRING when input is needed.")
488
489
490 ;;;; Documentation
491
492 (definterface arglist (name)
493 "Return the lambda list for the symbol NAME. NAME can also be
494 a lisp function object, on lisps which support this.
495
496 The result can be a list or the :not-available keyword if the
497 arglist cannot be determined."
498 (declare (ignore name))
499 :not-available)
500
501 (defgeneric declaration-arglist (decl-identifier)
502 (:documentation
503 "Return the argument list of the declaration specifier belonging to the
504 declaration identifier DECL-IDENTIFIER. If the arglist cannot be determined,
505 the keyword :NOT-AVAILABLE is returned.
506
507 The different SWANK backends can specialize this generic function to
508 include implementation-dependend declaration specifiers, or to provide
509 additional information on the specifiers defined in ANSI Common Lisp.")
510 (:method (decl-identifier)
511 (case decl-identifier
512 (dynamic-extent '(&rest vars))
513 (ignore '(&rest vars))
514 (ignorable '(&rest vars))
515 (special '(&rest vars))
516 (inline '(&rest function-names))
517 (notinline '(&rest function-name))
518 (optimize '(&any compilation-speed debug safety space speed))
519 (type '(type-specifier &rest args))
520 (ftype '(type-specifier &rest function-names))
521 (otherwise
522 (flet ((typespec-p (symbol) (member :type (describe-symbol-for-emacs symbol))))
523 (cond ((and (symbolp decl-identifier) (typespec-p decl-identifier))
524 '(&rest vars))
525 ((and (listp decl-identifier) (typespec-p (first decl-identifier)))
526 '(&rest vars))
527 (t :not-available)))))))
528
529 (defgeneric type-specifier-arglist (typespec-operator)
530 (:documentation
531 "Return the argument list of the type specifier belonging to
532 TYPESPEC-OPERATOR.. If the arglist cannot be determined, the keyword
533 :NOT-AVAILABLE is returned.
534
535 The different SWANK backends can specialize this generic function to
536 include implementation-dependend declaration specifiers, or to provide
537 additional information on the specifiers defined in ANSI Common Lisp.")
538 (:method (typespec-operator)
539 (declare (special *type-specifier-arglists*)) ; defined at end of file.
540 (typecase typespec-operator
541 (symbol (or (cdr (assoc typespec-operator *type-specifier-arglists*))
542 :not-available))
543 (t :not-available))))
544
545 (definterface function-name (function)
546 "Return the name of the function object FUNCTION.
547
548 The result is either a symbol, a list, or NIL if no function name is available."
549 (declare (ignore function))
550 nil)
551
552 (definterface macroexpand-all (form)
553 "Recursively expand all macros in FORM.
554 Return the resulting form.")
555
556 (definterface compiler-macroexpand-1 (form &optional env)
557 "Call the compiler-macro for form.
558 If FORM is a function call for which a compiler-macro has been
559 defined, invoke the expander function using *macroexpand-hook* and
560 return the results and T. Otherwise, return the original form and
561 NIL."
562 (let ((fun (and (consp form) (compiler-macro-function (car form)))))
563 (if fun
564 (let ((result (funcall *macroexpand-hook* fun form env)))
565 (values result (not (eq result form))))
566 (values form nil))))
567
568 (definterface compiler-macroexpand (form &optional env)
569 "Repetitively call `compiler-macroexpand-1'."
570 (labels ((frob (form expanded)
571 (multiple-value-bind (new-form newly-expanded)
572 (compiler-macroexpand-1 form env)
573 (if newly-expanded
574 (frob new-form t)
575 (values new-form expanded)))))
576 (frob form env)))
577
578 (definterface describe-symbol-for-emacs (symbol)
579 "Return a property list describing SYMBOL.
580
581 The property list has an entry for each interesting aspect of the
582 symbol. The recognised keys are:
583
584 :VARIABLE :FUNCTION :SETF :SPECIAL-OPERATOR :MACRO :COMPILER-MACRO
585 :TYPE :CLASS :ALIEN-TYPE :ALIEN-STRUCT :ALIEN-UNION :ALIEN-ENUM
586
587 The value of each property is the corresponding documentation string,
588 or :NOT-DOCUMENTED. It is legal to include keys not listed here (but
589 slime-print-apropos in Emacs must know about them).
590
591 Properties should be included if and only if they are applicable to
592 the symbol. For example, only (and all) fbound symbols should include
593 the :FUNCTION property.
594
595 Example:
596 \(describe-symbol-for-emacs 'vector)
597 => (:CLASS :NOT-DOCUMENTED
598 :TYPE :NOT-DOCUMENTED
599 :FUNCTION \"Constructs a simple-vector from the given objects.\")")
600
601 (definterface describe-definition (name type)
602 "Describe the definition NAME of TYPE.
603 TYPE can be any value returned by DESCRIBE-SYMBOL-FOR-EMACS.
604
605 Return a documentation string, or NIL if none is available.")
606
607
608 ;;;; Debugging
609
610 (definterface install-debugger-globally (function)
611 "Install FUNCTION as the debugger for all threads/processes. This
612 usually involves setting *DEBUGGER-HOOK* and, if the implementation
613 permits, hooking into BREAK as well."
614 (setq *debugger-hook* function))
615
616 (definterface call-with-debugging-environment (debugger-loop-fn)
617 "Call DEBUGGER-LOOP-FN in a suitable debugging environment.
618
619 This function is called recursively at each debug level to invoke the
620 debugger loop. The purpose is to setup any necessary environment for
621 other debugger callbacks that will be called within the debugger loop.
622
623 For example, this is a reasonable place to compute a backtrace, switch
624 to safe reader/printer settings, and so on.")
625
626 (definterface call-with-debugger-hook (hook fun)
627 "Call FUN and use HOOK as debugger hook.
628
629 HOOK should be called for both BREAK and INVOKE-DEBUGGER."
630 (let ((*debugger-hook* hook))
631 (funcall fun)))
632
633 (define-condition sldb-condition (condition)
634 ((original-condition
635 :initarg :original-condition
636 :accessor original-condition))
637 (:report (lambda (condition stream)
638 (format stream "Condition in debugger code~@[: ~A~]"
639 (original-condition condition))))
640 (:documentation
641 "Wrapper for conditions that should not be debugged.
642
643 When a condition arises from the internals of the debugger, it is not
644 desirable to debug it -- we'd risk entering an endless loop trying to
645 debug the debugger! Instead, such conditions can be reported to the
646 user without (re)entering the debugger by wrapping them as
647 `sldb-condition's."))
648
649 ;;; The following functions in this section are supposed to be called
650 ;;; within the dynamic contour of CALL-WITH-DEBUGGING-ENVIRONMENT only.
651
652 (definterface compute-backtrace (start end)
653 "Returns a backtrace of the condition currently being debugged,
654 that is an ordered list consisting of frames. ``Ordered list''
655 means that an integer I can be mapped back to the i-th frame of this
656 backtrace.
657
658 START and END are zero-based indices constraining the number of frames
659 returned. Frame zero is defined as the frame which invoked the
660 debugger. If END is nil, return the frames from START to the end of
661 the stack.")
662
663 (definterface print-frame (frame stream)
664 "Print frame to stream.")
665
666 (definterface frame-restartable-p (frame)
667 "Is the frame FRAME restartable?.
668 Return T if `restart-frame' can safely be called on the frame."
669 (declare (ignore frame))
670 nil)
671
672 (definterface frame-source-location-for-emacs (frame-number)
673 "Return the source location for the frame associated to FRAME-NUMBER.")
674
675 (definterface frame-catch-tags (frame-number)
676 "Return a list of catch tags for being printed in a debugger stack
677 frame."
678 (declare (ignore frame-number))
679 '())
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 (declare (ignore id))
973 (current-thread))
974
975 (definterface thread-name (thread)
976 "Return the name of THREAD.
977
978 Thread names are be single-line strings and are meaningful to the
979 user. They do not have to be unique."
980 (declare (ignore thread))
981 "The One True Thread")
982
983 (definterface thread-status (thread)
984 "Return a string describing THREAD's state."
985 (declare (ignore thread))
986 "")
987
988 (definterface thread-description (thread)
989 "Return a string describing THREAD."
990 (declare (ignore thread))
991 "")
992
993 (definterface set-thread-description (thread description)
994 "Set THREAD's description to DESCRIPTION."
995 (declare (ignore thread description))
996 "")
997
998 (definterface make-lock (&key name)
999 "Make a lock for thread synchronization.
1000 Only one thread may hold the lock (via CALL-WITH-LOCK-HELD) at a time
1001 but that thread may hold it more than once."
1002 (declare (ignore name))
1003 :null-lock)
1004
1005 (definterface call-with-lock-held (lock function)
1006 "Call FUNCTION with LOCK held, queueing if necessary."
1007 (declare (ignore lock)
1008 (type function function))
1009 (funcall function))
1010
1011 (definterface current-thread ()
1012 "Return the currently executing thread."
1013 0)
1014
1015 (definterface all-threads ()
1016 "Return a fresh list of all threads.")
1017
1018 (definterface thread-alive-p (thread)
1019 "Test if THREAD is termintated."
1020 (member thread (all-threads)))
1021
1022 (definterface interrupt-thread (thread fn)
1023 "Cause THREAD to execute FN.")
1024
1025 (definterface kill-thread (thread)
1026 "Kill THREAD."
1027 (declare (ignore thread))
1028 nil)
1029
1030 (definterface send (thread object)
1031 "Send OBJECT to thread THREAD.")
1032
1033 (definterface receive (&optional timeout)
1034 "Return the next message from current thread's mailbox."
1035 (receive-if (constantly t) timeout))
1036
1037 (definterface receive-if (predicate &optional timeout)
1038 "Return the first message satisfiying PREDICATE.")
1039
1040 (definterface set-default-initial-binding (var form)
1041 "Initialize special variable VAR by default with FORM.
1042
1043 Some implementations initialize certain variables in each newly
1044 created thread. This function sets the form which is used to produce
1045 the initial value."
1046 (set var (eval form)))
1047
1048 ;; List of delayed interrupts.
1049 ;; This should only have thread-local bindings, so no init form.
1050 (defvar *pending-slime-interrupts*)
1051
1052 (defun check-slime-interrupts ()
1053 "Execute pending interrupts if any.
1054 This should be called periodically in operations which
1055 can take a long time to complete.
1056 Return a boolean indicating whether any interrupts was processed."
1057 (when (and (boundp '*pending-slime-interrupts*)
1058 *pending-slime-interrupts*)
1059 (funcall (pop *pending-slime-interrupts*))
1060 t))
1061
1062 (define-condition slime-interrupt-queued () ()
1063 (:documentation
1064 "Non-serious condition signalled when an interrupt
1065 occurs while interrupt handling is disabled.
1066 Backends can use this to abort blocking operations."))
1067
1068 (definterface wait-for-input (streams &optional timeout)
1069 "Wait for input on a list of streams. Return those that are ready.
1070 STREAMS is a list of streams
1071 TIMEOUT nil, t, or real number. If TIMEOUT is t, return
1072 those streams which are ready immediately, without waiting.
1073 If TIMEOUT is a number and no streams is ready after TIMEOUT seconds,
1074 return nil.
1075
1076 Return :interrupt if an interrupt occurs while waiting."
1077 (assert (member timeout '(nil t)))
1078 (cond #+(or)
1079 ((null (cdr streams))
1080 (wait-for-one-stream (car streams) timeout))
1081 (t
1082 (wait-for-streams streams timeout))))
1083
1084 (defun wait-for-streams (streams timeout)
1085 (loop
1086 (when (check-slime-interrupts) (return :interrupt))
1087 (let ((ready (remove-if-not #'stream-readable-p streams)))
1088 (when ready (return ready)))
1089 (when timeout (return nil))
1090 (sleep 0.1)))
1091
1092 ;; Note: Usually we can't interrupt PEEK-CHAR cleanly.
1093 (defun wait-for-one-stream (stream timeout)
1094 (ecase timeout
1095 ((nil)
1096 (cond ((check-slime-interrupts) :interrupt)
1097 (t (peek-char nil stream nil nil)
1098 (list stream))))
1099 ((t)
1100 (let ((c (read-char-no-hang stream nil nil)))
1101 (cond (c
1102 (unread-char c stream)
1103 (list stream))
1104 (t '()))))))
1105
1106 (defun stream-readable-p (stream)
1107 (let ((c (read-char-no-hang stream nil :eof)))
1108 (cond ((not c) nil)
1109 ((eq c :eof) t)
1110 (t (unread-char c stream) t))))
1111
1112 (definterface toggle-trace (spec)
1113 "Toggle tracing of the function(s) given with SPEC.
1114 SPEC can be:
1115 (setf NAME) ; a setf function
1116 (:defmethod NAME QUALIFIER... (SPECIALIZER...)) ; a specific method
1117 (:defgeneric NAME) ; a generic function with all methods
1118 (:call CALLER CALLEE) ; trace calls from CALLER to CALLEE.
1119 (:labels TOPLEVEL LOCAL)
1120 (:flet TOPLEVEL LOCAL) ")
1121
1122
1123 ;;;; Weak datastructures
1124
1125 (definterface make-weak-key-hash-table (&rest args)
1126 "Like MAKE-HASH-TABLE, but weak w.r.t. the keys."
1127 (apply #'make-hash-table args))
1128
1129 (definterface make-weak-value-hash-table (&rest args)
1130 "Like MAKE-HASH-TABLE, but weak w.r.t. the values."
1131 (apply #'make-hash-table args))
1132
1133 (definterface hash-table-weakness (hashtable)
1134 "Return nil or one of :key :value :key-or-value :key-and-value"
1135 (declare (ignore hashtable))
1136 nil)
1137
1138
1139 ;;;; Character names
1140
1141 (definterface character-completion-set (prefix matchp)
1142 "Return a list of names of characters that match PREFIX."
1143 ;; Handle the standard and semi-standard characters.
1144 (loop for name in '("Newline" "Space" "Tab" "Page" "Rubout"
1145 "Linefeed" "Return" "Backspace")
1146 when (funcall matchp prefix name)
1147 collect name))
1148
1149
1150 (defparameter *type-specifier-arglists*
1151 '((and . (&rest type-specifiers))
1152 (array . (&optional element-type dimension-spec))
1153 (base-string . (&optional size))
1154 (bit-vector . (&optional size))
1155 (complex . (&optional type-specifier))
1156 (cons . (&optional car-typespec cdr-typespec))
1157 (double-float . (&optional lower-limit upper-limit))
1158 (eql . (object))
1159 (float . (&optional lower-limit upper-limit))
1160 (function . (&optional arg-typespec value-typespec))
1161 (integer . (&optional lower-limit upper-limit))
1162 (long-float . (&optional lower-limit upper-limit))
1163 (member . (&rest eql-objects))
1164 (mod . (n))
1165 (not . (type-specifier))
1166 (or . (&rest type-specifiers))
1167 (rational . (&optional lower-limit upper-limit))
1168 (real . (&optional lower-limit upper-limit))
1169 (satisfies . (predicate-symbol))
1170 (short-float . (&optional lower-limit upper-limit))
1171 (signed-byte . (&optional size))
1172 (simple-array . (&optional element-type dimension-spec))
1173 (simple-base-string . (&optional size))
1174 (simple-bit-vector . (&optional size))
1175 (simple-string . (&optional size))
1176 (single-float . (&optional lower-limit upper-limit))
1177 (simple-vector . (&optional size))
1178 (string . (&optional size))
1179 (unsigned-byte . (&optional size))
1180 (values . (&rest typespecs))
1181 (vector . (&optional element-type size))
1182 ))
1183
1184 ;;; Heap dumps
1185
1186 (definterface save-image (filename &optional restart-function)
1187 "Save a heap image to the file FILENAME.
1188 RESTART-FUNCTION, if non-nil, should be called when the image is loaded.")
1189
1190
1191

  ViewVC Help
Powered by ViewVC 1.1.5