/[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.172 by heller, Sat Feb 14 12:33:28 2009 UTC
# Line 19  Line 19 
19             #:short-message             #:short-message
20             #:condition             #:condition
21             #:severity             #:severity
22               #:with-compilation-hooks
23             #:location             #:location
24             #:location-p             #:location-p
25             #:location-buffer             #:location-buffer
# Line 29  Line 30 
30             #:quit-lisp             #:quit-lisp
31             #:references             #:references
32             #:unbound-slot-filler             #: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               #:*interrupt-queued-handler*
39             ;; inspector related symbols             ;; inspector related symbols
40             #:inspector             #:emacs-inspect
            #:inspect-for-emacs  
            #:raw-inspection  
            #:fancy-inspection  
41             #:label-value-line             #:label-value-line
42             #:label-value-line*             #:label-value-line*
43    
44               #:with-struct
45             ))             ))
46    
47  (defpackage :swank-mop  (defpackage :swank-mop
# Line 84  Line 90 
90     #:slot-definition-type     #:slot-definition-type
91     #:slot-definition-readers     #:slot-definition-readers
92     #:slot-definition-writers     #:slot-definition-writers
93       #:slot-boundp-using-class
94       #:slot-value-using-class
95       #:slot-makunbound-using-class
96     ;; generic function protocol     ;; generic function protocol
97     #:compute-applicable-methods-using-classes     #:compute-applicable-methods-using-classes
98     #:finalize-inheritance))     #:finalize-inheritance))
# Line 102  DEFINTERFACE adds to this list and DEFIM Line 111  DEFINTERFACE adds to this list and DEFIM
111    
112  (defmacro definterface (name args documentation &rest default-body)  (defmacro definterface (name args documentation &rest default-body)
113    "Define an interface function for the backend to implement.    "Define an interface function for the backend to implement.
114  A generic function is defined with NAME, ARGS, and DOCUMENTATION.  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  If a DEFAULT-BODY is supplied then NO-APPLICABLE-METHOD is specialized  that is indicated by 'IMPLEMENTATION; failing that, it looks for a
117  to execute the body if the backend doesn't provide a specific  function indicated by 'DEFAULT. If neither is present, an error is
118  implementation.  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."  Backends implement these functions using DEFIMPLEMENTATION."
125    (check-type documentation string "a documentation string")    (check-type documentation string "a documentation string")
126    (flet ((gen-default-impl ()    (assert (every #'symbolp args) ()
127             `(defmethod ,name ,args ,@default-body)))            "Complex lambda-list not supported: ~S ~S" name args)
128      `(progn (defgeneric ,name ,args (:documentation ,documentation))    (labels ((gen-default-impl ()
129              (pushnew ',name *interface-functions*)               `(setf (get ',name 'default) (lambda ,args ,@default-body)))
130              ,(if (null default-body)             (args-as-list (args)
131                   `(pushnew ',name *unimplemented-interfaces*)               (destructuring-bind (req opt key rest) (parse-lambda-list args)
132                   (gen-default-impl))                 `(,@req ,@opt
133              ;; 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))
134              (eval-when (:compile-toplevel :load-toplevel :execute)                         ,@(or rest '(())))))
135                (export ',name :swank-backend))             (parse-lambda-list (args)
136              ',name)))               (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)  (defmacro defimplementation (name args &body body)
163    `(progn (defmethod ,name ,args ,@body)    (assert (every #'symbolp args) ()
164            (if (member ',name *interface-functions*)            "Complex lambda-list not supported: ~S ~S" name args)
165                (setq *unimplemented-interfaces*    `(progn
166                      (remove ',name *unimplemented-interfaces*))       (setf (get ',name 'implementation) (lambda ,args ,@body))
167                (warn "DEFIMPLEMENTATION of undefined interface (~S)" ',name))       (if (member ',name *interface-functions*)
168            ',name))           (setq *unimplemented-interfaces*
169                   (remove ',name *unimplemented-interfaces*))
170             (warn "DEFIMPLEMENTATION of undefined interface (~S)" ',name))
171         ',name))
172    
173  (defun warn-unimplemented-interfaces ()  (defun warn-unimplemented-interfaces ()
174    "Warn the user about unimplemented backend features.    "Warn the user about unimplemented backend features.
175  The portable code calls this function at startup."  The portable code calls this function at startup."
176    (warn "These Swank interfaces are unimplemented:~% ~A"    (warn "These Swank interfaces are unimplemented:~% ~:<~{~A~^ ~:_~}~:>"
177          (sort (copy-list *unimplemented-interfaces*) #'string<)))          (list (sort (copy-list *unimplemented-interfaces*) #'string<))))
178    
179  (defun import-to-swank-mop (symbol-list)  (defun import-to-swank-mop (symbol-list)
180    (dolist (sym symbol-list)    (dolist (sym symbol-list)
# Line 158  EXCEPT is a list of symbol names which s Line 198  EXCEPT is a list of symbol names which s
198  (defvar *gray-stream-symbols*  (defvar *gray-stream-symbols*
199    '(:fundamental-character-output-stream    '(:fundamental-character-output-stream
200      :stream-write-char      :stream-write-char
201        :stream-write-string
202      :stream-fresh-line      :stream-fresh-line
203      :stream-force-output      :stream-force-output
204      :stream-finish-output      :stream-finish-output
205      :fundamental-character-input-stream      :fundamental-character-input-stream
206      :stream-read-char      :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      :stream-listen
213      :stream-unread-char      :stream-unread-char
214      :stream-clear-input      :stream-clear-input
# Line 199  EXCEPT is a list of symbol names which s Line 245  EXCEPT is a list of symbol names which s
245                       (t (error "Malformed syntax in WITH-STRUCT: ~A" name))))                       (t (error "Malformed syntax in WITH-STRUCT: ~A" name))))
246            ,@body)))))            ,@body)))))
247    
248    (defun with-symbol (name package)
249      "Generate a form suitable for testing with #+."
250      (if (find-symbol (string name) (string package))
251          '(:and)
252          '(:or)))
253    
254    
255  ;;;; TCP server  ;;;; TCP server
256    
# Line 212  EXCEPT is a list of symbol names which s Line 264  EXCEPT is a list of symbol names which s
264    "Close the socket SOCKET.")    "Close the socket SOCKET.")
265    
266  (definterface accept-connection (socket &key external-format  (definterface accept-connection (socket &key external-format
267                                          buffering)                                          buffering timeout)
268     "Accept a client connection on the listening socket SOCKET.     "Accept a client connection on the listening socket SOCKET.
269  Return a stream for the new connection.")  Return a stream for the new connection.")
270    
# Line 232  Return a stream for the new connection." Line 284  Return a stream for the new connection."
284    "Return one of the symbols :spawn, :sigio, :fd-handler, or NIL."    "Return one of the symbols :spawn, :sigio, :fd-handler, or NIL."
285    nil)    nil)
286    
287    (definterface set-stream-timeout (stream timeout)
288      "Set the 'stream 'timeout.  The timeout is either the real number
289      specifying the timeout in seconds or 'nil for no timeout."
290      (declare (ignore stream timeout))
291      nil)
292    
293  ;;; Base condition for networking errors.  ;;; Base condition for networking errors.
294  (define-condition network-error (simple-error) ())  (define-condition network-error (simple-error) ())
295    
# Line 256  that the calling thread is the one that Line 314  that the calling thread is the one that
314  (definterface getpid ()  (definterface getpid ()
315    "Return the (Unix) process ID of this superior Lisp.")    "Return the (Unix) process ID of this superior Lisp.")
316    
317    (definterface install-sigint-handler (function)
318      "Call FUNCTION on SIGINT (instead of invoking the debugger).
319    Return old signal handler."
320      (declare (ignore function))
321      nil)
322    
323    (definterface call-with-user-break-handler (handler function)
324      "Install the break handler HANDLER while executing FUNCTION."
325      (let ((old-handler (install-sigint-handler handler)))
326        (unwind-protect (funcall function)
327          (install-sigint-handler old-handler))))
328    
329    (definterface quit-lisp ()
330      "Exit the current lisp image.")
331    
332  (definterface lisp-implementation-type-name ()  (definterface lisp-implementation-type-name ()
333    "Return a short name for the Lisp implementation."    "Return a short name for the Lisp implementation."
334    (lisp-implementation-type))    (lisp-implementation-type))
335    
336    
337    ;; pathnames are sooo useless
338    
339    (definterface filename-to-pathname (filename)
340      "Return a pathname for FILENAME.
341    A filename in Emacs may for example contain asterisks which should not
342    be translated to wildcards."
343      (parse-namestring filename))
344    
345    (definterface pathname-to-filename (pathname)
346      "Return the filename for PATHNAME."
347      (namestring pathname))
348    
349  (definterface default-directory ()  (definterface default-directory ()
350    "Return the default directory."    "Return the default directory."
351    (directory-namestring (truename *default-pathname-defaults*)))    (directory-namestring (truename *default-pathname-defaults*)))
# Line 270  This is used to resolve filenames withou Line 356  This is used to resolve filenames withou
356    (setf *default-pathname-defaults* (truename (merge-pathnames directory)))    (setf *default-pathname-defaults* (truename (merge-pathnames directory)))
357    (default-directory))    (default-directory))
358    
359    
360  (definterface call-with-syntax-hooks (fn)  (definterface call-with-syntax-hooks (fn)
361    "Call FN with hooks to handle special syntax."    "Call FN with hooks to handle special syntax."
362    (funcall fn))    (funcall fn))
# Line 278  This is used to resolve filenames withou Line 365  This is used to resolve filenames withou
365    "Return a suitable initial value for SWANK:*READTABLE-ALIST*."    "Return a suitable initial value for SWANK:*READTABLE-ALIST*."
366    '())    '())
367    
 (definterface quit-lisp ()  
   "Exit the current lisp image.")  
   
368    
369  ;;;; Compilation  ;;;; Compilation
370    
# Line 292  This is used to resolve filenames withou Line 376  This is used to resolve filenames withou
376    (declare (ignore ignore))    (declare (ignore ignore))
377    `(call-with-compilation-hooks (lambda () (progn ,@body))))    `(call-with-compilation-hooks (lambda () (progn ,@body))))
378    
379  (definterface swank-compile-string (string &key buffer position directory)  (definterface swank-compile-string (string &key buffer position filename
380    "Compile source from STRING.  During compilation, compiler                                             policy)
381  conditions must be trapped and resignalled as COMPILER-CONDITIONs.    "Compile source from STRING.
382    During compilation, compiler conditions must be trapped and
383    resignalled as COMPILER-CONDITIONs.
384    
385  If supplied, BUFFER and POSITION specify the source location in Emacs.  If supplied, BUFFER and POSITION specify the source location in Emacs.
386    
387  Additionally, if POSITION is supplied, it must be added to source  Additionally, if POSITION is supplied, it must be added to source
388  positions reported in compiler conditions.  positions reported in compiler conditions.
389    
390  If DIRECTORY is specified it may be used by certain implementations to  If FILENAME is specified it may be used by certain implementations to
391  rebind *DEFAULT-PATHNAME-DEFAULTS* which may improve the recording of  rebind *DEFAULT-PATHNAME-DEFAULTS* which may improve the recording of
392  source information.")  source information.
393    
394  (definterface operate-on-system (system-name operation-name &rest keyword-args)  If POLICY is supplied, and non-NIL, it may be used by certain
395    "Perform OPERATION-NAME on SYSTEM-NAME using ASDF.  implementations to compile with a debug optimization quality of its
396  The KEYWORD-ARGS are passed on to the operation.  value.
397  Example:  
398  \(operate-on-system \"SWANK\" \"COMPILE-OP\" :force t)"  Should return T on successfull compilation, NIL otherwise.
399    (unless (member :asdf *features*)  ")
400      (error "ASDF is not loaded."))  
401    (with-compilation-hooks ()  (definterface swank-compile-file (input-file output-file load-p
402      (let ((operate (find-symbol "OPERATE" :asdf))                                               external-format)
403            (operation (find-symbol operation-name :asdf)))     "Compile INPUT-FILE signalling COMPILE-CONDITIONs.
404        (when (null operation)  If LOAD-P is true, load the file after compilation.
405          (error "Couldn't find ASDF operation ~S" operation-name))  EXTERNAL-FORMAT is a value returned by find-external-format or
406        (apply operate operation system-name keyword-args))))  :default.
407    
408  (definterface swank-compile-file (filename load-p &optional external-format)  Should return OUTPUT-TRUENAME, WARNINGS-P and FAILURE-p
409     "Compile FILENAME signalling COMPILE-CONDITIONs.  like `compile-file'")
 If LOAD-P is true, load the file after compilation.")  
410    
411  (deftype severity ()  (deftype severity ()
412    '(member :error :read-error :warning :style-warning :note))    '(member :error :read-error :warning :style-warning :note))
# Line 353  If LOAD-P is true, load the file after c Line 438  If LOAD-P is true, load the file after c
438     (location :initarg :location     (location :initarg :location
439               :accessor location)))               :accessor location)))
440    
441    (definterface find-external-format (coding-system)
442      "Return a \"external file format designator\" for CODING-SYSTEM.
443    CODING-SYSTEM is Emacs-style coding system name (a string),
444    e.g. \"latin-1-unix\"."
445      (if (equal coding-system "iso-latin-1-unix")
446          :default
447          nil))
448    
449    (definterface guess-external-format (pathname)
450      "Detect the external format for the file with name pathname.
451    Return nil if the file contains no special markers."
452      ;; Look for a Emacs-style -*- coding: ... -*- or Local Variable: section.
453      (with-open-file (s pathname :if-does-not-exist nil
454                         :external-format (or (find-external-format "latin-1-unix")
455                                              :default))
456        (if s
457            (or (let* ((line (read-line s nil))
458                       (p (search "-*-" line)))
459                  (when p
460                    (let* ((start (+ p (length "-*-")))
461                           (end (search "-*-" line :start2 start)))
462                      (when end
463                        (%search-coding line start end)))))
464                (let* ((len (file-length s))
465                       (buf (make-string (min len 3000))))
466                  (file-position s (- len (length buf)))
467                  (read-sequence buf s)
468                  (let ((start (search "Local Variables:" buf :from-end t))
469                        (end (search "End:" buf :from-end t)))
470                    (and start end (< start end)
471                         (%search-coding buf start end))))))))
472    
473    (defun %search-coding (str start end)
474      (let ((p (search "coding:" str :start2 start :end2 end)))
475        (when p
476          (incf p (length "coding:"))
477          (loop while (and (< p end)
478                           (member (aref str p) '(#\space #\tab)))
479                do (incf p))
480          (let ((end (position-if (lambda (c) (find c '(#\space #\tab #\newline)))
481                                  str :start p)))
482            (find-external-format (subseq str p end))))))
483    
484    
485  ;;;; Streams  ;;;; Streams
486    
487  (definterface make-fn-streams (input-fn output-fn)  (definterface make-output-stream (write-string)
488     "Return character input and output streams backended by functions.    "Return a new character output stream.
489  When input is needed, INPUT-FN is called with no arguments to  The stream calls WRITE-STRING when output is ready.")
490  return a string.  
491  When output is ready, OUTPUT-FN is called with the output as its  (definterface make-input-stream (read-string)
492  argument.    "Return a new character input stream.
493    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)  
494    
495    
496  ;;;; Documentation  ;;;; Documentation
# Line 383  like." Line 499  like."
499     "Return the lambda list for the symbol NAME. NAME can also be     "Return the lambda list for the symbol NAME. NAME can also be
500  a lisp function object, on lisps which support this.  a lisp function object, on lisps which support this.
501    
502  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
503  cannot be determined."  arglist cannot be determined."
504     (declare (ignore name))     (declare (ignore name))
505     :not-available)     :not-available)
506    
507    (defgeneric declaration-arglist (decl-identifier)
508      (:documentation
509       "Return the argument list of the declaration specifier belonging to the
510    declaration identifier DECL-IDENTIFIER. If the arglist cannot be determined,
511    the keyword :NOT-AVAILABLE is returned.
512    
513    The different SWANK backends can specialize this generic function to
514    include implementation-dependend declaration specifiers, or to provide
515    additional information on the specifiers defined in ANSI Common Lisp.")
516      (:method (decl-identifier)
517        (case decl-identifier
518          (dynamic-extent '(&rest vars))
519          (ignore         '(&rest vars))
520          (ignorable      '(&rest vars))
521          (special        '(&rest vars))
522          (inline         '(&rest function-names))
523          (notinline      '(&rest function-name))
524          (optimize       '(&any compilation-speed debug safety space speed))
525          (type           '(type-specifier &rest args))
526          (ftype          '(type-specifier &rest function-names))
527          (otherwise
528           (flet ((typespec-p (symbol) (member :type (describe-symbol-for-emacs symbol))))
529             (cond ((and (symbolp decl-identifier) (typespec-p decl-identifier))
530                    '(&rest vars))
531                   ((and (listp decl-identifier) (typespec-p (first decl-identifier)))
532                    '(&rest vars))
533                   (t :not-available)))))))
534    
535    (defgeneric type-specifier-arglist (typespec-operator)
536      (:documentation
537       "Return the argument list of the type specifier belonging to
538    TYPESPEC-OPERATOR.. If the arglist cannot be determined, the keyword
539    :NOT-AVAILABLE is returned.
540    
541    The different SWANK backends can specialize this generic function to
542    include implementation-dependend declaration specifiers, or to provide
543    additional information on the specifiers defined in ANSI Common Lisp.")
544      (:method (typespec-operator)
545        (declare (special *type-specifier-arglists*)) ; defined at end of file.
546        (typecase typespec-operator
547          (symbol (or (cdr (assoc typespec-operator *type-specifier-arglists*))
548                      :not-available))
549          (t :not-available))))
550    
551  (definterface function-name (function)  (definterface function-name (function)
552    "Return the name of the function object FUNCTION.    "Return the name of the function object FUNCTION.
553    
# Line 492  debug the debugger! Instead, such condit Line 652  debug the debugger! Instead, such condit
652  user without (re)entering the debugger by wrapping them as  user without (re)entering the debugger by wrapping them as
653  `sldb-condition's."))  `sldb-condition's."))
654    
655    ;;; The following functions in this section are supposed to be called
656    ;;; within the dynamic contour of CALL-WITH-DEBUGGING-ENVIRONMENT only.
657    
658  (definterface compute-backtrace (start end)  (definterface compute-backtrace (start end)
659     "Return a list containing a backtrace of the condition current     "Returns a backtrace of the condition currently being debugged,
660  being debugged.  The results are unspecified if this function is  that is an ordered list consisting of frames. ``Ordered list''
661  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
662    backtrace.
663    
664  START and END are zero-based indices constraining the number of frames  START and END are zero-based indices constraining the number of frames
665  returned.  Frame zero is defined as the frame which invoked the  returned. Frame zero is defined as the frame which invoked the
666  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
667  the stack.")  the stack.")
668    
669  (definterface print-frame (frame stream)  (definterface print-frame (frame stream)
670    "Print frame to stream.")    "Print frame to stream.")
671    
672    (definterface frame-restartable-p (frame)
673      "Is the frame FRAME restartable?.
674    Return T if `restart-frame' can safely be called on the frame."
675      (declare (ignore frame))
676      nil)
677    
678  (definterface frame-source-location-for-emacs (frame-number)  (definterface frame-source-location-for-emacs (frame-number)
679    "Return the source location for FRAME-NUMBER.")    "Return the source location for the frame associated to FRAME-NUMBER.")
680    
681  (definterface frame-catch-tags (frame-number)  (definterface frame-catch-tags (frame-number)
682    "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
683  stack frame.  The results are undefined unless this is called  frame."
684  within the dynamic contour of a function defined by    (declare (ignore frame-number))
685  DEFINE-DEBUGGER-HOOK.")    '())
686    
687  (definterface frame-locals (frame-number)  (definterface frame-locals (frame-number)
688    "Return a list of XXX local variable designators define me    "Return a list of ((&key NAME ID VALUE) ...) where each element of
689  for a debugger stack frame.  The results are undefined unless  the list represents a local variable in the stack frame associated to
690  this is called within the dynamic contour of a function defined  FRAME-NUMBER.
691  by DEFINE-DEBUGGER-HOOK.")  
692    NAME, a symbol; the name of the local variable.
693  (definterface frame-var-value (frame var)  
694    "Return the value of VAR in FRAME.  ID, an integer; used as primary key for the local variable, unique
695  FRAME is the number of the frame in the backtrace.  relatively to the frame under operation.
696  VAR is the number of the variable in the frame.")  
697    value, an object; the value of the local variable.")
698    
699    (definterface frame-var-value (frame-number var-id)
700      "Return the value of the local variable associated to VAR-ID
701    relatively to the frame associated to FRAME-NUMBER.")
702    
703  (definterface disassemble-frame (frame-number)  (definterface disassemble-frame (frame-number)
704    "Disassemble the code for the FRAME-NUMBER.    "Disassemble the code for the FRAME-NUMBER.
# Line 532  FRAME-NUMBER is a non-negative integer." Line 707  FRAME-NUMBER is a non-negative integer."
707    
708  (definterface eval-in-frame (form frame-number)  (definterface eval-in-frame (form frame-number)
709     "Evaluate a Lisp form in the lexical context of a stack frame     "Evaluate a Lisp form in the lexical context of a stack frame
710  in the debugger.  The results are undefined unless called in the  in the debugger.
 dynamic contour of a function defined by DEFINE-DEBUGGER-HOOK.  
711    
712  FRAME-NUMBER must be a positive integer with 0 indicating the  FRAME-NUMBER must be a positive integer with 0 indicating the
713  frame which invoked the debugger.  frame which invoked the debugger.
# Line 559  as it was called originally.") Line 733  as it was called originally.")
733    "Format a condition for display in SLDB."    "Format a condition for display in SLDB."
734    (princ-to-string condition))    (princ-to-string condition))
735    
 (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))  
   '())  
   
736  (definterface condition-extras (condition)  (definterface condition-extras (condition)
737    "Return a list of extra for the debugger.    "Return a list of extra for the debugger.
738  The allowed elements are of the form:  The allowed elements are of the form:
739    (:SHOW-FRAME-SOURCE frame-number)"    (:SHOW-FRAME-SOURCE frame-number)
740      (:REFERENCES &rest refs)
741    "
742    (declare (ignore condition))    (declare (ignore condition))
743    '())    '())
744    
# Line 585  The allowed elements are of the form: Line 751  The allowed elements are of the form:
751  (definterface sldb-break-at-start (symbol)  (definterface sldb-break-at-start (symbol)
752    "Set a breakpoint on the beginning of the function for SYMBOL.")    "Set a breakpoint on the beginning of the function for SYMBOL.")
753    
754    (definterface sldb-stepper-condition-p (condition)
755      "Return true if SLDB was invoked due to a single-stepping condition,
756    false otherwise. "
757      (declare (ignore condition))
758      nil)
759    
760    (definterface sldb-step-into ()
761      "Step into the current single-stepper form.")
762    
763    (definterface sldb-step-next ()
764      "Step to the next form in the current function.")
765    
766    (definterface sldb-step-out ()
767      "Stop single-stepping temporarily, but resume it once the current function
768    returns.")
769    
770    
771  ;;;; Definition finding  ;;;; Definition finding
# Line 615  definition, e.g., FOO or (METHOD FOO (ST Line 796  definition, e.g., FOO or (METHOD FOO (ST
796    
797  LOCATION is the source location for the definition.")  LOCATION is the source location for the definition.")
798    
799    (definterface find-source-location (object)
800      "Returns the source location of OBJECT, or NIL.
801    
802    That is the source location of the underlying datastructure of
803    OBJECT. E.g. on a STANDARD-OBJECT, the source location of the
804    respective DEFCLASS definition is returned, on a STRUCTURE-CLASS the
805    respective DEFSTRUCT definition, and so on."
806      ;; This returns one source location and not a list of locations. It's
807      ;; supposed to return the location of the DEFGENERIC definition on
808      ;; #'SOME-GENERIC-FUNCTION.
809      )
810    
811    
812  (definterface buffer-first-change (filename)  (definterface buffer-first-change (filename)
813    "Called for effect the first time FILENAME's buffer is modified."    "Called for effect the first time FILENAME's buffer is modified."
814    (declare (ignore filename))    (declare (ignore filename))
815    nil)    nil)
816    
817    
818    
819  ;;;; XREF  ;;;; XREF
820    
# Line 706  themselves, that is, their dispatch func Line 901  themselves, that is, their dispatch func
901    
902  ;;;; Inspector  ;;;; Inspector
903    
904  (defclass inspector ()  (defgeneric emacs-inspect (object)
905    ()    (:documentation
   (:documentation "Super class of inspector objects.  
   
 Implementations should sub class in order to dispatch off of the  
 inspect-for-emacs method."))  
   
 (definterface make-default-inspector ()  
   "Return an inspector object suitable for passing to inspect-for-emacs.")  
   
 (definterface inspect-for-emacs (object inspector)  
906     "Explain to Emacs how to inspect OBJECT.     "Explain to Emacs how to inspect OBJECT.
907    
908  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.  
909    
910  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
911  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 916  inserted into the buffer as is, or a lis
916    
917   (:newline) - Render a \\n   (:newline) - Render a \\n
918    
919   (:action label lambda) - Render LABEL (a text string) which when   (:action label lambda &key (refresh t)) - Render LABEL (a text
920   clicked will call LAMBDA.   string) which when clicked will call LAMBDA. If REFRESH is
921     non-NIL the currently inspected object will be re-inspected
922     after calling the lambda.
923    "))
924    
925   NIL - do nothing.")  (defmethod emacs-inspect ((object t))
   
 (defmethod inspect-for-emacs ((object t) (inspector t))  
926    "Generic method for inspecting any kind of object.    "Generic method for inspecting any kind of object.
927    
928  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
929  output of CL:DESCRIBE."  output of CL:DESCRIBE."
   (declare (ignore inspector))  
   (values  
    "A value."  
930     `("Type: " (:value ,(type-of object)) (:newline)     `("Type: " (:value ,(type-of object)) (:newline)
931       "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:"
932       (:newline) (:newline)       (:newline) (:newline)
933       ,(with-output-to-string (desc) (describe object desc)))))       ,(with-output-to-string (desc) (describe object desc))))
934    
935  ;;; Utilities for inspector methods.  ;;; Utilities for inspector methods.
936  ;;;  ;;;
937  (defun label-value-line (label value)  (defun label-value-line (label value &key (newline t))
938    "Create a control list which prints \"LABEL: VALUE\" in the inspector."    "Create a control list which prints \"LABEL: VALUE\" in the inspector.
939    (list (princ-to-string label) ": " `(:value ,value) '(:newline)))  If NEWLINE is non-NIL a `(:newline)' is added to the result."
940      (list* (princ-to-string label) ": " `(:value ,value)
941             (if newline '((:newline)) nil)))
942    
943  (defmacro label-value-line* (&rest label-values)  (defmacro label-value-line* (&rest label-values)
944    ` (append ,@(loop for (label value) in label-values    ` (append ,@(loop for (label value) in label-values
# Line 778  output of CL:DESCRIBE." Line 955  output of CL:DESCRIBE."
955  ;;; The default implementations are sufficient for non-multiprocessing  ;;; The default implementations are sufficient for non-multiprocessing
956  ;;; implementations.  ;;; implementations.
957    
958  (definterface initialize-multiprocessing ()  (definterface initialize-multiprocessing (continuation)
959     "Initialize multiprocessing, if necessary."     "Initialize multiprocessing, if necessary and then invoke CONTINUATION.
    nil)  
960    
961  (definterface startup-idle-and-top-level-loops ()  Depending on the impleimentaion, this function may never return."
962    "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)  
963    
964  (definterface spawn (fn &key name)  (definterface spawn (fn &key name)
965    "Create a new thread to call FN.")    "Create a new thread to call FN.")
# Line 796  normal function." Line 968  normal function."
968    "Return an Emacs-parsable object to identify THREAD.    "Return an Emacs-parsable object to identify THREAD.
969    
970  Ids should be comparable with equal, i.e.:  Ids should be comparable with equal, i.e.:
971   (equal (thread-id <t1>) (thread-id <t2>)) <==> (eq <t1> <t2>)")   (equal (thread-id <t1>) (thread-id <t2>)) <==> (eq <t1> <t2>)"
972      thread)
973    
974  (definterface find-thread (id)  (definterface find-thread (id)
975    "Return the thread for ID.    "Return the thread for ID.
976  ID should be an id previously obtained with THREAD-ID.  ID should be an id previously obtained with THREAD-ID.
977  Can return nil if the thread no longer exists.")  Can return nil if the thread no longer exists."
978      (declare (ignore id))
979      (current-thread))
980    
981  (definterface thread-name (thread)  (definterface thread-name (thread)
982     "Return the name of THREAD.     "Return the name of THREAD.
# Line 816  user. They do not have to be unique." Line 991  user. They do not have to be unique."
991     (declare (ignore thread))     (declare (ignore thread))
992     "")     "")
993    
994    (definterface thread-description (thread)
995      "Return a string describing THREAD."
996      (declare (ignore thread))
997      "")
998    
999    (definterface set-thread-description (thread description)
1000      "Set THREAD's description to DESCRIPTION."
1001      (declare (ignore thread description))
1002      "")
1003    
1004  (definterface make-lock (&key name)  (definterface make-lock (&key name)
1005     "Make a lock for thread synchronization.     "Make a lock for thread synchronization.
1006  Only one thread may hold the lock (via CALL-WITH-LOCK-HELD) at a time."  Only one thread may hold the lock (via CALL-WITH-LOCK-HELD) at a time
1007    but that thread may hold it more than once."
1008     (declare (ignore name))     (declare (ignore name))
1009     :null-lock)     :null-lock)
1010    
# Line 833  Only one thread may hold the lock (via C Line 1019  Only one thread may hold the lock (via C
1019    0)    0)
1020    
1021  (definterface all-threads ()  (definterface all-threads ()
1022    "Return a list of all threads.")    "Return a fresh list of all threads.")
1023    
1024  (definterface thread-alive-p (thread)  (definterface thread-alive-p (thread)
1025    "Test if THREAD is termintated."    "Test if THREAD is termintated."
# Line 850  Only one thread may hold the lock (via C Line 1036  Only one thread may hold the lock (via C
1036  (definterface send (thread object)  (definterface send (thread object)
1037    "Send OBJECT to thread THREAD.")    "Send OBJECT to thread THREAD.")
1038    
1039  (definterface receive ()  (definterface receive (&optional timeout)
1040    "Return the next message from current thread's mailbox.")    "Return the next message from current thread's mailbox."
1041      (receive-if (constantly t) timeout))
1042    
1043    (definterface receive-if (predicate &optional timeout)
1044      "Return the first message satisfiying PREDICATE.")
1045    
1046    (definterface set-default-initial-binding (var form)
1047      "Initialize special variable VAR by default with FORM.
1048    
1049    Some implementations initialize certain variables in each newly
1050    created thread.  This function sets the form which is used to produce
1051    the initial value."
1052      (set var (eval form)))
1053    
1054    ;; List of delayed interrupts.
1055    ;; This should only have thread-local bindings, so no init form.
1056    (defvar *pending-slime-interrupts*)
1057    
1058    (defun check-slime-interrupts ()
1059      "Execute pending interrupts if any.
1060    This should be called periodically in operations which
1061    can take a long time to complete.
1062    Return a boolean indicating whether any interrupts was processed."
1063      (when (and (boundp '*pending-slime-interrupts*)
1064                 *pending-slime-interrupts*)
1065        (funcall (pop *pending-slime-interrupts*))
1066        t))
1067    
1068    (defvar *interrupt-queued-handler* nil
1069      "Function to call on queued interrupts.
1070    Interrupts get queued when an interrupt occurs while interrupt
1071    handling is disabled.
1072    
1073    Backends can use this function to abort slow operations.")
1074    
1075    (definterface wait-for-input (streams &optional timeout)
1076      "Wait for input on a list of streams.  Return those that are ready.
1077    STREAMS is a list of streams
1078    TIMEOUT nil, t, or real number. If TIMEOUT is t, return
1079    those streams which are ready immediately, without waiting.
1080    If TIMEOUT is a number and no streams is ready after TIMEOUT seconds,
1081    return nil.
1082    
1083    Return :interrupt if an interrupt occurs while waiting."
1084      (assert (member timeout '(nil t)))
1085      (cond #+(or)
1086            ((null (cdr streams))
1087             (wait-for-one-stream (car streams) timeout))
1088            (t
1089             (wait-for-streams streams timeout))))
1090    
1091    (defun wait-for-streams (streams timeout)
1092      (loop
1093       (when (check-slime-interrupts) (return :interrupt))
1094       (let ((ready (remove-if-not #'stream-readable-p streams)))
1095         (when ready (return ready)))
1096       (when timeout (return nil))
1097       (sleep 0.1)))
1098    
1099    ;; Note: Usually we can't interrupt PEEK-CHAR cleanly.
1100    (defun wait-for-one-stream (stream timeout)
1101      (ecase timeout
1102        ((nil)
1103         (cond ((check-slime-interrupts) :interrupt)
1104               (t (peek-char nil stream nil nil)
1105                  (list stream))))
1106        ((t)
1107         (let ((c (read-char-no-hang stream nil nil)))
1108           (cond (c
1109                  (unread-char c stream)
1110                  (list stream))
1111                 (t '()))))))
1112    
1113    (defun stream-readable-p (stream)
1114      (let ((c (read-char-no-hang stream nil :eof)))
1115        (cond ((not c) nil)
1116              ((eq c :eof) t)
1117              (t (unread-char c stream) t))))
1118    
1119  (definterface toggle-trace (spec)  (definterface toggle-trace (spec)
1120    "Toggle tracing of the function(s) given with SPEC.    "Toggle tracing of the function(s) given with SPEC.
# Line 873  SPEC can be: Line 1136  SPEC can be:
1136  (definterface make-weak-value-hash-table (&rest args)  (definterface make-weak-value-hash-table (&rest args)
1137    "Like MAKE-HASH-TABLE, but weak w.r.t. the values."    "Like MAKE-HASH-TABLE, but weak w.r.t. the values."
1138    (apply #'make-hash-table args))    (apply #'make-hash-table args))
1139    
1140    (definterface hash-table-weakness (hashtable)
1141      "Return nil or one of :key :value :key-or-value :key-and-value"
1142      (declare (ignore hashtable))
1143      nil)
1144    
1145    
1146    ;;;; Character names
1147    
1148    (definterface character-completion-set (prefix matchp)
1149      "Return a list of names of characters that match PREFIX."
1150      ;; Handle the standard and semi-standard characters.
1151      (loop for name in '("Newline" "Space" "Tab" "Page" "Rubout"
1152                          "Linefeed" "Return" "Backspace")
1153         when (funcall matchp prefix name)
1154         collect name))
1155    
1156    
1157    (defparameter *type-specifier-arglists*
1158      '((and                . (&rest type-specifiers))
1159        (array              . (&optional element-type dimension-spec))
1160        (base-string        . (&optional size))
1161        (bit-vector         . (&optional size))
1162        (complex            . (&optional type-specifier))
1163        (cons               . (&optional car-typespec cdr-typespec))
1164        (double-float       . (&optional lower-limit upper-limit))
1165        (eql                . (object))
1166        (float              . (&optional lower-limit upper-limit))
1167        (function           . (&optional arg-typespec value-typespec))
1168        (integer            . (&optional lower-limit upper-limit))
1169        (long-float         . (&optional lower-limit upper-limit))
1170        (member             . (&rest eql-objects))
1171        (mod                . (n))
1172        (not                . (type-specifier))
1173        (or                 . (&rest type-specifiers))
1174        (rational           . (&optional lower-limit upper-limit))
1175        (real               . (&optional lower-limit upper-limit))
1176        (satisfies          . (predicate-symbol))
1177        (short-float        . (&optional lower-limit upper-limit))
1178        (signed-byte        . (&optional size))
1179        (simple-array       . (&optional element-type dimension-spec))
1180        (simple-base-string . (&optional size))
1181        (simple-bit-vector  . (&optional size))
1182        (simple-string      . (&optional size))
1183        (single-float       . (&optional lower-limit upper-limit))
1184        (simple-vector      . (&optional size))
1185        (string             . (&optional size))
1186        (unsigned-byte      . (&optional size))
1187        (values             . (&rest typespecs))
1188        (vector             . (&optional element-type size))
1189        ))
1190    
1191    ;;; Heap dumps
1192    
1193    (definterface save-image (filename &optional restart-function)
1194      "Save a heap image to the file FILENAME.
1195    RESTART-FUNCTION, if non-nil, should be called when the image is loaded.")
1196    
1197    
1198    

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

  ViewVC Help
Powered by ViewVC 1.1.5