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

Diff of /slime/swank-backend.lisp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.94 by heller, Sun Nov 20 23:25:38 2005 UTC revision 1.215 by heller, Sat Dec 10 12:34:09 2011 UTC
# Line 12  Line 12 
12    
13  (defpackage :swank-backend  (defpackage :swank-backend
14    (:use :common-lisp)    (:use :common-lisp)
15    (:export #:sldb-condition    (:export #:*debug-swank-backend*
16             #:original-condition             #:sldb-condition
17             #:compiler-condition             #:compiler-condition
18               #:original-condition
19             #:message             #:message
20             #:short-message             #:source-context
21             #:condition             #:condition
22             #:severity             #:severity
23               #:with-compilation-hooks
24             #:location             #:location
25             #:location-p             #:location-p
26             #:location-buffer             #:location-buffer
# Line 29  Line 31 
31             #:quit-lisp             #:quit-lisp
32             #:references             #:references
33             #:unbound-slot-filler             #:unbound-slot-filler
34               #:declaration-arglist
35               #:type-specifier-arglist
36               #:with-struct
37               #:when-let
38               ;; interrupt macro for the backend
39               #:*pending-slime-interrupts*
40               #:check-slime-interrupts
41               #:*interrupt-queued-handler*
42             ;; inspector related symbols             ;; inspector related symbols
43             #:inspector             #:emacs-inspect
            #:inspect-for-emacs  
            #:raw-inspection  
            #:fancy-inspection  
44             #:label-value-line             #:label-value-line
45             #:label-value-line*             #:label-value-line*
46             ))             #:with-symbol))
47    
48  (defpackage :swank-mop  (defpackage :swank-mop
49    (:use)    (:use)
# Line 84  Line 91 
91     #:slot-definition-type     #:slot-definition-type
92     #:slot-definition-readers     #:slot-definition-readers
93     #:slot-definition-writers     #:slot-definition-writers
94       #:slot-boundp-using-class
95       #:slot-value-using-class
96       #:slot-makunbound-using-class
97     ;; generic function protocol     ;; generic function protocol
98     #:compute-applicable-methods-using-classes     #:compute-applicable-methods-using-classes
99     #:finalize-inheritance))     #:finalize-inheritance))
# Line 93  Line 103 
103    
104  ;;;; Metacode  ;;;; Metacode
105    
106    (defparameter *debug-swank-backend* nil
107      "If this is true, backends should not catch errors but enter the
108    debugger where appropriate. Also, they should not perform backtrace
109    magic but really show every frame including SWANK related ones.")
110    
111  (defparameter *interface-functions* '()  (defparameter *interface-functions* '()
112    "The names of all interface functions.")    "The names of all interface functions.")
113    
# Line 102  DEFINTERFACE adds to this list and DEFIM Line 117  DEFINTERFACE adds to this list and DEFIM
117    
118  (defmacro definterface (name args documentation &rest default-body)  (defmacro definterface (name args documentation &rest default-body)
119    "Define an interface function for the backend to implement.    "Define an interface function for the backend to implement.
120  A generic function is defined with NAME, ARGS, and DOCUMENTATION.  A function is defined with NAME, ARGS, and DOCUMENTATION.  This
121    function first looks for a function to call in NAME's property list
122  If a DEFAULT-BODY is supplied then NO-APPLICABLE-METHOD is specialized  that is indicated by 'IMPLEMENTATION; failing that, it looks for a
123  to execute the body if the backend doesn't provide a specific  function indicated by 'DEFAULT. If neither is present, an error is
124  implementation.  signaled.
125    
126    If a DEFAULT-BODY is supplied, then a function with the same body and
127    ARGS will be added to NAME's property list as the property indicated
128    by 'DEFAULT.
129    
130  Backends implement these functions using DEFIMPLEMENTATION."  Backends implement these functions using DEFIMPLEMENTATION."
131    (check-type documentation string "a documentation string")    (check-type documentation string "a documentation string")
132    (flet ((gen-default-impl ()    (assert (every #'symbolp args) ()
133             `(defmethod ,name ,args ,@default-body)))            "Complex lambda-list not supported: ~S ~S" name args)
134      `(progn (defgeneric ,name ,args (:documentation ,documentation))    (labels ((gen-default-impl ()
135              (pushnew ',name *interface-functions*)               `(setf (get ',name 'default) (lambda ,args ,@default-body)))
136              ,(if (null default-body)             (args-as-list (args)
137                   `(pushnew ',name *unimplemented-interfaces*)               (destructuring-bind (req opt key rest) (parse-lambda-list args)
138                   (gen-default-impl))                 `(,@req ,@opt
139              ;; see <http://www.franz.com/support/documentation/6.2/doc/pages/variables/compiler/s_cltl1-compile-file-toplevel-compatibility-p_s.htm>                         ,@(loop for k in key append `(,(kw k) ,k))
140              (eval-when (:compile-toplevel :load-toplevel :execute)                         ,@(or rest '(())))))
141                (export ',name :swank-backend))             (parse-lambda-list (args)
142              ',name)))               (parse args '(&optional &key &rest)
143                        (make-array 4 :initial-element nil)))
144               (parse (args keywords vars)
145                 (cond ((null args)
146                        (reverse (map 'list #'reverse vars)))
147                       ((member (car args) keywords)
148                        (parse (cdr args) (cdr (member (car args) keywords)) vars))
149                       (t (push (car args) (aref vars (length keywords)))
150                          (parse (cdr args) keywords vars))))
151               (kw (s) (intern (string s) :keyword)))
152        `(progn
153           (defun ,name ,args
154             ,documentation
155             (let ((f (or (get ',name 'implementation)
156                          (get ',name 'default))))
157               (cond (f (apply f ,@(args-as-list args)))
158                     (t (error "~S not implemented" ',name)))))
159           (pushnew ',name *interface-functions*)
160           ,(if (null default-body)
161                `(pushnew ',name *unimplemented-interfaces*)
162                (gen-default-impl))
163           ;; see <http://www.franz.com/support/documentation/6.2/doc/pages/variables/compiler/s_cltl1-compile-file-toplevel-compatibility-p_s.htm>
164           (eval-when (:compile-toplevel :load-toplevel :execute)
165             (export ',name :swank-backend))
166           ',name)))
167    
168  (defmacro defimplementation (name args &body body)  (defmacro defimplementation (name args &body body)
169    `(progn (defmethod ,name ,args ,@body)    (assert (every #'symbolp args) ()
170            (if (member ',name *interface-functions*)            "Complex lambda-list not supported: ~S ~S" name args)
171                (setq *unimplemented-interfaces*    `(progn
172                      (remove ',name *unimplemented-interfaces*))       (setf (get ',name 'implementation)
173                (warn "DEFIMPLEMENTATION of undefined interface (~S)" ',name))             ;; For implicit BLOCK. FLET because of interplay w/ decls.
174            ',name))             (flet ((,name ,args ,@body)) #',name))
175         (if (member ',name *interface-functions*)
176             (setq *unimplemented-interfaces*
177                   (remove ',name *unimplemented-interfaces*))
178             (warn "DEFIMPLEMENTATION of undefined interface (~S)" ',name))
179         ',name))
180    
181  (defun warn-unimplemented-interfaces ()  (defun warn-unimplemented-interfaces ()
182    "Warn the user about unimplemented backend features.    "Warn the user about unimplemented backend features.
183  The portable code calls this function at startup."  The portable code calls this function at startup."
184    (warn "These Swank interfaces are unimplemented:~% ~A"    (let ((*print-pretty* t))
185          (sort (copy-list *unimplemented-interfaces*) #'string<)))      (warn "These Swank interfaces are unimplemented:~% ~:<~{~A~^ ~:_~}~:>"
186              (list (sort (copy-list *unimplemented-interfaces*) #'string<)))))
187    
188  (defun import-to-swank-mop (symbol-list)  (defun import-to-swank-mop (symbol-list)
189    (dolist (sym symbol-list)    (dolist (sym symbol-list)
# Line 158  EXCEPT is a list of symbol names which s Line 207  EXCEPT is a list of symbol names which s
207  (defvar *gray-stream-symbols*  (defvar *gray-stream-symbols*
208    '(:fundamental-character-output-stream    '(:fundamental-character-output-stream
209      :stream-write-char      :stream-write-char
210        :stream-write-string
211      :stream-fresh-line      :stream-fresh-line
212      :stream-force-output      :stream-force-output
213      :stream-finish-output      :stream-finish-output
214      :fundamental-character-input-stream      :fundamental-character-input-stream
215      :stream-read-char      :stream-read-char
216        :stream-peek-char
217        :stream-read-line
218        ;; STREAM-FILE-POSITION is not available on all implementations, or
219        ;; partially under a different name.
220        ; :stream-file-posiion
221      :stream-listen      :stream-listen
222      :stream-unread-char      :stream-unread-char
223      :stream-clear-input      :stream-clear-input
# Line 199  EXCEPT is a list of symbol names which s Line 254  EXCEPT is a list of symbol names which s
254                       (t (error "Malformed syntax in WITH-STRUCT: ~A" name))))                       (t (error "Malformed syntax in WITH-STRUCT: ~A" name))))
255            ,@body)))))            ,@body)))))
256    
257    (defmacro when-let ((var value) &body body)
258      `(let ((,var ,value))
259         (when ,var ,@body)))
260    
261    (defun with-symbol (name package)
262      "Generate a form suitable for testing with #+."
263      (if (and (find-package package)
264               (find-symbol (string name) package))
265          '(:and)
266          '(:or)))
267    
268    
269    ;;;; UFT8
270    
271    (deftype octet () '(unsigned-byte 8))
272    (deftype octets () '(simple-array octet (*)))
273    
274    ;; Helper function.  Decode the next N bytes starting from INDEX.
275    ;; Return the decoded char and the new index.
276    (defun utf8-decode-aux (buffer index limit byte0 n)
277      (declare (type octets buffer) (fixnum index limit byte0 n))
278      (if (< (- limit index) n)
279          (values nil index)
280          (do ((i 0 (1+ i))
281               (code byte0 (let ((byte (aref buffer (+ index i))))
282                             (cond ((= (ldb (byte 2 6) byte) #b10)
283                                    (+ (ash code 6) (ldb (byte 6 0) byte)))
284                                   (t
285                                    (error "Invalid encoding"))))))
286              ((= i n)
287               (values (cond ((<= code #xff) (code-char code))
288                             ((<= #xd800 code #xdfff)
289                              (error "Invalid Unicode code point: #x~x" code))
290                             ((and (< code char-code-limit)
291                                   (code-char code)))
292                             (t
293                              (error
294                               "Can't represent code point: #x~x ~
295                                (char-code-limit is #x~x)"
296                               code char-code-limit)))
297                       (+ index n))))))
298    
299    ;; Decode one character in BUFFER starting at INDEX.
300    ;; Return 2 values: the character and the new index.
301    ;; If there aren't enough bytes between INDEX and LIMIT return nil.
302    (defun utf8-decode (buffer index limit)
303      (declare (type octets buffer) (fixnum index limit))
304      (if (= index limit)
305          (values nil index)
306          (let ((b (aref buffer index)))
307            (if (<= b #x7f)
308                (values (code-char b) (1+ index))
309                (macrolet ((try (marker else)
310                             (let* ((l (integer-length marker))
311                                    (n (- l 2)))
312                               `(if (= (ldb (byte ,l ,(- 8 l)) b) ,marker)
313                                    (utf8-decode-aux buffer (1+ index) limit
314                                                     (ldb (byte ,(- 8 l) 0) b)
315                                                     ,n)
316                                    ,else))))
317                  (try #b110
318                       (try #b1110
319                            (try #b11110
320                                 (try #b111110
321                                      (try #b1111110
322                                           (error "Invalid encoding")))))))))))
323    
324    ;; Decode characters from BUFFER and write them to STRING.
325    ;; Return 2 values: LASTINDEX and LASTSTART where
326    ;; LASTINDEX is the last index in BUFFER that was not decoded
327    ;; and LASTSTART is the last index in STRING not written.
328    (defun utf8-decode-into (buffer index limit string start end)
329      (declare (string string) (fixnum index limit start end) (type octets buffer))
330      (loop
331       (cond ((= start end)
332              (return (values index start)))
333             (t
334              (multiple-value-bind (c i) (utf8-decode buffer index limit)
335                (cond (c
336                       (setf (aref string start) c)
337                       (setq index i)
338                       (setq start (1+ start)))
339                      (t
340                       (return (values index start)))))))))
341    
342    (defun default-utf8-to-string (octets)
343      (let* ((limit (length octets))
344             (str (make-string limit)))
345        (multiple-value-bind (i s) (utf8-decode-into octets 0 limit str 0 limit)
346          (if (= i limit)
347              (if (= limit s)
348                  str
349                  (adjust-array str s))
350              (loop
351               (let ((end (+ (length str) (- limit i))))
352                 (setq str (adjust-array str end))
353                 (multiple-value-bind (i2 s2)
354                     (utf8-decode-into octets i limit str s end)
355                   (cond ((= i2 limit)
356                          (return (adjust-array str s2)))
357                         (t
358                          (setq i i2)
359                          (setq s s2))))))))))
360    
361    (defmacro utf8-encode-aux (code buffer start end n)
362      `(cond ((< (- ,end ,start) ,n)
363              ,start)
364             (t
365              (setf (aref ,buffer ,start)
366                    (dpb (ldb (byte ,(- 7 n) ,(* 6 (1- n))) ,code)
367                         (byte ,(- 7 n) 0)
368                         ,(dpb 0 (byte 1 (- 7 n)) #xff)))
369              ,@(loop for i from 0 upto (- n 2) collect
370                      `(setf (aref ,buffer (+ ,start ,(- n 1 i)))
371                             (dpb (ldb (byte 6 ,(* 6 i)) ,code)
372                                  (byte 6 0)
373                                  #b10111111)))
374              (+ ,start ,n))))
375    
376    (defun utf8-encode (char buffer start end)
377      (declare (character char) (type octets buffer) (fixnum start end))
378      (let ((code (char-code char)))
379        (cond ((<= code #x7f)
380               (cond ((< start end)
381                      (setf (aref buffer start) code)
382                      (1+ start))
383                     (t start)))
384              ((<= code #x7ff) (utf8-encode-aux code buffer start end 2))
385              ((<= #xd800 code #xdfff)
386               (error "Invalid Unicode code point (surrogate): #x~x" code))
387              ((<= code #xffff) (utf8-encode-aux code buffer start end 3))
388              ((<= code #x1fffff) (utf8-encode-aux code buffer start end 4))
389              ((<= code #x3ffffff) (utf8-encode-aux code buffer start end 5))
390              ((<= code #x7fffffff) (utf8-encode-aux code buffer start end 6))
391              (t (error "Can't encode ~s (~x)" char code)))))
392    
393    (defun utf8-encode-into (string start end buffer index limit)
394      (declare (string string) (type octets buffer) (fixnum start end index limit))
395      (loop
396       (cond ((= start end)
397              (return (values start index)))
398             ((= index limit)
399              (return (values start index)))
400             (t
401              (let ((i2 (utf8-encode (char string start) buffer index limit)))
402                (cond ((= i2 index)
403                       (return (values start index)))
404                      (t
405                       (setq index i2)
406                       (incf start))))))))
407    
408    (defun default-string-to-utf8 (string)
409      (let* ((len (length string))
410             (b (make-array len :element-type 'octet)))
411        (multiple-value-bind (s i) (utf8-encode-into string 0 len b 0 len)
412          (if (= s len)
413              b
414              (loop
415               (let ((limit (+ (length b) (- len s))))
416                 (setq b (coerce (adjust-array b limit) 'octets))
417                 (multiple-value-bind (s2 i2)
418                     (utf8-encode-into string s len b i limit)
419                   (cond ((= s2 len)
420                          (return (coerce (adjust-array b i2) 'octets)))
421                         (t
422                          (setq i i2)
423                          (setq s s2))))))))))
424    
425    (definterface string-to-utf8 (string)
426      "Convert the string STRING to a (simple-array (unsigned-byte 8))"
427      (default-string-to-utf8 string))
428    
429    (definterface utf8-to-string (octets)
430      "Convert the (simple-array (unsigned-byte 8)) OCTETS to a string."
431      (default-utf8-to-string octets))
432    
433    ;;; Codepoint length
434    
435    ;; we don't need this anymore.
436    (definterface codepoint-length (string)
437      "Return the number of codepoints in STRING.
438    With some Lisps, like cmucl, LENGTH returns the number of UTF-16 code
439    units, but other Lisps return the number of codepoints. The slime
440    protocol wants string lengths in terms of codepoints."
441      (length string))
442    
443    
444  ;;;; TCP server  ;;;; TCP server
445    
446  (definterface create-socket (host port)  (definterface create-socket (host port &key backlog)
447    "Create a listening TCP socket on interface HOST and port PORT .")    "Create a listening TCP socket on interface HOST and port PORT.
448    BACKLOG queue length for incoming connections.")
449    
450  (definterface local-port (socket)  (definterface local-port (socket)
451    "Return the local port number of SOCKET.")    "Return the local port number of SOCKET.")
# Line 212  EXCEPT is a list of symbol names which s Line 454  EXCEPT is a list of symbol names which s
454    "Close the socket SOCKET.")    "Close the socket SOCKET.")
455    
456  (definterface accept-connection (socket &key external-format  (definterface accept-connection (socket &key external-format
457                                          buffering)                                          buffering timeout)
458     "Accept a client connection on the listening socket SOCKET.     "Accept a client connection on the listening socket SOCKET.
459  Return a stream for the new connection.")  Return a stream for the new connection.
460    If EXTERNAL-FORMAT is nil return a binary stream
461    otherwise create a character stream.
462    BUFFERING can be one of:
463      nil   ... no buffering
464      t     ... enable buffering
465      :line ... enable buffering with automatic flushing on eol.")
466    
467  (definterface add-sigio-handler (socket fn)  (definterface add-sigio-handler (socket fn)
468    "Call FN whenever SOCKET is readable.")    "Call FN whenever SOCKET is readable.")
# Line 232  Return a stream for the new connection." Line 480  Return a stream for the new connection."
480    "Return one of the symbols :spawn, :sigio, :fd-handler, or NIL."    "Return one of the symbols :spawn, :sigio, :fd-handler, or NIL."
481    nil)    nil)
482    
483    (definterface set-stream-timeout (stream timeout)
484      "Set the 'stream 'timeout.  The timeout is either the real number
485      specifying the timeout in seconds or 'nil for no timeout."
486      (declare (ignore stream timeout))
487      nil)
488    
489  ;;; Base condition for networking errors.  ;;; Base condition for networking errors.
490  (define-condition network-error (simple-error) ())  (define-condition network-error (simple-error) ())
491    
# Line 249  that the calling thread is the one that Line 503  that the calling thread is the one that
503    
504  (defconstant +sigint+ 2)  (defconstant +sigint+ 2)
505    
 (definterface call-without-interrupts (fn)  
   "Call FN in a context where interrupts are disabled."  
   (funcall fn))  
   
506  (definterface getpid ()  (definterface getpid ()
507    "Return the (Unix) process ID of this superior Lisp.")    "Return the (Unix) process ID of this superior Lisp.")
508    
509    (definterface install-sigint-handler (function)
510      "Call FUNCTION on SIGINT (instead of invoking the debugger).
511    Return old signal handler."
512      (declare (ignore function))
513      nil)
514    
515    (definterface call-with-user-break-handler (handler function)
516      "Install the break handler HANDLER while executing FUNCTION."
517      (let ((old-handler (install-sigint-handler handler)))
518        (unwind-protect (funcall function)
519          (install-sigint-handler old-handler))))
520    
521    (definterface quit-lisp ()
522      "Exit the current lisp image.")
523    
524  (definterface lisp-implementation-type-name ()  (definterface lisp-implementation-type-name ()
525    "Return a short name for the Lisp implementation."    "Return a short name for the Lisp implementation."
526    (lisp-implementation-type))    (lisp-implementation-type))
527    
528    (definterface lisp-implementation-program ()
529      "Return the argv[0] of the running Lisp process, or NIL."
530      (let ((file (car (command-line-args))))
531        (when (and file (probe-file file))
532          (namestring (truename file)))))
533    
534    (definterface socket-fd (socket-stream)
535      "Return the file descriptor for SOCKET-STREAM.")
536    
537    (definterface make-fd-stream (fd external-format)
538      "Create a character stream for the file descriptor FD.")
539    
540    (definterface dup (fd)
541      "Duplicate a file descriptor.
542    If the syscall fails, signal a condition.
543    See dup(2).")
544    
545    (definterface exec-image (image-file args)
546      "Replace the current process with a new process image.
547    The new image is created by loading the previously dumped
548    core file IMAGE-FILE.
549    ARGS is a list of strings passed as arguments to
550    the new image.
551    This is thin wrapper around exec(3).")
552    
553    (definterface command-line-args ()
554      "Return a list of strings as passed by the OS."
555      nil)
556    
557    
558    ;; pathnames are sooo useless
559    
560    (definterface filename-to-pathname (filename)
561      "Return a pathname for FILENAME.
562    A filename in Emacs may for example contain asterisks which should not
563    be translated to wildcards."
564      (parse-namestring filename))
565    
566    (definterface pathname-to-filename (pathname)
567      "Return the filename for PATHNAME."
568      (namestring pathname))
569    
570  (definterface default-directory ()  (definterface default-directory ()
571    "Return the default directory."    "Return the default directory."
572    (directory-namestring (truename *default-pathname-defaults*)))    (directory-namestring (truename *default-pathname-defaults*)))
# Line 270  This is used to resolve filenames withou Line 577  This is used to resolve filenames withou
577    (setf *default-pathname-defaults* (truename (merge-pathnames directory)))    (setf *default-pathname-defaults* (truename (merge-pathnames directory)))
578    (default-directory))    (default-directory))
579    
580    
581  (definterface call-with-syntax-hooks (fn)  (definterface call-with-syntax-hooks (fn)
582    "Call FN with hooks to handle special syntax."    "Call FN with hooks to handle special syntax."
583    (funcall fn))    (funcall fn))
# Line 278  This is used to resolve filenames withou Line 586  This is used to resolve filenames withou
586    "Return a suitable initial value for SWANK:*READTABLE-ALIST*."    "Return a suitable initial value for SWANK:*READTABLE-ALIST*."
587    '())    '())
588    
 (definterface quit-lisp ()  
   "Exit the current lisp image.")  
   
589    
590  ;;;; Compilation  ;;;; Compilation
591    
# Line 292  This is used to resolve filenames withou Line 597  This is used to resolve filenames withou
597    (declare (ignore ignore))    (declare (ignore ignore))
598    `(call-with-compilation-hooks (lambda () (progn ,@body))))    `(call-with-compilation-hooks (lambda () (progn ,@body))))
599    
600  (definterface swank-compile-string (string &key buffer position directory)  (definterface swank-compile-string (string &key buffer position filename
601    "Compile source from STRING.  During compilation, compiler                                             policy)
602  conditions must be trapped and resignalled as COMPILER-CONDITIONs.    "Compile source from STRING.
603    During compilation, compiler conditions must be trapped and
604    resignalled as COMPILER-CONDITIONs.
605    
606  If supplied, BUFFER and POSITION specify the source location in Emacs.  If supplied, BUFFER and POSITION specify the source location in Emacs.
607    
608  Additionally, if POSITION is supplied, it must be added to source  Additionally, if POSITION is supplied, it must be added to source
609  positions reported in compiler conditions.  positions reported in compiler conditions.
610    
611  If DIRECTORY is specified it may be used by certain implementations to  If FILENAME is specified it may be used by certain implementations to
612  rebind *DEFAULT-PATHNAME-DEFAULTS* which may improve the recording of  rebind *DEFAULT-PATHNAME-DEFAULTS* which may improve the recording of
613  source information.")  source information.
614    
615  (definterface operate-on-system (system-name operation-name &rest keyword-args)  If POLICY is supplied, and non-NIL, it may be used by certain
616    "Perform OPERATION-NAME on SYSTEM-NAME using ASDF.  implementations to compile with optimization qualities of its
617  The KEYWORD-ARGS are passed on to the operation.  value.
618  Example:  
619  \(operate-on-system \"SWANK\" \"COMPILE-OP\" :force t)"  Should return T on successful compilation, NIL otherwise.
620    (unless (member :asdf *features*)  ")
621      (error "ASDF is not loaded."))  
622    (with-compilation-hooks ()  (definterface swank-compile-file (input-file output-file load-p
623      (let ((operate (find-symbol "OPERATE" :asdf))                                               external-format
624            (operation (find-symbol operation-name :asdf)))                                               &key policy)
625        (when (null operation)     "Compile INPUT-FILE signalling COMPILE-CONDITIONs.
626          (error "Couldn't find ASDF operation ~S" operation-name))  If LOAD-P is true, load the file after compilation.
627        (apply operate operation system-name keyword-args))))  EXTERNAL-FORMAT is a value returned by find-external-format or
628    :default.
629  (definterface swank-compile-file (filename load-p &optional external-format)  
630     "Compile FILENAME signalling COMPILE-CONDITIONs.  If POLICY is supplied, and non-NIL, it may be used by certain
631  If LOAD-P is true, load the file after compilation.")  implementations to compile with optimization qualities of its
632    value.
633    
634    Should return OUTPUT-TRUENAME, WARNINGS-P and FAILURE-p
635    like `compile-file'")
636    
637  (deftype severity ()  (deftype severity ()
638    '(member :error :read-error :warning :style-warning :note))    '(member :error :read-error :warning :style-warning :note :redefinition))
639    
640  ;; Base condition type for compiler errors, warnings and notes.  ;; Base condition type for compiler errors, warnings and notes.
641  (define-condition compiler-condition (condition)  (define-condition compiler-condition (condition)
# Line 342  If LOAD-P is true, load the file after c Line 653  If LOAD-P is true, load the file after c
653     (message :initarg :message     (message :initarg :message
654              :accessor message)              :accessor message)
655    
656     (short-message :initarg :short-message     ;; Macro expansion history etc. which may be helpful in some cases
657                    :initform nil     ;; but is often very verbose.
658                    :accessor short-message)     (source-context :initarg :source-context
659                       :type (or null string)
660                       :initform nil
661                       :accessor source-context)
662    
663     (references :initarg :references     (references :initarg :references
664                 :initform nil                 :initform nil
# Line 353  If LOAD-P is true, load the file after c Line 667  If LOAD-P is true, load the file after c
667     (location :initarg :location     (location :initarg :location
668               :accessor location)))               :accessor location)))
669    
670    (definterface find-external-format (coding-system)
671      "Return a \"external file format designator\" for CODING-SYSTEM.
672    CODING-SYSTEM is Emacs-style coding system name (a string),
673    e.g. \"latin-1-unix\"."
674      (if (equal coding-system "iso-latin-1-unix")
675          :default
676          nil))
677    
678    (definterface guess-external-format (pathname)
679      "Detect the external format for the file with name pathname.
680    Return nil if the file contains no special markers."
681      ;; Look for a Emacs-style -*- coding: ... -*- or Local Variable: section.
682      (with-open-file (s pathname :if-does-not-exist nil
683                         :external-format (or (find-external-format "latin-1-unix")
684                                              :default))
685        (if s
686            (or (let* ((line (read-line s nil))
687                       (p (search "-*-" line)))
688                  (when p
689                    (let* ((start (+ p (length "-*-")))
690                           (end (search "-*-" line :start2 start)))
691                      (when end
692                        (%search-coding line start end)))))
693                (let* ((len (file-length s))
694                       (buf (make-string (min len 3000))))
695                  (file-position s (- len (length buf)))
696                  (read-sequence buf s)
697                  (let ((start (search "Local Variables:" buf :from-end t))
698                        (end (search "End:" buf :from-end t)))
699                    (and start end (< start end)
700                         (%search-coding buf start end))))))))
701    
702    (defun %search-coding (str start end)
703      (let ((p (search "coding:" str :start2 start :end2 end)))
704        (when p
705          (incf p (length "coding:"))
706          (loop while (and (< p end)
707                           (member (aref str p) '(#\space #\tab)))
708                do (incf p))
709          (let ((end (position-if (lambda (c) (find c '(#\space #\tab #\newline)))
710                                  str :start p)))
711            (find-external-format (subseq str p end))))))
712    
713    
714  ;;;; Streams  ;;;; Streams
715    
716  (definterface make-fn-streams (input-fn output-fn)  (definterface make-output-stream (write-string)
717     "Return character input and output streams backended by functions.    "Return a new character output stream.
718  When input is needed, INPUT-FN is called with no arguments to  The stream calls WRITE-STRING when output is ready.")
719  return a string.  
720  When output is ready, OUTPUT-FN is called with the output as its  (definterface make-input-stream (read-string)
721  argument.    "Return a new character input stream.
722    The stream calls READ-STRING when input is needed.")
 Output should be forced to OUTPUT-FN before calling INPUT-FN.  
   
 The streams are returned as two values.")  
   
 (definterface make-stream-interactive (stream)  
   "Do any necessary setup to make STREAM work interactively.  
 This is called for each stream used for interaction with the user  
 \(e.g. *standard-output*). An implementation could setup some  
 implementation-specific functions to control output flushing at the  
 like."  
   (declare (ignore stream))  
   nil)  
723    
724    
725  ;;;; Documentation  ;;;; Documentation
# Line 383  like." Line 728  like."
728     "Return the lambda list for the symbol NAME. NAME can also be     "Return the lambda list for the symbol NAME. NAME can also be
729  a lisp function object, on lisps which support this.  a lisp function object, on lisps which support this.
730    
731  The result can be a list or the :not-available if the arglist  The result can be a list or the :not-available keyword if the
732  cannot be determined."  arglist cannot be determined."
733     (declare (ignore name))     (declare (ignore name))
734     :not-available)     :not-available)
735    
736    (defgeneric declaration-arglist (decl-identifier)
737      (:documentation
738       "Return the argument list of the declaration specifier belonging to the
739    declaration identifier DECL-IDENTIFIER. If the arglist cannot be determined,
740    the keyword :NOT-AVAILABLE is returned.
741    
742    The different SWANK backends can specialize this generic function to
743    include implementation-dependend declaration specifiers, or to provide
744    additional information on the specifiers defined in ANSI Common Lisp.")
745      (:method (decl-identifier)
746        (case decl-identifier
747          (dynamic-extent '(&rest variables))
748          (ignore         '(&rest variables))
749          (ignorable      '(&rest variables))
750          (special        '(&rest variables))
751          (inline         '(&rest function-names))
752          (notinline      '(&rest function-names))
753          (declaration    '(&rest names))
754          (optimize       '(&any compilation-speed debug safety space speed))
755          (type           '(type-specifier &rest args))
756          (ftype          '(type-specifier &rest function-names))
757          (otherwise
758           (flet ((typespec-p (symbol) (member :type (describe-symbol-for-emacs symbol))))
759             (cond ((and (symbolp decl-identifier) (typespec-p decl-identifier))
760                    '(&rest variables))
761                   ((and (listp decl-identifier) (typespec-p (first decl-identifier)))
762                    '(&rest variables))
763                   (t :not-available)))))))
764    
765    (defgeneric type-specifier-arglist (typespec-operator)
766      (:documentation
767       "Return the argument list of the type specifier belonging to
768    TYPESPEC-OPERATOR.. If the arglist cannot be determined, the keyword
769    :NOT-AVAILABLE is returned.
770    
771    The different SWANK backends can specialize this generic function to
772    include implementation-dependend declaration specifiers, or to provide
773    additional information on the specifiers defined in ANSI Common Lisp.")
774      (:method (typespec-operator)
775        (declare (special *type-specifier-arglists*)) ; defined at end of file.
776        (typecase typespec-operator
777          (symbol (or (cdr (assoc typespec-operator *type-specifier-arglists*))
778                      :not-available))
779          (t :not-available))))
780    
781  (definterface function-name (function)  (definterface function-name (function)
782    "Return the name of the function object FUNCTION.    "Return the name of the function object FUNCTION.
783    
# Line 395  The result is either a symbol, a list, o Line 785  The result is either a symbol, a list, o
785    (declare (ignore function))    (declare (ignore function))
786    nil)    nil)
787    
788    (definterface valid-function-name-p (form)
789      "Is FORM syntactically valid to name a function?
790       If true, FBOUNDP should not signal a type-error for FORM."
791      (flet ((length=2 (list)
792               (and (not (null (cdr list))) (null (cddr list)))))
793        (or (symbolp form)
794            (and (consp form) (length=2 form)
795                 (eq (first form) 'setf) (symbolp (second form))))))
796    
797  (definterface macroexpand-all (form)  (definterface macroexpand-all (form)
798     "Recursively expand all macros in FORM.     "Recursively expand all macros in FORM.
799  Return the resulting form.")  Return the resulting form.")
# Line 405  If FORM is a function call for which a c Line 804  If FORM is a function call for which a c
804  defined, invoke the expander function using *macroexpand-hook* and  defined, invoke the expander function using *macroexpand-hook* and
805  return the results and T.  Otherwise, return the original form and  return the results and T.  Otherwise, return the original form and
806  NIL."  NIL."
807    (let ((fun (and (consp form) (compiler-macro-function (car form)))))    (let ((fun (and (consp form)
808                      (valid-function-name-p (car form))
809                      (compiler-macro-function (car form)))))
810      (if fun      (if fun
811          (let ((result (funcall *macroexpand-hook* fun form env)))          (let ((result (funcall *macroexpand-hook* fun form env)))
812            (values result (not (eq result form))))            (values result (not (eq result form))))
# Line 421  NIL." Line 822  NIL."
822                     (values new-form expanded)))))                     (values new-form expanded)))))
823      (frob form env)))      (frob form env)))
824    
825    (definterface format-string-expand (control-string)
826      "Expand the format string CONTROL-STRING."
827      (macroexpand `(formatter ,control-string)))
828    
829  (definterface describe-symbol-for-emacs (symbol)  (definterface describe-symbol-for-emacs (symbol)
830     "Return a property list describing SYMBOL.     "Return a property list describing SYMBOL.
831    
# Line 470  For example, this is a reasonable place Line 875  For example, this is a reasonable place
875  to safe reader/printer settings, and so on.")  to safe reader/printer settings, and so on.")
876    
877  (definterface call-with-debugger-hook (hook fun)  (definterface call-with-debugger-hook (hook fun)
878    "Call FUN and use HOOK as debugger hook.    "Call FUN and use HOOK as debugger hook. HOOK can be NIL.
879    
880  HOOK should be called for both BREAK and INVOKE-DEBUGGER."  HOOK should be called for both BREAK and INVOKE-DEBUGGER."
881    (let ((*debugger-hook* hook))    (let ((*debugger-hook* hook))
# Line 492  debug the debugger! Instead, such condit Line 897  debug the debugger! Instead, such condit
897  user without (re)entering the debugger by wrapping them as  user without (re)entering the debugger by wrapping them as
898  `sldb-condition's."))  `sldb-condition's."))
899    
900    ;;; The following functions in this section are supposed to be called
901    ;;; within the dynamic contour of CALL-WITH-DEBUGGING-ENVIRONMENT only.
902    
903  (definterface compute-backtrace (start end)  (definterface compute-backtrace (start end)
904     "Return a list containing a backtrace of the condition current     "Returns a backtrace of the condition currently being debugged,
905  being debugged.  The results are unspecified if this function is  that is an ordered list consisting of frames. ``Ordered list''
906  called outside the dynamic contour CALL-WITH-DEBUGGING-ENVIRONMENT.  means that an integer I can be mapped back to the i-th frame of this
907    backtrace.
908    
909  START and END are zero-based indices constraining the number of frames  START and END are zero-based indices constraining the number of frames
910  returned.  Frame zero is defined as the frame which invoked the  returned. Frame zero is defined as the frame which invoked the
911  debugger.  If END is nil, return the frames from START to the end of  debugger. If END is nil, return the frames from START to the end of
912  the stack.")  the stack.")
913    
914  (definterface print-frame (frame stream)  (definterface print-frame (frame stream)
915    "Print frame to stream.")    "Print frame to stream.")
916    
917  (definterface frame-source-location-for-emacs (frame-number)  (definterface frame-restartable-p (frame)
918    "Return the source location for FRAME-NUMBER.")    "Is the frame FRAME restartable?.
919    Return T if `restart-frame' can safely be called on the frame."
920      (declare (ignore frame))
921      nil)
922    
923    (definterface frame-source-location (frame-number)
924      "Return the source location for the frame associated to FRAME-NUMBER.")
925    
926  (definterface frame-catch-tags (frame-number)  (definterface frame-catch-tags (frame-number)
927    "Return a list of XXX list of what? catch tags for a debugger    "Return a list of catch tags for being printed in a debugger stack
928  stack frame.  The results are undefined unless this is called  frame."
929  within the dynamic contour of a function defined by    (declare (ignore frame-number))
930  DEFINE-DEBUGGER-HOOK.")    '())
931    
932  (definterface frame-locals (frame-number)  (definterface frame-locals (frame-number)
933    "Return a list of XXX local variable designators define me    "Return a list of ((&key NAME ID VALUE) ...) where each element of
934  for a debugger stack frame.  The results are undefined unless  the list represents a local variable in the stack frame associated to
935  this is called within the dynamic contour of a function defined  FRAME-NUMBER.
936  by DEFINE-DEBUGGER-HOOK.")  
937    NAME, a symbol; the name of the local variable.
938  (definterface frame-var-value (frame var)  
939    "Return the value of VAR in FRAME.  ID, an integer; used as primary key for the local variable, unique
940  FRAME is the number of the frame in the backtrace.  relatively to the frame under operation.
941  VAR is the number of the variable in the frame.")  
942    value, an object; the value of the local variable.")
943    
944    (definterface frame-var-value (frame-number var-id)
945      "Return the value of the local variable associated to VAR-ID
946    relatively to the frame associated to FRAME-NUMBER.")
947    
948  (definterface disassemble-frame (frame-number)  (definterface disassemble-frame (frame-number)
949    "Disassemble the code for the FRAME-NUMBER.    "Disassemble the code for the FRAME-NUMBER.
# Line 532  FRAME-NUMBER is a non-negative integer." Line 952  FRAME-NUMBER is a non-negative integer."
952    
953  (definterface eval-in-frame (form frame-number)  (definterface eval-in-frame (form frame-number)
954     "Evaluate a Lisp form in the lexical context of a stack frame     "Evaluate a Lisp form in the lexical context of a stack frame
955  in the debugger.  The results are undefined unless called in the  in the debugger.
 dynamic contour of a function defined by DEFINE-DEBUGGER-HOOK.  
956    
957  FRAME-NUMBER must be a positive integer with 0 indicating the  FRAME-NUMBER must be a positive integer with 0 indicating the
958  frame which invoked the debugger.  frame which invoked the debugger.
# Line 541  frame which invoked the debugger. Line 960  frame which invoked the debugger.
960  The return value is the result of evaulating FORM in the  The return value is the result of evaulating FORM in the
961  appropriate context.")  appropriate context.")
962    
963    (definterface frame-package (frame-number)
964      "Return the package corresponding to the frame at FRAME-NUMBER.
965    Return nil if the backend can't figure it out."
966      (declare (ignore frame-number))
967      nil)
968    
969    (definterface frame-call (frame-number)
970      "Return a string representing a call to the entry point of a frame.")
971    
972  (definterface return-from-frame (frame-number form)  (definterface return-from-frame (frame-number form)
973    "Unwind the stack to the frame FRAME-NUMBER and return the value(s)    "Unwind the stack to the frame FRAME-NUMBER and return the value(s)
974  produced by evaluating FORM in the frame context to its caller.  produced by evaluating FORM in the frame context to its caller.
# Line 559  as it was called originally.") Line 987  as it was called originally.")
987    "Format a condition for display in SLDB."    "Format a condition for display in SLDB."
988    (princ-to-string condition))    (princ-to-string condition))
989    
 (definterface condition-references (condition)  
   "Return a list of documentation references for a condition.  
 Each reference is one of:  
   (:ANSI-CL  
    {:FUNCTION | :SPECIAL-OPERATOR | :MACRO | :SECTION | :GLOSSARY }  
    symbol-or-name)  
   (:SBCL :NODE node-name)"  
   (declare (ignore condition))  
   '())  
   
990  (definterface condition-extras (condition)  (definterface condition-extras (condition)
991    "Return a list of extra for the debugger.    "Return a list of extra for the debugger.
992  The allowed elements are of the form:  The allowed elements are of the form:
993    (:SHOW-FRAME-SOURCE frame-number)"    (:SHOW-FRAME-SOURCE frame-number)
994      (:REFERENCES &rest refs)
995    "
996    (declare (ignore condition))    (declare (ignore condition))
997    '())    '())
998    
999    (definterface gdb-initial-commands ()
1000      "List of gdb commands supposed to be executed first for the
1001       ATTACH-GDB restart."
1002      nil)
1003    
1004  (definterface activate-stepping (frame-number)  (definterface activate-stepping (frame-number)
1005    "Prepare the frame FRAME-NUMBER for stepping.")    "Prepare the frame FRAME-NUMBER for stepping.")
1006    
# Line 585  The allowed elements are of the form: Line 1010  The allowed elements are of the form:
1010  (definterface sldb-break-at-start (symbol)  (definterface sldb-break-at-start (symbol)
1011    "Set a breakpoint on the beginning of the function for SYMBOL.")    "Set a breakpoint on the beginning of the function for SYMBOL.")
1012    
1013    (definterface sldb-stepper-condition-p (condition)
1014      "Return true if SLDB was invoked due to a single-stepping condition,
1015    false otherwise. "
1016      (declare (ignore condition))
1017      nil)
1018    
1019    (definterface sldb-step-into ()
1020      "Step into the current single-stepper form.")
1021    
1022    (definterface sldb-step-next ()
1023      "Step to the next form in the current function.")
1024    
1025    (definterface sldb-step-out ()
1026      "Stop single-stepping temporarily, but resume it once the current function
1027    returns.")
1028    
1029    
1030  ;;;; Definition finding  ;;;; Definition finding
# Line 600  The allowed elements are of the form: Line 1040  The allowed elements are of the form:
1040    hints)    hints)
1041    
1042  (defstruct (:error (:type list) :named (:constructor)) message)  (defstruct (:error (:type list) :named (:constructor)) message)
1043  (defstruct (:file (:type list) :named (:constructor)) name)  
1044  (defstruct (:buffer (:type list) :named (:constructor)) name)  ;;; Valid content for BUFFER slot
1045    (defstruct (:file       (:type list) :named (:constructor)) name)
1046    (defstruct (:buffer     (:type list) :named (:constructor)) name)
1047    (defstruct (:etags-file (:type list) :named (:constructor)) filename)
1048    
1049    ;;; Valid content for POSITION slot
1050  (defstruct (:position (:type list) :named (:constructor)) pos)  (defstruct (:position (:type list) :named (:constructor)) pos)
1051    (defstruct (:tag      (:type list) :named (:constructor)) tag1 tag2)
1052    
1053    (defmacro converting-errors-to-error-location (&body body)
1054      "Catches errors during BODY and converts them to an error location."
1055      (let ((gblock (gensym "CONVERTING-ERRORS+")))
1056        `(block ,gblock
1057           (handler-bind ((error
1058                           #'(lambda (e)
1059                                (if *debug-swank-backend*
1060                                    nil     ;decline
1061                                    (return-from ,gblock
1062                                      (make-error-location e))))))
1063             ,@body))))
1064    
1065    (defun make-error-location (datum &rest args)
1066      (cond ((typep datum 'condition)
1067             `(:error ,(format nil "Error: ~A" datum)))
1068            ((symbolp datum)
1069             `(:error ,(format nil "Error: ~A" (apply #'make-condition datum args))))
1070            (t
1071             (assert (stringp datum))
1072             `(:error ,(apply #'format nil datum args)))))
1073    
1074  (definterface find-definitions (name)  (definterface find-definitions (name)
1075     "Return a list ((DSPEC LOCATION) ...) for NAME's definitions.     "Return a list ((DSPEC LOCATION) ...) for NAME's definitions.
# Line 615  definition, e.g., FOO or (METHOD FOO (ST Line 1082  definition, e.g., FOO or (METHOD FOO (ST
1082    
1083  LOCATION is the source location for the definition.")  LOCATION is the source location for the definition.")
1084    
1085    (definterface find-source-location (object)
1086      "Returns the source location of OBJECT, or NIL.
1087    
1088    That is the source location of the underlying datastructure of
1089    OBJECT. E.g. on a STANDARD-OBJECT, the source location of the
1090    respective DEFCLASS definition is returned, on a STRUCTURE-CLASS the
1091    respective DEFSTRUCT definition, and so on."
1092      ;; This returns one source location and not a list of locations. It's
1093      ;; supposed to return the location of the DEFGENERIC definition on
1094      ;; #'SOME-GENERIC-FUNCTION.
1095      (declare (ignore object))
1096      (make-error-location "FIND-DEFINITIONS is not yet implemented on ~
1097                            this implementation."))
1098    
1099  (definterface buffer-first-change (filename)  (definterface buffer-first-change (filename)
1100    "Called for effect the first time FILENAME's buffer is modified."    "Called for effect the first time FILENAME's buffer is modified.
1101    CMUCL/SBCL use this to cache the unmodified file and use the
1102    unmodified text to improve the precision of source locations."
1103    (declare (ignore filename))    (declare (ignore filename))
1104    nil)    nil)
1105    
1106    
1107    
1108  ;;;; XREF  ;;;; XREF
1109    
1110  (definterface who-calls (function-name)  (definterface who-calls (function-name)
1111    "Return the call sites of FUNCTION-NAME (a symbol).    "Return the call sites of FUNCTION-NAME (a symbol).
1112  The results is a list ((DSPEC LOCATION) ...).")  The results is a list ((DSPEC LOCATION) ...)."
1113      (declare (ignore function-name))
1114      :not-implemented)
1115    
1116  (definterface calls-who (function-name)  (definterface calls-who (function-name)
1117    "Return the call sites of FUNCTION-NAME (a symbol).    "Return the call sites of FUNCTION-NAME (a symbol).
1118  The results is a list ((DSPEC LOCATION) ...).")  The results is a list ((DSPEC LOCATION) ...)."
1119      (declare (ignore function-name))
1120      :not-implemented)
1121    
1122  (definterface who-references (variable-name)  (definterface who-references (variable-name)
1123    "Return the locations where VARIABLE-NAME (a symbol) is referenced.    "Return the locations where VARIABLE-NAME (a symbol) is referenced.
1124  See WHO-CALLS for a description of the return value.")  See WHO-CALLS for a description of the return value."
1125      (declare (ignore variable-name))
1126      :not-implemented)
1127    
1128  (definterface who-binds (variable-name)  (definterface who-binds (variable-name)
1129    "Return the locations where VARIABLE-NAME (a symbol) is bound.    "Return the locations where VARIABLE-NAME (a symbol) is bound.
1130  See WHO-CALLS for a description of the return value.")  See WHO-CALLS for a description of the return value."
1131      (declare (ignore variable-name))
1132      :not-implemented)
1133    
1134  (definterface who-sets (variable-name)  (definterface who-sets (variable-name)
1135    "Return the locations where VARIABLE-NAME (a symbol) is set.    "Return the locations where VARIABLE-NAME (a symbol) is set.
1136  See WHO-CALLS for a description of the return value.")  See WHO-CALLS for a description of the return value."
1137      (declare (ignore variable-name))
1138      :not-implemented)
1139    
1140  (definterface who-macroexpands (macro-name)  (definterface who-macroexpands (macro-name)
1141    "Return the locations where MACRO-NAME (a symbol) is expanded.    "Return the locations where MACRO-NAME (a symbol) is expanded.
1142  See WHO-CALLS for a description of the return value.")  See WHO-CALLS for a description of the return value."
1143      (declare (ignore macro-name))
1144      :not-implemented)
1145    
1146  (definterface who-specializes (class-name)  (definterface who-specializes (class-name)
1147    "Return the locations where CLASS-NAME (a symbol) is specialized.    "Return the locations where CLASS-NAME (a symbol) is specialized.
1148  See WHO-CALLS for a description of the return value.")  See WHO-CALLS for a description of the return value."
1149      (declare (ignore class-name))
1150      :not-implemented)
1151    
1152  ;;; Simpler variants.  ;;; Simpler variants.
1153    
# Line 704  generic functions having names in the gi Line 1202  generic functions having names in the gi
1202  themselves, that is, their dispatch functions, are left alone.")  themselves, that is, their dispatch functions, are left alone.")
1203    
1204    
1205  ;;;; Inspector  ;;;; Trace
1206    
1207  (defclass inspector ()  (definterface toggle-trace (spec)
1208    ()    "Toggle tracing of the function(s) given with SPEC.
1209    (:documentation "Super class of inspector objects.  SPEC can be:
1210     (setf NAME)                            ; a setf function
1211  Implementations should sub class in order to dispatch off of the   (:defmethod NAME QUALIFIER... (SPECIALIZER...)) ; a specific method
1212  inspect-for-emacs method."))   (:defgeneric NAME)                     ; a generic function with all methods
1213     (:call CALLER CALLEE)                  ; trace calls from CALLER to CALLEE.
1214     (:labels TOPLEVEL LOCAL)
1215     (:flet TOPLEVEL LOCAL) ")
1216    
1217  (definterface make-default-inspector ()  
1218    "Return an inspector object suitable for passing to inspect-for-emacs.")  ;;;; Inspector
1219    
1220  (definterface inspect-for-emacs (object inspector)  (defgeneric emacs-inspect (object)
1221      (:documentation
1222     "Explain to Emacs how to inspect OBJECT.     "Explain to Emacs how to inspect OBJECT.
1223    
1224  The argument INSPECTOR is an object representing how to get at  Returns a list specifying how to render the object for inspection.
 the internals of OBJECT, it is usually an implementation specific  
 class used simply for dispatching to the proper method.  
   
 The orgument INSPECTION-MODE is an object specifying how, and  
 what, to show to the user.  
   
 Returns two values: a string which will be used as the title of  
 the inspector buffer and a list specifying how to render the  
 object for inspection.  
1225    
1226  Every element of the list must be either a string, which will be  Every element of the list must be either a string, which will be
1227  inserted into the buffer as is, or a list of the form:  inserted into the buffer as is, or a list of the form:
# Line 739  inserted into the buffer as is, or a lis Line 1232  inserted into the buffer as is, or a lis
1232    
1233   (:newline) - Render a \\n   (:newline) - Render a \\n
1234    
1235   (:action label lambda) - Render LABEL (a text string) which when   (:action label lambda &key (refresh t)) - Render LABEL (a text
1236   clicked will call LAMBDA.   string) which when clicked will call LAMBDA. If REFRESH is
1237     non-NIL the currently inspected object will be re-inspected
1238   NIL - do nothing.")   after calling the lambda.
1239    "))
1240    
1241  (defmethod inspect-for-emacs ((object t) (inspector t))  (defmethod emacs-inspect ((object t))
1242    "Generic method for inspecting any kind of object.    "Generic method for inspecting any kind of object.
1243    
1244  Since we don't know how to deal with OBJECT we simply dump the  Since we don't know how to deal with OBJECT we simply dump the
1245  output of CL:DESCRIBE."  output of CL:DESCRIBE."
   (declare (ignore inspector))  
   (values  
    "A value."  
1246     `("Type: " (:value ,(type-of object)) (:newline)     `("Type: " (:value ,(type-of object)) (:newline)
1247       "Don't know how to inspect the object, dumping output of CL:DESCRIBE:"       "Don't know how to inspect the object, dumping output of CL:DESCRIBE:"
1248       (:newline) (:newline)       (:newline) (:newline)
1249       ,(with-output-to-string (desc) (describe object desc)))))       ,(with-output-to-string (desc) (describe object desc))))
1250    
1251    (definterface eval-context (object)
1252      "Return a list of bindings corresponding to OBJECT's slots."
1253      (declare (ignore object))
1254      '())
1255    
1256  ;;; Utilities for inspector methods.  ;;; Utilities for inspector methods.
1257  ;;;  ;;;
1258  (defun label-value-line (label value)  
1259    "Create a control list which prints \"LABEL: VALUE\" in the inspector."  (defun label-value-line (label value &key (newline t))
1260    (list (princ-to-string label) ": " `(:value ,value) '(:newline)))    "Create a control list which prints \"LABEL: VALUE\" in the inspector.
1261    If NEWLINE is non-NIL a `(:newline)' is added to the result."
1262      (list* (princ-to-string label) ": " `(:value ,value)
1263             (if newline '((:newline)) nil)))
1264    
1265  (defmacro label-value-line* (&rest label-values)  (defmacro label-value-line* (&rest label-values)
1266    ` (append ,@(loop for (label value) in label-values    ` (append ,@(loop for (label value) in label-values
# Line 778  output of CL:DESCRIBE." Line 1277  output of CL:DESCRIBE."
1277  ;;; The default implementations are sufficient for non-multiprocessing  ;;; The default implementations are sufficient for non-multiprocessing
1278  ;;; implementations.  ;;; implementations.
1279    
1280  (definterface initialize-multiprocessing ()  (definterface initialize-multiprocessing (continuation)
1281     "Initialize multiprocessing, if necessary."     "Initialize multiprocessing, if necessary and then invoke CONTINUATION.
    nil)  
1282    
1283  (definterface startup-idle-and-top-level-loops ()  Depending on the impleimentaion, this function may never return."
1284    "This function is called directly through the listener, not in an RPC     (funcall continuation))
 from Emacs. This is to support interfaces such as CMUCL's  
 MP::STARTUP-IDLE-AND-TOP-LEVEL-LOOPS which does not return like a  
 normal function."  
    nil)  
1285    
1286  (definterface spawn (fn &key name)  (definterface spawn (fn &key name)
1287    "Create a new thread to call FN.")    "Create a new thread to call FN.")
# Line 796  normal function." Line 1290  normal function."
1290    "Return an Emacs-parsable object to identify THREAD.    "Return an Emacs-parsable object to identify THREAD.
1291    
1292  Ids should be comparable with equal, i.e.:  Ids should be comparable with equal, i.e.:
1293   (equal (thread-id <t1>) (thread-id <t2>)) <==> (eq <t1> <t2>)")   (equal (thread-id <t1>) (thread-id <t2>)) <==> (eq <t1> <t2>)"
1294      thread)
1295    
1296  (definterface find-thread (id)  (definterface find-thread (id)
1297    "Return the thread for ID.    "Return the thread for ID.
1298  ID should be an id previously obtained with THREAD-ID.  ID should be an id previously obtained with THREAD-ID.
1299  Can return nil if the thread no longer exists.")  Can return nil if the thread no longer exists."
1300      (declare (ignore id))
1301      (current-thread))
1302    
1303  (definterface thread-name (thread)  (definterface thread-name (thread)
1304     "Return the name of THREAD.     "Return the name of THREAD.
1305    Thread names are short strings meaningful to the user. They do not
1306  Thread names are be single-line strings and are meaningful to the  have to be unique."
 user. They do not have to be unique."  
1307     (declare (ignore thread))     (declare (ignore thread))
1308     "The One True Thread")     "The One True Thread")
1309    
# Line 816  user. They do not have to be unique." Line 1312  user. They do not have to be unique."
1312     (declare (ignore thread))     (declare (ignore thread))
1313     "")     "")
1314    
1315  (definterface make-lock (&key name)  (definterface thread-attributes (thread)
1316     "Make a lock for thread synchronization.    "Return a plist of implementation-dependent attributes for THREAD"
1317  Only one thread may hold the lock (via CALL-WITH-LOCK-HELD) at a time."    (declare (ignore thread))
1318     (declare (ignore name))    '())
    :null-lock)  
   
 (definterface call-with-lock-held (lock function)  
    "Call FUNCTION with LOCK held, queueing if necessary."  
    (declare (ignore lock)  
             (type function function))  
    (funcall function))  
1319    
1320  (definterface current-thread ()  (definterface current-thread ()
1321    "Return the currently executing thread."    "Return the currently executing thread."
1322    0)    0)
1323    
1324  (definterface all-threads ()  (definterface all-threads ()
1325    "Return a list of all threads.")    "Return a fresh list of all threads."
1326      '())
1327    
1328  (definterface thread-alive-p (thread)  (definterface thread-alive-p (thread)
1329    "Test if THREAD is termintated."    "Test if THREAD is termintated."
# Line 843  Only one thread may hold the lock (via C Line 1333  Only one thread may hold the lock (via C
1333    "Cause THREAD to execute FN.")    "Cause THREAD to execute FN.")
1334    
1335  (definterface kill-thread (thread)  (definterface kill-thread (thread)
1336    "Kill THREAD."    "Terminate THREAD immediately.
1337    Don't execute unwind-protected sections, don't raise conditions.
1338    (Do not pass go, do not collect $200.)"
1339    (declare (ignore thread))    (declare (ignore thread))
1340    nil)    nil)
1341    
1342  (definterface send (thread object)  (definterface send (thread object)
1343    "Send OBJECT to thread THREAD.")    "Send OBJECT to thread THREAD.")
1344    
1345  (definterface receive ()  (definterface receive (&optional timeout)
1346    "Return the next message from current thread's mailbox.")    "Return the next message from current thread's mailbox."
1347      (receive-if (constantly t) timeout))
1348    
1349    (definterface receive-if (predicate &optional timeout)
1350      "Return the first message satisfiying PREDICATE.")
1351    
1352    (definterface set-default-initial-binding (var form)
1353      "Initialize special variable VAR by default with FORM.
1354    
1355    Some implementations initialize certain variables in each newly
1356    created thread.  This function sets the form which is used to produce
1357    the initial value."
1358      (set var (eval form)))
1359    
1360    ;; List of delayed interrupts.
1361    ;; This should only have thread-local bindings, so no init form.
1362    (defvar *pending-slime-interrupts*)
1363    
1364    (defun check-slime-interrupts ()
1365      "Execute pending interrupts if any.
1366    This should be called periodically in operations which
1367    can take a long time to complete.
1368    Return a boolean indicating whether any interrupts was processed."
1369      (when (and (boundp '*pending-slime-interrupts*)
1370                 *pending-slime-interrupts*)
1371        (funcall (pop *pending-slime-interrupts*))
1372        t))
1373    
1374    (defvar *interrupt-queued-handler* nil
1375      "Function to call on queued interrupts.
1376    Interrupts get queued when an interrupt occurs while interrupt
1377    handling is disabled.
1378    
1379    Backends can use this function to abort slow operations.")
1380    
1381    (definterface wait-for-input (streams &optional timeout)
1382      "Wait for input on a list of streams.  Return those that are ready.
1383    STREAMS is a list of streams
1384    TIMEOUT nil, t, or real number. If TIMEOUT is t, return those streams
1385    which are ready (or have reached end-of-file) without waiting.
1386    If TIMEOUT is a number and no streams is ready after TIMEOUT seconds,
1387    return nil.
1388    
1389  (definterface toggle-trace (spec)  Return :interrupt if an interrupt occurs while waiting.")
1390    "Toggle tracing of the function(s) given with SPEC.  
1391  SPEC can be:  
1392   (setf NAME)                            ; a setf function  ;;;;  Locks
1393   (:defmethod NAME QUALIFIER... (SPECIALIZER...)) ; a specific method  
1394   (:defgeneric NAME)                     ; a generic function with all methods  ;; Please use locks only in swank-gray.lisp.  Locks are too low-level
1395   (:call CALLER CALLEE)                  ; trace calls from CALLER to CALLEE.  ;; for our taste.
1396   (:labels TOPLEVEL LOCAL)  
1397   (:flet TOPLEVEL LOCAL) ")  (definterface make-lock (&key name)
1398       "Make a lock for thread synchronization.
1399    Only one thread may hold the lock (via CALL-WITH-LOCK-HELD) at a time
1400    but that thread may hold it more than once."
1401       (declare (ignore name))
1402       :null-lock)
1403    
1404    (definterface call-with-lock-held (lock function)
1405       "Call FUNCTION with LOCK held, queueing if necessary."
1406       (declare (ignore lock)
1407                (type function function))
1408       (funcall function))
1409    
1410    ;; Same here: don't use this outside of swank-gray.lisp.
1411    (definterface call-with-io-timeout (function &key seconds)
1412      "Calls function with the specified IO timeout."
1413      (declare (ignore seconds))
1414      (funcall function))
1415    
1416    
1417  ;;;; Weak datastructures  ;;;; Weak datastructures
# Line 873  SPEC can be: Line 1423  SPEC can be:
1423  (definterface make-weak-value-hash-table (&rest args)  (definterface make-weak-value-hash-table (&rest args)
1424    "Like MAKE-HASH-TABLE, but weak w.r.t. the values."    "Like MAKE-HASH-TABLE, but weak w.r.t. the values."
1425    (apply #'make-hash-table args))    (apply #'make-hash-table args))
1426    
1427    (definterface hash-table-weakness (hashtable)
1428      "Return nil or one of :key :value :key-or-value :key-and-value"
1429      (declare (ignore hashtable))
1430      nil)
1431    
1432    
1433    ;;;; Character names
1434    
1435    (definterface character-completion-set (prefix matchp)
1436      "Return a list of names of characters that match PREFIX."
1437      ;; Handle the standard and semi-standard characters.
1438      (loop for name in '("Newline" "Space" "Tab" "Page" "Rubout"
1439                          "Linefeed" "Return" "Backspace")
1440         when (funcall matchp prefix name)
1441         collect name))
1442    
1443    
1444    (defparameter *type-specifier-arglists*
1445      '((and                . (&rest type-specifiers))
1446        (array              . (&optional element-type dimension-spec))
1447        (base-string        . (&optional size))
1448        (bit-vector         . (&optional size))
1449        (complex            . (&optional type-specifier))
1450        (cons               . (&optional car-typespec cdr-typespec))
1451        (double-float       . (&optional lower-limit upper-limit))
1452        (eql                . (object))
1453        (float              . (&optional lower-limit upper-limit))
1454        (function           . (&optional arg-typespec value-typespec))
1455        (integer            . (&optional lower-limit upper-limit))
1456        (long-float         . (&optional lower-limit upper-limit))
1457        (member             . (&rest eql-objects))
1458        (mod                . (n))
1459        (not                . (type-specifier))
1460        (or                 . (&rest type-specifiers))
1461        (rational           . (&optional lower-limit upper-limit))
1462        (real               . (&optional lower-limit upper-limit))
1463        (satisfies          . (predicate-symbol))
1464        (short-float        . (&optional lower-limit upper-limit))
1465        (signed-byte        . (&optional size))
1466        (simple-array       . (&optional element-type dimension-spec))
1467        (simple-base-string . (&optional size))
1468        (simple-bit-vector  . (&optional size))
1469        (simple-string      . (&optional size))
1470        (single-float       . (&optional lower-limit upper-limit))
1471        (simple-vector      . (&optional size))
1472        (string             . (&optional size))
1473        (unsigned-byte      . (&optional size))
1474        (values             . (&rest typespecs))
1475        (vector             . (&optional element-type size))
1476        ))
1477    
1478    ;;; Heap dumps
1479    
1480    (definterface save-image (filename &optional restart-function)
1481      "Save a heap image to the file FILENAME.
1482    RESTART-FUNCTION, if non-nil, should be called when the image is loaded.")
1483    
1484    (definterface background-save-image (filename &key restart-function
1485                                                  completion-function)
1486      "Request saving a heap image to the file FILENAME.
1487    RESTART-FUNCTION, if non-nil, should be called when the image is loaded.
1488    COMPLETION-FUNCTION, if non-nil, should be called after saving the image.")

Legend:
Removed from v.1.94  
changed lines
  Added in v.1.215

  ViewVC Help
Powered by ViewVC 1.1.5