/[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.173 by trittweiler, Sun Feb 22 14:18:47 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 421  NIL." Line 581  NIL."
581                     (values new-form expanded)))))                     (values new-form expanded)))))
582      (frob form env)))      (frob form env)))
583    
584    (definterface format-string-expand (control-string)
585      "Expand the format string CONTROL-STRING."
586      (macroexpand `(formatter ,control-string)))
587    
588  (definterface describe-symbol-for-emacs (symbol)  (definterface describe-symbol-for-emacs (symbol)
589     "Return a property list describing SYMBOL.     "Return a property list describing SYMBOL.
590    
# Line 492  debug the debugger! Instead, such condit Line 656  debug the debugger! Instead, such condit
656  user without (re)entering the debugger by wrapping them as  user without (re)entering the debugger by wrapping them as
657  `sldb-condition's."))  `sldb-condition's."))
658    
659    ;;; The following functions in this section are supposed to be called
660    ;;; within the dynamic contour of CALL-WITH-DEBUGGING-ENVIRONMENT only.
661    
662  (definterface compute-backtrace (start end)  (definterface compute-backtrace (start end)
663     "Return a list containing a backtrace of the condition current     "Returns a backtrace of the condition currently being debugged,
664  being debugged.  The results are unspecified if this function is  that is an ordered list consisting of frames. ``Ordered list''
665  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
666    backtrace.
667    
668  START and END are zero-based indices constraining the number of frames  START and END are zero-based indices constraining the number of frames
669  returned.  Frame zero is defined as the frame which invoked the  returned. Frame zero is defined as the frame which invoked the
670  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
671  the stack.")  the stack.")
672    
673  (definterface print-frame (frame stream)  (definterface print-frame (frame stream)
674    "Print frame to stream.")    "Print frame to stream.")
675    
676    (definterface frame-restartable-p (frame)
677      "Is the frame FRAME restartable?.
678    Return T if `restart-frame' can safely be called on the frame."
679      (declare (ignore frame))
680      nil)
681    
682  (definterface frame-source-location-for-emacs (frame-number)  (definterface frame-source-location-for-emacs (frame-number)
683    "Return the source location for FRAME-NUMBER.")    "Return the source location for the frame associated to FRAME-NUMBER.")
684    
685  (definterface frame-catch-tags (frame-number)  (definterface frame-catch-tags (frame-number)
686    "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
687  stack frame.  The results are undefined unless this is called  frame."
688  within the dynamic contour of a function defined by    (declare (ignore frame-number))
689  DEFINE-DEBUGGER-HOOK.")    '())
690    
691  (definterface frame-locals (frame-number)  (definterface frame-locals (frame-number)
692    "Return a list of XXX local variable designators define me    "Return a list of ((&key NAME ID VALUE) ...) where each element of
693  for a debugger stack frame.  The results are undefined unless  the list represents a local variable in the stack frame associated to
694  this is called within the dynamic contour of a function defined  FRAME-NUMBER.
695  by DEFINE-DEBUGGER-HOOK.")  
696    NAME, a symbol; the name of the local variable.
697  (definterface frame-var-value (frame var)  
698    "Return the value of VAR in FRAME.  ID, an integer; used as primary key for the local variable, unique
699  FRAME is the number of the frame in the backtrace.  relatively to the frame under operation.
700  VAR is the number of the variable in the frame.")  
701    value, an object; the value of the local variable.")
702    
703    (definterface frame-var-value (frame-number var-id)
704      "Return the value of the local variable associated to VAR-ID
705    relatively to the frame associated to FRAME-NUMBER.")
706    
707  (definterface disassemble-frame (frame-number)  (definterface disassemble-frame (frame-number)
708    "Disassemble the code for the FRAME-NUMBER.    "Disassemble the code for the FRAME-NUMBER.
# Line 532  FRAME-NUMBER is a non-negative integer." Line 711  FRAME-NUMBER is a non-negative integer."
711    
712  (definterface eval-in-frame (form frame-number)  (definterface eval-in-frame (form frame-number)
713     "Evaluate a Lisp form in the lexical context of a stack frame     "Evaluate a Lisp form in the lexical context of a stack frame
714  in the debugger.  The results are undefined unless called in the  in the debugger.
 dynamic contour of a function defined by DEFINE-DEBUGGER-HOOK.  
715    
716  FRAME-NUMBER must be a positive integer with 0 indicating the  FRAME-NUMBER must be a positive integer with 0 indicating the
717  frame which invoked the debugger.  frame which invoked the debugger.
# Line 559  as it was called originally.") Line 737  as it was called originally.")
737    "Format a condition for display in SLDB."    "Format a condition for display in SLDB."
738    (princ-to-string condition))    (princ-to-string condition))
739    
 (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))  
   '())  
   
740  (definterface condition-extras (condition)  (definterface condition-extras (condition)
741    "Return a list of extra for the debugger.    "Return a list of extra for the debugger.
742  The allowed elements are of the form:  The allowed elements are of the form:
743    (:SHOW-FRAME-SOURCE frame-number)"    (:SHOW-FRAME-SOURCE frame-number)
744      (:REFERENCES &rest refs)
745    "
746    (declare (ignore condition))    (declare (ignore condition))
747    '())    '())
748    
# Line 585  The allowed elements are of the form: Line 755  The allowed elements are of the form:
755  (definterface sldb-break-at-start (symbol)  (definterface sldb-break-at-start (symbol)
756    "Set a breakpoint on the beginning of the function for SYMBOL.")    "Set a breakpoint on the beginning of the function for SYMBOL.")
757    
758    (definterface sldb-stepper-condition-p (condition)
759      "Return true if SLDB was invoked due to a single-stepping condition,
760    false otherwise. "
761      (declare (ignore condition))
762      nil)
763    
764    (definterface sldb-step-into ()
765      "Step into the current single-stepper form.")
766    
767    (definterface sldb-step-next ()
768      "Step to the next form in the current function.")
769    
770    (definterface sldb-step-out ()
771      "Stop single-stepping temporarily, but resume it once the current function
772    returns.")
773    
774    
775  ;;;; Definition finding  ;;;; Definition finding
# Line 615  definition, e.g., FOO or (METHOD FOO (ST Line 800  definition, e.g., FOO or (METHOD FOO (ST
800    
801  LOCATION is the source location for the definition.")  LOCATION is the source location for the definition.")
802    
803    (definterface find-source-location (object)
804      "Returns the source location of OBJECT, or NIL.
805    
806    That is the source location of the underlying datastructure of
807    OBJECT. E.g. on a STANDARD-OBJECT, the source location of the
808    respective DEFCLASS definition is returned, on a STRUCTURE-CLASS the
809    respective DEFSTRUCT definition, and so on."
810      ;; This returns one source location and not a list of locations. It's
811      ;; supposed to return the location of the DEFGENERIC definition on
812      ;; #'SOME-GENERIC-FUNCTION.
813      )
814    
815    
816  (definterface buffer-first-change (filename)  (definterface buffer-first-change (filename)
817    "Called for effect the first time FILENAME's buffer is modified."    "Called for effect the first time FILENAME's buffer is modified."
818    (declare (ignore filename))    (declare (ignore filename))
819    nil)    nil)
820    
821    
822    
823  ;;;; XREF  ;;;; XREF
824    
# Line 706  themselves, that is, their dispatch func Line 905  themselves, that is, their dispatch func
905    
906  ;;;; Inspector  ;;;; Inspector
907    
908  (defclass inspector ()  (defgeneric emacs-inspect (object)
909    ()    (: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)  
910     "Explain to Emacs how to inspect OBJECT.     "Explain to Emacs how to inspect OBJECT.
911    
912  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.  
913    
914  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
915  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 920  inserted into the buffer as is, or a lis
920    
921   (:newline) - Render a \\n   (:newline) - Render a \\n
922    
923   (:action label lambda) - Render LABEL (a text string) which when   (:action label lambda &key (refresh t)) - Render LABEL (a text
924   clicked will call LAMBDA.   string) which when clicked will call LAMBDA. If REFRESH is
925     non-NIL the currently inspected object will be re-inspected
926   NIL - do nothing.")   after calling the lambda.
927    "))
928    
929  (defmethod inspect-for-emacs ((object t) (inspector t))  (defmethod emacs-inspect ((object t))
930    "Generic method for inspecting any kind of object.    "Generic method for inspecting any kind of object.
931    
932  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
933  output of CL:DESCRIBE."  output of CL:DESCRIBE."
   (declare (ignore inspector))  
   (values  
    "A value."  
934     `("Type: " (:value ,(type-of object)) (:newline)     `("Type: " (:value ,(type-of object)) (:newline)
935       "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:"
936       (:newline) (:newline)       (:newline) (:newline)
937       ,(with-output-to-string (desc) (describe object desc)))))       ,(with-output-to-string (desc) (describe object desc))))
938    
939  ;;; Utilities for inspector methods.  ;;; Utilities for inspector methods.
940  ;;;  ;;;
941  (defun label-value-line (label value)  (defun label-value-line (label value &key (newline t))
942    "Create a control list which prints \"LABEL: VALUE\" in the inspector."    "Create a control list which prints \"LABEL: VALUE\" in the inspector.
943    (list (princ-to-string label) ": " `(:value ,value) '(:newline)))  If NEWLINE is non-NIL a `(:newline)' is added to the result."
944      (list* (princ-to-string label) ": " `(:value ,value)
945             (if newline '((:newline)) nil)))
946    
947  (defmacro label-value-line* (&rest label-values)  (defmacro label-value-line* (&rest label-values)
948    ` (append ,@(loop for (label value) in label-values    ` (append ,@(loop for (label value) in label-values
# Line 778  output of CL:DESCRIBE." Line 959  output of CL:DESCRIBE."
959  ;;; The default implementations are sufficient for non-multiprocessing  ;;; The default implementations are sufficient for non-multiprocessing
960  ;;; implementations.  ;;; implementations.
961    
962  (definterface initialize-multiprocessing ()  (definterface initialize-multiprocessing (continuation)
963     "Initialize multiprocessing, if necessary."     "Initialize multiprocessing, if necessary and then invoke CONTINUATION.
    nil)  
964    
965  (definterface startup-idle-and-top-level-loops ()  Depending on the impleimentaion, this function may never return."
966    "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)  
967    
968  (definterface spawn (fn &key name)  (definterface spawn (fn &key name)
969    "Create a new thread to call FN.")    "Create a new thread to call FN.")
# Line 796  normal function." Line 972  normal function."
972    "Return an Emacs-parsable object to identify THREAD.    "Return an Emacs-parsable object to identify THREAD.
973    
974  Ids should be comparable with equal, i.e.:  Ids should be comparable with equal, i.e.:
975   (equal (thread-id <t1>) (thread-id <t2>)) <==> (eq <t1> <t2>)")   (equal (thread-id <t1>) (thread-id <t2>)) <==> (eq <t1> <t2>)"
976      thread)
977    
978  (definterface find-thread (id)  (definterface find-thread (id)
979    "Return the thread for ID.    "Return the thread for ID.
980  ID should be an id previously obtained with THREAD-ID.  ID should be an id previously obtained with THREAD-ID.
981  Can return nil if the thread no longer exists.")  Can return nil if the thread no longer exists."
982      (declare (ignore id))
983      (current-thread))
984    
985  (definterface thread-name (thread)  (definterface thread-name (thread)
986     "Return the name of THREAD.     "Return the name of THREAD.
# Line 816  user. They do not have to be unique." Line 995  user. They do not have to be unique."
995     (declare (ignore thread))     (declare (ignore thread))
996     "")     "")
997    
998    (definterface thread-description (thread)
999      "Return a string describing THREAD."
1000      (declare (ignore thread))
1001      "")
1002    
1003    (definterface set-thread-description (thread description)
1004      "Set THREAD's description to DESCRIPTION."
1005      (declare (ignore thread description))
1006      "")
1007    
1008  (definterface make-lock (&key name)  (definterface make-lock (&key name)
1009     "Make a lock for thread synchronization.     "Make a lock for thread synchronization.
1010  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
1011    but that thread may hold it more than once."
1012     (declare (ignore name))     (declare (ignore name))
1013     :null-lock)     :null-lock)
1014    
# Line 833  Only one thread may hold the lock (via C Line 1023  Only one thread may hold the lock (via C
1023    0)    0)
1024    
1025  (definterface all-threads ()  (definterface all-threads ()
1026    "Return a list of all threads.")    "Return a fresh list of all threads.")
1027    
1028  (definterface thread-alive-p (thread)  (definterface thread-alive-p (thread)
1029    "Test if THREAD is termintated."    "Test if THREAD is termintated."
# Line 850  Only one thread may hold the lock (via C Line 1040  Only one thread may hold the lock (via C
1040  (definterface send (thread object)  (definterface send (thread object)
1041    "Send OBJECT to thread THREAD.")    "Send OBJECT to thread THREAD.")
1042    
1043  (definterface receive ()  (definterface receive (&optional timeout)
1044    "Return the next message from current thread's mailbox.")    "Return the next message from current thread's mailbox."
1045      (receive-if (constantly t) timeout))
1046    
1047    (definterface receive-if (predicate &optional timeout)
1048      "Return the first message satisfiying PREDICATE.")
1049    
1050    (definterface set-default-initial-binding (var form)
1051      "Initialize special variable VAR by default with FORM.
1052    
1053    Some implementations initialize certain variables in each newly
1054    created thread.  This function sets the form which is used to produce
1055    the initial value."
1056      (set var (eval form)))
1057    
1058    ;; List of delayed interrupts.
1059    ;; This should only have thread-local bindings, so no init form.
1060    (defvar *pending-slime-interrupts*)
1061    
1062    (defun check-slime-interrupts ()
1063      "Execute pending interrupts if any.
1064    This should be called periodically in operations which
1065    can take a long time to complete.
1066    Return a boolean indicating whether any interrupts was processed."
1067      (when (and (boundp '*pending-slime-interrupts*)
1068                 *pending-slime-interrupts*)
1069        (funcall (pop *pending-slime-interrupts*))
1070        t))
1071    
1072    (defvar *interrupt-queued-handler* nil
1073      "Function to call on queued interrupts.
1074    Interrupts get queued when an interrupt occurs while interrupt
1075    handling is disabled.
1076    
1077    Backends can use this function to abort slow operations.")
1078    
1079    (definterface wait-for-input (streams &optional timeout)
1080      "Wait for input on a list of streams.  Return those that are ready.
1081    STREAMS is a list of streams
1082    TIMEOUT nil, t, or real number. If TIMEOUT is t, return
1083    those streams which are ready immediately, without waiting.
1084    If TIMEOUT is a number and no streams is ready after TIMEOUT seconds,
1085    return nil.
1086    
1087    Return :interrupt if an interrupt occurs while waiting."
1088      (assert (member timeout '(nil t)))
1089      (cond #+(or)
1090            ((null (cdr streams))
1091             (wait-for-one-stream (car streams) timeout))
1092            (t
1093             (wait-for-streams streams timeout))))
1094    
1095    (defun wait-for-streams (streams timeout)
1096      (loop
1097       (when (check-slime-interrupts) (return :interrupt))
1098       (let ((ready (remove-if-not #'stream-readable-p streams)))
1099         (when ready (return ready)))
1100       (when timeout (return nil))
1101       (sleep 0.1)))
1102    
1103    ;; Note: Usually we can't interrupt PEEK-CHAR cleanly.
1104    (defun wait-for-one-stream (stream timeout)
1105      (ecase timeout
1106        ((nil)
1107         (cond ((check-slime-interrupts) :interrupt)
1108               (t (peek-char nil stream nil nil)
1109                  (list stream))))
1110        ((t)
1111         (let ((c (read-char-no-hang stream nil nil)))
1112           (cond (c
1113                  (unread-char c stream)
1114                  (list stream))
1115                 (t '()))))))
1116    
1117    (defun stream-readable-p (stream)
1118      (let ((c (read-char-no-hang stream nil :eof)))
1119        (cond ((not c) nil)
1120              ((eq c :eof) t)
1121              (t (unread-char c stream) t))))
1122    
1123  (definterface toggle-trace (spec)  (definterface toggle-trace (spec)
1124    "Toggle tracing of the function(s) given with SPEC.    "Toggle tracing of the function(s) given with SPEC.
# Line 873  SPEC can be: Line 1140  SPEC can be:
1140  (definterface make-weak-value-hash-table (&rest args)  (definterface make-weak-value-hash-table (&rest args)
1141    "Like MAKE-HASH-TABLE, but weak w.r.t. the values."    "Like MAKE-HASH-TABLE, but weak w.r.t. the values."
1142    (apply #'make-hash-table args))    (apply #'make-hash-table args))
1143    
1144    (definterface hash-table-weakness (hashtable)
1145      "Return nil or one of :key :value :key-or-value :key-and-value"
1146      (declare (ignore hashtable))
1147      nil)
1148    
1149    
1150    ;;;; Character names
1151    
1152    (definterface character-completion-set (prefix matchp)
1153      "Return a list of names of characters that match PREFIX."
1154      ;; Handle the standard and semi-standard characters.
1155      (loop for name in '("Newline" "Space" "Tab" "Page" "Rubout"
1156                          "Linefeed" "Return" "Backspace")
1157         when (funcall matchp prefix name)
1158         collect name))
1159    
1160    
1161    (defparameter *type-specifier-arglists*
1162      '((and                . (&rest type-specifiers))
1163        (array              . (&optional element-type dimension-spec))
1164        (base-string        . (&optional size))
1165        (bit-vector         . (&optional size))
1166        (complex            . (&optional type-specifier))
1167        (cons               . (&optional car-typespec cdr-typespec))
1168        (double-float       . (&optional lower-limit upper-limit))
1169        (eql                . (object))
1170        (float              . (&optional lower-limit upper-limit))
1171        (function           . (&optional arg-typespec value-typespec))
1172        (integer            . (&optional lower-limit upper-limit))
1173        (long-float         . (&optional lower-limit upper-limit))
1174        (member             . (&rest eql-objects))
1175        (mod                . (n))
1176        (not                . (type-specifier))
1177        (or                 . (&rest type-specifiers))
1178        (rational           . (&optional lower-limit upper-limit))
1179        (real               . (&optional lower-limit upper-limit))
1180        (satisfies          . (predicate-symbol))
1181        (short-float        . (&optional lower-limit upper-limit))
1182        (signed-byte        . (&optional size))
1183        (simple-array       . (&optional element-type dimension-spec))
1184        (simple-base-string . (&optional size))
1185        (simple-bit-vector  . (&optional size))
1186        (simple-string      . (&optional size))
1187        (single-float       . (&optional lower-limit upper-limit))
1188        (simple-vector      . (&optional size))
1189        (string             . (&optional size))
1190        (unsigned-byte      . (&optional size))
1191        (values             . (&rest typespecs))
1192        (vector             . (&optional element-type size))
1193        ))
1194    
1195    ;;; Heap dumps
1196    
1197    (definterface save-image (filename &optional restart-function)
1198      "Save a heap image to the file FILENAME.
1199    RESTART-FUNCTION, if non-nil, should be called when the image is loaded.")
1200    
1201    
1202    

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

  ViewVC Help
Powered by ViewVC 1.1.5